Skip to content

Commit

Permalink
Merge pull request #51 from Chia-Network/find-all-PRs
Browse files Browse the repository at this point in the history
Find all PRs
  • Loading branch information
pmaslana authored Sep 18, 2024
2 parents 6c29552 + 0fd0e89 commit c36689e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/github/checkUnsigned.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
24 changes: 19 additions & 5 deletions internal/github/communityPRs.go → internal/github/findPRs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -36,19 +46,23 @@ 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 {
break // Exit the loop if there are no more pages
}
opts.Page = resp.NextPage // Set next page number
}

return finalPRs, nil
}

0 comments on commit c36689e

Please sign in to comment.