refactor: put StripTagMeta into formatter package

Avoid circular import.
This commit is contained in:
2022-01-19 10:40:14 +01:00
parent 7a66a90ecb
commit f9a2c1d58f
7 changed files with 31 additions and 28 deletions

View File

@ -166,7 +166,7 @@ func (r Recipe) UpdateLabel(pattern, serviceName, label string) error {
func (r Recipe) UpdateTag(image, tag string) (bool, error) {
pattern := fmt.Sprintf("%s/%s/compose**yml", config.RECIPES_DIR, r.Name)
image = StripTagMeta(image)
image = formatter.StripTagMeta(image)
ok, err := compose.UpdateTag(pattern, image, tag, r.Name)
if err != nil {
@ -983,7 +983,7 @@ func GetRecipeVersions(recipeName, registryUsername, registryPassword string) (R
path := reference.Path(img)
path = StripTagMeta(path)
path = formatter.StripTagMeta(path)
var tag string
switch img.(type) {
@ -1050,25 +1050,6 @@ func GetRecipeCatalogueVersions(recipeName string, catl RecipeCatalogue) ([]stri
return versions, nil
}
// StripTagMeta strips front-matter image tag data that we don't need for parsing.
func StripTagMeta(image string) string {
originalImage := image
if strings.Contains(image, "docker.io") {
image = strings.Split(image, "/")[1]
}
if strings.Contains(image, "library") {
image = strings.Split(image, "/")[1]
}
if originalImage != image {
logrus.Debugf("stripped %s to %s for parsing", originalImage, image)
}
return image
}
// EnsureCatalogue ensures that the catalogue is cloned locally & present.
func EnsureCatalogue() error {
catalogueDir := path.Join(config.ABRA_DIR, "catalogue")