-
Notifications
You must be signed in to change notification settings - Fork 40
Commit message linting #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Commit message linting #90
Conversation
WalkthroughThis change introduces commit message linting and automation for the repository. It adds Commitlint configuration, Husky git hooks for local commit message validation and Commitizen prompts, and a GitHub Actions workflow to enforce commit message standards on pull requests. The package.json is created to manage dependencies and scripts for these tools. The .gitignore is updated to exclude node_modules from version control. No changes are made to application code or exported entities. Changes
Sequence Diagram(s)sequenceDiagram
participant Developer
participant Husky
participant Commitlint
participant Commitizen
participant GitHub Actions
Developer->>Husky: git commit (prepares commit message)
Husky->>Commitizen: Run Commitizen prompt (prepare-commit-msg)
Commitizen-->>Husky: Format commit message
Husky->>Commitlint: Validate commit message (commit-msg)
Commitlint-->>Husky: Approve or block commit
Developer->>GitHub Actions: Open/synchronize/edit PR
GitHub Actions->>Commitlint: Lint all PR commit messages
Commitlint-->>GitHub Actions: Pass/fail PR check
Assessment against linked issues
Poem
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (4)
commitlint.config.js (1)
1-3
: Configuration looks good with minor formatting inconsistencyThe commitlint configuration correctly extends the conventional commit rules, which will enforce standardized commit messages. There's a minor indentation inconsistency between line 2 (4 spaces) and line 3 (2 spaces).
module.exports = { extends: ['@commitlint/config-conventional'], - }; +};.github/workflows/commitlint.yml (1)
19-21
: Optionally cache npm dependencies for faster CI runs.Caching
~/.npm
between builds can significantly reduce install time.- - name: Install dependencies - run: npm install + - name: Cache npm modules + uses: actions/cache@v3 + with: + path: ~/.npm + key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-npm- + + - name: Install dependencies + run: npm installpackage.json (2)
4-5
: Resolve license mismatch in the description.The badge in
description
is for GPLv3, but thelicense
field isISC
. Align the badge with the actual license or update thelicense
field.- "description": "[](https://www.gnu.org/licenses/gpl-3.0) ", + "description": "[](https://opensource.org/licenses/ISC) ",
12-16
: Add a commitlint script for local validation.Contributors will appreciate a shortcut to lint commits locally. For example:
"scripts": { "test": "echo \"No tests specified\"", "prepare": "husky install", "commit": "cz", + "lint:commits": "commitlint --from=origin/main --to=HEAD" },
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.json
is excluded by!**/package-lock.json
📒 Files selected for processing (7)
.github/workflows/commitlint.yml
(1 hunks).gitignore
(1 hunks).husky/commit-msg
(1 hunks).husky/pre-commit
(1 hunks).husky/prepare-commit-msg
(1 hunks)commitlint.config.js
(1 hunks)package.json
(1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/commitlint.yml
12-12: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
15-15: the runner of "actions/setup-node@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
🔇 Additional comments (6)
.gitignore (1)
38-38
: Appropriate addition of node_modules to gitignoreAdding the node_modules directory to .gitignore is a standard practice for Node.js projects and aligns well with the introduction of Husky, Commitlint, and Commitizen dependencies.
.husky/pre-commit (1)
1-4
:✅ Verification successful
Verify that the npm test command is properly configured
The pre-commit hook correctly executes
npm test
before each commit, which is good practice for maintaining code quality. However, for this to work properly, a "test" script needs to be defined in your package.json file.
🏁 Script executed:
#!/bin/bash # Check if a test script is defined in package.json if [ -f "package.json" ]; then echo "Checking for test script in package.json..." grep -o '"test":[^,]*' package.json || echo "No test script found in package.json" else echo "package.json not found. The npm test command in the pre-commit hook won't work without it." fiLength of output: 198
Verified npm test configuration
The
package.json
includes atest
script, so the pre-commit hook in.husky/pre-commit
will execute successfully.• File: .husky/pre-commit
• Validation:"test": "echo \"No tests specified\""
found in package.jsonConsider replacing the placeholder test script with real tests to enforce code quality.
.husky/commit-msg (1)
1-4
: Appropriate commit message validation hookThis hook correctly invokes commitlint to validate commit messages against the conventional commit format rules defined in commitlint.config.js.
.github/workflows/commitlint.yml (1)
22-28
: Approve commitlint loop implementation.The workflow fetches
origin/main
, lists commits betweenorigin/main
andHEAD
, then runsnpx commitlint
per commit. This correctly enforces Conventional Commits on PRs.package.json (2)
7-11
: Commitizen adapter configured correctly.The
config.commitizen.path
points tocz-conventional-changelog
, ensuring interactive prompts generate Conventional Commits. Good to go.
28-34
: Dev dependencies for commit linting are correctly specified.You've added
@commitlint/cli
,@commitlint/config-conventional
,commitizen
,cz-conventional-changelog
, andhusky
at recent versions. This aligns with best practices.
.husky/prepare-commit-msg
Outdated
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
npx --no-install cz |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Verify the Commitizen usage in prepare-commit-msg hook
The current implementation runs Commitizen without passing the commit message file as a parameter, which may not work as expected. Typically, a prepare-commit-msg hook receives parameters ($1, $2, $3) that should be passed to the tool that modifies the commit message.
🏁 Script executed:
#!/bin/bash
# Check Commitizen documentation for proper usage in Git hooks
echo "Checking standard prepare-commit-msg hooks for Commitizen..."
curl -s https://github.com/commitizen/cz-cli/blob/master/README.md | grep -A 10 "prepare-commit-msg"
echo -e "\nStandard prepare-commit-msg hooks typically pass parameters:"
echo "Example: npx --no-install cz --hook || true"
echo "or: exec < /dev/tty && npx cz --hook || true"
echo -e "\nCurrent implementation:"
cat .husky/prepare-commit-msg
Length of output: 65842
Ensure the Husky hook invokes Commitizen with the --hook
flag and an interactive TTY
The current .husky/prepare-commit-msg
just runs
npx --no-install cz
but Commitizen’s hook mode requires the --hook
argument and a TTY for interactivity. Please update it to something like:
File: .husky/prepare-commit-msg
-------------------------------------------------------------------
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
-
-npx --no-install cz
+exec < /dev/tty && npx --no-install cz --hook || true
exec < /dev/tty
attaches the hook to your terminal for prompts--hook
tells CZ to process theprepare-commit-msg
hook parameters|| true
prevents hook failures from blocking commits if needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (1)
.github/workflows/commitlint.yml (1)
11-12
: Ensure full git history for commitlint.
By defaultactions/checkout@v3
only fetches a shallow clone, which can preventgit log origin/main..HEAD
from seeing all commits.Apply this diff to fetch the complete history:
- name: Checkout PR branch - uses: actions/checkout@v3 + uses: actions/checkout@v3 + with: + fetch-depth: 0🧰 Tools
🪛 actionlint (1.7.4)
12-12: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
🧹 Nitpick comments (2)
.github/workflows/commitlint.yml (2)
19-20
: Usenpm ci
for reproducible installs.
npm ci
is optimized for CI environments: it’s faster, cleansnode_modules
first, and guarantees a clean install matchingpackage-lock.json
.- - name: Install dependencies - run: npm install + - name: Install dependencies + run: npm ci
24-28
: Simplify commitlint invocation by linting the full range.
Instead of looping per commit, commitlint can lint an entire range in one command.- - name: Lint commit messages - run: | - git fetch origin main - COMMITS=$(git log origin/main..HEAD --pretty=format:"%H") - echo "$COMMITS" | while read commit; do - npx commitlint --from=$commit --to=$commit --verbose - done + - name: Lint commit messages + run: | + git fetch --no-tags origin main + npx commitlint --from=origin/main --to=HEAD --verbose
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
.github/workflows/commitlint.yml
(1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/commitlint.yml
12-12: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
15-15: the runner of "actions/setup-node@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
🔇 Additional comments (3)
.github/workflows/commitlint.yml (3)
1-1
: Workflow name is clear and descriptive.
The title “Commit Message Lint” accurately reflects the purpose of this workflow.
3-6
: Trigger configuration is appropriate.
Linting on PR events (opened
,synchronize
,edited
) covers the common use cases for commit message validation.
14-17
: Node.js setup is correctly pinned to an LTS version.
Using Node 20 ensures compatibility with current LTS tooling.🧰 Tools
🪛 actionlint (1.7.4)
15-15: the runner of "actions/setup-node@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
.github/workflows/commitlint.yml (2)
1-6
: Enhance trigger coverage to include reopened PRs
Currently the workflow only runs onopened
,synchronize
, andedited
events. To ensure commit messages are linted when a PR is reopened (e.g., after being closed and then reopened), consider adding thereopened
type:on: pull_request: - types: [opened, synchronize, edited] + types: [opened, reopened, synchronize, edited]
25-29
: Simplify commitlint invocation with the official Action
While the manual CLI call works, you can streamline maintenance by using the GitHub Action for commitlint. For example:- - name: Lint commit messages - run: | - git fetch --no-tags origin main - npx commitlint --from=origin/main --to=HEAD --verbose + - name: Lint commit messages + uses: wagoid/commitlint-github-action@v4 + with: + from: origin/main + to: HEAD + verbose: trueThis reduces custom scripting and leverages a maintained action.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
.github/workflows/commitlint.yml
(1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/commitlint.yml
13-13: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
18-18: the runner of "actions/setup-node@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
🔇 Additional comments (3)
.github/workflows/commitlint.yml (3)
11-15
: Ensure full commit history is available
Thefetch-depth: 0
option on the checkout step correctly provides the full Git history, which is essential forcommitlint --from=origin/main --to=HEAD
to validate all PR commits. Great catch.🧰 Tools
🪛 actionlint (1.7.4)
13-13: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
17-21
: Pin Node.js to a stable LTS version
Locking Node.js to version 20 ensures compatibility and avoids using unsupported or non-existent versions (e.g.,'22'
).🧰 Tools
🪛 actionlint (1.7.4)
18-18: the runner of "actions/setup-node@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
22-24
: Usenpm ci
for reproducible installs
Installing dependencies withnpm ci
guarantees a clean, reproducible environment by respecting thepackage-lock.json
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
.github/workflows/commitlint.yml (2)
3-6
: Include reopened event for PR linting
To ensure commit messages are linted when a pull request is reopened, consider adding thereopened
type to the trigger.Apply this diff:
on: pull_request: - types: [opened, synchronize, edited] + types: [opened, synchronize, edited, reopened]
25-31
: Use dynamic base/head refs in commitlint step
Hard‑codingorigin/develop
could lead to unexpected behavior if your default branch changes. You can leverage GitHub context to determine the PR’s base and head refs dynamically, and verify thatdevelop
is indeed the intended base.Apply this diff:
- - name: Lint commit messages - uses: wagoid/commitlint-github-action@v4 - with: - from: origin/develop - to: HEAD - verbose: true + - name: Lint commit messages + uses: wagoid/commitlint-github-action@v4 + with: + from: ${{ github.base_ref }} + to: ${{ github.head_ref }} + verbose: truePlease confirm whether
develop
is the correct base branch for your repository.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
.github/workflows/commitlint.yml
(1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/commitlint.yml
13-13: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
18-18: the runner of "actions/setup-node@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
🔇 Additional comments (4)
.github/workflows/commitlint.yml (4)
1-2
: Approve workflow naming
The workflow name “Commit Message Lint” clearly conveys its purpose.
12-15
: Checkout with full history
Usingfetch-depth: 0
ensures Commitlint can access all commits in the PR. This addresses prior feedback.🧰 Tools
🪛 actionlint (1.7.4)
13-13: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
17-21
: Pin stable Node.js version
Locking to Node.js v20 (LTS) guarantees a supported runtime for the linting tools. Well done.🧰 Tools
🪛 actionlint (1.7.4)
18-18: the runner of "actions/setup-node@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
22-24
: Install dependencies via npm ci
Usingnpm ci
provides a clean, reproducible installation for CI environments.
package.json
Outdated
"path": "cz-conventional-changelog" | ||
} | ||
}, | ||
"scripts": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indent looks off.
package.json
Outdated
{ | ||
"name": "identity-api", | ||
"version": "1.0.0", | ||
"description": "[](https://www.gnu.org/licenses/gpl-3.0) ", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need these badges. Simple description is enough
commitlint.config.js
Outdated
@@ -0,0 +1,3 @@ | |||
module.exports = { | |||
extends: ['@commitlint/config-conventional'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @drtechie for your feedbacks! |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
.github/workflows/commitlint.yml (1)
7-9
: Consider adding concurrency to avoid redundant runs.To cancel in‑progress runs for the same PR when new commits arrive, you can introduce a
concurrency
block at the job level:jobs: lint-commits: runs-on: ubuntu-latest + concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} + cancel-in-progress: true steps:
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
.github/workflows/commitlint.yml
(1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/commitlint.yml
13-13: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
18-18: the runner of "actions/setup-node@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
🔇 Additional comments (4)
.github/workflows/commitlint.yml (4)
12-15
: Good catch on fetching full history.Including
fetch-depth: 0
ensures Commitlint has access to all commits in the PR. This addresses the previous concern about single‑commit checkouts blocking linting tools.🧰 Tools
🪛 actionlint (1.7.4)
13-13: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
17-20
: Node.js version is properly pinned.Using the LTS
node-version: "20"
prevents build failures due to nonexistent versions and aligns with best practices.🧰 Tools
🪛 actionlint (1.7.4)
18-18: the runner of "actions/setup-node@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
22-23
: Installing dependencies withnpm ci
is correct.This step guarantees a clean, reproducible environment matching
package-lock.json
.
25-30
: Commit message linting step is configured correctly.The
wagoid/commitlint-github-action@v4
invocation withfrom
/to
refs andverbose: true
will enforce conventional commits as intended.
Hey @drtechie |
fixes: PSMRI/AMRIT#91
Added Commit Message Linting
Summary by CodeRabbit