From 9bd067c837c4b507b587a79bf4907ef415befa98 Mon Sep 17 00:00:00 2001 From: Bohan Chen Date: Wed, 7 Apr 2021 17:04:52 -0400 Subject: [PATCH 1/3] add --ignore-authors so that dependabot doesn't take over the release notes Signed-off-by: Bohan Chen Co-authored-by: Esteban Foronda --- cmd/generate.go | 7 ++++++- github/github.go | 13 +++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/cmd/generate.go b/cmd/generate.go index 6912ebf..1ecccd9 100644 --- a/cmd/generate.go +++ b/cmd/generate.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "regexp" + "strings" "github.com/clarafu/release-me/generate" "github.com/clarafu/release-me/github" @@ -23,6 +24,7 @@ func init() { generateCmd.Flags().String("github-branch", "master", "the branch name of the github repository to pull the pull requests from") generateCmd.Flags().String("last-commit-SHA", "", "will generate a release note using all prs merged up to this commit SHA. If empty, will generate release note until latest commit.") generateCmd.Flags().String("release-version", "", "the version that the release note will be generated for") + generateCmd.Flags().String("ignore-authors", "", "comma separated list of github handles, any PRs authored by these handles will be ignored.") generateCmd.Flags().String("ignore-release-regex", "", "a regular expression indicating releases to ignore when determining the previous release") generateCmd.MarkFlagRequired("release-version") } @@ -72,10 +74,13 @@ func generateReleaseNote(cmd *cobra.Command, args []string) { lastCommitSHA, _ := cmd.Flags().GetString("last-commit-SHA") + ignoreAuthorsStr, _ := cmd.Flags().GetString("ignore-authors") + ignoreAuthors := strings.Split(ignoreAuthorsStr, ",") + // Fetch all pull requests that are associated to a commit after the starting // commit SHA. If the pull request is already used for a patch release, it is // not included. - pullRequests, err := client.FetchPullRequestsAfterCommit(githubOwner, githubRepo, githubBranch, startingCommitSHA, lastCommitSHA) + pullRequests, err := client.FetchPullRequestsAfterCommit(githubOwner, githubRepo, githubBranch, startingCommitSHA, lastCommitSHA, ignoreAuthors) if err != nil { failf("failed to fetch pull requests: %s", err) } diff --git a/github/github.go b/github/github.go index 9b2248d..5f7b178 100644 --- a/github/github.go +++ b/github/github.go @@ -138,7 +138,7 @@ func (g GitHub) FetchLatestReleaseCommitFromBranch(owner, repo, branch, versionT return lastCommit, nil } -func (g GitHub) FetchPullRequestsAfterCommit(owner, repo, branch, startingCommitSHA, lastCommitSHA string) ([]PullRequest, error) { +func (g GitHub) FetchPullRequestsAfterCommit(owner, repo, branch, startingCommitSHA, lastCommitSHA string, ignoreAuthors []string) ([]PullRequest, error) { var pullRequestsQuery struct { Repository struct { Ref struct { @@ -186,7 +186,12 @@ func (g GitHub) FetchPullRequestsAfterCommit(owner, repo, branch, startingCommit var appendCommits bool pullRequests := []PullRequest{} - seen := map[string]bool{} + seen := make(map[string]bool) + + filteredAuthors := make(map[string]struct{}) + for _, username := range ignoreAuthors { + filteredAuthors[username] = struct{}{} + } for { err := g.client.Query(context.Background(), &pullRequestsQuery, pullRequestsVariables) @@ -212,6 +217,10 @@ func (g GitHub) FetchPullRequestsAfterCommit(owner, repo, branch, startingCommit continue } + if _, found := filteredAuthors[pr.Author.Login]; found { + continue + } + seen[pr.ID] = true if appendCommits { From d4f9da031af02dfac1f76424e8c62fb08b261447 Mon Sep 17 00:00:00 2001 From: Bohan Chen Date: Wed, 7 Apr 2021 17:05:43 -0400 Subject: [PATCH 2/3] fix tests https://github.com/clarafu/release-me/commit/838d15bc62184979959ed56d7ed167c6a9994ec0 Signed-off-by: Bohan Chen Co-authored-by: Esteban Foronda --- generate/generate_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/generate/generate_test.go b/generate/generate_test.go index c559115..42f4412 100644 --- a/generate/generate_test.go +++ b/generate/generate_test.go @@ -117,7 +117,7 @@ func (s *GenerateSuite) TestGenerate() { ExpectedBreaking: []generate.PullRequest{{Title: "new breaking change!"}}, }, { - It: "groups PRs as bugs before features and misc", + It: "groups PRs as misc before bugs and features", PRs: []github.PullRequest{ { @@ -126,10 +126,10 @@ func (s *GenerateSuite) TestGenerate() { }, }, - ExpectedBugFixes: []generate.PullRequest{{Title: "super fun pull request"}}, + ExpectedMisc: []generate.PullRequest{{Title: "super fun pull request"}}, }, { - It: "groups PRs as features before misc", + It: "groups PRs as misc before features", PRs: []github.PullRequest{ { @@ -138,7 +138,7 @@ func (s *GenerateSuite) TestGenerate() { }, }, - ExpectedFeatures: []generate.PullRequest{{Title: "best feature ever"}}, + ExpectedMisc: []generate.PullRequest{{Title: "best feature ever"}}, }, { It: "fails when PR does not have appropriate label", From b77258a97c85ce5c406cb92995ed1a1bc9499bf7 Mon Sep 17 00:00:00 2001 From: Bohan Chen Date: Tue, 13 Apr 2021 11:11:18 -0400 Subject: [PATCH 3/3] take ignore-authors flag as StringSlice instead of doing our own slicing Signed-off-by: Bohan Chen --- cmd/generate.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/cmd/generate.go b/cmd/generate.go index 1ecccd9..6f238f3 100644 --- a/cmd/generate.go +++ b/cmd/generate.go @@ -4,7 +4,6 @@ import ( "fmt" "os" "regexp" - "strings" "github.com/clarafu/release-me/generate" "github.com/clarafu/release-me/github" @@ -24,7 +23,7 @@ func init() { generateCmd.Flags().String("github-branch", "master", "the branch name of the github repository to pull the pull requests from") generateCmd.Flags().String("last-commit-SHA", "", "will generate a release note using all prs merged up to this commit SHA. If empty, will generate release note until latest commit.") generateCmd.Flags().String("release-version", "", "the version that the release note will be generated for") - generateCmd.Flags().String("ignore-authors", "", "comma separated list of github handles, any PRs authored by these handles will be ignored.") + generateCmd.Flags().StringSlice("ignore-authors", nil, "comma separated list of github handles, any PRs authored by these handles will be ignored.") generateCmd.Flags().String("ignore-release-regex", "", "a regular expression indicating releases to ignore when determining the previous release") generateCmd.MarkFlagRequired("release-version") } @@ -73,9 +72,7 @@ func generateReleaseNote(cmd *cobra.Command, args []string) { } lastCommitSHA, _ := cmd.Flags().GetString("last-commit-SHA") - - ignoreAuthorsStr, _ := cmd.Flags().GetString("ignore-authors") - ignoreAuthors := strings.Split(ignoreAuthorsStr, ",") + ignoreAuthors, _ := cmd.Flags().GetStringSlice("ignore-authors") // Fetch all pull requests that are associated to a commit after the starting // commit SHA. If the pull request is already used for a patch release, it is