From aafeb36d4a0395f23dd552f190da5745cb6aa339 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Wed, 18 Oct 2023 15:51:05 +0200 Subject: [PATCH] feat: add flag to control tag annotation (#13) --- app/app.go | 8 ++++++-- app/commands/tag.go | 15 +++++++++++++-- app/config.go | 5 +++++ cmd/git-sv/main.go | 3 ++- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/app/app.go b/app/app.go index 92bb78b..8ff60cc 100644 --- a/app/app.go +++ b/app/app.go @@ -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) } diff --git a/app/commands/tag.go b/app/commands/tag.go index 25980a9..c6fba46 100644 --- a/app/commands/tag.go +++ b/app/commands/tag.go @@ -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() @@ -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) } diff --git a/app/config.go b/app/config.go index 8291eeb..2484cc1 100644 --- a/app/config.go +++ b/app/config.go @@ -19,6 +19,7 @@ type Settings struct { ReleaseNotesSettings ReleaseNotesSettings CommitNotesSettings CommitNotesSettings CommitLogSettings CommitLogSettings + TagSettings TagSettings } type ChangelogSettings struct { @@ -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"` diff --git a/cmd/git-sv/main.go b/cmd/git-sv/main.go index 01f6f6a..c53b454 100644 --- a/cmd/git-sv/main.go +++ b/cmd/git-sv/main.go @@ -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",