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 action feedback #8

Merged
merged 2 commits into from
Nov 23, 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
40 changes: 16 additions & 24 deletions src/main/java/io/quarkus/bot/release/ReleaseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
import io.quarkus.arc.InstanceHandle;
import io.quarkus.bot.release.error.StatusUpdateException;
import io.quarkus.bot.release.error.StepExecutionException;
import io.quarkus.bot.release.step.ApproveCoreRelease;
import io.quarkus.bot.release.step.CoreReleasePrepare;
import io.quarkus.bot.release.step.Prerequisites;
import io.quarkus.bot.release.step.Step;
import io.quarkus.bot.release.step.StepHandler;
import io.quarkus.bot.release.step.StepStatus;
Expand All @@ -43,14 +40,6 @@ public class ReleaseAction {
@Inject
Processes processes;

// ugly workaround...
@Inject
Prerequisites prerequisites;
@Inject
ApproveCoreRelease approveCoreRelease;
@Inject
CoreReleasePrepare coreReleasePrepare;

@Action
void startRelease(Context context, Commands commands, @Issue.Opened GHEventPayload.Issue issuePayload) throws Exception {
GHIssue issue = issuePayload.getIssue();
Expand Down Expand Up @@ -160,7 +149,7 @@ private void handleSteps(Context context, Commands commands, GHIssue issue, GHIs
}

progressInformation(context, commands, releaseInformation, currentReleaseStatus, issue,
"Proceeding to step " + Step.values()[initialStepOrdinal]);
"Proceeding to step " + Step.values()[initialStepOrdinal].getDescription());

for (Step currentStep : Step.values()) {
if (currentStep.ordinal() < initialStepOrdinal) {
Expand Down Expand Up @@ -261,21 +250,23 @@ private static void progressInformation(Context context, Commands commands, Rele

private void progressError(Context context, Commands commands, ReleaseInformation releaseInformation, ReleaseStatus releaseStatus, GHIssue issue, String error) {
try {
issue.setBody(issues.appendReleaseStatus(issue.getBody(), releaseStatus.progress(StepStatus.FAILED)));
ReleaseStatus currentReleaseStatus = releaseStatus.progress(StepStatus.FAILED);
issue.setBody(issues.appendReleaseStatus(issue.getBody(), currentReleaseStatus));
issue.comment(":rotating_light: " + error + "\n\nYou can find more information about the failure [here](" + getWorkflowRunUrl(context) + ").\n\n"
+ "This is not a fatal error, you can retry by adding a `retry` comment."
+ youAreHere(releaseInformation, releaseStatus));
+ youAreHere(releaseInformation, currentReleaseStatus));
} catch (IOException e) {
throw new RuntimeException("Unable to add progress error comment or close the comment: " + error, e);
}
}

private void fatalError(Context context, Commands commands, ReleaseInformation releaseInformation, ReleaseStatus releaseStatus, GHIssue issue, String error) {
try {
issue.setBody(issues.appendReleaseStatus(issue.getBody(), releaseStatus.progress(Status.FAILED, StepStatus.FAILED)));
ReleaseStatus currentReleaseStatus = releaseStatus.progress(Status.FAILED, StepStatus.FAILED);
issue.setBody(issues.appendReleaseStatus(issue.getBody(), currentReleaseStatus));
issue.comment(":rotating_light: " + error + "\n\nYou can find more information about the failure [here](" + getWorkflowRunUrl(context) + ").\n\n"
+ "This is a fatal error, the issue will be closed."
+ youAreHere(releaseInformation, releaseStatus));
+ youAreHere(releaseInformation, currentReleaseStatus));
issue.close();
} catch (IOException e) {
throw new RuntimeException("Unable to add fatal error comment or close the comment: " + error, e);
Expand All @@ -287,7 +278,7 @@ private static String getWorkflowRunUrl(Context context) {
}

private static String youAreHere(ReleaseInformation releaseInformation, ReleaseStatus releaseStatus) {
return "\n\n<details><summary>You are here</summary>\n\n- " +
return "\n\n<details><summary>You are here</summary>\n\n" +
Arrays.stream(Step.values())
.filter(s -> releaseInformation.isFinal() || !s.isForFinalReleasesOnly())
.map(s -> {
Expand All @@ -299,14 +290,15 @@ private static String youAreHere(ReleaseInformation releaseInformation, ReleaseS
} else {
sb.append(" ");
}
sb.append("] ").append(s.name());
if (releaseStatus.getCurrentStepStatus() == StepStatus.STARTED) {
sb.append(" :gear:");
}
if (releaseStatus.getCurrentStepStatus() == StepStatus.FAILED) {
sb.append(" :rotating_light:");
}
sb.append("] ").append(s.getDescription());

if (releaseStatus.getCurrentStep() == s) {
if (releaseStatus.getCurrentStepStatus() == StepStatus.STARTED) {
sb.append(" :gear:");
}
if (releaseStatus.getCurrentStepStatus() == StepStatus.FAILED) {
sb.append(" :rotating_light:");
}
sb.append(" ☚ You are here");
}
return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import org.kohsuke.github.GHIssue;
import org.kohsuke.github.GHIssueComment;

import io.quarkus.arc.Unremovable;
import io.quarkus.bot.release.ReleaseInformation;
import io.quarkus.bot.release.ReleaseStatus;
import io.quarkus.bot.release.util.Command;

@Singleton
@Unremovable
public class ApproveCoreRelease implements StepHandler {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

import org.kohsuke.github.GHIssue;

import io.quarkus.arc.Unremovable;
import io.quarkus.bot.release.ReleaseInformation;

@Singleton
@Unremovable
public class CoreReleasePrepare implements StepHandler {

@Override
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/quarkus/bot/release/step/Prerequisites.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

import org.kohsuke.github.GHIssue;

import io.quarkus.arc.Unremovable;
import io.quarkus.bot.release.ReleaseInformation;
import io.quarkus.bot.release.util.Issues;
import io.quarkus.bot.release.util.Processes;

@Singleton
@Unremovable
public class Prerequisites implements StepHandler {

@Inject
Expand Down
6 changes: 4 additions & 2 deletions src/test/java/io/quarkus/bot/release/StepInjectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
import org.junit.jupiter.api.Test;

import io.quarkus.arc.Arc;
import io.quarkus.bot.release.step.Prerequisites;
import io.quarkus.bot.release.step.Step;
import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
public class StepInjectionTest {

@Test
void testStepInjection() {
assertThat(Arc.container().instance(Prerequisites.class).get()).isNotNull();
for (Step step : Step.values()) {
assertThat(Arc.container().instance(step.getStepHandler()).get()).isNotNull();
}
}
}