Skip to content

Commit 31d6b9f

Browse files
authored
Ask to add Jira ticket link to beginning of PR body (#57)
1 parent a094d9b commit 31d6b9f

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ After setup is complete, you can call the command like this:
177177
git-helper code-request
178178
```
179179

180-
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.
180+
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.
181181

182182
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.
183183

internal/githubPullRequest/githubPullRequest.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8+
"regexp"
89
"strconv"
910
"strings"
1011

@@ -69,8 +70,21 @@ func (pr *GitHubPullRequest) newPrBody() string {
6970
return ""
7071
}
7172

73+
re := regexp.MustCompile(`[A-Za-z]+-\d+`)
74+
match := re.FindString(pr.NewPrTitle)
75+
76+
if match != "" {
77+
includeJiraLink := commandline.AskYesNoQuestion(
78+
fmt.Sprintf("Include a link to the Jira ticket (%s) in the beginning of the pull request body?", match),
79+
)
80+
if includeJiraLink {
81+
return "### [" + match + "]\n\n" + string(content)
82+
}
83+
}
84+
7285
return string(content)
7386
}
87+
7488
return ""
7589
}
7690

internal/gitlabMergeRequest/gitlabMergeRequest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import (
1717
type GitLabMergeRequest struct {
1818
BaseBranch string
1919
Debug bool
20+
Draft string
2021
GitRootDir string
2122
LocalBranch string
22-
Draft string
2323
LocalProject string
2424
NewMrTitle string
2525
}

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
var (
2323
packageOwner = "emmahsax"
2424
packageRepository = "go-git-helper"
25-
packageVersion = "0.0.9"
25+
packageVersion = "0.0.10"
2626
)
2727

2828
func main() {

0 commit comments

Comments
 (0)