feat: expose JiraIssue.BaseURL and JiraIssue.BrowseURL

allows the release note templates to easily create hyperlinks
into jira like

    Jira: {{ print .JiraIssue.BaseURL "/browse/" .JiraIssueID }}

or

    Jira: {{ .JiraIssue.BrowseURL }}

resolves: #251
This commit is contained in:
David Alpert 2023-11-21 09:55:04 -06:00
parent 2a7ca9ecb0
commit 8ec17f63b0
4 changed files with 10 additions and 0 deletions

View file

@ -635,6 +635,8 @@ Within a `Commit`, the following Jira data can be used in template:
- `.JiraIssue.Description` - Description of the Jira issue
- `.JiraIssue.Type` - Original type of the Jira issue (also available as `.Type` unless the commit provided a Conventional Commit Type.
- `.JiraIssue.Labels` - A list of strings, each is a Jira label.
- `.JiraIssue.BaseURL` - The value of `options.jira.info.url` (or the `JIRA_URL` env var) which can be useful in the templates for creating links to your Jira instance
- `.JiraIssue.BrowseURL` - A default "browse" url for this issue (pre-formatted by concatenting `.JiraIssue.BaseURL` + "/browse/" + `.JiraIssueID`; e.g. "https://myorg.atlassian.net/browse/MYPROJ-1234")
## FAQ

View file

@ -461,6 +461,8 @@ func (p *commitParser) processJiraIssue(commit *Commit, issueID string) {
}
commit.JiraIssue = &JiraIssue{
Type: issue.Fields.Type.Name,
BaseURL: p.config.Options.JiraURL,
BrowseURL: fmt.Sprintf("%s/browse/%s", strings.TrimRight(p.config.Options.JiraURL, "/"), issueID),
Summary: issue.Fields.Summary,
Description: issue.Fields.Description,
Labels: issue.Fields.Labels,

View file

@ -399,6 +399,7 @@ func TestCommitParserParseWithJira(t *testing.T) {
"Subject",
},
JiraKeyPattern: "\\b(JIRA-\\d+)",
JiraURL: "https://myorg.atlassian.net",
JiraTypeMaps: map[string]string{
"Story": "feat",
},
@ -415,6 +416,8 @@ func TestCommitParserParseWithJira(t *testing.T) {
if commit.JiraIssue == nil {
t.Fatal("did not load jira issue JIRA-1111")
}
assert.Equal("https://myorg.atlassian.net", commit.JiraIssue.BaseURL)
assert.Equal("https://myorg.atlassian.net/browse/JIRA-1111", commit.JiraIssue.BrowseURL)
assert.Equal("Story", commit.JiraIssue.Type)
assert.Equal("summary of JIRA-1111", commit.JiraIssue.Summary)
assert.Equal("description of JIRA-1111", commit.JiraIssue.Description)
@ -426,6 +429,7 @@ func TestCommitParserParseWithJira(t *testing.T) {
if commit.JiraIssue == nil {
t.Fatal("did not load jira issue JIRA-1112")
}
assert.Equal("https://myorg.atlassian.net/browse/JIRA-1112", commit.JiraIssue.BrowseURL)
assert.Equal("Story", commit.JiraIssue.Type)
assert.Equal("summary of JIRA-1112", commit.JiraIssue.Summary)
assert.Equal("description of JIRA-1112", commit.JiraIssue.Description)

View file

@ -61,6 +61,8 @@ type NoteGroup struct {
// JiraIssue is information about a jira ticket (type, summary, description, and labels)
type JiraIssue struct {
Type string
BaseURL string
BrowseURL string
Summary string
Description string
Labels []string