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

339: Only show link to CONTRIBUTING.md if it exists #551

Closed
wants to merge 1 commit 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
@@ -30,6 +30,7 @@
import org.openjdk.skara.email.EmailAddress;

import java.io.*;
import java.nio.file.Path;
import java.util.*;
import java.util.logging.Logger;
import java.util.regex.*;
@@ -444,12 +445,24 @@ private String getMergeReadyComment(String commitMessage, List<Review> reviews,
var message = new StringBuilder();
message.append("@");
message.append(pr.author().userName());
message.append(" This change now passes all automated pre-integration checks. When the change also ");
message.append("fulfills all [project specific requirements](https://github.com/");
message.append(pr.repository().name());
message.append("/blob/");
message.append(pr.targetRef());
message.append("/CONTRIBUTING.md), type `/integrate` in a new comment to proceed. After integration, ");
message.append(" This change now passes all automated pre-integration checks");

try {
var hasContributingFile =
!prInstance.localRepo().files(prInstance.targetHash(), Path.of("CONTRIBUTING.md")).isEmpty();
if (hasContributingFile) {
message.append(". When the change also fulfills all ");
message.append("[project specific requirements](https://github.com/");
message.append(pr.repository().name());
message.append("/blob/");
message.append(pr.targetRef());
message.append("/CONTRIBUTING.md)");
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}

message.append(", type `/integrate` in a new comment to proceed. After integration, ");
message.append("the commit message will be:\n");
message.append("```\n");
message.append(commitMessage);
@@ -688,4 +688,80 @@ void noAutoRebase(TestInfo testInfo) throws IOException {
assertTrue(CheckableRepository.hasBeenEdited(pushedRepo));
}
}

@Test
void missingContributingFile(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 censusBuilder = credentials.getCensusBuilder()
.addCommitter(author.forge().currentUser().id())
.addReviewer(integrator.forge().currentUser().id());
var prBot = PullRequestBot.newBuilder().repo(integrator).censusRepo(censusBuilder.build()).build();

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

// Make a change with a corresponding PR
var editHash = CheckableRepository.appendAndCommit(localRepo);
localRepo.push(editHash, author.url(), "edit", true);
var pr = credentials.createPullRequest(author, "master", "edit", "This is a pull request");

// Approve it as another user
var approvalPr = integrator.pullRequest(pr.id());
approvalPr.addReview(Review.Verdict.APPROVED, "Approved");

TestBotRunner.runPeriodicItems(prBot);

// The bot should reply with an instructional message and no link to CONTRIBUTING.md
var lastComment = pr.comments().get(pr.comments().size() - 1);
assertFalse(lastComment.body().contains("CONTRIBUTING.md"));
}
}

@Test
void existingContributingFile(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 censusBuilder = credentials.getCensusBuilder()
.addCommitter(author.forge().currentUser().id())
.addReviewer(integrator.forge().currentUser().id());
var prBot = PullRequestBot.newBuilder().repo(integrator).censusRepo(censusBuilder.build()).build();

// Populate the projects repository
var localRepo = CheckableRepository.init(tempFolder.path(), author.repositoryType());
var contributingFile = localRepo.root().resolve("CONTRIBUTING.md");
Files.writeString(contributingFile, "Patches welcome!\n");
localRepo.add(contributingFile);
localRepo.commit("Add CONTRIBUTING.md", "duke", "duke@openjdk.org");
var masterHash = localRepo.resolve("master").orElseThrow();
assertFalse(CheckableRepository.hasBeenEdited(localRepo));
localRepo.push(masterHash, author.url(), "master", true);

// Make a change with a corresponding PR
var editHash = CheckableRepository.appendAndCommit(localRepo);
localRepo.push(editHash, author.url(), "edit", true);
var pr = credentials.createPullRequest(author, "master", "edit", "This is a pull request");

// Approve it as another user
var approvalPr = integrator.pullRequest(pr.id());
approvalPr.addReview(Review.Verdict.APPROVED, "Approved");

TestBotRunner.runPeriodicItems(prBot);

// The bot should reply with an instructional message and no link to CONTRIBUTING.md
var lastComment = pr.comments().get(pr.comments().size() - 1);
assertTrue(lastComment.body().contains("CONTRIBUTING.md"));
}
}
}