Skip to content
Permalink
Browse files
372: Tool support for small/minor/trivial "fast-track" changes.
Reviewed-by: ehelin
  • Loading branch information
rwestberg committed Jun 25, 2020
1 parent 5b5c3a5 commit 971c746c36ad5c768b72fe35d8df9d48132153f6
@@ -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()) {

1 comment on commit 971c746

@bridgekeeper

This comment has been minimized.

Copy link

@bridgekeeper bridgekeeper bot commented on 971c746 Jun 25, 2020

Please sign in to comment.