feat: add commit quality analysis and policy enforcement#58
Conversation
|
@vraj826 is attempting to deploy a commit to the nirvik34's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Warning
|
| Layer / File(s) | Summary |
|---|---|
Quality Analysis and Validation Core src/validators/commitQuality.ts, src/validators/commitQuality.test.ts |
Defines CommitQualityResult with score and warnings. analyzeCommitQuality() validates Conventional Commit format, detects generic messages (case-insensitive), and penalizes short subjects, returning a 0–100 score. shouldBlockCommitForQuality() blocks commits when strict mode is enabled and score falls below 60. Full test coverage validates all scoring paths and blocking behavior. |
Quality Check Configuration Schema src/config/loadConfig.ts |
GitbunConfig adds optional qualityCheck (defaults true) and strictQuality (defaults false) fields. loadConfig() merges user-provided values over these defaults, ensuring quality checks are enabled by default. |
CLI Quality Gate Integration src/index.ts |
Imports quality analysis helpers, loads config earlier in the flow, and adds a commit-quality gate after message generation. Displays warnings in interactive mode and throws ValidationError when quality violations block the commit based on strictQuality setting. |
Sequence Diagram
sequenceDiagram
participant User
participant CLI as run()
participant Generator as generateCommitMessage
participant Analyzer as analyzeCommitQuality
participant Blocker as shouldBlockCommitForQuality
User->>CLI: invoke gitbun
CLI->>CLI: loadConfig()
CLI->>Generator: generate message
Generator-->>CLI: commit message
CLI->>Analyzer: analyze message
Analyzer-->>CLI: score + warnings
CLI->>Blocker: check if should block
Blocker-->>CLI: block decision
alt Config qualityCheck enabled
CLI->>User: display warnings (non-auto mode)
end
alt shouldBlock returns true
CLI->>User: throw ValidationError
else allow commit
CLI->>User: proceed or confirm
end
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~25 minutes
Suggested labels
type: feature, level: advanced, gssoc:approved, quality:clean
Poem
🐰 A rabbit hops through commit streams,
With scores and warnings in between,
Generic WIP? Off it goes—
Only proper messages flow!
Quality gates with teeth so keen! 🌱
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title accurately summarizes the main changes: adding commit quality analysis and policy enforcement capabilities to the codebase. |
| Linked Issues check | ✅ Passed | The PR implements core features from #57 including Conventional Commit validation, generic message detection, quality scoring, and strict enforcement mode, but does not fully address semantic consistency, sensitive keyword detection, or documentation updates. |
| Out of Scope Changes check | ✅ Passed | All changes are directly related to commit quality validation and integration into the workflow as specified in #57; no out-of-scope modifications detected. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
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.
Comment @coderabbitai help to get the list of available commands and usage tips.
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/index.ts (1)
206-212:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winRemove duplicate
enhanceCommitcall.Lines 206-211 and line 212 call
enhanceCommitwith identical parameters, causing the commit message to be enhanced twice. This wastes resources (duplicate LLM API calls) and may degrade message quality through over-processing.🔧 Proposed fix to remove duplicate call
try { commitMessage = await enhanceCommit( commitMessage, summary, selectedModel, config ); - commitMessage = await enhanceCommit(commitMessage, summary, selectedModel, config); spinner.succeed(`Enhanced commit with AI (${selectedModel})`); } catch {🤖 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 `@src/index.ts` around lines 206 - 212, The code calls enhanceCommit twice with the same arguments (enhanceCommit(commitMessage, summary, selectedModel, config)), causing duplicate LLM calls and double-processing; remove the redundant invocation and keep a single assignment to commitMessage (use the first call that already updates commitMessage) so only one call to enhanceCommit occurs with the existing variables commitMessage, summary, selectedModel, and config.
🧹 Nitpick comments (1)
src/validators/commitQuality.ts (1)
52-57: ⚖️ Poor tradeoffConsider making the blocking threshold configurable.
The threshold of 60 is hardcoded. While this provides a sensible default, different projects may want stricter (e.g., 80) or more lenient (e.g., 40) thresholds. Consider accepting an optional
thresholdparameter or reading from config.💡 Example: Accept threshold parameter
export function shouldBlockCommitForQuality( result: CommitQualityResult, strictQuality = false, + threshold = 60, ): boolean { - return strictQuality && result.score < 60; + return strictQuality && result.score < threshold; }🤖 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 `@src/validators/commitQuality.ts` around lines 52 - 57, The function shouldBlockCommitForQuality currently hardcodes the blocking threshold (60); change it to accept an optional threshold parameter (e.g., threshold = 60) or read a configurable value and use that instead of 60 in the comparison inside shouldBlockCommitForQuality(result, strictQuality = false, threshold = 60); update all callers to pass a custom threshold where needed (or wire the config into places that call shouldBlockCommitForQuality) so projects can adjust the blocking cutoff without changing the function body.
🤖 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 `@src/validators/commitQuality.ts`:
- Around line 16-17: The regex constant CONVENTIONAL_COMMIT_PATTERN currently
uses the case-insensitive flag (/i), allowing uppercase types; update
CONVENTIONAL_COMMIT_PATTERN to enforce lowercase types by removing the /i flag
(keep the existing type list and scope pattern as-is) so only strictly lowercase
Conventional Commit types (feat|fix|docs|...) are accepted, then run unit/lint
tests that validate commit parsing to ensure no regressions.
---
Outside diff comments:
In `@src/index.ts`:
- Around line 206-212: The code calls enhanceCommit twice with the same
arguments (enhanceCommit(commitMessage, summary, selectedModel, config)),
causing duplicate LLM calls and double-processing; remove the redundant
invocation and keep a single assignment to commitMessage (use the first call
that already updates commitMessage) so only one call to enhanceCommit occurs
with the existing variables commitMessage, summary, selectedModel, and config.
---
Nitpick comments:
In `@src/validators/commitQuality.ts`:
- Around line 52-57: The function shouldBlockCommitForQuality currently
hardcodes the blocking threshold (60); change it to accept an optional threshold
parameter (e.g., threshold = 60) or read a configurable value and use that
instead of 60 in the comparison inside shouldBlockCommitForQuality(result,
strictQuality = false, threshold = 60); update all callers to pass a custom
threshold where needed (or wire the config into places that call
shouldBlockCommitForQuality) so projects can adjust the blocking cutoff without
changing the function body.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 02ccb359-fca1-416c-883f-9f4823886309
📒 Files selected for processing (4)
src/config/loadConfig.tssrc/index.tssrc/validators/commitQuality.test.tssrc/validators/commitQuality.ts
|
@nirvik34 Can you review the changes! |
Description
Fixes #57
Adds a lightweight Commit Quality Analysis & Policy Enforcement Engine that validates generated commit messages before execution.
Changes Made
commitQuality.ts)qualityCheck,strictQuality)Example Output
In strict mode, commits with a score below the configured threshold are blocked before execution.
Type of change
GSSoC '26 Contribution Details
Please select only one difficulty level that was assigned to you in the issue:
level:beginner
level:intermediate
level:advanced
level:critical
I have been assigned to this issue by a maintainer. (PRs without prior assignment will not count toward GSSoC).
How Has This Been Tested?
npm testpasses locallynpm run lintpasses without errorsnpm run devand verified the outputVerification
npm test npm run lint npm run buildResults:
Checklist:
Summary by CodeRabbit
New Features
Tests