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

pr: return HostedCommit from CheckRun.backportedFrom #950

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 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 @@ -247,15 +247,8 @@ private void updateReadyForReview(PullRequestCheckIssueVisitor visitor, List<Str
}
}

private boolean updateClean(Hash hash) {
var result = pr.repository().forge().search(hash);
if (result.isEmpty()) {
throw new IllegalStateException("Backport comment for PR " + pr.id() + " contains bad hash: " + hash.hex());
}

private boolean updateClean(Commit commit) {
var hasCleanLabel = labels.contains("clean");

var commit = result.get();
var originalPatches = new HashMap<String, Patch>();
for (var patch : commit.parentDiffs().get(0).patches()) {
originalPatches.put(patch.toString(), patch);
Expand Down Expand Up @@ -344,7 +337,7 @@ private boolean updateClean(Hash hash) {
return true;
}

private Optional<Hash> backportedFrom() {
private Optional<HostedCommit> backportedFrom() {
var botUser = pr.repository().forge().currentUser();
var backportLines = pr.comments()
.stream()
Expand All @@ -353,8 +346,16 @@ private Optional<Hash> backportedFrom() {
.map(l -> BACKPORT_PATTERN.matcher(l))
.filter(Matcher::find)
.collect(Collectors.toList());
return backportLines.isEmpty()?
Optional.empty() : Optional.of(new Hash(backportLines.get(0).group(1)));
if (backportLines.isEmpty()) {
return Optional.empty();
}

var hash = new Hash(backportLines.get(0).group(1));
var commit = pr.repository().forge().search(hash);
if (commit.isEmpty()) {
throw new IllegalStateException("Backport comment for PR " + pr.id() + " contains bad hash: " + hash.hex());
}
return commit;
}

private String getRole(String username) {
Expand Down Expand Up @@ -983,7 +984,7 @@ private void checkStatus() {
updateReviewedMessages(comments, allReviews);
}

var amendedHash = checkablePullRequest.amendManualReviewers(localHash, censusInstance.namespace(), original.orElse(null));
var amendedHash = checkablePullRequest.amendManualReviewers(localHash, censusInstance.namespace(), original.map(Commit::hash).orElse(null));
var commit = localRepo.lookup(amendedHash).orElseThrow();
var commitMessage = String.join("\n", commit.message());
var readyForIntegration = visitor.messages().isEmpty() &&
Expand Down