Skip to content
25 changes: 25 additions & 0 deletions .coderabbit.yaml
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
17 changes: 8 additions & 9 deletions .lefthook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,15 @@ pre-commit:
- go.sum
stage_fixed: true
- name: lint & format
run: golangci-lint run ./...
glob: "*.go"
stage_fixed: true
- name: format markdown
glob: "*md"
run: go tool markdownfmt -w .
stage_fixed: true
- name: check release config
glob: ".goreleaser.yaml"
run: go tool goreleaser check
group:
parallel: false
jobs:
- name: format
run: golangci-lint fmt ./...
stage_fixed: true
- name: lint
run: golangci-lint run ./...

post-checkout:
parallel: false
Expand Down
1 change: 1 addition & 0 deletions cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ import (

var commands = []*cli.Command{
version(),
commit(),
}
57 changes: 57 additions & 0 deletions cmd/commit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package cmd

import (
"context"
"errors"
"fmt"
"log"

"github.com/urfave/cli/v3"

"github.com/isokolovskii/commitizen/internal/conventional"
)

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

func commit() *cli.Command {
var commitType string
var scope string
var title string
var body string
var footer string

return &cli.Command{
Name: "commit",
Usage: "Create Conventional Commit",
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},
},
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 mus be provided", ErrInvalidFlag)
}

commit, err := conventional.BuildCommit(&conventional.Commit{
Type: commitType,
Scope: scope,
Title: title,
Body: body,
Footer: footer,
})
if err != nil {
return fmt.Errorf("error building commit: %w", err)
}

log.Println(commit)

return nil
},
}
}
36 changes: 36 additions & 0 deletions internal/conventional/build_commit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package conventional

import (
"errors"
"fmt"
)

var ErrRequiredPartNotPreset = errors.New("required part not present")

func BuildCommit(commit *Commit) (string, error) {
result := commit.Type

if commit.Type == "" {
return "", fmt.Errorf("%w: type", ErrRequiredPartNotPreset)
}

if commit.Title == "" {
return "", fmt.Errorf("%w: title", ErrRequiredPartNotPreset)
}

if commit.Scope != "" {
result = fmt.Sprintf("%s(%s)", result, commit.Scope)
}

result = fmt.Sprintf("%s: %s", result, commit.Title)

if commit.Body != "" {
result = fmt.Sprintf("%s\n\n%s", result, commit.Body)
}

if commit.Footer != "" {
result = fmt.Sprintf("%s\n\n%s\n", result, commit.Footer)
}

return result, nil
}
11 changes: 11 additions & 0 deletions internal/conventional/commit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package conventional

type (
Commit struct {
Type string
Scope string
Title string
Body string
Footer string
}
)
Loading