Skip to content

Commit

Permalink
Skip reviewer assignment on comment/review events (#307)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bluekeyes authored May 24, 2021
1 parent 1c7348c commit 56435f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions server/handler/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (b *Base) Evaluate(ctx context.Context, installationID int64, trigger commo
return err
}

return b.RequestReviewsForResult(ctx, prctx, client, result)
return b.RequestReviewsForResult(ctx, prctx, client, trigger, result)
}

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

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

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

// As of 2021-05-19, there are no predicates that use comments or reviews
// to enable or disable rules. This means these events will never cause a
// change in reviewer assignment and we can skip the whole process.
reviewTrigger := ^(common.TriggerComment | common.TriggerReview)
if !trigger.Matches(reviewTrigger) {
return nil
}

if reqs := reviewer.FindRequests(&result); len(reqs) > 0 {
logger.Debug().Msgf("Found %d pending rules with review requests enabled", len(reqs))
return b.requestReviews(ctx, prctx, client, reqs)
Expand Down
2 changes: 1 addition & 1 deletion server/handler/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (h *IssueComment) Handle(ctx context.Context, eventType, deliveryID string,
return err
}

return h.Base.RequestReviewsForResult(ctx, prctx, client, result)
return h.Base.RequestReviewsForResult(ctx, prctx, client, common.TriggerComment, result)
}

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

0 comments on commit 56435f6

Please sign in to comment.