diff --git a/chronicle/release/releasers/github/summarizer.go b/chronicle/release/releasers/github/summarizer.go index f4edd75..081ab87 100644 --- a/chronicle/release/releasers/github/summarizer.go +++ b/chronicle/release/releasers/github/summarizer.go @@ -23,6 +23,7 @@ type Config struct { Host string IncludeIssuePRAuthors bool IncludeIssues bool + IncludeIssuePRs bool IncludePRs bool ExcludeLabels []string ChangeTypesByLabel change.TypeSet @@ -306,18 +307,19 @@ func createChangesFromIssues(config Config, allMergedPRs []ghPullRequest, issues }, } - if config.IncludeIssuePRAuthors { - for _, pr := range allMergedPRs { - if pr.Author == "" { - continue + if config.IncludeIssuePRs || config.IncludeIssuePRAuthors { + for _, pr := range getLinkedPRs(allMergedPRs, issue) { + if config.IncludeIssuePRs { + references = append(references, change.Reference{ + Text: fmt.Sprintf("PR #%d", pr.Number), + URL: pr.URL, + }) } - for _, linkedIssue := range pr.LinkedIssues { - if linkedIssue.URL == issue.URL { - references = append(references, change.Reference{ - Text: pr.Author, - URL: fmt.Sprintf("https://%s/%s", config.Host, pr.Author), - }) - } + if config.IncludeIssuePRAuthors && pr.Author != "" { + references = append(references, change.Reference{ + Text: pr.Author, + URL: fmt.Sprintf("https://%s/%s", config.Host, pr.Author), + }) } } } @@ -335,6 +337,17 @@ func createChangesFromIssues(config Config, allMergedPRs []ghPullRequest, issues return changes } +func getLinkedPRs(allMergedPRs []ghPullRequest, issue ghIssue) (linked []ghPullRequest) { + for _, pr := range allMergedPRs { + for _, linkedIssue := range pr.LinkedIssues { + if linkedIssue.URL == issue.URL { + linked = append(linked, pr) + } + } + } + return linked +} + func extractGithubUserAndRepo(u string) (string, string) { switch { // e.g. git@github.com:anchore/chronicle.git diff --git a/chronicle/release/releasers/github/summarizer_test.go b/chronicle/release/releasers/github/summarizer_test.go index 3070851..7857760 100644 --- a/chronicle/release/releasers/github/summarizer_test.go +++ b/chronicle/release/releasers/github/summarizer_test.go @@ -797,36 +797,45 @@ func Test_createChangesFromIssues(t *testing.T) { Labels: []string{"bug"}, } - prWithLinkedIssues := ghPullRequest{ - Title: "pr with linked issues", - MergedAt: timeStart, + issue3 := ghIssue{ + Title: "Issue 3 no PRs", Number: 3, + URL: "issue-3-url", + ClosedAt: timeStart, + Labels: []string{"bug"}, + } + + prWithLinkedIssues1 := ghPullRequest{ + Title: "pr 1 with linked issues", + MergedAt: timeStart, + Number: 1, Labels: []string{"bug"}, Author: "some-author-1", - URL: "some-url-1", + URL: "pr-1-url", LinkedIssues: []ghIssue{ issue1, }, } prWithLinkedIssues2 := ghPullRequest{ - Title: "pr with linked issues 2", + Title: "pr 2 with linked issues", MergedAt: timeStart, - Number: 4, + Number: 2, Labels: []string{"another-label"}, Author: "some-author-2", - URL: "some-url-2", + URL: "pr-2-url", LinkedIssues: []ghIssue{ + issue1, issue2, }, } - prWithoutLinkedIssues := ghPullRequest{ + prWithoutLinkedIssues1 := ghPullRequest{ MergedAt: timeStart, - Title: "pr without linked issues", - Number: 6, + Title: "pr 3 without linked issues", + Number: 3, Author: "some-author", - URL: "some-url", + URL: "pr-3-url", } tests := []struct { @@ -840,17 +849,19 @@ func Test_createChangesFromIssues(t *testing.T) { name: "includes author for issues", config: Config{ IncludeIssuePRAuthors: true, + IncludeIssuePRs: true, ChangeTypesByLabel: changeTypeSet, Host: "some-host", }, inputPrs: []ghPullRequest{ - prWithLinkedIssues, + prWithLinkedIssues1, prWithLinkedIssues2, - prWithoutLinkedIssues, + prWithoutLinkedIssues1, }, issues: []ghIssue{ issue1, issue2, + issue3, }, expectedChanges: []change.Change{ { @@ -862,10 +873,22 @@ func Test_createChangesFromIssues(t *testing.T) { Text: "Issue #1", URL: "issue-1-url", }, + { + Text: "PR #1", + URL: "pr-1-url", + }, { Text: "some-author-1", URL: "https://some-host/some-author-1", }, + { + Text: "PR #2", + URL: "pr-2-url", + }, + { + Text: "some-author-2", + URL: "https://some-host/some-author-2", + }, }, EntryType: "githubIssue", Entry: issue1, @@ -879,6 +902,10 @@ func Test_createChangesFromIssues(t *testing.T) { Text: "Issue #2", URL: "issue-2-url", }, + { + Text: "PR #2", + URL: "pr-2-url", + }, { Text: "some-author-2", URL: "https://some-host/some-author-2", @@ -887,6 +914,19 @@ func Test_createChangesFromIssues(t *testing.T) { EntryType: "githubIssue", Entry: issue2, }, + { + Text: "Issue 3 no PRs", + ChangeTypes: []change.Type{patch}, + Timestamp: timeStart, + References: []change.Reference{ + { + Text: "Issue #3", + URL: "issue-3-url", + }, + }, + EntryType: "githubIssue", + Entry: issue3, + }, }, }, } diff --git a/internal/config/github.go b/internal/config/github.go index db9451b..0bc57a1 100644 --- a/internal/config/github.go +++ b/internal/config/github.go @@ -13,6 +13,7 @@ type githubSummarizer struct { Host string `yaml:"host" json:"host" mapstructure:"host"` ExcludeLabels []string `yaml:"exclude-labels" json:"exclude-labels" mapstructure:"exclude-labels"` IncludeIssuePRAuthors bool `yaml:"include-issue-pr-authors" json:"include-issue-pr-authors" mapstructure:"include-issue-pr-authors"` + IncludeIssuePRs bool `yaml:"include-issue-prs" json:"include-issue-prs" mapstructure:"include-issue-prs"` IncludePRs bool `yaml:"include-prs" json:"include-prs" mapstructure:"include-prs"` IncludeIssues bool `yaml:"include-issues" json:"include-issues" mapstructure:"include-issues"` IssuesRequireLinkedPR bool `yaml:"issues-require-linked-prs" json:"issues-require-linked-prs" mapstructure:"issues-require-linked-prs"` @@ -42,6 +43,7 @@ func (cfg githubSummarizer) ToGithubConfig() (github.Config, error) { return github.Config{ Host: cfg.Host, IncludeIssuePRAuthors: cfg.IncludeIssuePRAuthors, + IncludeIssuePRs: cfg.IncludeIssuePRs, IncludeIssues: cfg.IncludeIssues, IncludePRs: cfg.IncludePRs, ExcludeLabels: cfg.ExcludeLabels, @@ -57,6 +59,7 @@ func (cfg githubSummarizer) loadDefaultValues(v *viper.Viper) { v.SetDefault("github.consider-pr-merge-commits", true) v.SetDefault("github.include-prs", true) v.SetDefault("github.include-issue-pr-authors", true) + v.SetDefault("github.include-issue-prs", true) v.SetDefault("github.include-issues", true) v.SetDefault("github.exclude-labels", []string{"duplicate", "question", "invalid", "wontfix", "wont-fix", "release-ignore", "changelog-ignore", "ignore"}) v.SetDefault("github.changes", []githubChange{