Skip to content

Commit 0ba3653

Browse files
committed
feat: add the abilty to set a conventional commit scope
1 parent d0a03f5 commit 0ba3653

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

internal/app/gitops-commit/cmd/run.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ func newRunCommand() *cobra.Command {
1212
c := cobra.Command{
1313
Use: "run",
1414
RunE: func(cmd *cobra.Command, args []string) error {
15+
commitScope := cmd.Flag("commit-scope").Value.String()
1516
key := cmd.Flag("key").Value.String()
1617
email := cmd.Flag("email").Value.String()
1718
newVersion := cmd.Flag("version").Value.String()
@@ -38,15 +39,17 @@ func newRunCommand() *cobra.Command {
3839
defer c()
3940

4041
return gitops.DeployVersionHandler(gitops.DeployVersionCommand{
41-
GitOptions: *options,
42-
Repository: repo,
43-
Notation: notation,
44-
File: file,
45-
Version: newVersion,
42+
GitOptions: *options,
43+
Repository: repo,
44+
Notation: notation,
45+
File: file,
46+
Version: newVersion,
47+
CommitScope: commitScope,
4648
})
4749
},
4850
}
4951

52+
c.Flags().String("commit-scope", "", "If you want to add a commit scope inline with conventional commits")
5053
c.Flags().String("notation", "", "The yaml path in dot notation i.e. image.tag")
5154
c.Flags().String("email", "", "The email address of the commit")
5255
c.Flags().String("version", "", "The semver version you want to deploy i.e. v1.1.2")

internal/pkg/gitops/handler.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import (
66
)
77

88
type DeployVersionCommand struct {
9-
GitOptions GitOptions
10-
Repository string
11-
Notation string
12-
File string
13-
Version string
9+
GitOptions GitOptions
10+
Repository string
11+
Notation string
12+
File string
13+
Version string
14+
CommitScope string
1415
}
1516

1617
func DeployVersionHandler(c DeployVersionCommand) error {
@@ -38,5 +39,11 @@ func DeployVersionHandler(c DeployVersionCommand) error {
3839
return fmt.Errorf("cannot write new version: %w", err)
3940
}
4041

41-
return PushVersion(r, &c.GitOptions, c.File, fmt.Sprintf("ci: update tag to %s", c.Version))
42+
message := fmt.Sprintf("ci: update tag to %s", c.Version)
43+
44+
if len(c.CommitScope) > 0 {
45+
message = fmt.Sprintf("ci(%s): update tag to %s", c.CommitScope, c.Version)
46+
}
47+
48+
return PushVersion(r, &c.GitOptions, c.File, message)
4249
}

0 commit comments

Comments
 (0)