0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-13 21:30:40 +00:00

feat: add flag to control tag annotation (#13)

This commit is contained in:
Robert Kaussow 2023-10-18 15:51:05 +02:00 committed by GitHub
parent 53af856cc5
commit aafeb36d4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 5 deletions

View File

@ -152,11 +152,15 @@ func (g GitSV) Commit(header, body, footer string) error {
} }
// Tag create a git tag. // 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()) 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()) 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 { if out, err := tagCommand.CombinedOutput(); err != nil {
return tag, combinedOutputErr(err, out) return tag, combinedOutputErr(err, out)
} }

View File

@ -9,7 +9,18 @@ import (
"github.com/urfave/cli/v2" "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 { return func(c *cli.Context) error {
lastTag := g.LastTag() lastTag := g.LastTag()
@ -30,7 +41,7 @@ func TagHandler(g app.GitSV) cli.ActionFunc {
return nil return nil
} }
tagname, err := g.Tag(*nextVer) tagname, err := g.Tag(*nextVer, settings.Annotate)
if err != nil { if err != nil {
return fmt.Errorf("error generating tag version: %s: %w", nextVer.String(), err) return fmt.Errorf("error generating tag version: %s: %w", nextVer.String(), err)
} }

View File

@ -19,6 +19,7 @@ type Settings struct {
ReleaseNotesSettings ReleaseNotesSettings ReleaseNotesSettings ReleaseNotesSettings
CommitNotesSettings CommitNotesSettings CommitNotesSettings CommitNotesSettings
CommitLogSettings CommitLogSettings CommitLogSettings CommitLogSettings
TagSettings TagSettings
} }
type ChangelogSettings struct { type ChangelogSettings struct {
@ -48,6 +49,10 @@ type CommitLogSettings struct {
End string End string
} }
type TagSettings struct {
Annotate bool
}
// Config cli yaml config. // Config cli yaml config.
type Config struct { type Config struct {
Version string `yaml:"version"` Version string `yaml:"version"`

View File

@ -116,7 +116,8 @@ When flag range is "date", if "end" is YYYY-MM-DD the range will be inclusive.`,
Name: "tag", Name: "tag",
Aliases: []string{"tg"}, Aliases: []string{"tg"},
Usage: "generate tag with version based on git commit messages", 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", Name: "commit",