refactor(recipe): move Tags method to new struct

This commit is contained in:
2024-07-08 11:45:47 +02:00
parent 6f90fc3025
commit eb62e0ecc3
4 changed files with 28 additions and 28 deletions

View File

@ -262,3 +262,29 @@ func (r Recipe2) Push(dryRun bool) error {
return nil
}
// Tags list the recipe tags
func (r Recipe2) Tags() ([]string, error) {
var tags []string
repo, err := git.PlainOpen(r.Dir)
if err != nil {
return tags, err
}
gitTags, err := repo.Tags()
if err != nil {
return tags, err
}
if err := gitTags.ForEach(func(ref *plumbing.Reference) (err error) {
tags = append(tags, strings.TrimPrefix(string(ref.Name()), "refs/tags/"))
return nil
}); err != nil {
return tags, err
}
log.Debugf("detected %s as tags for recipe %s", strings.Join(tags, ", "), r.Name)
return tags, nil
}