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

322: Improve error message on non-author /integrate #527

wants to merge 1 commit into from
Changes from all commits
File filter

Filter by extension

Filter by extension

Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -57,7 +57,17 @@ private Optional<String> checkProblem(Map<String, Check> performedChecks, String
public void handle(PullRequestBot bot, PullRequest pr, CensusInstance censusInstance, Path scratchPath, String args, Comment comment, List<Comment> allComments, PrintWriter reply) {
if (! {
reply.println("Only the author (@" + + ") is allowed to issue the `integrate` command.");
reply.print("Only the author (@" + + ") is allowed to issue the `integrate` command.");

// 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, {
reply.print(" As this PR is ready to be sponsored, and you are an eligible sponsor, did you mean to issue the `/sponsor` command?");

@@ -426,6 +426,55 @@ void invalidCommandAuthor(TestInfo testInfo) throws IOException {

void invalidCommandSponsor(TestInfo testInfo) throws IOException {
try (var credentials = new HostCredentials(testInfo);
var tempFolder = new TemporaryDirectory()) {
var author = credentials.getHostedRepository();
var integrator = credentials.getHostedRepository();
var external = credentials.getHostedRepository();

var censusBuilder = credentials.getCensusBuilder()
var mergeBot = PullRequestBot.newBuilder().repo(integrator).censusRepo(;

// 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);

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

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

// Mark it as ready for integration

// Issue a merge command not as the PR author
var externalPr = external.pullRequest(;

// The bot should reply with an error message
var error = pr.comments().stream()
.filter(comment -> comment.body().contains("Only the author"))
.filter(comment -> comment.body().contains("did you mean to"))
.filter(comment -> comment.body().contains("`/sponsor`"))
assertEquals(1, error);

void autoRebase(TestInfo testInfo) throws IOException {
try (var credentials = new HostCredentials(testInfo);