From 3625bbe90c03ef4b5c819f547a6c1b3db98d66f2 Mon Sep 17 00:00:00 2001 From: RaviAnand Mohabir Date: Wed, 26 Jun 2024 16:09:18 +0200 Subject: [PATCH] feat: :sparkles: add option to fetch git tags when getting latest --- plugin/plugin.go | 7 ++++++- plugin/util.go | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/plugin/plugin.go b/plugin/plugin.go index daad73b..303562a 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -36,6 +36,7 @@ type Args struct { Notes string `envconfig:"PLUGIN_NOTES"` IsPrerelease bool `envconfig:"PLUGIN_IS_PRERELEASE"` SkipIfNoNotesFile bool `envconfig:"PLUGIN_SKIP_IF_NO_NOTES_FILE"` + FetchGitTags bool `envconfig:"PLUGIN_FETCH_GIT_TAGS" default:"true"` } type TitleTemplateCtx struct { @@ -74,7 +75,11 @@ func Exec(ctx context.Context, args Args) error { } if args.UseLatestGitTag { - tag, err = getLatestGitTag() + var options = make([]GetLatestGitTagOption, 0) + if args.FetchGitTags { + options = append(options, FetchTags) + } + tag, err = getLatestGitTag(options...) if err != nil { return fmt.Errorf("error getting git tag %w", err) diff --git a/plugin/util.go b/plugin/util.go index 41a48d1..a650931 100644 --- a/plugin/util.go +++ b/plugin/util.go @@ -13,7 +13,22 @@ import ( "os/exec" ) -func getLatestGitTag() (string, error) { +type GetLatestGitTagOption func() error + +var FetchTags = func() error { + err := exec.Command("git", "fetch", "--tags") + + return err.Err +} + +func getLatestGitTag(options ...GetLatestGitTagOption) (string, error) { + for _, opt := range options { + err := opt() + if err != nil { + return "", err + } + } + tag, err := exec.Command("git", "describe", "--tags", "--abbrev=0").Output() if err != nil {