Skip to content
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

feat: add comment matching to github review approval with new option #361

Merged

Conversation

devinburnette
Copy link
Contributor

Closes #359

As discussed in the attached issue, this feature would support new method options for github_review_comments: and github_review_comment_patterns: creating parity with issue comment approval for github review approval comment bodies. This would help in use cases where github review approval alone isn't sufficient.

I went with nesting the logic in the existing reviews for loop but first checking to confirm the review state is approved. That would make this feature work if github_review is provided in the config and set to true, or not provided in the config defaulting to true. As written, this feature doesn't work if github_review: false explicitly in the config. That doesn't seem surprising behavior to me, but let me know if there's an approach that makes better sense to accomplish the same.

Copy link
Member

@bluekeyes bluekeyes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding new tests along with this!

Comments []string `yaml:"comments,omitempty"`
CommentPatterns []Regexp `yaml:"comment_patterns,omitempty"`
GithubReview bool `yaml:"github_review,omitempty"`
GithubReviewComments []string `yaml:"github_review_comments,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this option and only support GitHubReviewCommentPatterns.

If I were to implement Policy Bot again (or make a v2 configuration format), I think I'd only support CommentPatterns, since it's a superset of the plain Comments field. While we haven't formally deprecated Comments, I consider it deprecated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, fine by me.

Comment on lines 134 to 141
for _, comment := range m.GithubReviewComments {
if strings.Contains(commentBody, comment) {
return true
}
}
for _, pattern := range m.GithubReviewCommentPatterns {
if pattern.Matches(commentBody) {
return true
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this will have to be in a new method so that review comment patterns are not matched against regular comment patterns and vice versa.

CreatedAt: r.CreatedAt,
UpdatedAt: r.UpdatedAt,
})
if len(m.GithubReviewComments) > 0 || len(m.GithubReviewCommentPatterns) > 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of the way method defaults work, I don't think this will work as expected (or at least as we discussed in the issue.) We only use the defaults if the methods block is completely absent. If the user sets any fields, no defaults are used. That means that with the current code, users will have to set both github_reviews and github_review_comment_patterns to have things work.

We may want to change the condition on L76 to m.GitubReview || len(m.GithubReviewCommandPatterns) > 0 so that setting either field will enable review processing - unless we actually want to require that both fields are set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh ok, i think i misunderstood how the defaults were applied. Lemme look into fixing this.

@devinburnette devinburnette force-pushed the review-approval-with-comments branch 3 times, most recently from e9a64ea to 7f8ee6b Compare January 7, 2022 23:29
@devinburnette devinburnette force-pushed the review-approval-with-comments branch from 7f8ee6b to 4f06a5f Compare January 7, 2022 23:30
# review approvals matching the included patterns will be accepted as
# approval candidates. Defaults to an empty list.
github_review_comment_patterns:
- '\b(?i)domain\s*lgtm\b'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bluekeyes ok! I think this is all set. I've also updated the readme to reflect the use case more accurately.

Copy link
Member

@bluekeyes bluekeyes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: add comment matching to github review approval
2 participants