Skip to content

Commit

Permalink
Ask to add Jira ticket link to beginning of PR body (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmahsax authored Aug 20, 2024
1 parent a094d9b commit 31d6b9f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ After setup is complete, you can call the command like this:
git-helper code-request
```

The command will provide an autogenerated code request title based on your branch name. It will separate the branch name by `'_'` if underscores are in the branch, or `'-'` if dashes are present. Then it will join the list of words together by spaces. If there's a pattern in the form of `jira-123` or `jira_123` in the first part of the branch name, then it'll add `JIRA-123` to the first part of the code request. You can choose whether to accept this title or not. If the title's declined, you can provide your own code request title.
The command will provide an autogenerated code request title based on your branch name. It will separate the branch name by `'_'` if underscores are in the branch, or `'-'` if dashes are present. Then it will join the list of words together by spaces. If there's a pattern in the form of `jira-123` or `jira_123` in the first part of the branch name, then it'll add `JIRA-123` to the first part of the code request. You can choose whether to accept this title or not. If the title's declined, you can provide your own code request title. In addition, (GitHub PR feature only) if the code notices any match of `[A-Za-z]+-\d+` in the title of the code request, then it'll ask if you'd like to add a link for the _first_ match to your PR body.

The command will also ask you if the default branch of the repository is the proper base branch to use. You can say whether that is correct or not, and if it's incorrect, you can give the command your chosen base branch.

Expand Down
14 changes: 14 additions & 0 deletions internal/githubPullRequest/githubPullRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"

Expand Down Expand Up @@ -69,8 +70,21 @@ func (pr *GitHubPullRequest) newPrBody() string {
return ""
}

re := regexp.MustCompile(`[A-Za-z]+-\d+`)
match := re.FindString(pr.NewPrTitle)

if match != "" {
includeJiraLink := commandline.AskYesNoQuestion(
fmt.Sprintf("Include a link to the Jira ticket (%s) in the beginning of the pull request body?", match),
)
if includeJiraLink {
return "### [" + match + "]\n\n" + string(content)
}
}

return string(content)
}

return ""
}

Expand Down
2 changes: 1 addition & 1 deletion internal/gitlabMergeRequest/gitlabMergeRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (
type GitLabMergeRequest struct {
BaseBranch string
Debug bool
Draft string
GitRootDir string
LocalBranch string
Draft string
LocalProject string
NewMrTitle string
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
var (
packageOwner = "emmahsax"
packageRepository = "go-git-helper"
packageVersion = "0.0.9"
packageVersion = "0.0.10"
)

func main() {
Expand Down

0 comments on commit 31d6b9f

Please sign in to comment.