Skip to content

Commit 56435f6

Browse files
authored
Skip reviewer assignment on comment/review events (#307)
With the current set of predicates, these events can never change the set of requested reviewers or trigger a re-request so there's no reason to do the work of computing and assigning reviewers. This is an alternate solution to the re-request loops that I fixed by including head commit reviews in the set of reviewers. I think the other approach is more correct, but this doesn't hurt. The main downside is that if we add predicates that use comments or reviews in the future, it will be easy to forget to change this trigger condition and it might be a while before someone reports unexpected behavior with the new predicate and reviewer assignment.
1 parent 1c7348c commit 56435f6

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

server/handler/base.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (b *Base) Evaluate(ctx context.Context, installationID int64, trigger commo
171171
return err
172172
}
173173

174-
return b.RequestReviewsForResult(ctx, prctx, client, result)
174+
return b.RequestReviewsForResult(ctx, prctx, client, trigger, result)
175175
}
176176

177177
func (b *Base) ValidateFetchedConfig(ctx context.Context, prctx pull.Context, client *github.Client, fetchedConfig FetchedConfig, trigger common.Trigger) (common.Evaluator, error) {
@@ -250,13 +250,21 @@ func (b *Base) EvaluateFetchedConfig(ctx context.Context, prctx pull.Context, cl
250250
return result, nil
251251
}
252252

253-
func (b *Base) RequestReviewsForResult(ctx context.Context, prctx pull.Context, client *github.Client, result common.Result) error {
253+
func (b *Base) RequestReviewsForResult(ctx context.Context, prctx pull.Context, client *github.Client, trigger common.Trigger, result common.Result) error {
254254
logger := zerolog.Ctx(ctx)
255255

256256
if prctx.IsDraft() || result.Status != common.StatusPending {
257257
return nil
258258
}
259259

260+
// As of 2021-05-19, there are no predicates that use comments or reviews
261+
// to enable or disable rules. This means these events will never cause a
262+
// change in reviewer assignment and we can skip the whole process.
263+
reviewTrigger := ^(common.TriggerComment | common.TriggerReview)
264+
if !trigger.Matches(reviewTrigger) {
265+
return nil
266+
}
267+
260268
if reqs := reviewer.FindRequests(&result); len(reqs) > 0 {
261269
logger.Debug().Msgf("Found %d pending rules with review requests enabled", len(reqs))
262270
return b.requestReviews(ctx, prctx, client, reqs)

server/handler/issue_comment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (h *IssueComment) Handle(ctx context.Context, eventType, deliveryID string,
110110
return err
111111
}
112112

113-
return h.Base.RequestReviewsForResult(ctx, prctx, client, result)
113+
return h.Base.RequestReviewsForResult(ctx, prctx, client, common.TriggerComment, result)
114114
}
115115

116116
func (h *IssueComment) detectAndLogTampering(ctx context.Context, prctx pull.Context, client *github.Client, event github.IssueCommentEvent, config *policy.Config) bool {

0 commit comments

Comments
 (0)