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

Add pull request prune functionality #247

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -72,16 +72,31 @@ private String formatDuration(Duration duration) {
return count + " " + unit;
}

private final String noticeMarker = "<!-- PullrequestCloserBot auto close notification -->";

@Override
public void run(Path scratchPath) {
var message = "@" + pr.author().userName() + " This pull request has been inactive for more than " +
formatDuration(maxAge) + " and will be automatically closed. If you think this is incorrect, " +
"feel free to reopen it!";
var comments = pr.comments();
if (comments.size() > 0) {
var lastComment = comments.get(comments.size() - 1);
if (lastComment.author().equals(repository.forge().currentUser()) && lastComment.body().contains(noticeMarker)) {
var message = "@" + pr.author().userName() + " This pull request has been inactive for more than " +
formatDuration(maxAge.multipliedBy(2)) + " and will now be automatically closed. If you would " +
"like to continue working on this pull request in the future, feel free to reopen it!";
log.fine("Posting prune message");
pr.addComment(message);
pr.setState(PullRequest.State.CLOSED);
return;
}
}

log.fine("Posting prune message");
pr.addComment(message);
var message = "@" + pr.author().userName() + " This pull request has been inactive for more than " +
formatDuration(maxAge) + " and will be automatically closed if another " + formatDuration(maxAge) +
" passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free " +
"to ask for assistance if you need help with progressing this pull request towards integration!";

pr.setState(PullRequest.State.CLOSED);
log.fine("Posting prune notification message");
pr.addComment(noticeMarker + "\n\n" + message);
}
}

@@ -29,7 +29,7 @@
import java.io.IOException;
import java.time.Duration;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.*;

class PullRequestPrunerBotTests {
@Test
@@ -52,7 +52,27 @@ void close(TestInfo testInfo) throws IOException, InterruptedException {
// Make sure the timeout expires
Thread.sleep(100);

// Let the bot see it
// Let the bot see it - it should give a notice
TestBotRunner.runPeriodicItems(bot);

assertEquals(1, pr.comments().size());
assertTrue(pr.comments().get(0).body().contains("will be automatically closed if"));

pr.addComment("I'm still working on it!");

// Make sure the timeout expires again
Thread.sleep(100);

// Let the bot see it - it should post a second notice
TestBotRunner.runPeriodicItems(bot);

assertEquals(3, pr.comments().size());
assertTrue(pr.comments().get(2).body().contains("will be automatically closed if"));

// Make sure the timeout expires again
Thread.sleep(100);

// The bot should now close it
TestBotRunner.runPeriodicItems(bot);

// There should now be no open PRs
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.