refactor(recipe): move Tags method to new struct

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

View File

@ -97,7 +97,7 @@ your SSH keys configured on your account.
}
}
tags, err := recipe.Tags()
tags, err := r.Tags()
if err != nil {
log.Fatal(err)
}

View File

@ -59,7 +59,7 @@ local file system.
mainAppVersion := imagesTmp[mainApp]
tags, err := recipe.Tags()
tags, err := r.Tags()
if err != nil {
log.Fatal(err)
}

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
}

View File

@ -141,32 +141,6 @@ func (r Recipe) Dir() string {
return path.Join(config.RECIPES_DIR, r.Name)
}
// Tags list the recipe tags
func (r Recipe) 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
}
// Get retrieves a recipe.
func Get(recipeName string, offline bool) (Recipe, error) {
r := Get2(recipeName)