From bfdc33452e49695340b40203a380e1af0d7bd908 Mon Sep 17 00:00:00 2001 From: Patrick Maslana Date: Wed, 18 Sep 2024 08:48:20 -0700 Subject: [PATCH 1/2] Modify the code so there is an option to find either all PRs or community PRs --- internal/github/checkUnsigned.go | 2 +- .../github/{communityPRs.go => findPRs.go} | 23 +++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) rename internal/github/{communityPRs.go => findPRs.go} (56%) diff --git a/internal/github/checkUnsigned.go b/internal/github/checkUnsigned.go index a7de1d8..63ddf25 100644 --- a/internal/github/checkUnsigned.go +++ b/internal/github/checkUnsigned.go @@ -36,7 +36,7 @@ func CheckUnsignedCommits(ctx context.Context, githubClient *github.Client, cfg } owner, repo := parts[0], parts[1] - communityPRs, err := FindCommunityPRs(cfg, teamMembers, githubClient, owner, repo, fullRepo.MinimumNumber) + communityPRs, err := FindAllPRs(cfg, teamMembers, githubClient, owner, repo, fullRepo.MinimumNumber) if err != nil { return nil, err } diff --git a/internal/github/communityPRs.go b/internal/github/findPRs.go similarity index 56% rename from internal/github/communityPRs.go rename to internal/github/findPRs.go index 3886655..2ef8f5a 100644 --- a/internal/github/communityPRs.go +++ b/internal/github/findPRs.go @@ -10,8 +10,18 @@ import ( "github.com/chia-network/github-bot/internal/config" ) -// FindCommunityPRs obtains PRs based on provided filters +// FindCommunityPRs obtains PRs based on provided filters for community members func FindCommunityPRs(cfg *config.Config, teamMembers map[string]bool, githubClient *github.Client, owner string, repo string, minimumNumber int) ([]*github.PullRequest, error) { + return findPRs(cfg, teamMembers, githubClient, owner, repo, minimumNumber, true) +} + +// FindAllPRs obtains all PRs for the repository +func FindAllPRs(cfg *config.Config, teamMembers map[string]bool, githubClient *github.Client, owner string, repo string, minimumNumber int) ([]*github.PullRequest, error) { + return findPRs(cfg, teamMembers, githubClient, owner, repo, minimumNumber, false) +} + +// findPRs handles fetching and filtering PRs based on community or all contributors +func findPRs(cfg *config.Config, teamMembers map[string]bool, githubClient *github.Client, owner string, repo string, minimumNumber int, filterCommunity bool) ([]*github.PullRequest, error) { var finalPRs []*github.PullRequest opts := &github.PullRequestListOptions{ State: "open", @@ -36,13 +46,15 @@ func FindCommunityPRs(cfg *config.Config, teamMembers map[string]bool, githubCli if *pullRequest.Draft { continue } + user := *pullRequest.User.Login - if !teamMembers[user] && !cfg.SkipUsersMap[user] { - slogs.Logr.Info("Pull request meets criteria, adding to final list", "PR", pullRequest.GetHTMLURL(), "user", user) - finalPRs = append(finalPRs, pullRequest) - } else { + if filterCommunity && (teamMembers[user] || cfg.SkipUsersMap[user]) { slogs.Logr.Info("Pull request does not meet criteria, skipping", "PR", pullRequest.GetHTMLURL(), "user", user) + continue } + + slogs.Logr.Info("Pull request meets criteria, adding to final list", "PR", pullRequest.GetHTMLURL(), "user", user) + finalPRs = append(finalPRs, pullRequest) } if resp.NextPage == 0 { @@ -50,5 +62,6 @@ func FindCommunityPRs(cfg *config.Config, teamMembers map[string]bool, githubCli } opts.Page = resp.NextPage // Set next page number } + return finalPRs, nil } From 0fd0e8970b9e6b64e408336cdf12ebc9d802bfe6 Mon Sep 17 00:00:00 2001 From: Patrick Maslana Date: Wed, 18 Sep 2024 08:53:28 -0700 Subject: [PATCH 2/2] Add a comment --- internal/github/findPRs.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/github/findPRs.go b/internal/github/findPRs.go index 2ef8f5a..105015c 100644 --- a/internal/github/findPRs.go +++ b/internal/github/findPRs.go @@ -48,6 +48,7 @@ func findPRs(cfg *config.Config, teamMembers map[string]bool, githubClient *gith } user := *pullRequest.User.Login + // If filtering community PRs, skip PRs by internal team members and users in SkipUsersMap if filterCommunity && (teamMembers[user] || cfg.SkipUsersMap[user]) { slogs.Logr.Info("Pull request does not meet criteria, skipping", "PR", pullRequest.GetHTMLURL(), "user", user) continue