Skip to content

Commit 1c7348c

Browse files
authored
Fix re-request loop for team reviewers (#306)
Similar to the previous issue for users, if a user left a review on behalf of a team, but the review did not change the rule state, policy-bot would immediately re-requst a review from the team, leading to extra notification noise.
1 parent 9fdeeb2 commit 1c7348c

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

pull/context.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ type Review struct {
202202
State ReviewState
203203
Body string
204204
SHA string
205+
206+
Teams []string
205207
}
206208

207209
type ReviewerType string

pull/github.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,18 +983,33 @@ type v4PullRequestReview struct {
983983
State string
984984
Body string
985985
SubmittedAt time.Time
986-
Commit struct {
986+
987+
Commit struct {
987988
OID string
988989
}
990+
991+
// GitHub currently allows at most 15 review requests, so any review could
992+
// not be on behalf of more than 15 teams.
993+
OnBehalfOf struct {
994+
Nodes []struct {
995+
Slug string
996+
}
997+
} `graphql:"onBehalfOf(first: 15)"`
989998
}
990999

9911000
func (r *v4PullRequestReview) ToReview() *Review {
1001+
teams := make([]string, len(r.OnBehalfOf.Nodes))
1002+
for i, n := range r.OnBehalfOf.Nodes {
1003+
teams[i] = n.Slug
1004+
}
1005+
9921006
return &Review{
9931007
CreatedAt: r.SubmittedAt,
9941008
Author: r.Author.GetV3Login(),
9951009
State: ReviewState(strings.ToLower(r.State)),
9961010
Body: r.Body,
9971011
SHA: r.Commit.OID,
1012+
Teams: teams,
9981013
}
9991014
}
10001015

server/handler/base.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,13 @@ func (b *Base) requestReviews(ctx context.Context, prctx pull.Context, client *g
322322
Type: pull.ReviewerUser,
323323
Name: r.Author,
324324
})
325+
326+
for _, team := range r.Teams {
327+
reviewers = append(reviewers, &pull.Reviewer{
328+
Type: pull.ReviewerTeam,
329+
Name: team,
330+
})
331+
}
325332
}
326333
}
327334

0 commit comments

Comments
 (0)