diff --git a/src/main/java/io/quarkus/bot/release/PostInteractionCommentAction.java b/src/main/java/io/quarkus/bot/release/PostInteractionCommentAction.java index 4f47046..f7e46a2 100644 --- a/src/main/java/io/quarkus/bot/release/PostInteractionCommentAction.java +++ b/src/main/java/io/quarkus/bot/release/PostInteractionCommentAction.java @@ -7,6 +7,7 @@ import org.kohsuke.github.GHIssue; import io.quarkiverse.githubaction.Action; +import io.quarkiverse.githubaction.Commands; import io.quarkiverse.githubaction.Inputs; import io.quarkiverse.githubapp.event.Issue; import io.quarkiverse.githubapp.event.IssueComment; @@ -15,19 +16,22 @@ public class PostInteractionCommentAction { @Action("post-interaction-comment") - void postInteractionComment(Inputs inputs, @Issue.Opened GHEventPayload.Issue issuePayload) throws IOException { - postInteractionComment(inputs, issuePayload.getIssue()); + void postInteractionComment(Commands commands, Inputs inputs, @Issue.Opened GHEventPayload.Issue issuePayload) + throws IOException { + postInteractionComment(commands, inputs, issuePayload.getIssue()); } @Action("post-interaction-comment") - void postInteractionComment(Inputs inputs, @IssueComment.Created GHEventPayload.IssueComment issueCommentPayload) + void postInteractionComment(Commands commands, Inputs inputs, + @IssueComment.Created GHEventPayload.IssueComment issueCommentPayload) throws IOException { - postInteractionComment(inputs, issueCommentPayload.getIssue()); + postInteractionComment(commands, inputs, issueCommentPayload.getIssue()); } - private void postInteractionComment(Inputs inputs, GHIssue issue) throws IOException { + private void postInteractionComment(Commands commands, Inputs inputs, GHIssue issue) throws IOException { Optional interactionCommentInput = inputs.get(Outputs.INTERACTION_COMMENT); if (interactionCommentInput.isEmpty() || interactionCommentInput.get().isBlank()) { + commands.warning("No " + Outputs.INTERACTION_COMMENT + " input, not posting interaction comment"); return; } diff --git a/src/main/java/io/quarkus/bot/release/ReleaseAction.java b/src/main/java/io/quarkus/bot/release/ReleaseAction.java index b13b5d1..e9a3cef 100644 --- a/src/main/java/io/quarkus/bot/release/ReleaseAction.java +++ b/src/main/java/io/quarkus/bot/release/ReleaseAction.java @@ -112,20 +112,17 @@ void onComment(Context context, Commands commands, @IssueComment.Created GHEvent private void handleSteps(Context context, Commands commands, GHIssue issue, UpdatedIssueBody updatedIssueBody, GHIssueComment issueComment, ReleaseInformation releaseInformation, ReleaseStatus releaseStatus) throws Exception { - int initialStepOrdinal = releaseStatus.getCurrentStep().ordinal(); - if (releaseStatus.getCurrentStepStatus() == StepStatus.COMPLETED) { - initialStepOrdinal++; - } - if (initialStepOrdinal >= Step.values().length) { - return; - } - ReleaseStatus currentReleaseStatus = releaseStatus; if (issueComment != null) { - // Handle retries + if (currentReleaseStatus.getCurrentStepStatus() == StepStatus.COMPLETED) { + commands.error("Current step status is completed, ignoring comment"); + react(commands, issueComment, ReactionContent.MINUS_ONE); + return; + } if (currentReleaseStatus.getCurrentStepStatus() == StepStatus.FAILED || currentReleaseStatus.getCurrentStepStatus() == StepStatus.STARTED) { + // Handle retries if (currentReleaseStatus.getCurrentStep().isRecoverable()) { if (Command.RETRY.matches(issueComment.getBody())) { react(commands, issueComment, ReactionContent.PLUS_ONE); @@ -141,17 +138,14 @@ private void handleSteps(Context context, Commands commands, GHIssue issue, Upda "A previous step failed with unrecoverable error"); return; } - } - - // Handle paused, we will continue the process with the next step - if (currentReleaseStatus.getCurrentStepStatus() == StepStatus.PAUSED) { + } else if (currentReleaseStatus.getCurrentStepStatus() == StepStatus.PAUSED) { + // Handle paused, we will continue the process with the next step StepHandler stepHandler = getStepHandler(currentReleaseStatus.getCurrentStep()); if (stepHandler.shouldContinue(releaseInformation, currentReleaseStatus, issueComment)) { react(commands, issueComment, ReactionContent.PLUS_ONE); currentReleaseStatus = currentReleaseStatus.progress(StepStatus.COMPLETED); updateReleaseStatus(issue, updatedIssueBody, currentReleaseStatus); - initialStepOrdinal++; } else { react(commands, issueComment, ReactionContent.CONFUSED); return; @@ -159,11 +153,21 @@ private void handleSteps(Context context, Commands commands, GHIssue issue, Upda } } + if (currentReleaseStatus.getCurrentStepStatus() == StepStatus.COMPLETED) { + if (currentReleaseStatus.getCurrentStep().isLast()) { + markAsReleased(issue, updatedIssueBody, releaseInformation, currentReleaseStatus); + return; + } else { + currentReleaseStatus = currentReleaseStatus.progress(currentReleaseStatus.getCurrentStep().next()); + updateReleaseStatus(issue, updatedIssueBody, currentReleaseStatus); + } + } + progressInformation(context, commands, releaseInformation, currentReleaseStatus, issue, - "Proceeding to step " + Step.values()[initialStepOrdinal].getDescription()); + "Proceeding to step " + currentReleaseStatus.getCurrentStep().getDescription()); for (Step currentStep : Step.values()) { - if (currentStep.ordinal() < initialStepOrdinal) { + if (currentStep.ordinal() < currentReleaseStatus.getCurrentStep().ordinal()) { // we already handled this step, skipping to next one continue; } @@ -208,6 +212,11 @@ private void handleSteps(Context context, Commands commands, GHIssue issue, Upda } } + markAsReleased(issue, updatedIssueBody, releaseInformation, currentReleaseStatus); + } + + private void markAsReleased(GHIssue issue, UpdatedIssueBody updatedIssueBody, ReleaseInformation releaseInformation, + ReleaseStatus currentReleaseStatus) { currentReleaseStatus = currentReleaseStatus.progress(Status.COMPLETED); updateReleaseStatus(issue, updatedIssueBody, currentReleaseStatus); diff --git a/src/main/java/io/quarkus/bot/release/step/Step.java b/src/main/java/io/quarkus/bot/release/step/Step.java index 36df9ce..35d5cb2 100644 --- a/src/main/java/io/quarkus/bot/release/step/Step.java +++ b/src/main/java/io/quarkus/bot/release/step/Step.java @@ -50,4 +50,16 @@ public boolean isRecoverable() { public boolean isForFinalReleasesOnly() { return forFinalReleasesOnly; } + + public boolean isLast() { + return this.ordinal() == values().length -1; + } + + public Step next() { + if (isLast()) { + throw new IllegalStateException("Called next() on the last step"); + } + + return Step.values()[this.ordinal() + 1]; + } }