Skip to content

Commit

Permalink
Merge pull request #12 from gsmet/improve-increment-handling
Browse files Browse the repository at this point in the history
Improve increment handling on pause/continue
  • Loading branch information
gsmet authored Nov 24, 2023
2 parents e1744a2 + 9a5b0b8 commit a6ab112
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> interactionCommentInput = inputs.get(Outputs.INTERACTION_COMMENT);
if (interactionCommentInput.isEmpty() || interactionCommentInput.get().isBlank()) {
commands.warning("No " + Outputs.INTERACTION_COMMENT + " input, not posting interaction comment");
return;
}

Expand Down
41 changes: 25 additions & 16 deletions src/main/java/io/quarkus/bot/release/ReleaseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -141,29 +138,36 @@ 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;
}
}
}

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;
}
Expand Down Expand Up @@ -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);

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/io/quarkus/bot/release/step/Step.java
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}

0 comments on commit a6ab112

Please sign in to comment.