Skip to content

Add a review to a PR instead of a comment (issue #14) #36

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

su7edja
Copy link

@su7edja su7edja commented Oct 14, 2019

For this issue: #14

When PR is not compliant, instead of just leaving a comment, the bot would leave a "REQUEST_CHANGES" review with a message of the non-compliance.

@googlebot googlebot added the cla: yes PR is CLA-compliant label Oct 14, 2019
@mbrukman mbrukman changed the title Issue 14 Add a review to a PR instead of a comment (issue #14) Oct 15, 2019
Copy link
Member

@mbrukman mbrukman 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 your contribution! Can you please add tests to your PR?

If it's hard to do that now (because some methods in this file are large), please note that I'm refactoring this file and adding tests as I go, e.g., see #37 for my latest refactoring; more coming soon. Let me know if something is complex or hard to test, I'm working on improving this and happy to do that to enable you to write tests easier.

Thanks again!

ghutil/ghutil.go Outdated
@@ -416,7 +420,7 @@ func (ghc *GitHubClient) ProcessPullRequest(ctx context.Context, orgName string,
}

if labelsUpdatedForNonCompliance {
addComment(pullRequestNonComplianceReason)
addReview(pullRequestNonComplianceReason, ReviewRequestChanges)
Copy link
Member

Choose a reason for hiding this comment

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

Can we have the tool resolve its own review if the user updates their PR such that next time, it's a compliant PR?

@su7edja
Copy link
Author

su7edja commented Oct 15, 2019

@mbrukman
Yes your response about the all checks on the issue makes sense. I will keep that in mind when I work on that part that you mentioned above about resolving its own issues.
I will also give the testing a try. Thanks!

@su7edja
Copy link
Author

su7edja commented Oct 27, 2019

@mbrukman finally got the tests working. Let me know what you think.

Copy link
Member

@mbrukman mbrukman 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 updating the code and adding tests! A few comments / questions below.

@@ -409,26 +414,23 @@ func (ghc *GitHubClient) ProcessPullRequest(ctx context.Context, orgName string,
} else {
logging.Infof(" No action needed: [%s] label already added", LabelClaYes)
}

addReview(pullRequestNonComplianceReason, ReviewApprove)
Copy link
Member

Choose a reason for hiding this comment

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

If "ReviewApprove" is going to add an "approval" to the PR in the sense of getting a check mark on the PR, that's a bit of an issue, because the bot having commit permissions on the repo (which appears to be required to add/remove labels) means that just passing the CLA check gets a user a valid green check, and thus making it look like it's ready for merge.

Is there another state we can have the bot take which just resolves their comments on the PR, without approving the PR for the contents, since it's not actually reviewing the meaning of the PR, just CLA compliance?

},
},
}
var prNum = 42
Copy link
Member

Choose a reason for hiding this comment

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

You're using prNum here, but there's already a global const pullNumber which has the same value, and you're using both of them below, so I think you can just drop this line. Similarly in the other test method.

mockGhc.Issues.EXPECT().AddLabelsToIssue(ctx, orgName, repoName, prNum, []string{"cla: yes"}).Return(nil, nil, nil)
var reviewBody = ""
var body *string
body = &reviewBody
Copy link
Member

Choose a reason for hiding this comment

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

Just inline &"" below where you use body? Or if that's not possible, just inline &reviewBody? Similarly below and in the other test method.

var reviewBody = ""
var body *string
body = &reviewBody
var reviewEvent = "APPROVE"
Copy link
Member

Choose a reason for hiding this comment

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

Can you use the constant from the ghutil package here and in the other test method instead of copying it here?

if labelsUpdatedForNonCompliance {
addComment(pullRequestNonComplianceReason)
}
addReview(pullRequestNonComplianceReason, ReviewRequestChanges)
Copy link
Member

Choose a reason for hiding this comment

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

Another thing I just realized: this is a big change of behavior for crbot, so it would be nice to control this with a command-line flag, and to be able to keep the old behavior (adding labels) as an option as well.

In fact, it would probably be safest to keep the old behavior as default, and make the new behavior something users can enable with a command-line flag, so that folks can try it out, without being suddenly surprised with a new behavior when they sync + rebuild their binaries.

@su7edja
Copy link
Author

su7edja commented Nov 13, 2019

@mbrukman Thanks for the feedback! Sorry it took me a while to get back to you.
Your feedback makes sense. I will get working on them soon and tag you once I'm done. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes PR is CLA-compliant
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants