-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit.go
More file actions
83 lines (74 loc) · 1.9 KB
/
commit.go
File metadata and controls
83 lines (74 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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 {
commitData := conventional.Commit{}
return &cli.Command{
Name: "commit",
Usage: "Create Conventional Commit",
Flags: flags(&commitData),
Action: func(_ context.Context, _ *cli.Command) error {
message, err := conventional.BuildCommitMessage(&commitData)
if err != nil {
return fmt.Errorf("error building commit: %w", err)
}
_, err = fmt.Println(message)
if err != nil {
return fmt.Errorf("error printing built commit message: %w", err)
}
return nil
},
}
}
func flags(commitData *conventional.Commit) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "type",
OnlyOnce: true,
Destination: &commitData.Type,
Required: true,
Usage: "Type of change (e.g., feat, fix, docs)",
},
&cli.StringFlag{
Name: "scope",
OnlyOnce: true,
Destination: &commitData.Scope,
Required: false,
Usage: "Optional context for the change (e.g., api, cli)",
},
&cli.StringFlag{
Name: "title",
OnlyOnce: true,
Destination: &commitData.Title,
Required: true,
Usage: "Short description of changes",
},
&cli.StringFlag{
Name: "body",
OnlyOnce: true,
Destination: &commitData.Body,
Required: false,
Usage: "Optional longer description of the change",
},
&cli.StringFlag{
Name: "breaking",
OnlyOnce: true,
Destination: &commitData.BreakingChange,
Required: false,
Usage: "Optional description of breaking changes introduced with commit",
},
&cli.StringFlag{
Name: "issue",
OnlyOnce: true,
Destination: &commitData.Issue,
Required: false,
Usage: "Optional issue number",
},
}
}