Skip to content

Commit

Permalink
fix(ghpr): Do not count reviewers/approvers multiple times
Browse files Browse the repository at this point in the history
Signed-off-by: Cezar Craciunoiu <[email protected]>
  • Loading branch information
craciunoiuc committed Dec 19, 2023
1 parent 7f9c738 commit 16d09dd
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions internal/ghpr/ghpr_mergable.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,33 @@ func (pr *PullRequest) SatisfiesMergeRequirements(ctx context.Context, opts ...P
return false, nil, fmt.Errorf("could not list pull request reviews: %w", err)
}

var existingReviewers []string
var existingApprovers []string

for _, r := range reviews {
if ok, matches := mopts.requestsApproverRegex(*r.Body); ok {
if mopts.requestsApproverTeam(ctx, *pull, *r.User.Login) {
if !mopts.requestsApproveState(*r.State) {
continue
}

for k, v := range matches {
if _, ok := res[k]; !ok {
res[k] = make([]string, 0)
var alreadyApproved bool
for _, approver := range existingApprovers {
if strings.Contains(approver, *r.User.Login) {
alreadyApproved = true
break
}
}

if !alreadyApproved {
for k, v := range matches {
if _, ok := res[k]; !ok {
res[k] = make([]string, 0)
}
res[k] = append(res[k], v)
prApprovals++
existingApprovers = append(existingApprovers, *r.User.Login)
}
res[k] = append(res[k], v)
prApprovals++
}
}
}
Expand All @@ -136,12 +150,23 @@ func (pr *PullRequest) SatisfiesMergeRequirements(ctx context.Context, opts ...P
continue
}

for k, v := range matches {
if _, ok := res[k]; !ok {
res[k] = make([]string, 0)
var alreadyReviewed bool
for _, reviewer := range existingReviewers {
if strings.Contains(reviewer, *r.User.Login) {
alreadyReviewed = true
break
}
}

if !alreadyReviewed {
for k, v := range matches {
if _, ok := res[k]; !ok {
res[k] = make([]string, 0)
}
res[k] = append(res[k], v)
prReviews++
existingReviewers = append(existingReviewers, *r.User.Login)
}
res[k] = append(res[k], v)
prReviews++
}
}
}
Expand Down

0 comments on commit 16d09dd

Please sign in to comment.