From fd098abe15e1ccb5132f1901b68411a04796a4e0 Mon Sep 17 00:00:00 2001 From: Isaac Heist Date: Fri, 2 Feb 2024 08:45:18 -0800 Subject: [PATCH] feat: show versions of configured hooks for repo (#419) secureli-175 When running `secureli --version` will display the versions of all the pre-commit hooks installed ## Changes ![image](https://github.com/slalombuild/secureli/assets/127901972/f6279aa8-2863-40ba-84e5-f9a1bdddfc96) * Display list versions of versions of pre-commit hooks installed when running `secureli --version` * Added launch.json setting file to debug in vscode ## Testing * All existing unit tests are passing ## Clean Code Checklist - [x] Meets acceptance criteria for issue - [ ] New logic is covered with automated tests - [ ] Appropriate exception handling added - [ ] Thoughtful logging included - [ ] Documentation is updated - [ ] Follow-up work is documented in TODOs - [ ] TODOs have a ticket associated with them - [x] No commented-out code included --- .vscode/launch.json | 60 +++++++++++++++++++++++++++++++++++++++++++ .vscode/settings.json | 5 ++++ secureli/main.py | 15 +++++++++++ 3 files changed, 80 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..06863c0b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,60 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Python: secureli --version", + "type": "python", + "request": "launch", + "program": "${workspaceFolder}/secureli/main.py", + "cwd": "${workspaceFolder}", + "stopOnEntry": false, + "console": "integratedTerminal", + "justMyCode": true, + "args": ["--version"] + }, + { + "name": "Python: secureli --help", + "type": "python", + "request": "launch", + "program": "${workspaceFolder}/secureli/main.py", + "cwd": "${workspaceFolder}", + "stopOnEntry": false, + "console": "integratedTerminal", + "justMyCode": true, + "args": ["--help"] + }, + { + "name": "Python: secureli init", + "type": "python", + "request": "launch", + "program": "${workspaceFolder}/secureli/main.py", + "cwd": "${workspaceFolder}", + "stopOnEntry": false, + "console": "integratedTerminal", + "justMyCode": true, + "args": ["init"] + }, + { + "name": "Python: secureli scan", + "type": "python", + "request": "launch", + "program": "${workspaceFolder}/secureli/main.py", + "cwd": "${workspaceFolder}", + "stopOnEntry": false, + "console": "integratedTerminal", + "justMyCode": true, + "args": ["scan"] + }, + { + "name": "Python: secureli update", + "type": "python", + "request": "launch", + "program": "${workspaceFolder}/secureli/main.py", + "cwd": "${workspaceFolder}", + "stopOnEntry": false, + "console": "integratedTerminal", + "justMyCode": true, + "args": ["update"] + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..e400bd34 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "python.testing.pytestArgs": ["tests"], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true +} diff --git a/secureli/main.py b/secureli/main.py index 971d76d1..289b8940 100644 --- a/secureli/main.py +++ b/secureli/main.py @@ -28,6 +28,21 @@ def version_callback(value: bool): if value: typer.echo(secureli_version()) + typer.echo("\nHook Versions:") + typer.echo("--------------") + config = container.pre_commit_abstraction().get_pre_commit_config(Path(".")) + + all_repos = [ + (hook.id, repo.rev.lstrip("v")) + for repo in config.repos + for hook in repo.hooks + ] + + sorted_repos = sorted(all_repos, key=lambda x: x[0]) + + for hook_id, version in sorted_repos: + typer.echo(f"{hook_id:<30} {version}") + raise typer.Exit()