diff --git a/main.go b/main.go index 7c1a311..c95e9f6 100644 --- a/main.go +++ b/main.go @@ -24,6 +24,7 @@ func init() { tagRegex *string = flag.String("tag-regex", "", "Regex pattern to look for tag in tag-file") notes *string = flag.String("notes", "", "Notes to use in release") notesFile *string = flag.String("notes-file", "", "File to use for release notes") + logLevel *string = flag.String("log-level", "", "Level for logging") ) flag.Parse() @@ -47,6 +48,10 @@ func init() { if notesFile != nil && *notesFile != "" { args.NotesFile = *notesFile } + + if logLevel != nil && *logLevel != "" { + args.Level = *logLevel + } } func main() { diff --git a/plugin/plugin.go b/plugin/plugin.go index e809099..6de7ed8 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -96,6 +96,8 @@ func Exec(ctx context.Context, args Args) error { if err != nil { return fmt.Errorf("error getting git tag %w", err) } + + log.WithField("tag", tag).Info("Fetched latest git tag") } else if args.TagFile != "" { log.WithField("file", args.TagFile).Info("Reading tag from file") diff --git a/plugin/util.go b/plugin/util.go index ae5d617..143d9e3 100644 --- a/plugin/util.go +++ b/plugin/util.go @@ -9,7 +9,6 @@ import ( "encoding/json" "fmt" "io" - "log" "net/http" "os" "strings" @@ -17,6 +16,7 @@ import ( "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing/transport/client" githttp "github.com/go-git/go-git/v5/plumbing/transport/http" + log "github.com/sirupsen/logrus" ) type GetLatestGitTagOption func(repo *git.Repository) error @@ -50,7 +50,7 @@ func SetBasicAuth(username, password string) func(repo *git.Repository) error { func FetchTags() func(repo *git.Repository) error { return func(repo *git.Repository) error { - log.Println("Fetching latest git tags") + log.Info("Fetching latest git tags") err := repo.Fetch(&git.FetchOptions{Tags: git.AllTags}) @@ -82,19 +82,25 @@ func getLatestGitTag(options ...GetLatestGitTagOption) (tag string, err error) { return "", fmt.Errorf("error getting git tag refs %w", err) } - ref, err := tagRefs.Next() + for { + r, err := tagRefs.Next() - if err == io.EOF { - return tag, fmt.Errorf("couldn't find any git tags %w", err) + if err == io.EOF { + break + } + + if err != nil { + return "", fmt.Errorf("error iterating tags %w", err) + } + + parts := strings.Split(string(r.Name()), "/") + tag = strings.Join(parts[2:], "/") } - if err != nil { - return tag, fmt.Errorf("error iterating tags %w", err) + if tag == "" { + return tag, fmt.Errorf("couldn't find any git tags") } - parts := strings.Split(string(ref.Name()), "/") - tag = strings.Join(parts[2:], "/") - return }