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 53% rename from internal/github/communityPRs.go rename to internal/github/findPRs.go index 3886655..105015c 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,16 @@ 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 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 } + + 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 +63,6 @@ func FindCommunityPRs(cfg *config.Config, teamMembers map[string]bool, githubCli } opts.Page = resp.NextPage // Set next page number } + return finalPRs, nil }