refactor: improve API usage and test robustness

- Extract the part after the last colon in the input string for `GetDefaultPRTitle` function

Signed-off-by: appleboy <appleboy.tw@gmail.com>
This commit is contained in:
appleboy 2023-04-29 08:24:24 +08:00
parent 6da66a0318
commit a554c30e6c

View file

@ -140,10 +140,17 @@ func GetHeadSpec(owner, branch, baseOwner string) string {
// GetDefaultPRTitle transforms a string like a branchname to a readable text
func GetDefaultPRTitle(header string) string {
// Extract the part after the last colon in the input string
colonIndex := strings.LastIndex(header, ":")
if colonIndex != -1 {
header = header[colonIndex+1:]
}
title := noSpace.ReplaceAllString(header, "")
title = spaceRegex.ReplaceAllString(title, " ")
title = strings.TrimSpace(title)
title = strings.Title(strings.ToLower(title))
title = consecutive.ReplaceAllString(title, " ")
return title
}