Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve increment handling on pause/continue #12

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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];
}
}