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

292: Add comment to PR when it becomes outdated #513

Closed
wants to merge 2 commits 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
@@ -49,6 +49,7 @@ class CheckRun {
private final Logger log = Logger.getLogger("org.openjdk.skara.bots.pr");
private final String progressMarker = "<!-- Anything below this marker will be automatically updated, please do not edit manually! -->";
private final String mergeReadyMarker = "<!-- PullRequestBot merge is ready comment -->";
private final String outdatedHelpMarker = "<!-- PullRequestBot outdated help comment -->";
private final Pattern mergeSourceFullPattern = Pattern.compile("^Merge ([-/\\w]+):([-\\w]+)$");
private final Pattern mergeSourceBranchOnlyPattern = Pattern.compile("^Merge ([-\\w]+)$");
private final Set<String> newLabels;
@@ -533,6 +534,27 @@ private void updateMergeReadyComment(boolean isReady, String commitMessage, List
}
}

private void addOutdatedComment(List<Comment> comments) {
var existing = findComment(comments, outdatedHelpMarker);
if (existing.isPresent()) {
// Only add the comment once per PR
return;
}
var message = "@" + pr.author().userName() + " this pull request can no longer be integrated into " +
"`" + pr.targetRef() + "` due to one or more merge conflicts. To resolve these merge conflicts " +
"and update this pull request you can run the following commands in the local repository for your personal fork:\n" +
"```bash\n" +
"git checkout " + pr.sourceRef() + "\n" +
"git fetch " + pr.repository().webUrl() + " " + pr.targetRef() + "\n" +
"git merge FETCH_HEAD\n" +
"# resolve conflicts and follow the instructions given by git merge\n" +
"git commit -m \"Merge " + pr.targetRef() + "\"\n" +
"git push\n" +
"```\n" +
outdatedHelpMarker;
pr.addComment(message);
}

private void checkStatus() {
var checkBuilder = CheckBuilder.create("jcheck", pr.headHash());
var censusDomain = censusInstance.configuration().census().domain();
@@ -586,6 +608,7 @@ private void checkStatus() {
newLabels.remove("ready");
}
if (!rebasePossible) {
addOutdatedComment(comments);
newLabels.add("outdated");
} else {
newLabels.remove("outdated");
@@ -583,6 +583,12 @@ void cannotRebase(TestInfo testInfo) throws IOException {
// The PR should be flagged as outdated
assertTrue(pr.labels().contains("outdated"));

// An instructional message should have been bosted
var help = pr.comments().stream()
.filter(comment -> comment.body().contains("To resolve these merge conflicts"))
.count();
assertEquals(1, help);

// But it should still pass jcheck
var checks = pr.checks(editHash);
assertEquals(1, checks.size());