-
Notifications
You must be signed in to change notification settings - Fork 0
Basic conventional commit builder #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
88b3e63
feat(commit): basic conventional commit builder
isokolovskii e0652c6
chore(lefthook): modifications to lefthook config
isokolovskii ecfc352
feat: coderabbit for AI review
isokolovskii c94e211
docs(commit): add docs to commit data structure
isokolovskii 2a54c0d
refactor(commit): redo commit message builder
isokolovskii 6c8ae62
test(commit): tests for commit message builder
isokolovskii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| reviews: | ||
| profile: chill | ||
| request_changes_workflow: true | ||
| high_level_summary: true | ||
| review_status: true | ||
| commit_status: true | ||
| collapse_walkthrough: true | ||
| auto_assign_reviewers: true | ||
| in_progress_fortune: false | ||
| poem: false | ||
| auto_review: | ||
| enabled: true | ||
| auto_incremental_review: true | ||
| ignore_title_keywords: | ||
| - "WIP" | ||
| - "DO NOT MERGE" | ||
| drafts: false | ||
| base_branches: | ||
| - "main" | ||
| pre_merge_checks: | ||
| title: | ||
| mode: error | ||
| requirements: 'Title should be concise and descriptive, ideally under 72 characters. Use imperative mood (e.g., "Add database for snippets").' | ||
| chat: | ||
| auto_reply: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,4 +6,5 @@ import ( | |
|
|
||
| var commands = []*cli.Command{ | ||
| version(), | ||
| commit(), | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| "github.com/urfave/cli/v3" | ||
|
|
||
| "github.com/isokolovskii/commitizen/internal/conventional" | ||
| ) | ||
|
|
||
| var ErrInvalidFlag = errors.New("invalid flag") | ||
|
|
||
| func commit() *cli.Command { | ||
| commit := conventional.Commit{} | ||
|
|
||
| return &cli.Command{ | ||
| Name: "commit", | ||
| Usage: "Create Conventional Commit", | ||
| Flags: flags(&commit), | ||
| Action: func(_ context.Context, _ *cli.Command) error { | ||
| commit, err := conventional.BuildCommitMessage(&commit) | ||
| if err != nil { | ||
| return fmt.Errorf("error building commit: %w", err) | ||
| } | ||
|
|
||
| _, err = fmt.Println(commit) | ||
| if err != nil { | ||
| return fmt.Errorf("error printing built commit message: %w", err) | ||
| } | ||
|
|
||
| return nil | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func flags(commit *conventional.Commit) []cli.Flag { | ||
| return []cli.Flag{ | ||
| &cli.StringFlag{ | ||
| Name: "type", | ||
| OnlyOnce: true, | ||
| Destination: &commit.Type, | ||
| Required: true, | ||
| Usage: "Type of change (e.g., feat, fix, docs)", | ||
| }, | ||
| &cli.StringFlag{ | ||
| Name: "scope", | ||
| OnlyOnce: true, | ||
| Destination: &commit.Scope, | ||
| Required: false, | ||
| Usage: "Optional context for the change (e.g., api, cli)", | ||
| }, | ||
| &cli.StringFlag{ | ||
| Name: "title", | ||
| OnlyOnce: true, | ||
| Destination: &commit.Title, | ||
| Required: true, | ||
| Usage: "Short description of changes", | ||
| }, | ||
| &cli.StringFlag{ | ||
| Name: "body", | ||
| OnlyOnce: true, | ||
| Destination: &commit.Body, | ||
| Required: false, | ||
| Usage: "Optional longer description of the change", | ||
| }, | ||
| &cli.StringFlag{ | ||
| Name: "breaking", | ||
| OnlyOnce: true, | ||
| Destination: &commit.BreakingChange, | ||
| Required: false, | ||
| Usage: "Optional description of breaking changes introduced with commit", | ||
| }, | ||
| &cli.StringFlag{ | ||
| Name: "issue", | ||
| OnlyOnce: true, | ||
| Destination: &commit.Issue, | ||
| Required: false, | ||
| Usage: "Optional issue number", | ||
| }, | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package conventional | ||
|
|
||
| type ( | ||
| // Commit represents the components of a Conventional Commit message. | ||
| // See https://www.conventionalcommits.org/ for the specification. | ||
| 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 | ||
| // Breaking change description. | ||
| BreakingChange string | ||
| // Issue number. | ||
| Issue string | ||
| } | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| package conventional | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| ) | ||
|
|
||
| const ( | ||
| newLine = "\n" | ||
| ) | ||
|
|
||
| // ErrRequiredPartNotPreset - error used for missing required conventional commit fields. | ||
| var ErrRequiredPartNotPreset = errors.New("required part not present") | ||
|
|
||
| // BuildCommitMessage - builds conventional commit message. | ||
| func BuildCommitMessage(commit *Commit) (string, error) { | ||
| if commit.Type == "" { | ||
| return "", fmt.Errorf("%w: type", ErrRequiredPartNotPreset) | ||
| } | ||
|
|
||
| if commit.Title == "" { | ||
| return "", fmt.Errorf("%w: title", ErrRequiredPartNotPreset) | ||
| } | ||
|
|
||
| header := buildHeader(commit) | ||
| footer := buildFooter(commit) | ||
|
|
||
| return header + newLine + footer, nil | ||
| } | ||
|
|
||
| func buildHeader(commit *Commit) string { | ||
| header := commit.Type | ||
|
|
||
| if commit.Scope != "" { | ||
| header = fmt.Sprintf("%s(%s)", header, commit.Scope) | ||
| } | ||
|
|
||
| if commit.BreakingChange != "" { | ||
| header += "!" | ||
| } | ||
|
|
||
| header += ": " + commit.Title | ||
|
|
||
| return header | ||
| } | ||
|
|
||
| func buildFooter(commit *Commit) string { | ||
| footer := "" | ||
|
|
||
| if commit.BreakingChange != "" { | ||
| footer += newLine + "BREAKING CHANGE: " + commit.BreakingChange | ||
| } | ||
|
|
||
| if commit.Issue != "" { | ||
| footer += newLine + "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 | ||
| } | ||
|
|
||
| return footer | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.