Skip to content

Conversation

@isokolovskii
Copy link
Owner

@isokolovskii isokolovskii commented Nov 25, 2025

Summary by CodeRabbit

  • New Features
    • Added a new CLI command to compose Conventional Commit messages with structured fields (type, scope, title, body, breaking note, issue).
  • Chores
    • Introduced repository configuration enabling automated review and chat auto-replies.
    • Reworked pre-commit lint/format steps into ordered sub-tasks.
  • Tests
    • Added unit tests covering the commit message construction logic.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Nov 25, 2025

📝 Walkthrough

Walkthrough

Adds a new commit CLI subcommand and a conventional-commit builder, plus unit tests; introduces CodeRabbit review config and refactors pre-commit lint/format steps in Lefthook.

Changes

Cohort / File(s) Summary
Configuration
/.coderabbit.yaml, /.lefthook.yml
Adds CodeRabbit automated review configuration (.coderabbit.yaml) and restructures pre-commit steps in .lefthook.yml to group formatting and linting as distinct sub-jobs (format and lint).
CLI command registration
cmd/commands.go
Adds commit() to the exported commands slice to expose the new subcommand in the root CLI.
CLI command implementation
cmd/commit.go
New commit subcommand using urfave/cli/v3: defines flags (type, scope, title, body, breaking, issue), builds a conventional.Commit, calls the builder, prints message, and declares ErrInvalidFlag.
Conventional commit model
internal/conventional/commit.go
Adds exported Commit struct with fields Type, Scope, Title, Body, BreakingChange, and Issue and documentation referencing the Conventional Commits spec.
Commit message builder
internal/conventional/message.go
Adds BuildCommitMessage(commit *Commit) (string, error), ErrRequiredPartNotPreset, and helpers buildHeader/buildFooter to validate and assemble header/footer with careful newline handling.
Tests
internal/conventional/message_test.go
Adds unit tests covering various commit permutations (scope, breaking changes, body, issue) and error cases; uses parallel tests and testify/assert.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI as Commit Command
    participant Builder as Message Builder
    participant Stdout as Output

    User->>CLI: run `app commit` with flags (--type, --scope, --title, --body, --breaking, --issue)
    CLI->>CLI: parse flags → conventional.Commit
    CLI->>Builder: BuildCommitMessage(commit)
    Builder->>Builder: validate Type & Title
    alt validation fails
        Builder-->>CLI: ErrRequiredPartNotPreset
        CLI-->>User: print error
    else validation succeeds
        Builder->>Builder: buildHeader(Type, Scope, Breaking, Title)
        Builder->>Builder: buildFooter(Breaking, Issue, Body)
        Builder->>Builder: concat header + newline + footer
        Builder-->>CLI: formatted message
        CLI->>Stdout: print message
        CLI-->>User: exit success
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Inspect newline and spacing logic in internal/conventional/message.go (header/footer assembly).
  • Verify tests in internal/conventional/message_test.go cover edge cases and assert error values correctly.
  • Confirm CLI flag wiring and error propagation in cmd/commit.go (required fields, ErrInvalidFlag usage).
  • Review .lefthook.yml restructure for intended ordering and parallelism.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'Basic conventional commit builder' is concise (33 characters), descriptive of the main changes, and clearly relates to the implementation of conventional commit functionality added across multiple files.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/build-commit

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

@codecov
Copy link

codecov bot commented Nov 25, 2025

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

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

🧹 Nitpick comments (4)
internal/conventional/commit.go (1)

3-11: Consider adding documentation for the Commit struct.

Adding a comment describing the purpose of the struct and its fields would improve maintainability and help users understand the conventional commit structure.

Apply this diff to add documentation:

