Skip to content

Commit

Permalink
Generate correct PR name with params
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei-Predoiu committed Apr 16, 2024
1 parent 7f0c07d commit 0b355c6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion circleci/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func findNewestDockerVersion(currentVersion string, parameters *map[string]strin
imageName := current[0]
imageTag := current[1]

if param := extractParameterName(currentVersion); len(param) > 0 {
if param := ExtractParameterName(currentVersion); len(param) > 0 {
paramDefault, found := (*parameters)[param]
if !found {
log.Debug().Msgf("Parameter %s not found in parameters", param)
Expand Down
4 changes: 2 additions & 2 deletions circleci/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ func ReplaceVersion(orb *yaml.Node, oldVersion string, content string) string {
return output
}

func extractParameterName(param string) string {
func ExtractParameterName(param string) string {
r := regexp.MustCompile(`<<\s*parameters\.(\w+)\s*>>`)
match := r.FindStringSubmatch(param)
if len(match) == 2 {
if len(match) > 1 {
return match[1]
}
return ""
Expand Down
16 changes: 14 additions & 2 deletions dependabot/dependabot.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,20 @@ func generatePRTitle(update circleci.Update, newName string) string {
}
oldVersion = strings.Split(update.CurrentName, separator)
newVersion = strings.Split(newName, separator)

return fmt.Sprintf("Bump @%s from %s to %s", oldVersion[0], oldVersion[1], newVersion[1])
param := circleci.ExtractParameterName(oldVersion[1])
oldVersionNumber := oldVersion[1]
if len(param) > 0 {
// Try getting version from first changed file
for _, v := range update.FileUpdates {
if oldParamValue, found := (*v.Parameters)[param]; found {
oldVersionNumber = oldParamValue
} else {
oldVersionNumber = param
}
break
}
}
return fmt.Sprintf("Bump @%s from %s to %s", oldVersion[0], oldVersionNumber, newVersion[1])
}

func isYaml(fileName string) bool {
Expand Down

0 comments on commit 0b355c6

Please sign in to comment.