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

skara-840 #981

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
@@ -192,7 +192,17 @@ public Collection<WorkItem> run(Path scratchPath) {
var message = CommitMessageParsers.v1.parse(metadata.get().message());
var issues = message.issues();
if (!issues.isEmpty()) {
pr.setTitle(issues.get(0).toString());
var id = issues.get(0).id();
var issue = bot.issueProject().issue(id);
if (!issue.isPresent()) {
var text = "<!-- backport error -->\n" +
":warning: @" + pr.author().username() + " the issue `" + id + "` from commit " +
"`" + hash.hex() + "` does not exist in project [" +
bot.issueProject().name() + "](" + bot.issueProject().webUrl() + ")";
pr.addComment(text);
return List.of();
}
pr.setTitle(id + ": " + issue.get().title());
}

var comment = new ArrayList<String>();
@@ -1049,4 +1049,103 @@ void noWhitespace(TestInfo testInfo) throws IOException {
assertTrue(pr.labels().contains("backport"));
}
}

@Test
void commitWithMismatchingIssueTitle(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 + ": A 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"));

// Approve PR and re-run bot
var prAsReviewer = reviewer.pullRequest(pr.id());
prAsReviewer.addReview(Review.Verdict.APPROVED, "Looks good");
TestBotRunner.runPeriodicItems(bot);
assertLastCommentContains(pr, "This change now passes all *automated* pre-integration checks");

// Integrate
var prAsCommitter = author.pullRequest(pr.id());
pr.addComment("/integrate");
TestBotRunner.runPeriodicItems(bot);

// Find the commit
assertLastCommentContains(pr, "Pushed as commit");

String hex = null;
var comment = pr.comments().get(pr.comments().size() - 1);
var lines = comment.body().split("\n");
var pattern = Pattern.compile(".* Pushed as commit ([0-9a-z]{40}).*");
for (var line : lines) {
var m = pattern.matcher(line);
if (m.matches()) {
hex = m.group(1);
break;
}
}
assertNotNull(hex);
assertEquals(40, hex.length());
localRepo.checkout(localRepo.defaultBranch());
localRepo.pull(author.url().toString(), "master", false);
var commit = localRepo.lookup(new Hash(hex)).orElseThrow();

var message = CommitMessageParsers.v1.parse(commit);
assertEquals(1, message.issues().size());
assertEquals("An issue", message.issues().get(0).description());
assertEquals(List.of("integrationreviewer3"), message.reviewers());
assertEquals(Optional.of(releaseHash), message.original());
assertEquals(List.of(), message.contributors());
assertEquals(List.of(), message.summaries());
assertEquals(List.of(), message.additional());
}
}
}