Skip to content
Permalink
Browse files
pr: relaxed matching of backport PR titles
Reviewed-by: rwestberg
  • Loading branch information
edvbld committed Nov 18, 2020
1 parent 8295855 commit 1eb72e24d4593a66b4ea9824db307c4bb04fb7d8
Showing 2 changed files with 178 additions and 1 deletion.
@@ -45,7 +45,7 @@ class CheckWorkItem extends PullRequestWorkItem {
private final Pattern metadataComments = Pattern.compile("<!-- (?:(add|remove) (?:contributor|reviewer))|(?:summary: ')|(?:solves: ')|(?:additional required reviewers)");
private final Logger log = Logger.getLogger("org.openjdk.skara.bots.pr");
static final Pattern ISSUE_ID_PATTERN = Pattern.compile("^(?:[A-Za-z][A-Za-z0-9]+-)?([0-9]+)$");
private static final Pattern BACKPORT_TITLE_PATTERN = Pattern.compile("^Backport ([0-9a-z]{40})$");
private static final Pattern BACKPORT_TITLE_PATTERN = Pattern.compile("^Backport\\s*([0-9a-z]{40})\\s*$");

CheckWorkItem(PullRequestBot bot, PullRequest pr, Consumer<RuntimeException> errorHandler) {
super(bot, pr, errorHandler);
@@ -872,4 +872,181 @@ void cleanBackportFromAuthorCanBeIntegrated(TestInfo testInfo) throws IOExceptio
assertEquals(List.of(), message.additional());
}
}

@Test
void whitespaceInMiddle(TestInfo testInfo) throws IOException {
try (var credentials = new HostCredentials(testInfo);
var tempFolder = new TemporaryDirectory();
var pushedFolder = new TemporaryDirectory()) {

var author = credentials.getHostedRepository();
var integrator = credentials.getHostedRepository();
var reviewer = credentials.getHostedRepository();
var issues = credentials.getIssueProject();
var censusBuilder = credentials.getCensusBuilder()
.addCommitter(author.forge().currentUser().id())
.addReviewer(integrator.forge().currentUser().id())
.addReviewer(reviewer.forge().currentUser().id());
var bot = PullRequestBot.newBuilder()
.repo(integrator)
.censusRepo(censusBuilder.build())
.issueProject(issues)
.build();

// Populate the projects repository
var localRepo = CheckableRepository.init(tempFolder.path(), author.repositoryType());
var masterHash = localRepo.resolve("master").orElseThrow();
localRepo.push(masterHash, author.url(), "master", true);

var releaseBranch = localRepo.branch(masterHash, "release");
localRepo.checkout(releaseBranch);
var newFile = localRepo.root().resolve("a_new_file.txt");
Files.writeString(newFile, "hello");
localRepo.add(newFile);
var issue1 = credentials.createIssue(issues, "An issue");
var issue1Number = issue1.id().split("-")[1];
var originalMessage = issue1Number + ": An issue\n" +
"\n" +
"Reviewed-by: integrationreviewer2";
var releaseHash = localRepo.commit(originalMessage, "integrationcommitter1", "integrationcommitter1@openjdk.java.net");
localRepo.push(releaseHash, author.url(), "refs/heads/release", true);

// "backport" the new file to the master branch
localRepo.checkout(localRepo.defaultBranch());
var editBranch = localRepo.branch(masterHash, "edit");
localRepo.checkout(editBranch);
var newFile2 = localRepo.root().resolve("a_new_file.txt");
Files.writeString(newFile2, "hello");
localRepo.add(newFile2);
var editHash = localRepo.commit("Backport", "duke", "duke@openjdk.java.net");
localRepo.push(editHash, author.url(), "refs/heads/edit", true);
var pr = credentials.createPullRequest(author, "master", "edit", "Backport " + releaseHash.hex());

// The bot should reply with a backport message
TestBotRunner.runPeriodicItems(bot);
var backportComment = pr.comments().get(0).body();
assertTrue(backportComment.contains("This backport pull request has now been updated with issue"));
assertTrue(backportComment.contains("<!-- backport " + releaseHash.hex() + " -->"));
assertEquals(issue1Number + ": An issue", pr.title());
assertTrue(pr.labels().contains("backport"));
}
}

