diff --git a/.gitignore b/.gitignore index da3bbaa..2163f79 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ testWorkdir/*** /issuectl-* -gh-access-token -jira-access-token +gh-access-token* +jira-access-token* diff --git a/README.md b/README.md index 0a81080..3e01565 100644 --- a/README.md +++ b/README.md @@ -281,6 +281,8 @@ Let's configure GitHub backend for our repository: And Jira backend for our issues: +> Please remember you have to use Jira with language set to English (US) + ```bash ➜ issuectl config backend add \ --jira-host https://my-org.atlassian.net/ \ diff --git a/pkg/backend_jira.go b/pkg/backend_jira.go index f8bafc4..855327d 100644 --- a/pkg/backend_jira.go +++ b/pkg/backend_jira.go @@ -14,11 +14,9 @@ type Jira struct { } const ( - ToDo = "To Do" - InProgress = "In Progress" - Done = "Done" - DefaultStartMessage = "On it 👀" - DefaultCloseMessage = "✅" + ToDo = "To Do" + InProgress = "In Progress" + Done = "Done" ) func NewJiraClient(email, apiToken, baseURL string) *Jira { @@ -55,7 +53,7 @@ func (j *Jira) LinkIssueToRepo(owner string, repo RepoConfigName, issueID IssueI pullRequestURL := fmt.Sprintf("https://github.com/%s/%s/pull/%s", owner, repo, pullRequestID) comment := jira.Comment{ - Body: fmt.Sprintf("Working on changes here: %s", pullRequestURL), + Body: fmt.Sprintf(DefaultOpenPRMessage, pullRequestURL), } _, _, err := j.client.Issue.AddComment(string(issueID), &comment) if err != nil { @@ -91,6 +89,7 @@ func (j *Jira) moveIssueToState(issueID IssueID, desiredState string, message st } if transitionID == "" { + Log.V(3).Infof("Failed looking for transition %v in list of transitions %v", desiredState, transitions) return fmt.Errorf("unable to find '%s' transition", desiredState) } diff --git a/pkg/backends.go b/pkg/backends.go index c04a066..02f564c 100644 --- a/pkg/backends.go +++ b/pkg/backends.go @@ -6,6 +6,12 @@ import ( "strconv" ) +const ( + DefaultStartMessage = "On it 👀" + DefaultCloseMessage = "✅" + DefaultOpenPRMessage = "Working on changes here: %s" +) + // getIssueNumberFromString converts IssueID to int func getIssueNumberFromString(issueID IssueID) (int, error) { issueNumber, err := strconv.Atoi(string(issueID)) diff --git a/pkg/issue.go b/pkg/issue.go index 7c925eb..e378d53 100644 --- a/pkg/issue.go +++ b/pkg/issue.go @@ -100,16 +100,41 @@ func getBranchName(config IssuectlConfig, issueBackend IssueBackend, profile *Pr return "", fmt.Errorf(errFailedToGetIssue, err) } + toReplace := []string{ + " ", + ",", + ":", + "|", + ";", + "(", + ")", + "#", + "@", + "!", + ".", + "$", + "%", + "^", + "&", + "*", + } + switch t := issue.(type) { default: return "", fmt.Errorf("Missing issue type") case *github.Issue: Log.V(5).Infof("%v", t) - branchName := fmt.Sprintf("%v-%v", issueID, strings.ReplaceAll(*issue.(*github.Issue).Title, " ", "-")) + branchName := fmt.Sprintf("%v-%v", issueID, *issue.(*github.Issue).Title) + for _, charToReplace := range toReplace { + branchName = strings.ReplaceAll(branchName, charToReplace, "-") + } return branchName, nil case *jira.Issue: Log.V(5).Infof("%v", t) - branchName := fmt.Sprintf("%v-%v", issueID, strings.ReplaceAll(issue.(*jira.Issue).Fields.Summary, " ", "-")) + branchName := fmt.Sprintf("%v-%v", issueID, issue.(*jira.Issue).Fields.Summary) + for _, charToReplace := range toReplace { + branchName = strings.ReplaceAll(branchName, charToReplace, "-") + } return branchName, nil } }