Skip to content

Commit

Permalink
Fix escaping branch name
Browse files Browse the repository at this point in the history
  • Loading branch information
janekbaraniewski committed Jul 24, 2023
1 parent 22f76fd commit d66eac6
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
testWorkdir/***
/issuectl-*
gh-access-token
jira-access-token
gh-access-token*
jira-access-token*
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/ \
Expand Down
11 changes: 5 additions & 6 deletions pkg/backend_jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
29 changes: 27 additions & 2 deletions pkg/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit d66eac6

Please sign in to comment.