@Test
void whitespaceAtEnd(TestInfo testInfo) throws IOException {
try (var credentials = new HostCredentials(testInfo);
var tempFolder = new TemporaryDirectory();
var pushedFolder = new TemporaryDirectory()) {

var author = credentials.getHostedRepository();
var integrator = credentials.getHostedRepository();
var reviewer = credentials.getHostedRepository();
var issues = credentials.getIssueProject();
var censusBuilder = credentials.getCensusBuilder()
.addCommitter(author.forge().currentUser().id())
.addReviewer(integrator.forge().currentUser().id())
.addReviewer(reviewer.forge().currentUser().id());
var bot = PullRequestBot.newBuilder()
.repo(integrator)
.censusRepo(censusBuilder.build())
.issueProject(issues)
.build();

// Populate the projects repository
var localRepo = CheckableRepository.init(tempFolder.path(), author.repositoryType());
var masterHash = localRepo.resolve("master").orElseThrow();
localRepo.push(masterHash, author.url(), "master", true);

var releaseBranch = localRepo.branch(masterHash, "release");
localRepo.checkout(releaseBranch);
var newFile = localRepo.root().resolve("a_new_file.txt");
Files.writeString(newFile, "hello");
localRepo.add(newFile);
var issue1 = credentials.createIssue(issues, "An issue");
var issue1Number = issue1.id().split("-")[1];
var originalMessage = issue1Number + ": An issue\n" +
"\n" +
"Reviewed-by: integrationreviewer2";
var releaseHash = localRepo.commit(originalMessage, "integrationcommitter1", "integrationcommitter1@openjdk.java.net");
localRepo.push(releaseHash, author.url(), "refs/heads/release", true);

// "backport" the new file to the master branch
localRepo.checkout(localRepo.defaultBranch());
var editBranch = localRepo.branch(masterHash, "edit");
localRepo.checkout(editBranch);
var newFile2 = localRepo.root().resolve("a_new_file.txt");
Files.writeString(newFile2, "hello");
localRepo.add(newFile2);
var editHash = localRepo.commit("Backport", "duke", "duke@openjdk.java.net");
localRepo.push(editHash, author.url(), "refs/heads/edit", true);
var pr = credentials.createPullRequest(author, "master", "edit", "Backport " + releaseHash.hex() + " ");

// The bot should reply with a backport message
TestBotRunner.runPeriodicItems(bot);
var backportComment = pr.comments().get(0).body();
assertTrue(backportComment.contains("This backport pull request has now been updated with issue"));
assertTrue(backportComment.contains("<!-- backport " + releaseHash.hex() + " -->"));
assertEquals(issue1Number + ": An issue", pr.title());
assertTrue(pr.labels().contains("backport"));
}
}

@Test
void noWhitespace(TestInfo testInfo) throws IOException {
try (var credentials = new HostCredentials(testInfo);
var tempFolder = new TemporaryDirectory();
var pushedFolder = new TemporaryDirectory()) {

var author = credentials.getHostedRepository();
var integrator = credentials.getHostedRepository();
var reviewer = credentials.getHostedRepository();
var issues = credentials.getIssueProject();
var censusBuilder = credentials.getCensusBuilder()
.addCommitter(author.forge().currentUser().id())
.addReviewer(integrator.forge().currentUser().id())
.addReviewer(reviewer.forge().currentUser().id());
var bot = PullRequestBot.newBuilder()
.repo(integrator)
.censusRepo(censusBuilder.build())
.issueProject(issues)
.build();

// Populate the projects repository
var localRepo = CheckableRepository.init(tempFolder.path(), author.repositoryType());
var masterHash = localRepo.resolve("master").orElseThrow();
localRepo.push(masterHash, author.url(), "master", true);

var releaseBranch = localRepo.branch(masterHash, "release");
localRepo.checkout(releaseBranch);
var newFile = localRepo.root().resolve("a_new_file.txt");
Files.writeString(newFile, "hello");
localRepo.add(newFile);
var issue1 = credentials.createIssue(issues, "An issue");
var issue1Number = issue1.id().split("-")[1];
var originalMessage = issue1Number + ": An issue\n" +
"\n" +
"Reviewed-by: integrationreviewer2";
var releaseHash = localRepo.commit(originalMessage, "integrationcommitter1", "integrationcommitter1@openjdk.java.net");
localRepo.push(releaseHash, author.url(), "refs/heads/release", true);

// "backport" the new file to the master branch
localRepo.checkout(localRepo.defaultBranch());
var editBranch = localRepo.branch(masterHash, "edit");
localRepo.checkout(editBranch);
var newFile2 = localRepo.root().resolve("a_new_file.txt");
Files.writeString(newFile2, "hello");
localRepo.add(newFile2);
var editHash = localRepo.commit("Backport", "duke", "duke@openjdk.java.net");
localRepo.push(editHash, author.url(), "refs/heads/edit", true);
var pr = credentials.createPullRequest(author, "master", "edit", "Backport" + releaseHash.hex());

// The bot should reply with a backport message
TestBotRunner.runPeriodicItems(bot);
var backportComment = pr.comments().get(0).body();
assertTrue(backportComment.contains("This backport pull request has now been updated with issue"));
assertTrue(backportComment.contains("<!-- backport " + releaseHash.hex() + " -->"));
assertEquals(issue1Number + ": An issue", pr.title());
assertTrue(pr.labels().contains("backport"));
}
}
}

1 comment on commit 1eb72e2

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 1eb72e2 Nov 18, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.