Skip to content

Commit

Permalink
Merge pull request #3 from chenbh/master
Browse files Browse the repository at this point in the history
add flag to ignore specific PR authors
  • Loading branch information
clarafu authored Apr 13, 2021
2 parents 838d15b + b77258a commit bfa4322
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
4 changes: 3 additions & 1 deletion cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +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().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")
}
Expand Down Expand Up @@ -71,11 +72,12 @@ func generateReleaseNote(cmd *cobra.Command, args []string) {
}

lastCommitSHA, _ := cmd.Flags().GetString("last-commit-SHA")
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
// 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)
}
Expand Down
8 changes: 4 additions & 4 deletions generate/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand All @@ -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{
{
Expand All @@ -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",
Expand Down
13 changes: 11 additions & 2 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit bfa4322

Please sign in to comment.