Skip to content

Commit

Permalink
replaced git branch name sanitation
Browse files Browse the repository at this point in the history
- convert type and subject to lower case
- replace whitespace with -
- drop every other character not being alphanumeric
  • Loading branch information
Kharonus committed Aug 6, 2024
1 parent d41c5eb commit e0a80c7
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions cmd/git/start/work_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,23 @@ func deriveBranchName(id uint64) (string, error) {
return "", err
}

typeName := strings.Replace(strings.ToLower(workPackage.Type), " ", "-", -1)
subject := regexp.MustCompile("[^a-zA-Z0-9-/_.]").
ReplaceAllStringFunc(workPackage.Subject, escapeWhiteSpaceAndDropSpecials)
name := fmt.Sprintf(
"%s/%d-%s",
sanitizeString(workPackage.Type),
workPackage.Id,
sanitizeString(workPackage.Subject),
)

name := fmt.Sprintf("%s/%d-%s", typeName, workPackage.Id, subject)
return name, nil
}

func escapeWhiteSpaceAndDropSpecials(s string) string {
if s == " " {
return "-"
}
func sanitizeString(str string) string {
lower := strings.ToLower(str)
return regexp.MustCompile("[^a-zA-Z0-9-/_.]").ReplaceAllStringFunc(lower, func(s string) string {
if s == " " {
return "-"
}

return ""
return ""
})
}

0 comments on commit e0a80c7

Please sign in to comment.