-
Notifications
You must be signed in to change notification settings - Fork 29
Added Commit Message Linting for Inventory API #72
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?
Conversation
WalkthroughThis change introduces a standardized commit message enforcement system to the project. It adds configuration and tooling for Commitlint, Husky, and Commitizen, along with a GitHub Actions workflow that validates commit messages on pull requests. The Changes
Sequence Diagram(s)sequenceDiagram
participant Developer
participant Git
participant Husky
participant Commitlint
participant GitHub
participant GitHub Actions
Developer->>Git: git commit
Git->>Husky: Trigger commit-msg hook
Husky->>Commitlint: Lint commit message
Commitlint-->>Husky: Pass/Fail
Husky-->>Git: Allow/Block commit
Developer->>GitHub: Push branch / Create PR
GitHub->>GitHub Actions: Trigger commitlint workflow
GitHub Actions->>Commitlint: Lint PR commit messages
Commitlint-->>GitHub Actions: Pass/Fail
GitHub Actions-->>GitHub: Report status on PR
Possibly related issues
Poem
Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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: 2
🧹 Nitpick comments (3)
.github/workflows/commitlint.yml (2)
30-30
: Missing newline at end of file
YAML files should end with a newline to satisfy linters and POSIX text file standards.🧰 Tools
🪛 YAMLlint (1.35.1)
[error] 30-30: no new line character at the end of file
(new-line-at-end-of-file)
25-27
: Consider caching npm dependencies to speed up workflow
Adding anactions/cache
step keyed onpackage-lock.json
can greatly reduce CI install time and network usage.- name: Cache npm dependencies uses: actions/cache@v3 with: path: ~/.npm key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} restore-keys: | ${{ runner.os }}-npm-package.json (1)
4-4
: Move badges out of package.json description
Including Markdown badges in thedescription
field is unconventional and may render incorrectly on npm. Consider relocating those badges toREADME.md
and using a concise, plain-text description here.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
.github/workflows/commitlint.yml
(1 hunks).gitignore
(1 hunks).husky/commit-msg
(1 hunks)commitlint.config.js
(1 hunks)package.json
(1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.35.1)
.github/workflows/commitlint.yml
[error] 30-30: no new line character at the end of file
(new-line-at-end-of-file)
🔇 Additional comments (2)
.gitignore (1)
4-5
: Appropriate ignore patterns for Node modules and lockfile introduced
Ignoringnode_modules
andpackage-lock.json
aligns with the new Node.js tooling and prevents bulky artifacts from being committed.commitlint.config.js (1)
1-36
: Commitlint configuration follows conventional commit standards
The rules and presets correctly enforce conventional commits, with clear constraints on types, casing, and line lengths.
@@ -0,0 +1 @@ | |||
npx --no -- commitlint --edit "$1" No newline at end of 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.
Incomplete Husky hook script: missing shell header and setup
Husky hook scripts require a shebang and sourcing the Husky environment (. "$(dirname "$0")/_/husky.sh"
). Without these, the hook will not execute. Also, use --no-install
instead of --no
to prevent npx from attempting to auto-install missing packages.
Apply this diff:
- npx --no -- commitlint --edit "$1"
+ #!/usr/bin/env sh
+ . "$(dirname "$0")/_/husky.sh"
+
+ npx --no-install commitlint --edit "$1"
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
npx --no -- commitlint --edit "$1" | |
#!/usr/bin/env sh | |
. "$(dirname "$0")/_/husky.sh" | |
npx --no-install commitlint --edit "$1" |
@Sneha6003 PTAL! |
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)
25-27
: Consider caching dependencies to speed up CI
You can add anactions/cache
step keyed onpackage-lock.json
(ornpm-shrinkwrap.json
) to cache~/.npm
between runs and reduce the time spent innpm ci
.
30-30
: Add a newline at end-of-file
YAML files should end with a newline to satisfy linters likeYAMLlint
.Proposed diff:
run: | npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose +
🧰 Tools
🪛 YAMLlint (1.35.1)
[error] 30-30: no new line character at the end of file
(new-line-at-end-of-file)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.github/workflows/commitlint.yml
(1 hunks)package.json
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- package.json
🧰 Additional context used
🪛 YAMLlint (1.35.1)
.github/workflows/commitlint.yml
[error] 30-30: no new line character at the end of file
(new-line-at-end-of-file)
🔇 Additional comments (5)
.github/workflows/commitlint.yml (5)
1-6
: Workflow event triggers are correctly scoped to PR events
Triggering onopened
,synchronize
, andreopened
pull request events aligns perfectly with the goal of validating commit messages on incoming changes.
7-10
: No comment necessary
The job name andruns-on: ubuntu-latest
setting are appropriate for this workflow.
12-19
: Checkout step correctly fetches full history
Usingactions/checkout@v4
withfetch-depth: 0
and submodules enabled ensurescommitlint
can access the full commit range between base and head.
20-24
: No comment necessary
The Node.js setup viaactions/setup-node@v4
targeting version 18 is correctly configured.
28-30
: Commitlint invocation is properly scoped between commits
Thenpx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
command will lint exactly the new commits in the PR.🧰 Tools
🪛 YAMLlint (1.35.1)
[error] 30-30: no new line character at the end of file
(new-line-at-end-of-file)
|
!.mvn/wrapper/maven-wrapper.jar | ||
|
||
node_modules | ||
package-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.
@ARKEOLOGIST let's add package-lock.json
https://stackoverflow.com/questions/44206782/do-i-commit-the-package-lock-json-file-created-by-npm-5
{ | ||
"name": "inventory-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.
This description doesn't look fine @ARKEOLOGIST
@ARKEOLOGIST will you be addressing the comments? refer to these PRs. |
📋 Description
JIRA ID: PSMRI/AMRIT#82
Possibility to be explored : Using spotless to clean the Java code being pushed before final commit
✅ Type of Change
ℹ️ Additional Information
Trying to commit with a bad commit message now shows the issues like this:

Trying to configure a commit before push now shows this:

Summary by CodeRabbit