diff --git a/bots/mlbridge/src/main/java/org/openjdk/skara/bots/mlbridge/ArchiveItem.java b/bots/mlbridge/src/main/java/org/openjdk/skara/bots/mlbridge/ArchiveItem.java index 53d092121..06a371f3d 100644 --- a/bots/mlbridge/src/main/java/org/openjdk/skara/bots/mlbridge/ArchiveItem.java +++ b/bots/mlbridge/src/main/java/org/openjdk/skara/bots/mlbridge/ArchiveItem.java @@ -78,7 +78,7 @@ private static Optional conflictCommit(PullRequest pr, Repository localR } try { - localRepo.merge(PullRequestUtils.targetHash(pr, localRepo)); + localRepo.merge(PullRequestUtils.targetHash(localRepo)); // No problem means no conflict return Optional.empty(); } catch (IOException e) { diff --git a/bots/pr/src/main/java/org/openjdk/skara/bots/pr/CheckRun.java b/bots/pr/src/main/java/org/openjdk/skara/bots/pr/CheckRun.java index 5e455e69a..8031721b5 100644 --- a/bots/pr/src/main/java/org/openjdk/skara/bots/pr/CheckRun.java +++ b/bots/pr/src/main/java/org/openjdk/skara/bots/pr/CheckRun.java @@ -35,7 +35,6 @@ import java.util.*; import java.util.logging.Logger; import java.util.regex.Matcher; -import java.util.regex.Pattern; import java.util.stream.*; class CheckRun { @@ -62,7 +61,6 @@ class CheckRun { private static final String emptyPrBodyMarker = ""; private static final String fullNameWarningMarker = ""; - private static final Pattern BACKPORT_PATTERN = Pattern.compile(""); private final static Set primaryTypes = Set.of("Bug", "New Feature", "Enhancement", "Task", "Sub-task"); private final Set newLabels; @@ -138,7 +136,7 @@ private List allowedTargetBranches() { } // Additional bot-specific checks that are not handled by JCheck - private List botSpecificChecks(Hash finalHash) throws IOException { + private List botSpecificChecks() { var ret = new ArrayList(); if (bodyWithoutStatus().isBlank()) { @@ -291,19 +289,10 @@ private boolean updateClean(Commit commit) { } private Optional backportedFrom() { - var botUser = pr.repository().forge().currentUser(); - var backportLines = pr.comments() - .stream() - .filter(c -> c.author().equals(botUser)) - .flatMap(c -> Stream.of(c.body().split("\n"))) - .map(l -> BACKPORT_PATTERN.matcher(l)) - .filter(Matcher::find) - .collect(Collectors.toList()); - if (backportLines.isEmpty()) { + var hash = checkablePullRequest.findOriginalBackportHash(); + if (hash == null) { 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()); @@ -339,7 +328,7 @@ private String formatReviewer(HostUser reviewer) { ret.append(contributor.fullName().orElse(contributor.username())); if (censusLink.isPresent()) { ret.append("]("); - ret.append(censusLink.get().toString()); + ret.append(censusLink.get()); ret.append(")"); } ret.append(" (@"); @@ -475,7 +464,6 @@ private String getStatusMessage(List comments, List reviews, Pu try { var iss = issueProject.issue(currentIssue.shortId()); if (iss.isPresent()) { - var properties = iss.get().properties(); progressBody.append("["); progressBody.append(iss.get().id()); progressBody.append("]("); @@ -594,16 +582,11 @@ private String updateStatusMessage(String message) { } private String verdictToString(Review.Verdict verdict) { - switch (verdict) { - case APPROVED: - return "changes are approved"; - case DISAPPROVED: - return "more changes needed"; - case NONE: - return "comment added"; - default: - throw new RuntimeException("Unknown verdict: " + verdict); - } + return switch (verdict) { + case APPROVED -> "changes are approved"; + case DISAPPROVED -> "more changes needed"; + case NONE -> "comment added"; + }; } private void updateReviewedMessages(List comments, List reviews) { @@ -636,7 +619,7 @@ private String getMergeReadyComment(String commitMessage, List reviews) try { var hasContributingFile = - !localRepo.files(PullRequestUtils.targetHash(pr, localRepo), Path.of("CONTRIBUTING.md")).isEmpty(); + !localRepo.files(checkablePullRequest.targetHash(), Path.of("CONTRIBUTING.md")).isEmpty(); if (hasContributingFile) { message.append("\n\nℹ️ This project also has non-automated pre-integration requirements. Please see the file "); message.append("[CONTRIBUTING.md](https://github.com/"); @@ -724,7 +707,6 @@ private String getMergeReadyComment(String commitMessage, List reviews) if (!censusInstance.isCommitter(pr.author())) { message.append("\n"); - var contributor = censusInstance.namespace().get(pr.author().id()); message.append("As you do not have [Committer](https://openjdk.java.net/bylaws#committer) status in "); message.append("[this project](https://openjdk.java.net/census#"); message.append(censusInstance.project().name()); @@ -811,7 +793,7 @@ private void updateMergeReadyComment(boolean isReady, String commitMessage, List } } - private void addSourceBranchWarningComment(List comments) throws IOException { + private void addSourceBranchWarningComment(List comments) { var existing = findComment(comments, sourceBranchWarningMarker); if (existing.isPresent()) { // Only add the comment once per PR @@ -822,7 +804,7 @@ private void addSourceBranchWarningComment(List comments) throws IOExce "a branch with the same name as the source branch for this pull request (`" + branch + "`) " + "is present in the [target repository](" + pr.repository().nonTransformedWebUrl() + "). " + "If you eventually integrate this pull request then the branch `" + branch + "` " + - "in your [personal fork](" + pr.sourceRepository().get().nonTransformedWebUrl() + ") will diverge once you sync " + + "in your [personal fork](" + pr.sourceRepository().orElseThrow().nonTransformedWebUrl() + ") will diverge once you sync " + "your personal fork with the upstream repository.\n" + "\n" + "To avoid this situation, create a new branch for your changes and reset the `" + branch + "` branch. " + @@ -911,18 +893,18 @@ private void checkStatus() { additionalErrors = List.of(e.getMessage()); localHash = baseHash; } - PullRequestCheckIssueVisitor visitor = checkablePullRequest.createVisitor(localHash); + PullRequestCheckIssueVisitor visitor = checkablePullRequest.createVisitor(); if (localHash.equals(baseHash)) { if (additionalErrors.isEmpty()) { additionalErrors = List.of("This PR contains no changes"); } - } else if (localHash.equals(PullRequestUtils.targetHash(pr, localRepo))) { + } else if (localHash.equals(checkablePullRequest.targetHash())) { additionalErrors = List.of("This PR only contains changes already present in the target"); } else { // Determine current status var additionalConfiguration = AdditionalConfiguration.get(localRepo, localHash, pr.repository().forge().currentUser(), comments); checkablePullRequest.executeChecks(localHash, censusInstance, visitor, additionalConfiguration); - additionalErrors = botSpecificChecks(localHash); + additionalErrors = botSpecificChecks(); } updateCheckBuilder(checkBuilder, visitor, additionalErrors); updateReadyForReview(visitor, additionalErrors); diff --git a/bots/pr/src/main/java/org/openjdk/skara/bots/pr/CheckablePullRequest.java b/bots/pr/src/main/java/org/openjdk/skara/bots/pr/CheckablePullRequest.java index 68ee80f2d..f331a0c22 100644 --- a/bots/pr/src/main/java/org/openjdk/skara/bots/pr/CheckablePullRequest.java +++ b/bots/pr/src/main/java/org/openjdk/skara/bots/pr/CheckablePullRequest.java @@ -32,10 +32,14 @@ import java.io.*; import java.util.*; +import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; +import java.util.stream.Stream; public class CheckablePullRequest { + private static final Pattern BACKPORT_PATTERN = Pattern.compile(""); + private final PullRequest pr; private final Repository localRepo; private final boolean ignoreStaleReviews; @@ -121,8 +125,6 @@ private String commitMessage(Hash head, List activeReviews, Namespace na /** * The Review list is in chronological order, the latest one from a particular reviewer is the * one that is "active". - * @param allReviews - * @return */ static List filterActiveReviews(List allReviews) { var reviewPerUser = new LinkedHashMap(); @@ -142,7 +144,7 @@ Hash commit(Hash finalHead, Namespace namespace, String censusDomain, String spo throw new CommitFailure("Merge PRs can only be created by known OpenJDK authors."); } - var head = localRepo.lookup(pr.headHash()).get(); + var head = localRepo.lookup(pr.headHash()).orElseThrow(); author = head.author(); } else { author = new Author(contributor.fullName().orElseThrow(), contributor.username() + "@" + censusDomain); @@ -172,8 +174,8 @@ Hash amendManualReviewers(Hash commit, Namespace namespace, Hash original) throw } } - PullRequestCheckIssueVisitor createVisitor(Hash localHash) throws IOException { - var checks = JCheck.checksFor(localRepo, PullRequestUtils.targetHash(pr, localRepo)); + PullRequestCheckIssueVisitor createVisitor() throws IOException { + var checks = JCheck.checksFor(localRepo, targetHash()); return new PullRequestCheckIssueVisitor(checks); } @@ -182,10 +184,10 @@ void executeChecks(Hash localHash, CensusInstance censusInstance, PullRequestChe if (confOverride != null) { conf = JCheck.parseConfiguration(confOverride, additionalConfiguration); } else { - conf = JCheck.parseConfiguration(localRepo, PullRequestUtils.targetHash(pr, localRepo), additionalConfiguration); + conf = JCheck.parseConfiguration(localRepo, targetHash(), additionalConfiguration); } if (conf.isEmpty()) { - throw new RuntimeException("Failed to parse jcheck configuration at: " + PullRequestUtils.targetHash(pr, localRepo) + " with extra: " + additionalConfiguration); + throw new RuntimeException("Failed to parse jcheck configuration at: " + targetHash() + " with extra: " + additionalConfiguration); } try (var issues = JCheck.check(localRepo, censusInstance.census(), CommitMessageParsers.v1, localHash, conf.get())) { @@ -201,8 +203,8 @@ List divergingCommits() { private List divergingCommits(Hash commitHash) { try { - var updatedBase = localRepo.mergeBase(PullRequestUtils.targetHash(pr, localRepo), commitHash); - return localRepo.commitMetadata(updatedBase, PullRequestUtils.targetHash(pr, localRepo)); + var updatedBase = localRepo.mergeBase(targetHash(), commitHash); + return localRepo.commitMetadata(updatedBase, targetHash()); } catch (IOException e) { throw new RuntimeException(e); } @@ -227,7 +229,7 @@ Optional mergeTarget(PrintWriter reply) { .forEach(c -> reply.println(" * " + c.hash().hex() + ": " + c.message().get(0))); if (divergingCommits.size() > 10) { try { - var baseHash = localRepo.mergeBase(PullRequestUtils.targetHash(pr, localRepo), pr.headHash()); + var baseHash = localRepo.mergeBase(targetHash(), pr.headHash()); reply.println(" * ... and " + (divergingCommits.size() - 10) + " more: " + pr.repository().webUrl(baseHash.hex(), pr.targetRef())); } catch (IOException e) { @@ -240,11 +242,11 @@ Optional mergeTarget(PrintWriter reply) { localRepo.checkout(pr.headHash(), true); Hash hash; try { - localRepo.merge(PullRequestUtils.targetHash(pr, localRepo)); + localRepo.merge(targetHash()); hash = localRepo.commit("Automatic merge with latest target", "duke", "duke@openjdk.org"); } catch (IOException e) { localRepo.abortMerge(); - localRepo.rebase(PullRequestUtils.targetHash(pr, localRepo), "duke", "duke@openjdk.org"); + localRepo.rebase(targetHash(), "duke", "duke@openjdk.org"); hash = localRepo.head(); } reply.println(); @@ -263,4 +265,25 @@ Optional mergeTarget(PrintWriter reply) { } } + Hash findOriginalBackportHash() { + var botUser = pr.repository().forge().currentUser(); + var backportLines = pr.comments() + .stream() + .filter(c -> c.author().equals(botUser)) + .flatMap(c -> Stream.of(c.body().split("\n"))) + .map(BACKPORT_PATTERN::matcher) + .filter(Matcher::find) + .collect(Collectors.toList()); + return backportLines.isEmpty() ? null : new Hash(backportLines.get(0).group(1)); + } + + // Lazily initiated + private Hash targetHash; + + public Hash targetHash() throws IOException { + if (targetHash == null) { + targetHash = PullRequestUtils.targetHash(localRepo); + } + return targetHash; + } } diff --git a/bots/pr/src/main/java/org/openjdk/skara/bots/pr/IntegrateCommand.java b/bots/pr/src/main/java/org/openjdk/skara/bots/pr/IntegrateCommand.java index ee304fc4e..5705f0214 100644 --- a/bots/pr/src/main/java/org/openjdk/skara/bots/pr/IntegrateCommand.java +++ b/bots/pr/src/main/java/org/openjdk/skara/bots/pr/IntegrateCommand.java @@ -32,7 +32,6 @@ import java.time.Duration; import java.util.*; import java.util.logging.Level; -import java.util.stream.Stream; import java.util.stream.Collectors; import java.util.logging.Logger; import java.util.regex.Pattern; @@ -40,7 +39,6 @@ public class IntegrateCommand implements CommandHandler { private final static Logger log = Logger.getLogger("org.openjdk.skara.bots.pr"); - private static final Pattern BACKPORT_PATTERN = Pattern.compile(""); private static final String PRE_PUSH_MARKER = ""; private static final Pattern PRE_PUSH_PATTERN = Pattern.compile(""); @@ -149,9 +147,9 @@ public void handle(PullRequestBot bot, PullRequest pr, CensusInstance censusInst bot.confOverrideName(), bot.confOverrideRef()); - if (targetHash != null && !PullRequestUtils.targetHash(pr, localRepo).equals(targetHash)) { + if (targetHash != null && !checkablePr.targetHash().equals(targetHash)) { reply.print("The head of the target branch is no longer at the requested hash " + targetHash); - reply.println(" - it has moved to " + PullRequestUtils.targetHash(pr, localRepo) + ". Aborting integration."); + reply.println(" - it has moved to " + checkablePr.targetHash() + ". Aborting integration."); return; } @@ -160,30 +158,14 @@ public void handle(PullRequestBot bot, PullRequest pr, CensusInstance censusInst var rebaseWriter = new PrintWriter(rebaseMessage); var rebasedHash = checkablePr.mergeTarget(rebaseWriter); if (rebasedHash.isEmpty()) { - reply.println(rebaseMessage.toString()); + reply.println(rebaseMessage); return; } - var botUser = pr.repository().forge().currentUser(); - var backportLines = pr.comments() - .stream() - .filter(c -> c.author().equals(botUser)) - .flatMap(c -> Stream.of(c.body().split("\n"))) - .map(l -> BACKPORT_PATTERN.matcher(l)) - .filter(Matcher::find) - .collect(Collectors.toList()); - var original = backportLines.isEmpty() ? null : new Hash(backportLines.get(0).group(1)); + var original = checkablePr.findOriginalBackportHash(); var localHash = checkablePr.commit(rebasedHash.get(), censusInstance.namespace(), censusInstance.configuration().census().domain(), null, original); - var issues = checkablePr.createVisitor(localHash); - var additionalConfiguration = AdditionalConfiguration.get(localRepo, localHash, pr.repository().forge().currentUser(), allComments); - checkablePr.executeChecks(localHash, censusInstance, issues, additionalConfiguration); - if (!issues.messages().isEmpty()) { - reply.print("Your integration request cannot be fulfilled at this time, as "); - reply.println("your changes failed the final jcheck:"); - issues.messages().stream() - .map(line -> " * " + line) - .forEach(reply::println); + if (runJcheck(pr, censusInstance, allComments, reply, localRepo, checkablePr, localHash)) { return; } @@ -199,7 +181,7 @@ public void handle(PullRequestBot bot, PullRequest pr, CensusInstance censusInst } // Rebase and push it! - if (!localHash.equals(PullRequestUtils.targetHash(pr, localRepo))) { + if (!localHash.equals(checkablePr.targetHash())) { var amendedHash = checkablePr.amendManualReviewers(localHash, censusInstance.namespace(), original); addPrePushComment(pr, amendedHash, rebaseMessage.toString()); localRepo.push(amendedHash, pr.repository().url(), pr.targetRef()); @@ -216,6 +198,25 @@ public void handle(PullRequestBot bot, PullRequest pr, CensusInstance censusInst } } + /** + * Runs the checks adding to the reply message and returns true if any of them failed + */ + static boolean runJcheck(PullRequest pr, CensusInstance censusInstance, List allComments, PrintWriter reply, + Repository localRepo, CheckablePullRequest checkablePr, Hash localHash) throws IOException { + var issues = checkablePr.createVisitor(); + var additionalConfiguration = AdditionalConfiguration.get(localRepo, localHash, pr.repository().forge().currentUser(), allComments); + checkablePr.executeChecks(localHash, censusInstance, issues, additionalConfiguration); + if (!issues.messages().isEmpty()) { + reply.print("Your integration request cannot be fulfilled at this time, as "); + reply.println("your changes failed the final jcheck:"); + issues.messages().stream() + .map(line -> " * " + line) + .forEach(reply::println); + return true; + } + return false; + } + static Repository materializeLocalRepo(PullRequestBot bot, PullRequest pr, Path scratchPath, String subdir) throws IOException { var path = scratchPath.resolve(subdir).resolve(pr.repository().name()); var seedPath = bot.seedStorage().orElse(scratchPath.resolve("seeds")); @@ -239,9 +240,6 @@ static Optional checkForPrePushHash(PullRequestBot bot, PullRequest pr, Pa .map(m -> m.group(1)) .collect(Collectors.toList()); if (!prePushHashes.isEmpty()) { - var path = scratchPath.resolve("integrate").resolve(pr.repository().name()); - var seedPath = bot.seedStorage().orElse(scratchPath.resolve("seeds")); - var hostedRepositoryPool = new HostedRepositoryPool(seedPath); try { var localRepo = materializeLocalRepo(bot, pr, scratchPath, subdir); for (String prePushHash : prePushHashes) { diff --git a/bots/pr/src/main/java/org/openjdk/skara/bots/pr/SponsorCommand.java b/bots/pr/src/main/java/org/openjdk/skara/bots/pr/SponsorCommand.java index e308e855c..9f37ad1de 100644 --- a/bots/pr/src/main/java/org/openjdk/skara/bots/pr/SponsorCommand.java +++ b/bots/pr/src/main/java/org/openjdk/skara/bots/pr/SponsorCommand.java @@ -31,15 +31,10 @@ import java.time.Duration; import java.util.*; import java.util.logging.Level; -import java.util.stream.Stream; -import java.util.stream.Collectors; import java.util.logging.Logger; -import java.util.regex.Pattern; -import java.util.regex.Matcher; public class SponsorCommand implements CommandHandler { private final Logger log = Logger.getLogger("org.openjdk.skara.bots.pr"); - private static final Pattern BACKPORT_PATTERN = Pattern.compile(""); @Override public void handle(PullRequestBot bot, PullRequest pr, CensusInstance censusInstance, Path scratchPath, CommandInvocation command, List allComments, PrintWriter reply) { @@ -64,7 +59,7 @@ public void handle(PullRequestBot bot, PullRequest pr, CensusInstance censusInst return; } - var acceptedHash = readyHash.get(); + var acceptedHash = readyHash.orElseThrow(); if (!pr.labelNames().contains("auto") && !pr.headHash().equals(acceptedHash)) { reply.print("The PR has been updated since the change author (@" + pr.author().username() + ") "); reply.println("issued the `integrate` command - the author must perform this command again."); @@ -100,9 +95,9 @@ public void handle(PullRequestBot bot, PullRequest pr, CensusInstance censusInst // Validate the target hash if requested if (!command.args().isBlank()) { var wantedHash = new Hash(command.args()); - if (!PullRequestUtils.targetHash(pr, localRepo).equals(wantedHash)) { + if (!checkablePr.targetHash().equals(wantedHash)) { reply.print("The head of the target branch is no longer at the requested hash " + wantedHash); - reply.println(" - it has moved to " + PullRequestUtils.targetHash(pr, localRepo) + ". Aborting integration."); + reply.println(" - it has moved to " + checkablePr.targetHash() + ". Aborting integration."); return; } } @@ -112,35 +107,19 @@ public void handle(PullRequestBot bot, PullRequest pr, CensusInstance censusInst var rebaseWriter = new PrintWriter(rebaseMessage); var rebasedHash = checkablePr.mergeTarget(rebaseWriter); if (rebasedHash.isEmpty()) { - reply.println(rebaseMessage.toString()); + reply.println(rebaseMessage); return; } - var botUser = pr.repository().forge().currentUser(); - var backportLines = pr.comments() - .stream() - .filter(c -> c.author().equals(botUser)) - .flatMap(c -> Stream.of(c.body().split("\n"))) - .map(l -> BACKPORT_PATTERN.matcher(l)) - .filter(Matcher::find) - .collect(Collectors.toList()); - var original = backportLines.isEmpty() ? null : new Hash(backportLines.get(0).group(1)); + var original = checkablePr.findOriginalBackportHash(); var localHash = checkablePr.commit(rebasedHash.get(), censusInstance.namespace(), censusInstance.configuration().census().domain(), command.user().id(), original); - var issues = checkablePr.createVisitor(localHash); - var additionalConfiguration = AdditionalConfiguration.get(localRepo, localHash, pr.repository().forge().currentUser(), allComments); - checkablePr.executeChecks(localHash, censusInstance, issues, additionalConfiguration); - if (!issues.messages().isEmpty()) { - reply.print("Your integration request cannot be fulfilled at this time, as "); - reply.println("your changes failed the final jcheck:"); - issues.messages().stream() - .map(line -> " * " + line) - .forEach(reply::println); + if (IntegrateCommand.runJcheck(pr, censusInstance, allComments, reply, localRepo, checkablePr, localHash)) { return; } - if (!localHash.equals(PullRequestUtils.targetHash(pr, localRepo))) { + if (!localHash.equals(checkablePr.targetHash())) { var amendedHash = checkablePr.amendManualReviewers(localHash, censusInstance.namespace(), original); IntegrateCommand.addPrePushComment(pr, amendedHash, rebaseMessage.toString()); localRepo.push(amendedHash, pr.repository().url(), pr.targetRef()); diff --git a/forge/src/main/java/org/openjdk/skara/forge/PullRequestUtils.java b/forge/src/main/java/org/openjdk/skara/forge/PullRequestUtils.java index d5de18aaf..21aa83d2e 100644 --- a/forge/src/main/java/org/openjdk/skara/forge/PullRequestUtils.java +++ b/forge/src/main/java/org/openjdk/skara/forge/PullRequestUtils.java @@ -34,20 +34,21 @@ import java.util.stream.Collectors; public class PullRequestUtils { - private static Hash commitSquashed(PullRequest pr, Repository localRepo, Hash finalHead, Author author, Author committer, String commitMessage) throws IOException { + private static Hash commitSquashed(Repository localRepo, Hash finalHead, Author author, Author committer, String commitMessage) throws IOException { return localRepo.commit(commitMessage, author.name(), author.email(), ZonedDateTime.now(), - committer.name(), committer.email(), ZonedDateTime.now(), List.of(targetHash(pr, localRepo)), localRepo.tree(finalHead)); + committer.name(), committer.email(), ZonedDateTime.now(), List.of(targetHash(localRepo)), localRepo.tree(finalHead)); } private final static Pattern mergeSourcePattern = Pattern.compile("^Merge ([-/\\w:+]+)$"); private final static Pattern hashSourcePattern = Pattern.compile("[0-9a-fA-F]{6,40}"); - private static Optional fetchRef(Repository localRepo, URI uri, String ref) throws IOException { + private static Optional fetchRef(Repository localRepo, URI uri, String ref) { // Just a plain name - is this a branch? try { var hash = localRepo.fetch(uri, "+" + ref + ":refs/heads/merge_source", false); return Optional.of(hash); } catch (IOException e) { + // Ignored } // Perhaps it is an actual tag object - it cannot be fetched to a branch ref @@ -55,6 +56,7 @@ private static Optional fetchRef(Repository localRepo, URI uri, String ref var hash = localRepo.fetch(uri, "+" + ref + ":refs/tags/merge_source_tag", false); return Optional.of(hash); } catch (IOException e) { + // Ignored } return Optional.empty(); @@ -64,7 +66,7 @@ private static Hash fetchMergeSource(PullRequest pr, Repository localRepo) throw var sourceMatcher = mergeSourcePattern.matcher(pr.title()); if (!sourceMatcher.matches()) { throw new CommitFailure("Could not determine the source for this merge. A Merge PR title must be specified in the format: `" + - mergeSourcePattern.toString() + "` to allow verification of the merge contents."); + mergeSourcePattern + "` to allow verification of the merge contents."); } var source = sourceMatcher.group(1); @@ -74,7 +76,7 @@ private static Hash fetchMergeSource(PullRequest pr, Repository localRepo) throw var hash = localRepo.resolve(source); if (hash.isPresent()) { // A valid merge source hash cannot be an ancestor of the target branch (if so it would not need to be merged) - var prTargetHash = PullRequestUtils.targetHash(pr, localRepo); + var prTargetHash = PullRequestUtils.targetHash(localRepo); if (!localRepo.isAncestor(hash.get(), prTargetHash)) { return hash.get(); } @@ -127,7 +129,7 @@ private static Hash findSourceHash(PullRequest pr, Repository localRepo, List new IllegalStateException("Must materialize PR first")); } @@ -175,7 +177,7 @@ public static boolean isMerge(PullRequest pr) { public static Hash createCommit(PullRequest pr, Repository localRepo, Hash finalHead, Author author, Author committer, String commitMessage) throws IOException, CommitFailure { Hash commit; if (!isMerge(pr)) { - commit = commitSquashed(pr, localRepo, finalHead, author, committer, commitMessage); + commit = commitSquashed(localRepo, finalHead, author, committer, commitMessage); } else { commit = commitMerge(pr, localRepo, finalHead, author, committer, commitMessage); } @@ -184,7 +186,7 @@ public static Hash createCommit(PullRequest pr, Repository localRepo, Hash final } public static Hash baseHash(PullRequest pr, Repository localRepo) throws IOException { - return localRepo.mergeBase(targetHash(pr, localRepo), pr.headHash()); + return localRepo.mergeBase(targetHash(localRepo), pr.headHash()); } public static Set changedFiles(PullRequest pr, Repository localRepo) throws IOException { @@ -217,7 +219,7 @@ public static boolean containsForeignMerge(PullRequest pr, Repository localRepo) .flatMap(commit -> commit.parents().stream().skip(1)) .collect(Collectors.toList()); for (var mergeParent : mergeParents) { - if (!localRepo.mergeBase(targetHash(pr, localRepo), mergeParent).equals(mergeParent)) { + if (!localRepo.mergeBase(targetHash(localRepo), mergeParent).equals(mergeParent)) { return true; } }