From a6cef358f2e30332bf93fb6ad3c4c9e67f0cd0b1 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Wed, 17 Jan 2024 15:02:43 +0100 Subject: [PATCH] Provide precise error messages in case of issues in CreateBranch --- .../bot/release/step/CreateBranch.java | 50 ++++++++++++++----- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/quarkus/bot/release/step/CreateBranch.java b/src/main/java/io/quarkus/bot/release/step/CreateBranch.java index b6566cb..a496a90 100644 --- a/src/main/java/io/quarkus/bot/release/step/CreateBranch.java +++ b/src/main/java/io/quarkus/bot/release/step/CreateBranch.java @@ -109,15 +109,20 @@ public boolean shouldSkipAfterPause(Context context, Commands commands, GitHub q @Override public int run(Context context, Commands commands, GitHub quarkusBotGitHub, ReleaseInformation releaseInformation, - ReleaseStatus releaseStatus, GHIssue issue, UpdatedIssueBody updatedIssueBody) throws IOException, InterruptedException { + ReleaseStatus releaseStatus, GHIssue issue, UpdatedIssueBody updatedIssueBody) throws InterruptedException, IOException { GHRepository repository = Repositories.getQuarkusRepository(quarkusBotGitHub); try { repository.getBranch(releaseInformation.getBranch()); } catch (Exception e) { // the branch does not exist, let's create it - String sha = repository.getBranch(Branches.MAIN).getSHA1(); - repository.createRef("refs/heads/" + releaseInformation.getBranch(), sha); + try { + String sha = repository.getBranch(Branches.MAIN).getSHA1(); + repository.createRef("refs/heads/" + releaseInformation.getBranch(), sha); + } catch (Exception e2) { + throw new IllegalStateException( + "Unable to create branch " + releaseInformation.getBranch() + ": " + e2.getMessage(), e2); + } } Optional versionedMilestone = getMilestone(repository, releaseInformation.getVersion()); @@ -128,9 +133,13 @@ public int run(Context context, Commands commands, GitHub quarkusBotGitHub, Rele Optional milestone = getMilestone(repository, releaseInformation.getBranch() + MAIN_MILESTONE_SUFFIX); if (milestone.isPresent()) { - milestone.get().setTitle(releaseInformation.getVersion()); + try { + milestone.get().setTitle(releaseInformation.getVersion()); - repository.createMilestone(nextMinor + MAIN_MILESTONE_SUFFIX, ""); + repository.createMilestone(nextMinor + MAIN_MILESTONE_SUFFIX, ""); + } catch (Exception e) { + throw new IllegalStateException("Unable to update the milestone or create the new milestone: " + e.getMessage(), e); + } } else { throw new IllegalStateException( "Milestone " + releaseInformation.getVersion() + " does not exist and we were unable to find milestone " @@ -138,25 +147,42 @@ public int run(Context context, Commands commands, GitHub quarkusBotGitHub, Rele } } - String previousMinorBranch = getPreviousMinorBranch(repository, releaseInformation.getBranch()); + String previousMinorBranch; + try { + previousMinorBranch = getPreviousMinorBranch(repository, releaseInformation.getBranch()); + } catch (Exception e) { + throw new IllegalStateException("Unable to resolve previous minor branch: " + e.getMessage(), e); + } String previousMinorBackportLabel = "triage/backport-" + previousMinorBranch; try { repository.getLabel(previousMinorBackportLabel); } catch (Exception e) { - repository.getLabel(BACKPORT_LABEL).update().name(previousMinorBackportLabel).done(); + try { + repository.getLabel(BACKPORT_LABEL).update().name(previousMinorBackportLabel).done(); + } catch (Exception e2) { + throw new IllegalStateException("Unable to rename backport label: " + e2.getMessage(), e2); + } } try { repository.getLabel(BACKPORT_LABEL); } catch (Exception e) { - repository.createLabel(BACKPORT_LABEL, BACKPORT_LABEL_COLOR); + try { + repository.createLabel(BACKPORT_LABEL, BACKPORT_LABEL_COLOR); + } catch (Exception e2) { + throw new IllegalStateException("Unable to create new backport label: " + e2.getMessage(), e2); + } } - List openedPullRequestsToBackport = repository.searchPullRequests().label(previousMinorBackportLabel).isOpen().list().toList(); + try { + List openedPullRequestsToBackport = repository.searchPullRequests().label(previousMinorBackportLabel).isOpen().list().toList(); - for (GHPullRequest openedPullRequestToBackport : openedPullRequestsToBackport) { - openedPullRequestToBackport.addLabels(BACKPORT_LABEL); + for (GHPullRequest openedPullRequestToBackport : openedPullRequestsToBackport) { + openedPullRequestToBackport.addLabels(BACKPORT_LABEL); + } + } catch (Exception e) { + throw new IllegalStateException("Unable to affect pull requests to the new backport label: " + e.getMessage(), e); } String comment = ":white_check_mark: Branch " + releaseInformation.getBranch() @@ -183,7 +209,7 @@ private static String getPreviousMinorBranch(GHRepository repository, String cur return Versions.getPreviousMinorBranch(tags, Versions.getBranch(currentBranch)); } - private static String getNextMinor(String currentBranch) throws IOException { + private static String getNextMinor(String currentBranch) { String[] segments = currentBranch.toString().split("\\."); if (segments.length < 2) {