refactor: code style / error handling improvements
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
8635922b9f
commit
d0a30f6b7b
|
@ -136,7 +136,7 @@ A new catalogue copy can be published to the recipes repository by passing the
|
||||||
|
|
||||||
isClean, err := gitPkg.IsClean(rm.Name)
|
isClean, err := gitPkg.IsClean(rm.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !isClean {
|
if !isClean {
|
||||||
|
@ -175,6 +175,9 @@ A new catalogue copy can be published to the recipes repository by passing the
|
||||||
}
|
}
|
||||||
|
|
||||||
features, category, err := catalogue.GetRecipeFeaturesAndCategory(recipeMeta.Name)
|
features, category, err := catalogue.GetRecipeFeaturesAndCategory(recipeMeta.Name)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
catl[recipeMeta.Name] = catalogue.RecipeMeta{
|
catl[recipeMeta.Name] = catalogue.RecipeMeta{
|
||||||
Name: recipeMeta.Name,
|
Name: recipeMeta.Name,
|
||||||
|
|
|
@ -374,18 +374,18 @@ func ReadReposMetadata() (RepoCatalogue, error) {
|
||||||
return reposMeta, nil
|
return reposMeta, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetStringInBetween(str string, start string, end string) (result string) {
|
func GetStringInBetween(str, start, end string) (result string, err error) {
|
||||||
// GetStringInBetween returns empty string if no start or end string found
|
// GetStringInBetween returns empty string if no start or end string found
|
||||||
s := strings.Index(str, start)
|
s := strings.Index(str, start)
|
||||||
if s == -1 {
|
if s == -1 {
|
||||||
return
|
return "", fmt.Errorf("marker string '%s' not found", start)
|
||||||
}
|
}
|
||||||
s += len(start)
|
s += len(start)
|
||||||
e := strings.Index(str[s:], end)
|
e := strings.Index(str[s:], end)
|
||||||
if e == -1 {
|
if e == -1 {
|
||||||
return
|
return "", fmt.Errorf("end marker '%s' not found", end)
|
||||||
}
|
}
|
||||||
return str[s : s+e]
|
return str[s : s+e], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetImageMetadata(imageRowString string) (image, error) {
|
func GetImageMetadata(imageRowString string) (image, error) {
|
||||||
|
@ -394,11 +394,11 @@ func GetImageMetadata(imageRowString string) (image, error) {
|
||||||
imgFields := strings.Split(imageRowString, ",")
|
imgFields := strings.Split(imageRowString, ",")
|
||||||
|
|
||||||
for i, elem := range imgFields {
|
for i, elem := range imgFields {
|
||||||
imgFields[i] = strings.TrimSpace(elem)
|
imgFields[i] = strings.TrimSpace(elem)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(imgFields) < 3 {
|
if len(imgFields) < 3 {
|
||||||
logrus.Warnf("Image string has incorrect format: %s", imageRowString)
|
logrus.Warnf("image string has incorrect format: %s", imageRowString)
|
||||||
return img, nil
|
return img, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,11 +407,17 @@ func GetImageMetadata(imageRowString string) (image, error) {
|
||||||
|
|
||||||
imgString := imgFields[0]
|
imgString := imgFields[0]
|
||||||
|
|
||||||
img.Image = GetStringInBetween(imgString, "[", "]")
|
imageName, err := GetStringInBetween(imgString, "[", "]")
|
||||||
img.URL = GetStringInBetween(imgString, "(", ")")
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
img.Image = imageName
|
||||||
|
|
||||||
logrus.Debugf("Image: %s", img.Image)
|
imageURL, err := GetStringInBetween(imgString, "(", ")")
|
||||||
logrus.Debugf("URL: %s", img.URL)
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
img.URL = imageURL
|
||||||
|
|
||||||
return img, nil
|
return img, nil
|
||||||
}
|
}
|
||||||
|
@ -430,14 +436,19 @@ func GetRecipeFeaturesAndCategory(recipeName string) (features, string, error) {
|
||||||
return feat, category, err
|
return feat, category, err
|
||||||
}
|
}
|
||||||
|
|
||||||
readmeLines := strings.Split( // Array item from lines
|
readmeMetadata, err := GetStringInBetween( // Find text between delimiters
|
||||||
strings.ReplaceAll( // Remove \t tabs
|
string(readmeFS),
|
||||||
GetStringInBetween( // Find text between delimiters
|
"<!-- metadata -->", "<!-- endmetadata -->",
|
||||||
string(readmeFS),
|
)
|
||||||
"<!-- metadata -->", "<!-- endmetadata -->",
|
if err != nil {
|
||||||
), "\t", "",
|
logrus.Fatal(err)
|
||||||
),
|
}
|
||||||
"\n")
|
|
||||||
|
readmeLines := strings.Split( // Array item from lines
|
||||||
|
strings.ReplaceAll( // Remove \t tabs
|
||||||
|
readmeMetadata, "\t", "",
|
||||||
|
),
|
||||||
|
"\n")
|
||||||
|
|
||||||
for _, val := range readmeLines {
|
for _, val := range readmeLines {
|
||||||
if strings.Contains(val, "**Category**") {
|
if strings.Contains(val, "**Category**") {
|
||||||
|
|
Loading…
Reference in New Issue