From a7f7cfbc65e87db88214529b3d19e8e105e19f1f Mon Sep 17 00:00:00 2001 From: RaviAnand Mohabir Date: Thu, 11 Jul 2024 16:55:20 +0200 Subject: [PATCH] fix: :bug: use latest instead of last (oldest) tag --- card.json | 25 +++++++++++++++++++++++++ plugin/util.go | 22 ++++++++-------------- 2 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 card.json diff --git a/card.json b/card.json new file mode 100644 index 0000000..9bb331c --- /dev/null +++ b/card.json @@ -0,0 +1,25 @@ +{ + "type": "AdaptiveCard", + "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", + "version": "1.5", + "body": [ + { + "type": "TextBlock", + "text": "${title}", + "wrap": true, + "style": "heading" + }, + { + "type": "TextBlock", + "text": "Tag: ${tag}", + "wrap": true + } + ], + "actions": [ + { + "type": "Action.OpenUrl", + "title": "View release", + "url": "${url}" + } + ] +} diff --git a/plugin/util.go b/plugin/util.go index 0f4255e..4ae7ced 100644 --- a/plugin/util.go +++ b/plugin/util.go @@ -77,25 +77,19 @@ func getLatestGitTag(options ...GetLatestGitTagOption) (tag string, err error) { return "", fmt.Errorf("error getting git tag refs %w", err) } - for { - r, err := tagRefs.Next() + ref, err := tagRefs.Next() - 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 == io.EOF { + return tag, fmt.Errorf("couldn't find any git tags %w", err) } - if tag == "" { - return tag, fmt.Errorf("couldn't find any git tags") + if err != nil { + return tag, fmt.Errorf("error iterating tags %w", err) } + parts := strings.Split(string(ref.Name()), "/") + tag = strings.Join(parts[2:], "/") + return }