Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: output each PR# along with issues #43

Merged
merged 1 commit into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions chronicle/release/releasers/github/summarizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Config struct {
Host string
IncludeIssuePRAuthors bool
IncludeIssues bool
IncludeIssuePRs bool
IncludePRs bool
ExcludeLabels []string
ChangeTypesByLabel change.TypeSet
Expand Down Expand Up @@ -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),
})
}
}
}
Expand All @@ -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. [email protected]:anchore/chronicle.git
Expand Down
66 changes: 53 additions & 13 deletions chronicle/release/releasers/github/summarizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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{
{
Expand All @@ -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,
Expand All @@ -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",
Expand All @@ -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,
},
},
},
}
Expand Down
3 changes: 3 additions & 0 deletions internal/config/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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,
Expand All @@ -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{
Expand Down