-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix review dismissals bug #485
Fix review dismissals bug #485
Conversation
policy/approval/approve.go
Outdated
@@ -111,7 +111,8 @@ func (r *Rule) Evaluate(ctx context.Context, prctx pull.Context) (res common.Res | |||
res.Name = r.Name | |||
res.Description = r.Description | |||
res.Status = common.StatusSkipped | |||
res.Requires = r.Requires.Actors | |||
res.Requires = common.Requires{Count: r.Requires.Count, Actors: r.Requires.Actors} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this felt a little funny, but i kept getting cyclical dependency issues when just trying to use the existing approval.Requires
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving types to common
is normal as they end up used in common.Result
, so I think this is fine.
server/handler/frontend.go
Outdated
"getRequires": func(results *common.Result) map[string][]Membership { | ||
return getRequires(results, strings.TrimSuffix(githubURL, "/")) | ||
"hasPatterns": func(results *common.Result) bool { | ||
return !results.Methods.IsEmpty() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's one thing I think I'm missing here and that's what if a github review approval (without comments) would satisfy the policy just fine? I think i can make it only show the Patterns if github_review: true
and github_review_comment_patterns
is not set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but then it's like the logic is slipping into the frontend a little bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if instead of thinking of this as patterns-only, we show all methods? I think that removes the need for hasPatterns
(every rule will have methods) and then we can change getPatterns
to getMethods
and update the template accordingly (see later comments)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sgtm
policy/common/methods.go
Outdated
@@ -179,3 +179,7 @@ func (m *Methods) BodyMatches(prBody string) bool { | |||
} | |||
return false | |||
} | |||
|
|||
func (m *Methods) IsEmpty() bool { | |||
return m == nil || (len(m.Comments) == 0 && len(m.CommentPatterns) == 0 && len(m.GithubReviewCommentPatterns) == 0 && len(m.BodyPatterns) == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh i can just put it here, and maybe call this something different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this also needs to check that m.GithubReview
is non-nil to account for all fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea i realized that, but with the new approach, i think we don't need it anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this and expanding the details view! I had some suggestions on the UI part, but the rest of the change looks good.
policy/approval/approve.go
Outdated
@@ -111,7 +111,8 @@ func (r *Rule) Evaluate(ctx context.Context, prctx pull.Context) (res common.Res | |||
res.Name = r.Name | |||
res.Description = r.Description | |||
res.Status = common.StatusSkipped | |||
res.Requires = r.Requires.Actors | |||
res.Requires = common.Requires{Count: r.Requires.Count, Actors: r.Requires.Actors} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving types to common
is normal as they end up used in common.Result
, so I think this is fine.
@@ -59,14 +59,20 @@ type ReviewRequestRule struct { | |||
Mode RequestMode | |||
} | |||
|
|||
type Requires struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of duplicating Requires
in this package, I think it might be better to move approval.Requires
to this package and then fix the references in the approval
packages. That should reduce confusion between the two types in the future since they're otherwise the same.
policy/common/methods.go
Outdated
@@ -179,3 +179,7 @@ func (m *Methods) BodyMatches(prBody string) bool { | |||
} | |||
return false | |||
} | |||
|
|||
func (m *Methods) IsEmpty() bool { | |||
return m == nil || (len(m.Comments) == 0 && len(m.CommentPatterns) == 0 && len(m.GithubReviewCommentPatterns) == 0 && len(m.BodyPatterns) == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this also needs to check that m.GithubReview
is non-nil to account for all fields.
server/handler/frontend.go
Outdated
"getRequires": func(results *common.Result) map[string][]Membership { | ||
return getRequires(results, strings.TrimSuffix(githubURL, "/")) | ||
"hasPatterns": func(results *common.Result) bool { | ||
return !results.Methods.IsEmpty() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if instead of thinking of this as patterns-only, we show all methods? I think that removes the need for hasPatterns
(every rule will have methods) and then we can change getPatterns
to getMethods
and update the template accordingly (see later comments)
server/templates/details.html.tmpl
Outdated
<div class="pt-2"> | ||
{{template "result-requires-permissions-details" .}} | ||
{{template "result-patterns-details" .}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would make sense to reorder these templates so it reads something like:
This rule needs N approvals from people in these groups or people with these permissions. Approvals can use these patterns.
As currently structured, it kind of implies that the sections are independent so that the pattern section doesn't also require the approvers have certain team membership/permissions.
server/templates/details.html.tmpl
Outdated
{{define "result-requires-details"}} | ||
<b class="font-bold text-sm">This rule requires review from</b> | ||
{{define "result-patterns-details"}} | ||
<b class="font-bold text-sm">This rule requires {{.Requires.Count}} review(s) using any of these patterns</b> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call adding the count to all of these - I'm not sure why we didn't add it earlier. I think it would be better to only show the count once before all the other approval details. With the count repeated, people could interpret it as if they need N reviews for each section instead of N reviews total for the rule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea that's fair, i was trying to play with the wording so that wouldn't be the case, but I think this is a better idea.
d7530b6
to
384abc1
Compare
} | ||
} else { | ||
patternInfo["Github Review State"] = append(patternInfo["Github Review State"], string(result.Methods.GithubReviewState)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the only part where i feel like the logic slipped into the view a little, but i thought the result would be more helpful for humans to read.
Disapproval does not support counts, so using the common type is misleading. Add an new comment explaining this.
This shouldn't be nil in practice, but would prefer to not panic over this if something changes in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing the comments and sorry about the delayed review, this looks good to merge
Closes #480
In #463 we introduced a feature to dismiss stale reviews, while iterating on it some additional logic slipped in to also dismiss reviews that didn't match review patterns if people were using the
github_review_comment_patterns
field in their policies. This worked well until a predicate was included in a policy causing certain reviews to be skipped from evaluation and therefore not added to the list of approved candidates. This manifested in buggy/broken behavior with a misleading dismissal reason until the predicate was satisfied.After deliberating in the issue above, I think we agreed that the dismissal of non-matching patterns is just a little too heavy handed and doesn't really fit well with dismissing "stale" reviews. In other words, if we aren't also dismissing all other reviews that can never satisfy a rule under any condition than the feature seems broken. So this PR removes dismissal of non-matching patterns, but keeps dismissal for both edited and invalidated reviews, classifying those as "stale" if people have the
ignore_edited_comments
orinvalidate_on_push
fields set to true in their policies. In addition, this PR also highlights which patterns will satisfy which rules on the details page in hopes to clear up confusion for folks using approval comments.