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
673: PR author should be able to use /reviewers command #820
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ public class ReviewersCommand implements CommandHandler { | |
"committers", "committers", | ||
"committer", "committers", | ||
"authors", "authors", | ||
"author", "author", | ||
"author", "authors", | ||
"contributors", "contributors", | ||
"contributor", "contributors"); | ||
|
||
|
@@ -47,10 +47,35 @@ private void showHelp(PrintWriter reply) { | |
"If role is set, the reviewers need to have that project role. If omitted, role defaults to `authors`."); | ||
} | ||
|
||
private static boolean roleIsLower(String updated, String existing) { | ||
if (existing.equals("lead")) { | ||
return !updated.equals("lead"); | ||
} | ||
if (existing.equals("reviewers")) { | ||
return !updated.equals("lead") && | ||
!updated.equals("reviewers"); | ||
} | ||
if (existing.equals("committers")) { | ||
return !updated.equals("lead") && | ||
!updated.equals("reviewers") && | ||
!updated.equals("committers"); | ||
} | ||
if (existing.equals("authors")) { | ||
return !updated.equals("lead") && | ||
!updated.equals("reviewers") && | ||
!updated.equals("committers") && | ||
!updated.equals("authors"); | ||
} | ||
if (existing.equals("contributors")) { | ||
return false; | ||
} | ||
throw new IllegalArgumentException("Unexpected existing role: " + existing); | ||
} | ||
|
||
@Override | ||
public void handle(PullRequestBot bot, PullRequest pr, CensusInstance censusInstance, Path scratchPath, CommandInvocation command, List<Comment> allComments, PrintWriter reply) { | ||
if (!censusInstance.isReviewer(command.user())) { | ||
reply.println("Only [Reviewers](https://openjdk.java.net/bylaws#reviewer) are allowed to change the number of required reviewers."); | ||
if (!pr.author().equals(command.user()) && !censusInstance.isReviewer(command.user())) { | ||
reply.println("Only the author of the pull request or [Reviewers](https://openjdk.java.net/bylaws#reviewer) are allowed to change the number of required reviewers."); | ||
return; | ||
} | ||
|
||
|
@@ -83,6 +108,21 @@ public void handle(PullRequestBot bot, PullRequest pr, CensusInstance censusInst | |
role = roleMappings.get(splitArgs[1].toLowerCase()); | ||
} | ||
|
||
if (pr.author().equals(command.user()) && !censusInstance.isReviewer(command.user())) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe simplify this to just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, we don't want people who are not the PR author and who are not Reviewers to be able to increase the required number of reviewers. Allowing that makes it possible to harass pull request by e.g. registering a spam account and just drop a bunch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, but that isn't related to this block (your concern is a good one and is handled by the previous block). By adding the |
||
var user = pr.repository().forge().currentUser(); | ||
var previous = ReviewersTracker.additionalRequiredReviewers(user, allComments); | ||
if (previous.isPresent()) { | ||
if (roleIsLower(role, previous.get().role())) { | ||
reply.println("Cannot lower the role for additional reviewers"); | ||
return; | ||
} | ||
if (numReviewers < previous.get().number()) { | ||
reply.println("Cannot decrease the number of required reviewers"); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
var updatedLimits = ReviewersTracker.updatedRoleLimits(censusInstance.configuration(), numReviewers, role); | ||
if (updatedLimits.get(role) > numReviewers) { | ||
showHelp(reply); | ||
|
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 would suggest that my assumption is wrong, and that an author can reduce the number of reviewers required even if they are not a Reviewer. I think this might not be what we want.
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 is fine to let them increase it.
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.
Agreed. It's the case of an author reducing it after a Reviewer has increased it that I think should be disallowed.
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.
@kevinrushforth and @prrace - I agree, see changes in commit 347594f