Skip to content

Conversation

ARKEOLOGIST
Copy link

@ARKEOLOGIST ARKEOLOGIST commented Apr 19, 2025

📋 Description

JIRA ID: PSMRI/AMRIT#82

  1. Added a new commitlint config.
  2. Added a new Github CI/CD workflow for checking messages
  3. Set up Spotless to clean up code pre-commit
  4. Added Husky to check commit messages

Possibility to be explored : Using spotless to clean the Java code being pushed before final commit


✅ Type of Change

  • 🐞 Bug fix (non-breaking change which resolves an issue)
  • New feature (non-breaking change which adds functionality)
  • 🔥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 🛠 Refactor (change that is neither a fix nor a new feature)
  • ⚙️ Config change (configuration file or build script updates)
  • 📚 Documentation (updates to docs or readme)
  • 🧪 Tests (adding new or updating existing tests)
  • 🎨 UI/UX (changes that affect the user interface)
  • 🚀 Performance (improves performance)
  • 🧹 Chore (miscellaneous changes that don't modify src or test files)

ℹ️ Additional Information

Trying to commit with a bad commit message now shows the issues like this:
husky-issue-Arkadyuti

Trying to configure a commit before push now shows this:
npm-run-commit

Summary by CodeRabbit

  • Chores
    • Added automated checks for commit message compliance on pull requests.
    • Updated project to ignore node modules and lock files in version control.
    • Introduced configuration to enforce standardized commit message formatting.
    • Set up Git hooks to validate commit messages before commits are finalized.
    • Added project metadata and development tools for commit linting and formatting.

Copy link

coderabbitai bot commented Apr 19, 2025

Walkthrough

This 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 .gitignore file is updated to exclude node_modules and package-lock.json. The new setup ensures that commit messages adhere to a defined conventional format, both locally via Git hooks and remotely via CI, by integrating Commitlint rules, Husky hooks, and Commitizen prompts.

Changes

File(s) Change Summary
.github/workflows/commitlint.yml Added a GitHub Actions workflow to lint commit messages on pull request events using Commitlint.
.gitignore Updated to ignore node_modules and package-lock.json.
.husky/commit-msg Added Husky commit-msg hook to run Commitlint on commit messages during local commits.
commitlint.config.js Added Commitlint configuration enforcing conventional commit message rules.
package.json Added project metadata, scripts, dev dependencies for Commitlint, Husky, Commitizen, and configuration for Commitizen.

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
Loading

Possibly related issues

Poem

In the warren of code, we now decree,
Commit messages neat as can be!
With Husky and Lint, we hop on the case,
Ensuring our history’s tidy and in place.
Actions on GitHub, Commitizen too—
All join the dance for a codebase anew!
🐇✨

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 02354ec and b7feefe.

📒 Files selected for processing (1)
  • package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json

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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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: 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 an actions/cache step keyed on package-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 the description field is unconventional and may render incorrectly on npm. Consider relocating those badges to README.md and using a concise, plain-text description here.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c3323d0 and 90c6fa4.

📒 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
Ignoring node_modules and package-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
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

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.

Suggested change
npx --no -- commitlint --edit "$1"
#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"
npx --no-install commitlint --edit "$1"

@ARKEOLOGIST
Copy link
Author

@Sneha6003 PTAL!

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: 0

🧹 Nitpick comments (2)
.github/workflows/commitlint.yml (2)

25-27: Consider caching dependencies to speed up CI
You can add an actions/cache step keyed on package-lock.json (or npm-shrinkwrap.json) to cache ~/.npm between runs and reduce the time spent in npm ci.


30-30: Add a newline at end-of-file
YAML files should end with a newline to satisfy linters like YAMLlint.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 90c6fa4 and 02354ec.

📒 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 on opened, synchronize, and reopened pull request events aligns perfectly with the goal of validating commit messages on incoming changes.


7-10: No comment necessary
The job name and runs-on: ubuntu-latest setting are appropriate for this workflow.


12-19: Checkout step correctly fetches full history
Using actions/checkout@v4 with fetch-depth: 0 and submodules enabled ensures commitlint can access the full commit range between base and head.


20-24: No comment necessary
The Node.js setup via actions/setup-node@v4 targeting version 18 is correctly configured.


28-30: Commitlint invocation is properly scoped between commits
The npx 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)

Copy link

!.mvn/wrapper/maven-wrapper.jar

node_modules
package-lock.json
Copy link
Member

Choose a reason for hiding this comment

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

{
"name": "inventory-api",
"version": "1.0.0",
"description": "[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) ![branch parameter](https://github.com/PSMRI/Inventory-API/actions/workflows/sast-and-package.yml/badge.svg)",
Copy link
Member

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

@drtechie
Copy link
Member

drtechie commented May 1, 2025

@ARKEOLOGIST will you be addressing the comments?
PSMRI/MMU-API#76
PSMRI/MMU-API#74

refer to these PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants