Skip to content

Add a pre-commit linter hook#1624

Merged
Neon-White merged 1 commit intonoobaa:masterfrom
Neon-White:add-precommit-linter
Jul 14, 2025
Merged

Add a pre-commit linter hook#1624
Neon-White merged 1 commit intonoobaa:masterfrom
Neon-White:add-precommit-linter

Conversation

@Neon-White
Copy link
Contributor

@Neon-White Neon-White commented Jun 6, 2025

Explain the changes

  1. Enforce pre-commit hooks for all contributors by using a shared .githooks directory and configuring core.hooksPath automatically upon calls to most make <target> runs (in order to ensure consistency across devs and envs)
  2. Added an install-hooks Makefile target that sets the Git hooks path to .githooks only if not already set, and only if the repository is a Git repo.
  3. Made install-hooks a dependency of the gen target, ensuring hooks are installed for both containerized and non-containerized workflows.
  4. Improved Makefile logic to avoid unnecessary output if the hooks path is already set.

Testing Instructions:

  1. Clone the repository
  2. Run go mod vendor to make sure golangci-lint is installed with the right version and in the right path
  3. Run any standard Makefile target (e.g., make gen, make build, make all).
  4. Verify that .githooks is set as the hooks path (git config core.hooksPath should output .githooks).
  5. Attempt a commit (e.g. with an unused variable) and confirm that the pre-commit hook runs as expected.
  6. Run make gen and confirm there are no prints related to git hooks in the console.

Alternatively, after cloning the repo, cd into the repo's root and run git config core.hooksPath .githooks.
Then, follow the instructions from step 3 onwards.

Summary by CodeRabbit

  • Chores
    • Added a Git pre-commit hook to run linting checks on staged Go files before committing.
    • Updated the build process to automatically configure Git hooks path for consistent linting enforcement.

@Neon-White Neon-White changed the title Add a pre-commit linter hook Add a pre-commit DCO and linter hook Jun 6, 2025
@Neon-White Neon-White force-pushed the add-precommit-linter branch 2 times, most recently from 6ca0e54 to ee42d57 Compare June 6, 2025 11:03
@Neon-White Neon-White changed the title Add a pre-commit DCO and linter hook Add a pre-commit linter hook Jun 6, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jun 11, 2025

"""

Walkthrough

A new Git pre-commit hook script is added to run golangci-lint on staged Go files before each commit. The Makefile is updated to set up this hook automatically by configuring Git's hooks path to .githooks. No codebase logic or exported entities are changed.

Changes

Files/Paths Change Summary
.githooks/pre-commit Added a pre-commit hook script to lint staged Go files before commit using golangci-lint.
Makefile Added install-hooks target to configure Git hooks path to .githooks; updated gen target to depend on it.

Poem

In the burrow, code must shine,
Linting checks before commit time.
Hooks now guard the warren door,
Ensuring Go code’s never poor.
Makefile magic sets the scene,
For the cleanest code you’ve ever seen!
🐇✨
"""


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 83d6b8b and e008adc.

📒 Files selected for processing (2)
  • .githooks/pre-commit (1 hunks)
  • Makefile (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • .githooks/pre-commit
  • Makefile
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: run-operator-tests
  • GitHub Check: cnpg-deployment-test
  • GitHub Check: run-kms-key-rotate-test
  • GitHub Check: run-azure-vault-test
  • GitHub Check: run-kms-tls-sa-test
  • GitHub Check: run-kms-kmip-test
  • GitHub Check: run-cli-tests
  • GitHub Check: run-hac-test
  • GitHub Check: run-admission-test

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (2)
.golangci.yml (1)

8-9: Restore trailing newline to satisfy linters

The removal of the final newline triggers YAMLlint error new-line-at-end-of-file, and some editors re-add it automatically, causing noisy diffs.

-    - zz_generated\.go
+    - zz_generated\.go\n
🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 9-9: no new line character at the end of file

(new-line-at-end-of-file)

.githooks/pre-commit (1)

4-10: STAGED_FILES variable is built but never used

You collect the staged file list only to test for emptiness, then ignore it when invoking the linter. Either:

  1. Drop the unused pipeline and simply test via git diff --cached --quiet --diff-filter=ACMR -- '*.go'
  2. Or pass the file list to golangci-lint run --path-prefix / --files, which speeds up execution on large repos.

Cleaning this up avoids needless subshells.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8e707ef and 1950ff6.

📒 Files selected for processing (4)
  • .githooks/pre-commit (1 hunks)
  • .golangci.yml (1 hunks)
  • Makefile (3 hunks)
  • go.mod (1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.37.1)
.golangci.yml

[error] 9-9: no new line character at the end of file

(new-line-at-end-of-file)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: run-kms-key-rotate-test
  • GitHub Check: cnpg-deployment-test
  • GitHub Check: run-core-config-map-tests
  • GitHub Check: run-operator-tests
🔇 Additional comments (1)
Makefile (1)

326-333: Nice touch: idempotent Git hooks installation

The install-hooks recipe correctly checks for .git and an existing core.hooksPath, avoiding noisy output. 👍

@Neon-White Neon-White force-pushed the add-precommit-linter branch from c1f4507 to 10af05c Compare June 11, 2025 14:51
@Neon-White Neon-White force-pushed the add-precommit-linter branch 2 times, most recently from ffeeef2 to 9397c1d Compare July 7, 2025 15:11
Copy link
Member

@aayushchouhan09 aayushchouhan09 left a comment

Choose a reason for hiding this comment

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

LGTM

@Neon-White Neon-White force-pushed the add-precommit-linter branch 2 times, most recently from f85f9fd to 83d6b8b Compare July 14, 2025 07:10
Signed-off-by: Ben <belimele@redhat.com>
@Neon-White Neon-White force-pushed the add-precommit-linter branch from 83d6b8b to e008adc Compare July 14, 2025 10:10
@Neon-White Neon-White merged commit 0baa57e into noobaa:master Jul 14, 2025
16 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Jul 15, 2025
@coderabbitai coderabbitai bot mentioned this pull request Dec 3, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants