Skip to content

Conversation

@blazethunderstorm
Copy link

@blazethunderstorm blazethunderstorm commented Apr 19, 2025

Implemented it for ECD-API

📋 Description

JIRA ID: Fixes PSMRI/AMRIT#80

This PR introduces commit message standardization for the FHIR-API project by setting up Commitlint, Husky, and Commitizen.
The goal is to enforce a consistent commit message format across the repository, improving collaboration, readability,
and enabling future automation (like changelogs and versioning).

These tools are now integrated:

  • Commitlint enforces the conventional commit message structure.
  • Husky prevents non-compliant commits by using Git hooks.
  • Commitizen provides an interactive CLI for making properly formatted commits.
  • GitHub Actions validate commit messages for all pull requests.

PS: Implemented with the same standardization as for the UI repositories to ensure clean and well-maintained code.

✅ 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

  • Added commitlint.config.js with conventional commit rules.
  • Configured Husky to run Commitlint on every commit via .husky/commit-msg.
  • Set up Commitizen with configuration in package.json for interactive commit prompts.
  • Added GitHub Actions workflow .github/workflows/commit-lint.yml to check commit messages on PRs.
  • Updated package.json and package-lock.json with the following dev dependencies:
    • @commitlint/cli
    • @commitlint/config-conventional
    • commitizen
    • cz-conventional-changelog

🧪 Testing & Validation:

  • Invalid commit messages are blocked locally with clear lint errors.
  • Interactive commit flow works via npm run commit or npx cz.
  • GitHub Actions workflow correctly fails PRs with non-compliant commit messages.
  • No disruption to existing build or CI pipelines.

PROOF(SCREENSHOTS)

image

image

Summary by CodeRabbit

  • New Features

    • Introduced automated commit message linting on pull requests and during local commits to enforce
      consistent commit message standards.
    • Added pre-commit checks to automatically lint and format staged files for improved code quality.
  • Chores

    • Added project configuration files for commit message linting, code formatting, and development
      dependencies management.
    • Enhanced documentation with setup instructions for commit hooks and commit message conventions.

@coderabbitai
Copy link

coderabbitai bot commented Apr 19, 2025

Walkthrough

This change introduces a comprehensive commit message linting and automation system to the repository. It adds configuration and setup for Commitlint, Husky, Commitizen, and lint-staged, along with a GitHub Actions workflow to enforce commit message standards on pull requests. The README is rewritten to document these new development workflows and tools, replacing previous project-specific build instructions. The new setup ensures that commit messages follow a standardized format both locally (via Git hooks) and in CI, and provides contributors with tools for guided commit creation.

Changes

File(s) Change Summary
.github/workflows/commit-lint.yml Added GitHub Actions workflow to lint commit messages on PRs using Commitlint.
.husky/commit-msg, .husky/pre-commit Added Husky Git hooks: commit-msg runs Commitlint; pre-commit runs lint-staged.
commitlint.config.js Added Commitlint configuration enforcing commit message rules and allowed types/scopes.
package.json Added Node.js project manifest with scripts, Commitlint, Commitizen, Husky, and lint-staged.
README.md Rewrote documentation to focus on FHIR compliance, API overview, and new commit tooling setup.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant Husky
    participant Commitlint
    participant Commitizen
    participant GitHub Actions

    Developer->>Commitizen: Run "npm run commit"
    Commitizen->>Developer: Prompt for commit details (type, scope, subject, etc.)
    Developer->>Husky: git commit
    Husky->>Commitlint: Validate commit message (commit-msg hook)
    Commitlint-->>Husky: Pass/Fail
    Husky-->>Developer: Allow or block commit

    Developer->>GitHub Actions: Open PR / push commits
    GitHub Actions->>Commitlint: Lint all PR commit messages
    Commitlint-->>GitHub Actions: Pass/Fail
    GitHub Actions-->>Developer: PR check result
Loading

Assessment against linked issues

Objective Addressed Explanation
Integrate Commitlint to enforce commit message standards (#80)
Set up Husky to trigger commit-msg hooks (#80)
Add Commitizen to provide structured commit prompts to contributors (#80)
Configure GitHub Actions to verify commit format in Pull Requests (#80)
Ensure no conflicts/interference with existing CI/CD workflows (#80)

Possibly related issues

Poem

Hoppity-hop, a linting delight,
Now every commit must look just right!
With Husky and friends, the rules are set,
Commitizen guides—no need to fret.
On PRs, the bots will check your prose,
For tidy histories, this rabbit chose.
🐇✨ Code neat as a carrot row!

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.
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

@sonarqubecloud
Copy link

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 (10)
.husky/pre-commit (1)

1-1: Add a shebang and error handling to the hook script.

Husky hook scripts should include a shebang (e.g., #!/usr/bin/env sh) and optionally source the Husky environment to ensure consistent behavior:

+#!/usr/bin/env sh
+. "$(dirname "$0")/_/husky.sh"
 npx lint-staged
.github/workflows/commit-lint.yml (1)

25-27: Consider caching Node.js dependencies in CI.

To speed up the workflow, add an actions/cache step before npm ci to cache ~/.npm or node_modules:

- name: Cache NPM modules
  uses: actions/cache@v3
  with:
    path: ~/.npm
    key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
    restore-keys: |
      ${{ runner.os }}-npm-
README.md (8)

3-4: Break up lengthy introduction and fix missing punctuation/article.
Line 3: insert a comma after “in a standard way” for clarity.
Line 4: add “the” before “rest of the 18 resources.”
Consider splitting this long paragraph into two or more shorter ones to improve readability.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~3-~3: Possible missing comma found.
Context: ...nicians and organizations in a standard way regardless of the ways local EHRs repre...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~4-~4: You might be missing the article “the” here.
Context: ... Contributors are working on developing rest of the 18 resources which will make AMR...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)


5-5: Adjust heading level for consistency.
Change ### Key APIs in ECD service (H3) to ## Key APIs in ECD service so that headings increment by only one level from the H1 title.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

5-5: Heading levels should only increment by one level at a time
Expected: h2; Actual: h3

(MD001, heading-increment)


14-16: Fix trailing space in link definition.
On line 14 remove the space before the period in the Developer Guide link—change (…setup) . to (…setup)..


26-27: Use consistent unordered list markers.
Lines 26–27 use dashes (- Node.js, - npm) whereas earlier lists use asterisks. Switch these to * for uniformity.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

26-26: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


27-27: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


34-37: Specify language for fenced code blocks.
The code fences on lines 34–37 and 40–42 currently lack a language identifier. Add e.g.

```bash
node --version
npm --version

and

```bash
npm ci

to enable proper syntax highlighting.

Also applies to: 40-42

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

34-34: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


49-62: Use consistent list syntax in commit conventions.
The commit-type list on lines 49–62 uses dashes (-) but earlier sections use asterisks. Switch these to * to maintain a single markdown style.

🧰 Tools
🪛 LanguageTool

[grammar] ~53-~53: “Bug” is a singular noun. It appears that the verb form is incorrect.
Context: ... - feat: A new feature - fix: A bug fix - docs: Documentation changes - `styl...

(PCT_SINGULAR_NOUN_PLURAL_VERB_AGREEMENT)


[uncategorized] ~56-~56: Loose punctuation mark.
Context: ... changes (formatting, etc.) - refactor: Code changes that neither fix bugs nor ...

(UNLIKELY_OPENING_PUNCTUATION)

🪛 markdownlint-cli2 (0.17.2)

49-49: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


50-50: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


52-52: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


53-53: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


54-54: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


55-55: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


56-56: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


57-57: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


58-58: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


59-59: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


60-60: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


61-61: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


63-65: Clean up trailing spaces and blank lines.
Remove the extra blank line at 63 and strip any trailing spaces on lines 65 for tighter formatting.


66-78: Consolidate community section and remove superfluous blank lines.
Lines 66–78 include many empty lines and layout markers. Collapse them into a succinct block, for example:

## Join Our Community
We’d love to have you join our community discussions and get real-time support! Join our [Discord server](https://discord.gg/FVQWsf5ENS) to connect with contributors, ask questions, and stay updated.
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

73-73: Code block style
Expected: fenced; Actual: indented

(MD046, code-block-style)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 10002a5 and e8877d0.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (6)
  • .github/workflows/commit-lint.yml (1 hunks)
  • .husky/commit-msg (1 hunks)
  • .husky/pre-commit (1 hunks)
  • README.md (1 hunks)
  • commitlint.config.js (1 hunks)
  • package.json (1 hunks)
🧰 Additional context used
🪛 LanguageTool
README.md

[uncategorized] ~3-~3: Possible missing comma found.
Context: ...nicians and organizations in a standard way regardless of the ways local EHRs repre...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~4-~4: You might be missing the article “the” here.
Context: ... Contributors are working on developing rest of the 18 resources which will make AMR...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)


[uncategorized] ~32-~32: The official spelling of this programming framework is “Node.js”.
Context: ...d npm** - Download and install from nodejs.org - Verify i...

(NODE_JS)


[grammar] ~53-~53: “Bug” is a singular noun. It appears that the verb form is incorrect.
Context: ... - feat: A new feature - fix: A bug fix - docs: Documentation changes - `styl...

(PCT_SINGULAR_NOUN_PLURAL_VERB_AGREEMENT)


[uncategorized] ~56-~56: Loose punctuation mark.
Context: ... changes (formatting, etc.) - refactor: Code changes that neither fix bugs nor ...

(UNLIKELY_OPENING_PUNCTUATION)

🪛 markdownlint-cli2 (0.17.2)
README.md

5-5: Heading levels should only increment by one level at a time
Expected: h2; Actual: h3

(MD001, heading-increment)


26-26: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


27-27: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


32-32: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


33-33: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


34-34: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


39-39: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


40-40: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


43-43: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


45-45: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


46-46: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


49-49: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


50-50: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


52-52: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


53-53: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


54-54: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


55-55: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


56-56: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


57-57: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


58-58: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


59-59: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


60-60: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


61-61: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


73-73: Code block style
Expected: fenced; Actual: indented

(MD046, code-block-style)

🔇 Additional comments (2)
commitlint.config.js (1)

1-43: Commitlint rules are comprehensive and follow the conventional standard.

The configuration covers body and footer formatting, header length, type and scope casing, and restricts allowed types and scopes appropriately.

.github/workflows/commit-lint.yml (1)

28-30: Approve commitlint invocation on PR branches.

The job correctly checks out the code, installs dependencies, and runs npx commitlint between the base and head SHAs with verbose output.

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

Fix the npx invocation in the commit-msg hook.

The current npx --no -- commitlint --edit $1 may not behave as intended. Use the recommended Husky pattern with a shebang, source Husky, and invoke Commitlint without the invalid --no flag:

+#!/usr/bin/env sh
+. "$(dirname "$0")/_/husky.sh"
-npx --no -- commitlint --edit $1
+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"

Comment on lines +5 to +8
"test": "echo \"Error: no test specified\" && exit 1",
"prepare": "husky",
"commit": "cz"
},
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Update the prepare script to install Husky hooks.

The prepare script should invoke husky install to set up the Git hooks after install:

 "scripts": {
-    "test": "echo \"Error: no test specified\" && exit 1",
-    "prepare": "husky",
+    "test": "echo \"Error: no test specified\" && exit 1",
+    "prepare": "husky install",
     "commit": "cz"
 },
📝 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
"test": "echo \"Error: no test specified\" && exit 1",
"prepare": "husky",
"commit": "cz"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prepare": "husky install",
"commit": "cz"
},

@drtechie
Copy link
Member

drtechie commented May 9, 2025

@blazethunderstorm have you self-reviewed your PR?
README looks AI generated with no relation to the context of this microservice.

@blazethunderstorm
Copy link
Author

@drtechie will make the changes by today

@blazethunderstorm
Copy link
Author

@drtechie the changes are already done in the file what should i do ?

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.

[C4GT Community]: Implement Commit Message Linting and Automation for ECD-API

2 participants