+// Commit represents the components of a Conventional Commit message.
+// See https://www.conventionalcommits.org/ for the specification.
 type (
 	Commit struct {
+		// Type describes the kind of change (e.g., "feat", "fix", "docs")
 		Type   string
+		// Scope is an optional context for the change (e.g., "api", "cli")
 		Scope  string
+		// Title is a short description of the change
 		Title  string
+		// Body is an optional longer description
 		Body   string
+		// Footer is optional metadata (e.g., "BREAKING CHANGE:", issue refs)
 		Footer string
 	}
 )
cmd/commit.go (3)

26-32: Consider adding Required and Usage fields to flags.

The flags would benefit from descriptions and required markers to improve the CLI user experience. This helps users understand what each flag does without reading the code.

Apply this diff to improve flag definitions:

 		Flags: []cli.Flag{
-			&cli.StringFlag{Name: "type", OnlyOnce: true, Destination: &commitType},
-			&cli.StringFlag{Name: "scope", OnlyOnce: true, Destination: &scope},
-			&cli.StringFlag{Name: "title", OnlyOnce: true, Destination: &title},
-			&cli.StringFlag{Name: "body", OnlyOnce: true, Destination: &body},
-			&cli.StringFlag{Name: "footer", OnlyOnce: true, Destination: &footer},
+			&cli.StringFlag{Name: "type", OnlyOnce: true, Destination: &commitType, Required: true, Usage: "Type of change (e.g., feat, fix, docs)"},
+			&cli.StringFlag{Name: "scope", OnlyOnce: true, Destination: &scope, Usage: "Optional scope of the change"},
+			&cli.StringFlag{Name: "title", OnlyOnce: true, Destination: &title, Required: true, Usage: "Short description of the change"},
+			&cli.StringFlag{Name: "body", OnlyOnce: true, Destination: &body, Usage: "Optional longer description"},
+			&cli.StringFlag{Name: "footer", OnlyOnce: true, Destination: &footer, Usage: "Optional footer (e.g., breaking changes, issue refs)"},
 		},

34-39: Remove duplicate validation.

The validation for commitType and title is redundant since BuildCommit already validates these fields (lines 13-19 in internal/conventional/build_commit.go). Removing this duplicate code simplifies maintenance and follows the single responsibility principle.

