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
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions bots/pr/src/main/java/org/openjdk/skara/bots/pr/CheckRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:\n" +
rwestberg marked this conversation as resolved.
Show resolved Hide resolved
"```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();
Expand Down Expand Up @@ -586,6 +608,7 @@ private void checkStatus() {
newLabels.remove("ready");
}
if (!rebasePossible) {
addOutdatedComment(comments);
newLabels.add("outdated");
} else {
newLabels.remove("outdated");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down