- Notifications
You must be signed in to change notification settings - Fork11
Description
Hey, first of kudos for the nice work. I really like the functionality that you have put together with this branch.
I would like to know if you would be open to receive a PR with some added behavior for the JIRA template.
Let me know what you think of the suggestion and the approach and if you prefer I can open a PR with a draft and we discuss there.
Context
Internally we use a specific naming convention for branches. Would you consider to expand the current functionality to extract theJIRA_TASK based on a regex?
E.g., a branch with namefeature/PRJ-0001 would becomePRJ-0001 if I would pass the regex that would group the ID that I want.
Possible approach
With my approach I expect a valid regex to be defined in the config yaml (if the regex is not valid it will fail running CMF) and I also expect a group namedJIRA_TASK to be available inside the regex (if not provided it returns the original branch name).
Rough sample (The Go Playground):
package mainimport ("fmt""regexp")func findKey(names []string) int {key := "JIRA_TASK"for i, v := range names {if v == key {return i}}return 0}func getGitBranchName() string {// Current behaviour to fetch the branch namereturn "feature/PRJ-0001"}func getBranchName(regex string) (string, error) {branchName := getGitBranchName()r, err := regexp.Compile(regex)if err == nil {// Position of the group we expect (defaults to 0 to be the entire branch name)pos := findKey(r.SubexpNames())// Extracts the branch namebranchName = r.FindStringSubmatch(branchName)[pos]}return branchName, err}func main() {jiraTaskRegex := "feature/(?P<JIRA_TASK>PRJ-[0-9]+)(-.*)?"branchName, err := getBranchName(jiraTaskRegex)if err == nil {fmt.Println("Branch name: ", branchName)} else {fmt.Println("Error: ", err)}}