Skip to content

Commit

Permalink
add --ignore-authors
Browse files Browse the repository at this point in the history
so that dependabot doesn't take over the release notes

Signed-off-by: Bohan Chen <[email protected]>
Co-authored-by: Esteban Foronda <[email protected]>
  • Loading branch information
chenbh and EstebanFS committed Apr 7, 2021
1 parent 838d15b commit 9bd067c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 6 additions & 1 deletion cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"regexp"
"strings"

"github.com/clarafu/release-me/generate"
"github.com/clarafu/release-me/github"
Expand All @@ -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")
}
Expand Down Expand Up @@ -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)
}
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 9bd067c

Please sign in to comment.