Apply this diff to remove duplicate validation:

 		Action: func(_ context.Context, _ *cli.Command) error {
-			if commitType == "" {
-				return fmt.Errorf("%w: commitType must be provided", ErrInvalidFlag)
-			}
-			if title == "" {
-				return fmt.Errorf("%w: title must be provided", ErrInvalidFlag)
-			}
-
 			commit, err := conventional.BuildCommit(&conventional.Commit{

Alternatively, if you prefer validation at the CLI layer, consider marking the flags as Required: true (see previous comment) and removing validation from BuildCommit instead.


52-52: Use fmt.Println instead of log.Println for output.

Using log.Println adds timestamp and prefix information to the output, which is not appropriate for displaying the generated commit message. The output should be clean text that can be piped or copied.

Apply this diff to fix the output:

-			log.Println(commit)
+			fmt.Println(commit)

You can also remove the unused log import after this change:

 import (
 	"context"
 	"errors"
 	"fmt"
-	"log"
 
 	"github.com/urfave/cli/v3"
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5761ea9 and ecfc352.

📒 Files selected for processing (6)
  • .coderabbit.yaml (1 hunks)
  • .lefthook.yml (1 hunks)
  • cmd/commands.go (1 hunks)
  • cmd/commit.go (1 hunks)
  • internal/conventional/build_commit.go (1 hunks)
  • internal/conventional/commit.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
cmd/commit.go (2)
internal/conventional/build_commit.go (1)
  • BuildCommit (10-36)
internal/conventional/commit.go (1)
  • Commit (4-10)
internal/conventional/build_commit.go (1)
internal/conventional/commit.go (1)
  • Commit (4-10)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build
  • GitHub Check: Analyze (go)
🔇 Additional comments (3)
.lefthook.yml (1)

39-48: LGTM! Good pre-commit hook structure.

The nested group structure with sequential execution ensures that formatting is applied before linting runs, and stage_fixed: true automatically stages any formatting changes. This is a clean and effective approach.

.coderabbit.yaml (1)

1-25: LGTM! Valid CodeRabbit configuration.

The configuration settings are all valid according to the schema and establish a reasonable automated review workflow with pre-merge title checks enforced as errors.

cmd/commands.go (1)

7-10: LGTM! Clean integration of the new command.

The commit command is properly added to the commands array, following the existing pattern.

Change footer for issue and breaking in data structure,
rework message generation, add more params to flags
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: 1

🧹 Nitpick comments (2)
cmd/commit.go (1)

28-31: Consider simplifying stdout error handling.

While not incorrect, checking the error from fmt.Println when writing to stdout is overly defensive. In practice, writing to stdout rarely fails, and the application would likely have bigger problems if it did.

If you prefer simpler code, you could use:

-			_, err = fmt.Println(commitMessage)
-			if err != nil {
-				return fmt.Errorf("error printing built commit message: %w", err)
-			}
-
-			return nil
+			fmt.Println(commitMessage)
+			return nil

However, the current error handling is also acceptable if you prefer defensive programming.

internal/conventional/message.go (1)

47-69: Consider simplifying the footer assembly logic.

The current implementation is functionally correct and handles all edge cases properly. However, the logic is quite complex, especially lines 58-66, which makes it harder to understand and maintain.

Here's a clearer approach that builds the footer in logical order:

 func buildFooter(commit *Commit) string {
-	footer := ""
+	var parts []string
 
+	if commit.Body != "" {
+		parts = append(parts, commit.Body)
+	}
+
 	if commit.BreakingChange != "" {
-		footer += newLine + "BREAKING CHANGE: " + commit.BreakingChange
+		parts = append(parts, "BREAKING CHANGE: "+commit.BreakingChange)
 	}
 
 	if commit.Issue != "" {
-		footer += newLine + "Issue: " + commit.Issue
+		parts = append(parts, "Issue: "+commit.Issue)
 	}
 
-	if commit.Body != "" {
-		if footer != "" {
-			footer = newLine + commit.Body + newLine + footer + newLine
-		} else {
-			footer = newLine + commit.Body + newLine
-		}
-	} else if footer != "" {
-		footer += newLine
+	if len(parts) == 0 {
+		return ""
 	}
 
-	return footer
+	return newLine + strings.Join(parts, newLine+newLine) + newLine
 }

This approach:

  • Collects all parts in order (body, breaking change, issue)
  • Joins them with double newlines (blank line between sections)
  • Adds leading and trailing newlines
  • Is easier to understand and modify

Note: You'll need to add "strings" to the imports.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ecfc352 and 2a54c0d.

📒 Files selected for processing (3)
  • cmd/commit.go (1 hunks)
  • internal/conventional/commit.go (1 hunks)
  • internal/conventional/message.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
cmd/commit.go (2)
internal/conventional/commit.go (1)
  • Commit (6-19)
internal/conventional/message.go (1)
  • BuildCommitMessage (16-29)
internal/conventional/message.go (1)
internal/conventional/commit.go (1)
  • Commit (6-19)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (6)
internal/conventional/commit.go (1)

3-20: LGTM!

The Commit struct is well-designed with clear documentation and appropriate field types for representing Conventional Commit components.

cmd/commit.go (2)

38-83: LGTM!

The flag definitions are well-structured with appropriate required/optional markings, clear usage descriptions, and proper pointer destinations.


13-13: Remove unused error variable.

ErrInvalidFlag is declared but never used in this file. The urfave/cli framework handles required flag validation automatically, making this error variable unnecessary.

Apply this diff to remove the unused variable:

-var ErrInvalidFlag = errors.New("invalid flag")
-

Likely an incorrect or invalid review comment.

internal/conventional/message.go (3)

8-13: LGTM!

The constant and error variable are well-defined. The newLine constant is used consistently throughout the file, which aids maintainability.


15-29: LGTM!

The validation logic correctly enforces required fields (type and title) per the Conventional Commits specification, and error messages provide clear context.


31-45: LGTM!

The header formatting correctly implements the Conventional Commits specification with proper handling of optional scope and breaking change marker.

@coderabbitai
Copy link

coderabbitai bot commented Nov 26, 2025

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

CodeRabbit commands

These commands are invoked using PR/Issue 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 evaluate custom pre-merge check --instructions <custom-checks-instructions> --name <custom-checks-title> [--mode <error|warning>] to validate the custom pre-merge checks instructions. Defaults to error when --mode is omitted.
    • @coderabbitai ignore pre-merge checks to override pre-merge checks and get an approval on PR.
    • @coderabbitai run pre-merge checks to run pre-merge checks on the pull request.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve to 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 or @coderabbit 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.

Status, support, documentation and community

  • Visit our status page to check the current availability of CodeRabbit.
  • Create a ticket on our support page for assistance with any issues or questions.
  • Visit our documentation site for detailed information on how to use CodeRabbit.
  • Join our Discord community to connect with other users and get help from the community.
  • 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: 0

🧹 Nitpick comments (2)
internal/conventional/message_test.go (2)

10-16: Minor style note: simplify type declaration.

The type declaration uses parentheses for a single type, which is typically reserved for grouping multiple types. Consider simplifying to:

-type (
-	testCases struct {
-		commitData *Commit
-		err        error
-		result     string
-	}
-)
+type testCases struct {
+	commitData *Commit
+	err        error
+	result     string
+}

98-110: Consider more descriptive test names.

The tests use numeric indices (strconv.Itoa(i)) for naming, which makes it harder to identify failing tests at a glance. Consider adding descriptive names to each test case and using them for t.Run().

Example:

type testCases struct {
    name       string
    commitData *Commit
    err        error
    result     string
}

// Then in the test:
t.Run(tt.name, func(t *testing.T) {
    // ...
})
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2a54c0d and 6c8ae62.

📒 Files selected for processing (2)
  • cmd/commit.go (1 hunks)
  • internal/conventional/message_test.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
cmd/commit.go (2)
internal/conventional/commit.go (1)
  • Commit (6-19)
internal/conventional/message.go (1)
  • BuildCommitMessage (16-29)
internal/conventional/message_test.go (2)
internal/conventional/commit.go (1)
  • Commit (6-19)
internal/conventional/message.go (2)
  • ErrRequiredPartNotPreset (13-13)
  • BuildCommitMessage (16-29)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Analyze (go)
  • GitHub Check: build
🔇 Additional comments (3)
cmd/commit.go (2)

15-36: LGTM! Previous shadowing issue resolved.

The variable shadowing issue from the previous review has been fixed. The code now uses distinct variable names (commitData for the struct, message for the built string), making it clear and maintainable. The Action function correctly builds and prints the commit message with appropriate error handling.


38-83: LGTM!

The flag definitions are well-structured and correctly map to the Commit struct fields. The required flags (type and title) align with the validation in BuildCommitMessage, and the usage descriptions are clear and helpful.

internal/conventional/message_test.go (1)

18-96: LGTM!

The test cases provide comprehensive coverage of the BuildCommitMessage function, including:

  • Various combinations of optional fields (scope, body, issue, breaking changes)
  • Error cases for missing required fields (type and title)

The expected output strings correctly follow the conventional commit format.

Repository owner deleted a comment from coderabbitai bot Nov 26, 2025
@isokolovskii isokolovskii enabled auto-merge (rebase) November 26, 2025 19:22
@isokolovskii isokolovskii merged commit 6b290dd into main Nov 26, 2025
9 of 11 checks passed
@isokolovskii isokolovskii deleted the feature/build-commit branch November 26, 2025 19:23
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