Skip to content

feat: add commit quality analysis and policy enforcement#58

Open
vraj826 wants to merge 1 commit into
nirvik34:mainfrom
vraj826:feat/commit-quality-policy-engine
Open

feat: add commit quality analysis and policy enforcement#58
vraj826 wants to merge 1 commit into
nirvik34:mainfrom
vraj826:feat/commit-quality-policy-engine

Conversation

@vraj826

@vraj826 vraj826 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #57

Adds a lightweight Commit Quality Analysis & Policy Enforcement Engine that validates generated commit messages before execution.

Changes Made

  • Added commit quality validator module (commitQuality.ts)
  • Added Conventional Commit format validation
  • Added generic commit message detection
  • Added configurable commit quality scoring
  • Added optional strict quality enforcement mode
  • Added default configuration support (qualityCheck, strictQuality)
  • Integrated quality validation into the commit generation workflow
  • Added focused Vitest coverage for validation and scoring logic

Example Output

Commit Quality: 60/100

Warnings:
- Generic commit message
- Subject too short

In strict mode, commits with a score below the configured threshold are blocked before execution.


Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Documentation update
  • Frontend styling/component update

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 test passes locally
  • npm run lint passes without errors
  • I ran the CLI locally using npm run dev and verified the output

Verification

npm test
npm run lint
npm run build

Results:

  • ✅ 40 tests passed
  • ✅ Build completed successfully
  • ✅ Quality validation integrated and verified in CLI workflow

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas

Summary by CodeRabbit

  • New Features

    • Added commit quality validation with configurable quality checks (enabled by default).
    • Quality checks analyze commit messages for format compliance and warn about generic or poorly formatted commits.
    • Added optional strict mode to block commits failing quality thresholds.
  • Tests

    • Added comprehensive test suite for commit quality validation.

@vercel

vercel Bot commented Jun 5, 2026

Copy link
Copy Markdown

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

@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

.coderabbit.yaml has a parsing error

The CodeRabbit configuration file in this repository has a parsing error and default settings were used instead. Please fix the error(s) in the configuration file. You can initialize chat with CodeRabbit to get help with the configuration file.

💥 Parsing errors (1)
Validation error: Invalid option: expected one of "chill"|"assertive" at "reviews.profile"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • 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
📝 Walkthrough

Walkthrough

Introduces a commit quality validation engine that scores generated commit messages, detects format violations and generic placeholders, and optionally enforces minimum quality thresholds before allowing commits based on configurable policies.

Changes

Commit Quality Analysis and Enforcement

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
Loading

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 ⚠️ Warning 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 win

Remove duplicate enhanceCommit call.

Lines 206-211 and line 212 call enhanceCommit with 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 tradeoff

Consider 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 threshold parameter 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

📥 Commits

Reviewing files that changed from the base of the PR and between 07b25af and a867438.

📒 Files selected for processing (4)
  • src/config/loadConfig.ts
  • src/index.ts
  • src/validators/commitQuality.test.ts
  • src/validators/commitQuality.ts

Comment thread src/validators/commitQuality.ts
@vraj826

vraj826 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

@nirvik34 Can you review the changes!

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.

[FEATURE] Implement Commit Quality Analysis & Policy Enforcement Engine

1 participant