From 8ec17f63b061de68355bba2cd0392d7fd4bb87b7 Mon Sep 17 00:00:00 2001 From: David Alpert Date: Tue, 21 Nov 2023 09:55:04 -0600 Subject: [PATCH] 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 --- README.md | 2 ++ commit_parser.go | 2 ++ commit_parser_test.go | 4 ++++ fields.go | 2 ++ 4 files changed, 10 insertions(+) diff --git a/README.md b/README.md index c9eda7ce..71b9f87e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/commit_parser.go b/commit_parser.go index 4d5a4290..dddd65d1 100644 --- a/commit_parser.go +++ b/commit_parser.go @@ -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, diff --git a/commit_parser_test.go b/commit_parser_test.go index 00ea851e..af79cc39 100644 --- a/commit_parser_test.go +++ b/commit_parser_test.go @@ -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) diff --git a/fields.go b/fields.go index 2d68b885..a7b9bb26 100644 --- a/fields.go +++ b/fields.go @@ -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