Skip to content

Add githooks to auto format, lint and test - #911

Open
ChrisSchneider wants to merge 5 commits into
open-component-model:masterfrom
ChrisSchneider:add-githooks-format-lint-test
Open

Add githooks to auto format, lint and test#911
ChrisSchneider wants to merge 5 commits into
open-component-model:masterfrom
ChrisSchneider:add-githooks-format-lint-test

Conversation

@ChrisSchneider

@ChrisSchneider ChrisSchneider commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

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

Signed-off-by: Chris Schneider <chris.schneider02@sap.com>
@ChrisSchneider
ChrisSchneider requested a review from a team as a code owner August 11, 2026 20:38
@github-project-automation github-project-automation Bot moved this to 🔦 Needs Triage in Open Delivery Gear Aug 11, 2026
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@ChrisSchneider, you've reached your PR review limit, so we couldn't start this review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 33476626-5339-4911-8615-eab0a22ece66

📥 Commits

Reviewing files that changed from the base of the PR and between f6b3e58 and d6c0a68.

📒 Files selected for processing (2)
  • .githooks/pre-commit
  • .githooks/pre-push
📝 Walkthrough

Walkthrough

The pull request adds Git hooks for staged-file formatting, linting, and testing. The setup target configures Git to use the .githooks directory.

Changes

Repository validation workflow

Layer / File(s) Summary
Validation hook scripts
.githooks/pre-commit, .githooks/pre-push
The pre-commit hook formats and fixes staged Python files with Ruff. The pre-push hook runs linting and tests with fail-fast behavior.
Hook path setup
Makefile
The setup target configures Git to use .githooks for repository hooks.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: 8r0wni3

Poem

A rabbit checks each staged file,
Then hops through lint and tests in style.
Ruff tidies every line,
Git hooks guard the commit sign.
Setup points the path just right—
Clean checks before takeoff night.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the main changes and related issue but omits the special notes, checklist, and release note sections. Add the required Special notes section, complete the applicable checklist items, and provide a release note or state NONE.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the addition of Git hooks for formatting, linting, and testing.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7c73104 and f6b3e58.

📒 Files selected for processing (3)
  • .githooks/pre-commit
  • .githooks/pre-push
  • Makefile

Comment thread .githooks/pre-commit Outdated
Comment thread .githooks/pre-commit Outdated
Comment thread .githooks/pre-commit
echo "pre-commit: applying ruff format..."
ruff format "$ROOT"

echo "pre-commit: running ruff lint (auto-fix)..."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about the bandit linter?

@ChrisSchneider ChrisSchneider Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bandit would run pre-push, pre-commit just auto formats/lints code

Comment thread .githooks/pre-push Outdated
"$ROOT/.ci/lint"

echo "pre-push: running tests..."
"$ROOT/.ci/test" No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use the available make commands instead and also include make format?

Also (nit), please add empty lines to the newly introduced files 🙃

@ChrisSchneider ChrisSchneider Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to replicate the CI setup, so that it runs the same checks as the CI pipeline pre-push

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🔦 Needs Triage

Development

Successfully merging this pull request may close these issues.

Improve Onboarding / Local Setup

3 participants