NO-JIRA: Add gitlint to pre-commit hooks - #8701
Conversation
Add run-gitlint hook to the pre-commit stage so commit message format is validated on every commit. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Pipeline controller notification For optional jobs, comment This repository is configured in: LGTM mode |
|
@bryan-cox: This pull request explicitly references no jira issue. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
Skipping CI for Draft Pull Request. |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bryan-cox The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/area ci-tooling |
|
/verified bypass |
WalkthroughThis PR adds a single pre-commit hook configuration to validate commit messages. A new local hook named ChangesPre-commit hook configuration
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 5 | ❌ 10❌ Failed checks (10 inconclusive)
✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
@bryan-cox: The DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
@bryan-cox: This pull request explicitly references no jira issue. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8701 +/- ##
==========================================
+ Coverage 41.49% 41.50% +0.01%
==========================================
Files 756 758 +2
Lines 93648 93689 +41
==========================================
+ Hits 38855 38882 +27
- Misses 52057 52070 +13
- Partials 2736 2737 +1 see 7 files with indirect coverage changes
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
|
/lgtm |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 @.pre-commit-config.yaml:
- Around line 43-48: The gitlint hook (id: run-gitlint) is configured to run in
the pre-commit stage but needs to run after a commit because it lints a commit
range; update the hook configuration for run-gitlint to use stages:
[post-commit] instead of stages: [pre-commit] so it runs on the newly created
commit message/range (leave the entry/description/name unchanged).
🪄 Autofix (Beta)
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: Repository: openshift/coderabbit/.coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: bdf8d897-3603-44bd-968a-e86e6640bff3
📒 Files selected for processing (1)
.pre-commit-config.yaml
| - id: run-gitlint | ||
| name: Run gitlint | ||
| description: Runs `make run-gitlint` to validate commit messages. | ||
| entry: make run-gitlint | ||
| language: system | ||
| stages: [pre-commit] |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify whether run-gitlint is wired for commit-msg semantics.
# Expected for commit-msg stage: hook receives commit message file and Make target passes it to gitlint.
set -euo pipefail
echo "== Hook definition =="
rg -n -C3 'id:\s*run-gitlint|stages:|entry:' .pre-commit-config.yaml
echo
echo "== Locate run-gitlint target in Makefiles =="
fd -i 'makefile|GNUmakefile|.*\.mk' | while read -r f; do
rg -n -C3 '(^|\s)run-gitlint:|gitlint|COMMIT_EDITMSG|--msg-filename|-f\s' "$f" || true
done
echo
echo "== Locate gitlint config =="
fd -i '(\.gitlint|gitlint.*|.*gitlint.*\.(toml|ini|cfg|yaml|yml))' || trueRepository: openshift/hypershift
Length of output: 15161
🏁 Script executed:
#!/bin/bash
set -euo pipefail
sed -n '1,120p' .pre-commit-config.yaml
echo '---'
nl -ba .pre-commit-config.yaml | sed -n '30,90p'Repository: openshift/hypershift
Length of output: 2205
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== .pre-commit-config.yaml (relevant lines) =="
awk 'NR>=35 && NR<=70 {printf "%d\t%s\n", NR, $0}' .pre-commit-config.yaml
echo
echo "== Find exact run-gitlint target definition(s) =="
rg -n --hidden --no-messages '^\s*run-gitlint\s*:' -S . || true
echo
echo "== Show run-gitlint target implementation =="
# For any matches, print ~30 lines around the match
rg -n --hidden --no-messages '^\s*run-gitlint\s*:' -S . -H | awk -F: '{print $1 ":" $2}' | while read -r loc; do
file="${loc%%:*}"
line="${loc##*:}"
start=$((line-15)); end=$((line+35))
echo "--- $file:$line ---"
sed -n "${start},${end}p" "$file"
done
echo
echo "== Also check how gitlint is invoked for message-file usage =="
rg -n --hidden --no-messages '(gitlint.*--msg-filename|COMMIT_EDITMSG|--commit-msg-file|--message|--from|--commits)' -S . || trueRepository: openshift/hypershift
Length of output: 50376
🌐 Web query:
pre-commit framework stages pre-commit commit-msg post-commit when does HEAD update
💡 Result:
In the Git commit process, HEAD is updated only after the commit object has been successfully created [1][2][3]. The standard Git commit lifecycle follows this order [3][4]: 1. pre-commit hook 2. prepare-commit-msg hook 3. User edits/confirms the commit message 4. commit-msg hook 5. Commit object creation (the index is finalized and the commit is written to the object database) [1][3] 6. HEAD update (the branch or HEAD is updated to point to the new commit) [1][2] 7. post-commit hook The pre-commit framework is a tool for managing these Git hooks [5][6]. While it shares the name of the pre-commit hook, it is a separate entity that orchestrates various hooks by defining them in a configuration file [5][7]. In this framework, the stages property (e.g., [commit], [commit-msg]) determines which Git hook events trigger specific framework tasks [5][8][6]. For example, a task configured for the [commit-msg] stage will run when the native Git commit-msg hook is triggered by Git [5][4]. Crucially, HEAD is updated as part of the atomic finalization of the commit [2]. The post-commit hook runs after the commit object exists and HEAD has been updated to point to the new commit tip [9][3][4].
Citations:
- 1: https://git-scm.com/docs/git-commit
- 2: http://public-inbox.org/git/20171110110949.328-4-phillip.wood@talktalk.net/
- 3: https://www.git-tower.com/learn/git/faq/git-hooks
- 4: https://noteandsave.com/blog/git-hooks
- 5: https://wyattsnotes.wyattau.com/docs/tools/git/advanced-topics/pre-commit-framework
- 6: https://pre-commit.com/?featured_on=pythonbytes
- 7: https://www.andymadge.com/2026/03/10/git-hooks-comparison/
- 8: https://github.com/pre-commit/pre-commit.com/blob/main/sections/advanced.md
- 9: https://git-scm.com/docs/githooks
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== Search for gitlint usage patterns (message-file vs range) =="
rg -n --hidden --no-messages 'gitlint\b|COMMIT_EDITMSG|--msg-filename|--commit-msg|--msg-filename|-f\b' . \
| head -n 200
echo
echo "== Search for run-gitlint references =="
rg -n --hidden --no-messages '\brun-gitlint\b' . | head -n 200
echo
echo "== Find gitlint config files =="
fd -i 'gitlint.*|\.gitlint.*' . || true
fd -i '.*gitlint.*\.(toml|ini|cfg|yaml|yml)$' . || trueRepository: openshift/hypershift
Length of output: 33251
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== Inspect gitlint workflow =="
sed -n '1,120p' .github/workflows/gitlint-reusable.yaml
echo
echo "== Search for PULL_BASE_SHA / PULL_PULL_SHA usage =="
rg -n 'PULL_BASE_SHA|PULL_PULL_SHA' . | head -n 200
echo
echo "== Inspect .github/workflows references to run-gitlint pre-commit =="
rg -n 'run-gitlint|gitlint-reusable|commit-msg|post-commit|pre-commit' .github/workflows .pre-commit-config.yaml 2>/dev/null || trueRepository: openshift/hypershift
Length of output: 2694
🌐 Web query:
pre-commit framework stages post-commit available values pre-commit commit-msg post-commit
💡 Result:
In the pre-commit framework, the stages property defines when a specific hook runs [1][2]. By default, if no stages are specified, a hook is enabled for all supported stages [1]. Available Stage Values The values for the stages property correspond directly to the names of Git hooks [1][2]. As of pre-commit version 3.2.0, these values align with the underlying Git hook names [1][3]. The supported stages include: - pre-commit - commit-msg - post-commit [4] - pre-push - pre-merge-commit - prepare-commit-msg - post-checkout - post-merge - post-rewrite - manual (a special stage that is not triggered by any Git hook, useful for running hooks on demand via pre-commit run --hook-stage manual [hookid]) [1][2] Important Configuration Notes 1. Installation: For hooks to trigger automatically during specific Git events (like commit-msg or post-commit), you must install them using the appropriate --hook-type flag [4][5]. For example, run pre-commit install -t commit-msg to enable commit-msg hooks [5]. 2. Hook Behavior: When using specific stages like commit-msg, the framework passes the path to the commit message file to the hook [6][7]. 3. Manual Stage: The manual stage is reserved for on-demand execution and is never triggered automatically by Git [1][8]. 4. Versioning: Prior to version 3.2.0, some stages used different aliases (e.g., commit instead of pre-commit, push instead of pre-push, and merge-commit instead of pre-merge-commit) [1][9]. Modern configurations should use the current stage names [1]. To restrict a hook to specific stages, add the stages property to your configuration: - id: my-hook stages: [commit-msg, manual]
Citations:
- 1: https://github.com/pre-commit/pre-commit.com/blob/main/sections/advanced.md
- 2: https://pre-commit.com/
- 3: https://pre-commit.com/?featured_on=pythonbytes
- 4: https://www.python4data.science/en/24.3.0/_sources/productive/git/advanced/hooks/advanced.rst.txt
- 5: https://stackoverflow.com/questions/78770531/pre-commit-wont-run-stage-commit-msg-local-hooks
- 6: https://wyattsnotes.wyattau.com/docs/tools/git/advanced-topics/pre-commit-framework
- 7: Understanding how to run commit-msg hook pre-commit/pre-commit#1517
- 8: https://github.com/pre-commit/pre-commit/blob/main/pre_commit/clientlib.py
- 9: make
stagesandhook-typematch pre-commit/pre-commit#2732
Switch run-gitlint to post-commit (not pre-commit)
make run-gitlint runs gitlint on a commit range (gitlint --commits $(PULL_BASE_SHA)..$(PULL_PULL_SHA) / locally --commits $(MERGE_BASE)..HEAD) and does not consume the commit message file. With stages: [pre-commit], HEAD still points to the previous commit, so the just-created commit’s message may not be linted. Move the hook to stages: [post-commit] in .pre-commit-config.yaml (hook id run-gitlint).
🤖 Prompt for 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.
In @.pre-commit-config.yaml around lines 43 - 48, The gitlint hook (id:
run-gitlint) is configured to run in the pre-commit stage but needs to run after
a commit because it lints a commit range; update the hook configuration for
run-gitlint to use stages: [post-commit] instead of stages: [pre-commit] so it
runs on the newly created commit message/range (leave the entry/description/name
unchanged).
|
Scheduling tests matching the |
|
/lgtm |
|
/override ci/prow/e2e-aks |
|
/override ci/prow/e2e-aws |
|
/override ci/prow/e2e-aws-upgrade-hypershift-operator |
|
/override ci/prow/e2e-azure-self-managed |
|
/override ci/prow/e2e-azure-v2-self-managed |
|
/override ci/prow/e2e-kubevirt-aws-ovn-reduced |
|
/override ci/prow/e2e-v2-aws |
|
/override ci/prow/e2e-v2-gke |
|
@bryan-cox: Overrode contexts on behalf of bryan-cox: ci/prow/e2e-aks DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
@bryan-cox: Overrode contexts on behalf of bryan-cox: ci/prow/e2e-aws DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
@bryan-cox: Overrode contexts on behalf of bryan-cox: ci/prow/e2e-v2-gke DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
@bryan-cox: Overrode contexts on behalf of bryan-cox: ci/prow/e2e-azure-v2-self-managed DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
@bryan-cox: Overrode contexts on behalf of bryan-cox: ci/prow/e2e-azure-self-managed DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
@bryan-cox: Overrode contexts on behalf of bryan-cox: ci/prow/e2e-kubevirt-aws-ovn-reduced DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
@bryan-cox: Overrode contexts on behalf of bryan-cox: ci/prow/e2e-v2-aws DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
@bryan-cox: Overrode contexts on behalf of bryan-cox: ci/prow/e2e-aws-upgrade-hypershift-operator DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
@bryan-cox: all tests passed! Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
What this PR does / why we need it:
Adds
run-gitlintto the pre-commit stage so commit message format is validated on every commit, catching formatting issues before they reach CI.Pre-commit hooks (on commit):
Pre-push hooks (on push):
Which issue(s) this PR fixes:
N/A
Special notes for your reviewer:
make lintwas considered for the commit stage but excluded sincelint-fixalready runs the same linter (with--fix), and both depend ongenerate— running both would double the commit time unnecessarily.Checklist:
🤖 Generated with Claude Code
Summary by CodeRabbit