Skip to content

Commit

Permalink
Merge pull request #56 from gsmet/precise-error-messages
Browse files Browse the repository at this point in the history
Provide precise error messages in case of issues in CreateBranch
  • Loading branch information
gsmet authored Jan 17, 2024
2 parents e123363 + a6cef35 commit f876a9e
Showing 1 changed file with 38 additions and 12 deletions.
50 changes: 38 additions & 12 deletions src/main/java/io/quarkus/bot/release/step/CreateBranch.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<GHMilestone> versionedMilestone = getMilestone(repository, releaseInformation.getVersion());
Expand All @@ -128,35 +133,56 @@ public int run(Context context, Commands commands, GitHub quarkusBotGitHub, Rele

Optional<GHMilestone> 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 "
+ releaseInformation.getBranch() + MAIN_MILESTONE_SUFFIX + " to rename it");
}
}

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<GHPullRequest> openedPullRequestsToBackport = repository.searchPullRequests().label(previousMinorBackportLabel).isOpen().list().toList();
try {
List<GHPullRequest> 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()
Expand All @@ -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) {
Expand Down

0 comments on commit f876a9e

Please sign in to comment.