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

372: Tool support for small/minor/trivial "fast-track" changes. #677

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -18,13 +18,10 @@
class ArchiveMessages {
private static final Pattern commentPattern = Pattern.compile("<!--.*?-->",
Pattern.DOTALL | Pattern.MULTILINE);
private static final Pattern cutoffPattern = Pattern.compile("(.*?)<!-- Anything below this marker will be .*? -->",
Pattern.DOTALL | Pattern.MULTILINE);

private static String filterComments(String body) {
var cutoffMatcher = cutoffPattern.matcher(body);
if (cutoffMatcher.find()) {
body = cutoffMatcher.group(1);
}
var parsedBody = PullRequestBody.parse(body);
body = parsedBody.bodyText();

var commentMatcher = commentPattern.matcher(body);
body = commentMatcher.replaceAll("");
@@ -57,7 +57,7 @@ private static void linkReply(PullRequest pr, Issue issue, PrintWriter writer) {

@Override
public void handle(PullRequestBot bot, PullRequest pr, CensusInstance censusInstance, Path scratchPath, String args, Comment comment, List<Comment> allComments, PrintWriter reply) {
if (!ProjectPermissions.mayReview(censusInstance, comment.author())) {
if (!censusInstance.isReviewer(comment.author())) {
reply.println("only [Reviewers](https://openjdk.java.net/bylaws#reviewer) are allowed require a CSR.");
return;
}
@@ -24,8 +24,9 @@

import org.openjdk.skara.census.*;
import org.openjdk.skara.forge.*;
import org.openjdk.skara.host.HostUser;
import org.openjdk.skara.jcheck.JCheckConfiguration;
import org.openjdk.skara.vcs.*;
import org.openjdk.skara.vcs.Repository;

import java.io.*;
import java.net.URLEncoder;
@@ -119,4 +120,36 @@ Project project() {
Namespace namespace() {
return namespace;
}

Optional<Contributor> contributor(HostUser hostUser) {
var contributor = namespace.get(hostUser.id());
return Optional.ofNullable(contributor);
}

boolean isAuthor(HostUser hostUser) {
int version = census.version().format();
var contributor = namespace.get(hostUser.id());
if (contributor == null) {
return false;
}
return project.isAuthor(contributor.username(), version);
}

boolean isCommitter(HostUser hostUser) {
int version = census.version().format();
var contributor = namespace.get(hostUser.id());
if (contributor == null) {
return false;
}
return project.isCommitter(contributor.username(), version);
}

boolean isReviewer(HostUser hostUser) {
int version = census.version().format();
var contributor = namespace.get(hostUser.id());
if (contributor == null) {
return false;
}
return project.isReviewer(contributor.username(), version);
}
}
@@ -586,7 +586,7 @@ private String getMergeReadyComment(String commitMessage, List<Review> reviews)
message.append("`.\n");
}

if (!ProjectPermissions.mayCommit(censusInstance, pr.author())) {
if (!censusInstance.isCommitter(pr.author())) {
message.append("\n");
var contributor = censusInstance.namespace().get(pr.author().id());
if (contributor == null) {
@@ -598,7 +598,7 @@ private String getMergeReadyComment(String commitMessage, List<Review> reviews)
message.append("an existing [Committer](https://openjdk.java.net/bylaws#committer) must agree to ");
message.append("[sponsor](https://openjdk.java.net/sponsor/) your change. ");
var candidates = reviews.stream()
.filter(review -> ProjectPermissions.mayCommit(censusInstance, review.reviewer()))
.filter(review -> censusInstance.isCommitter(review.reviewer()))
.map(review -> "@" + review.reviewer().userName())
.collect(Collectors.joining(", "));
if (candidates.length() > 0) {
@@ -60,7 +60,7 @@ public void handle(PullRequestBot bot, PullRequest pr, CensusInstance censusInst
// If the command author is allowed to sponsor this change, suggest that command
var readyHash = ReadyForSponsorTracker.latestReadyForSponsor(pr.repository().forge().currentUser(), allComments);
if (readyHash.isPresent()) {
if (ProjectPermissions.mayCommit(censusInstance, comment.author())) {
if (censusInstance.isCommitter(comment.author())) {
reply.print(" As this PR is ready to be sponsored, and you are an eligible sponsor, did you mean to issue the `/sponsor` command?");
return;
}
@@ -126,7 +126,7 @@ public void handle(PullRequestBot bot, PullRequest pr, CensusInstance censusInst
}

// Finally check if the author is allowed to perform the actual push
if (!ProjectPermissions.mayCommit(censusInstance, pr.author())) {
if (!censusInstance.isCommitter(pr.author())) {
reply.println(ReadyForSponsorTracker.addIntegrationMarker(pr.headHash()));
reply.println("Your change (at version " + pr.headHash() + ") is now ready to be sponsored by a Committer.");
if (!args.isBlank()) {