Add githooks to auto format, lint and test - #911
Conversation
Signed-off-by: Chris Schneider <chris.schneider02@sap.com>
|
Warning Review limit reached
Next review available in: 26 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe pull request adds Git hooks for staged-file formatting, linting, and testing. The ChangesRepository validation workflow
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.githooks/pre-commit:
- Around line 7-19: Update the pre-commit hook’s staged-file handling to use a
NUL-safe array that includes added, copied, modified, and renamed Python files;
reject any selected file with unstaged changes before running Ruff. Pass the
array to both `ruff format` and `ruff check --fix`, and always re-stage modified
files with `git add -- "${STAGED[@]}"`, including when linting reports remaining
violations.
- Around line 15-19: Update the pre-commit hook around ruff execution to declare
STAGED as an array and consistently use "${STAGED[@]}" for path handling.
Capture the exit status from "ruff check --fix" without allowing set -e to skip
subsequent commands, stage the selected files, then exit with the captured Ruff
status.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 49e6c01a-1242-4bc9-ac76-c45d737ce40b
📒 Files selected for processing (3)
.githooks/pre-commit.githooks/pre-pushMakefile
| echo "pre-commit: applying ruff format..." | ||
| ruff format "$ROOT" | ||
|
|
||
| echo "pre-commit: running ruff lint (auto-fix)..." |
There was a problem hiding this comment.
Bandit would run pre-push, pre-commit just auto formats/lints code
| "$ROOT/.ci/lint" | ||
|
|
||
| echo "pre-push: running tests..." | ||
| "$ROOT/.ci/test" No newline at end of file |
There was a problem hiding this comment.
Should we use the available make commands instead and also include make format?
Also (nit), please add empty lines to the newly introduced files 🙃
There was a problem hiding this comment.
I tried to replicate the CI setup, so that it runs the same checks as the CI pipeline pre-push
…o add-githooks-format-lint-test
Signed-off-by: Chris Schneider <chris.schneider02@sap.com>
…risSchneider/odg-core into add-githooks-format-lint-test
What this PR does / why we need it:
Adds .githooks/pre-commit (ruff format + lint with auto-fix) and .githooks/pre-push (ruff, bandit, and pytest via existing .ci/ scripts) to enforce code quality locally before changes reach the remote. make setup is updated to configure core.hooksPath so the hooks are automatically active after a fresh clone.
Which issue(s) this PR fixes:
Fixes open-component-model/open-delivery-gear#223