feat: ✨ use tagger.when to find latest tag
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
e65c52c67c
commit
6c787535a8
@ -11,7 +11,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/plumbing/transport/client"
|
||||
@ -62,28 +62,34 @@ func FetchTags() func(repo *git.Repository) error {
|
||||
}
|
||||
}
|
||||
|
||||
func getLatestGitTag(options ...GetLatestGitTagOption) (tag string, err error) {
|
||||
r, err := git.PlainOpen(".")
|
||||
func getLatestGitTag(options ...GetLatestGitTagOption) (string, error) {
|
||||
var (
|
||||
tag string
|
||||
tagDate *time.Time
|
||||
err error
|
||||
)
|
||||
|
||||
repo, err := git.PlainOpen(".")
|
||||
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error opening git repo at %s: %w", ".", err)
|
||||
}
|
||||
|
||||
for _, opt := range options {
|
||||
err := opt(r)
|
||||
err := opt(repo)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
tagRefs, err := r.Tags()
|
||||
tags, err := repo.TagObjects()
|
||||
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error getting git tag refs %w", err)
|
||||
return "", fmt.Errorf("error getting git tags %w", err)
|
||||
}
|
||||
|
||||
for {
|
||||
r, err := tagRefs.Next()
|
||||
t, err := tags.Next()
|
||||
|
||||
if err == io.EOF {
|
||||
break
|
||||
@ -93,15 +99,19 @@ func getLatestGitTag(options ...GetLatestGitTagOption) (tag string, err error) {
|
||||
return "", fmt.Errorf("error iterating tags %w", err)
|
||||
}
|
||||
|
||||
parts := strings.Split(string(r.Name()), "/")
|
||||
tag = strings.Join(parts[2:], "/")
|
||||
if tagDate != nil && t.Tagger.When.Sub(*tagDate) > 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
tagDate = &t.Tagger.When
|
||||
tag = t.Name
|
||||
}
|
||||
|
||||
if tag == "" {
|
||||
return tag, fmt.Errorf("couldn't find any git tags")
|
||||
}
|
||||
|
||||
return
|
||||
return tag, err
|
||||
}
|
||||
|
||||
func writeCard(path, schema string, card interface{}) {
|
||||
|
Loading…
Reference in New Issue
Block a user