Skip to content

Commit

Permalink
feat: add flag to control tag annotation (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoxys authored Oct 18, 2023
1 parent 53af856 commit aafeb36
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
8 changes: 6 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,15 @@ func (g GitSV) Commit(header, body, footer string) error {
}

// Tag create a git tag.
func (g GitSV) Tag(version semver.Version) (string, error) {
func (g GitSV) Tag(version semver.Version, annotate bool) (string, error) {
tag := fmt.Sprintf(*g.Config.Tag.Pattern, version.Major(), version.Minor(), version.Patch())
tagMsg := fmt.Sprintf("Version %d.%d.%d", version.Major(), version.Minor(), version.Patch())

tagCommand := exec.Command("git", "tag", "-a", tag, "-m", tagMsg)
tagCommand := exec.Command("git", "tag", tag)
if annotate {
tagCommand = exec.Command("git", "tag", "-a", tag, "-m", tagMsg)
}

if out, err := tagCommand.CombinedOutput(); err != nil {
return tag, combinedOutputErr(err, out)
}
Expand Down
15 changes: 13 additions & 2 deletions app/commands/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ import (
"github.com/urfave/cli/v2"
)

func TagHandler(g app.GitSV) cli.ActionFunc {
func TagFlags(settings *app.TagSettings) []cli.Flag {
return []cli.Flag{
&cli.BoolFlag{
Name: "annotate",
Aliases: []string{"a"},
Usage: "ignore size parameter, get changelog for every tag",
Destination: &settings.Annotate,
},
}
}

func TagHandler(g app.GitSV, settings *app.TagSettings) cli.ActionFunc {
return func(c *cli.Context) error {
lastTag := g.LastTag()

Expand All @@ -30,7 +41,7 @@ func TagHandler(g app.GitSV) cli.ActionFunc {
return nil
}

tagname, err := g.Tag(*nextVer)
tagname, err := g.Tag(*nextVer, settings.Annotate)
if err != nil {
return fmt.Errorf("error generating tag version: %s: %w", nextVer.String(), err)
}
Expand Down
5 changes: 5 additions & 0 deletions app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Settings struct {
ReleaseNotesSettings ReleaseNotesSettings
CommitNotesSettings CommitNotesSettings
CommitLogSettings CommitLogSettings
TagSettings TagSettings
}

type ChangelogSettings struct {
Expand Down Expand Up @@ -48,6 +49,10 @@ type CommitLogSettings struct {
End string
}

type TagSettings struct {
Annotate bool
}

// Config cli yaml config.
type Config struct {
Version string `yaml:"version"`
Expand Down
3 changes: 2 additions & 1 deletion cmd/git-sv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ When flag range is "date", if "end" is YYYY-MM-DD the range will be inclusive.`,
Name: "tag",
Aliases: []string{"tg"},
Usage: "generate tag with version based on git commit messages",
Action: commands.TagHandler(gsv),
Action: commands.TagHandler(gsv, &gsv.Settings.TagSettings),
Flags: commands.TagFlags(&gsv.Settings.TagSettings),
},
{
Name: "commit",
Expand Down

0 comments on commit aafeb36

Please sign in to comment.