Skip to content

Commit

Permalink
Merge pull request #9 from gsmet/improvements
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
gsmet authored Nov 24, 2023
2 parents 58bb5e0 + ddc9c7f commit 95f9e3b
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 22 deletions.
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ inputs:
action:
description: 'Name of the action (if named)'
required: false
interaction-comment:
description: 'Optional interaction comment'
required: false
outputs:
workflow-run-id:
value: ${{ steps.action.outputs.workflow-run-id }}
interaction-comment:
value: ${{ steps.action.outputs.interaction-comment }}
runs:
using: "composite"
steps:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<dependency>
<groupId>io.quarkiverse.githubaction</groupId>
<artifactId>quarkus-github-action</artifactId>
<version>2.0.4</version>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/io/quarkus/bot/release/GetWorkflowRunIdAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.quarkus.bot.release;

import jakarta.inject.Inject;

import org.kohsuke.github.GHEventPayload;

import io.quarkiverse.githubaction.Action;
import io.quarkiverse.githubaction.Commands;
import io.quarkiverse.githubapp.event.IssueComment;
import io.quarkus.bot.release.util.Issues;
import io.quarkus.bot.release.util.Outputs;

public class GetWorkflowRunIdAction {

@Inject
Issues issues;

@Action("get-workflow-run-id")
void getWorkflowRunId(Commands commands, @IssueComment.Created GHEventPayload.IssueComment issueCommentPayload) {
commands.setOutput(Outputs.WORKFLOW_RUN_ID,
issues.extractReleaseStatus(issueCommentPayload.getIssue().getBody()).getWorkflowRunId().toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.quarkus.bot.release;

import java.io.IOException;
import java.util.Optional;

import org.kohsuke.github.GHEventPayload;
import org.kohsuke.github.GHIssue;

import io.quarkiverse.githubaction.Action;
import io.quarkiverse.githubaction.Inputs;
import io.quarkiverse.githubapp.event.Issue;
import io.quarkiverse.githubapp.event.IssueComment;
import io.quarkus.bot.release.util.Outputs;

public class PostInteractionCommentAction {

@Action("post-interaction-comment")
void postInteractionComment(Inputs inputs, @Issue.Opened GHEventPayload.Issue issuePayload) throws IOException {
postInteractionComment(inputs, issuePayload.getIssue());
}

@Action("post-interaction-comment")
void postInteractionComment(Inputs inputs, @IssueComment.Created GHEventPayload.IssueComment issueCommentPayload)
throws IOException {
postInteractionComment(inputs, issueCommentPayload.getIssue());
}

private void postInteractionComment(Inputs inputs, GHIssue issue) throws IOException {
Optional<String> interactionCommentInput = inputs.get(Outputs.INTERACTION_COMMENT);
if (interactionCommentInput.isEmpty() || interactionCommentInput.get().isBlank()) {
return;
}

issue.comment(interactionCommentInput.get());
}
}
12 changes: 7 additions & 5 deletions src/main/java/io/quarkus/bot/release/ReleaseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
import io.quarkus.bot.release.step.StepStatus;
import io.quarkus.bot.release.util.Command;
import io.quarkus.bot.release.util.Issues;
import io.quarkus.bot.release.util.Outputs;
import io.quarkus.bot.release.util.Processes;
import io.quarkus.bot.release.util.Users;

public class ReleaseAction {

Expand Down Expand Up @@ -78,8 +80,7 @@ void onComment(Context context, Commands commands, @IssueComment.Created GHEvent
GHIssueComment issueComment = issueCommentPayload.getComment();
GHIssue issue = issueCommentPayload.getIssue();

if (issueCommentPayload.getSender().getLogin().endsWith("-bot")
|| issueCommentPayload.getSender().getLogin().endsWith("[bot]")) {
if (Users.isBot(issueCommentPayload.getSender().getLogin())) {
return;
}

Expand Down Expand Up @@ -175,7 +176,7 @@ private void handleSteps(Context context, Commands commands, GHIssue issue, GHIs
return;
}

int exitCode = stepHandler.run(releaseInformation, issue);
int exitCode = stepHandler.run(context, commands, releaseInformation, issue);
handleExitCode(exitCode, currentStep);

currentReleaseStatus = currentReleaseStatus.progress(StepStatus.COMPLETED);
Expand Down Expand Up @@ -252,8 +253,9 @@ private void progressError(Context context, Commands commands, ReleaseInformatio
try {
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."
commands.setOutput(Outputs.INTERACTION_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 `" + Command.RETRY.getFullCommand() + "` comment."
+ youAreHere(releaseInformation, currentReleaseStatus));
} catch (IOException e) {
throw new RuntimeException("Unable to add progress error comment or close the comment: " + error, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.kohsuke.github.GHIssue;
import org.kohsuke.github.GHIssueComment;

import io.quarkiverse.githubaction.Commands;
import io.quarkiverse.githubaction.Context;
import io.quarkus.arc.Unremovable;
import io.quarkus.bot.release.ReleaseInformation;
import io.quarkus.bot.release.ReleaseStatus;
Expand All @@ -27,7 +29,7 @@ public boolean shouldContinue(ReleaseInformation releaseInformation, ReleaseStat
}

@Override
public int run(ReleaseInformation releaseInformation, GHIssue issue) throws IOException, InterruptedException {
public int run(Context context, Commands commands, ReleaseInformation releaseInformation, GHIssue issue) throws IOException, InterruptedException {
issue.comment(":white_check_mark: Core release is approved, proceeding...");
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import org.kohsuke.github.GHIssue;

import io.quarkiverse.githubaction.Commands;
import io.quarkiverse.githubaction.Context;
import io.quarkus.arc.Unremovable;
import io.quarkus.bot.release.ReleaseInformation;

Expand All @@ -14,7 +16,7 @@
public class CoreReleasePrepare implements StepHandler {

@Override
public int run(ReleaseInformation releaseInformation, GHIssue issue) throws IOException, InterruptedException {
public int run(Context context, Commands commands, ReleaseInformation releaseInformation, GHIssue issue) throws IOException, InterruptedException {
throw new IllegalStateException("Testing error handling...");
}
}
11 changes: 8 additions & 3 deletions src/main/java/io/quarkus/bot/release/step/Prerequisites.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@

import org.kohsuke.github.GHIssue;

import io.quarkiverse.githubaction.Commands;
import io.quarkiverse.githubaction.Context;
import io.quarkus.arc.Unremovable;
import io.quarkus.bot.release.ReleaseInformation;
import io.quarkus.bot.release.util.Command;
import io.quarkus.bot.release.util.Issues;
import io.quarkus.bot.release.util.Outputs;
import io.quarkus.bot.release.util.Processes;

@Singleton
Expand All @@ -27,7 +31,7 @@ public class Prerequisites implements StepHandler {
Processes processes;

@Override
public int run(ReleaseInformation releaseInformation, GHIssue issue) throws IOException, InterruptedException {
public int run(Context context, Commands commands, ReleaseInformation releaseInformation, GHIssue issue) throws IOException, InterruptedException {
List<String> command = new ArrayList<String>();
command.add("./prerequisites.java");
command.add("--branch=" + releaseInformation.getBranch());
Expand Down Expand Up @@ -55,9 +59,10 @@ public int run(ReleaseInformation releaseInformation, GHIssue issue) throws IOEx
if (Files.exists(Path.of("work", "preview"))) {
comment.append("- This is a preview release (e.g.`Alpha`, `Beta`, `CR`).\n");
}
comment.append("\nPlease add a `yes` comment if you want to pursue with the release.\n");
comment.append(
"\nPlease add a `" + Command.YES.getFullCommand() + "` comment if you want to pursue with the release.\n");
comment.append("\nIf not, simply close this issue.");
issue.comment(comment.toString());
commands.setOutput(Outputs.INTERACTION_COMMENT, comment.toString());

return exitCode;
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/io/quarkus/bot/release/step/StepHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import org.kohsuke.github.GHIssue;
import org.kohsuke.github.GHIssueComment;

import io.quarkiverse.githubaction.Commands;
import io.quarkiverse.githubaction.Context;
import io.quarkus.bot.release.ReleaseInformation;
import io.quarkus.bot.release.ReleaseStatus;

public interface StepHandler {

int run(ReleaseInformation releaseInformation, GHIssue issue) throws IOException, InterruptedException;
int run(Context context, Commands commands, ReleaseInformation releaseInformation, GHIssue issue) throws IOException, InterruptedException;

default boolean shouldPause(ReleaseInformation releaseInformation, ReleaseStatus releaseStatus) {
return false;
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/io/quarkus/bot/release/util/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ public enum Command {

public boolean matches(String body) {
for (String command : commands) {
if (body.toLowerCase(Locale.ENGLISH).startsWith(command)) {
if (body.toLowerCase(Locale.ENGLISH).startsWith("@" + Users.QUARKUS_BOT + " " + command)) {
return true;
}
}

return false;
}

public String getFullCommand() {
return "@" + Users.QUARKUS_BOT + " " + commands[0];
}
}
10 changes: 10 additions & 0 deletions src/main/java/io/quarkus/bot/release/util/Outputs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.quarkus.bot.release.util;

public final class Outputs {

public static final String WORKFLOW_RUN_ID = "workflow-run-id";
public static final String INTERACTION_COMMENT = "interaction-comment";

private Outputs() {
}
}
9 changes: 0 additions & 9 deletions src/main/java/io/quarkus/bot/release/util/Teams.java

This file was deleted.

24 changes: 24 additions & 0 deletions src/main/java/io/quarkus/bot/release/util/Users.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.quarkus.bot.release.util;

import java.util.Locale;

public final class Users {

public static final String QUARKUS_BOT = "quarkusbot";
public static final String BOT_SUFFIX = "[bot]";
public static final String BOT_SUFFIX_2 = "-bot";

private Users() {
}

public static boolean isBot(String login) {
if (login == null || login.isBlank()) {
return true;
}

String normalizedLogin = login.toLowerCase(Locale.ENGLISH).trim();
return normalizedLogin.equals(QUARKUS_BOT)
|| normalizedLogin.endsWith(BOT_SUFFIX)
|| normalizedLogin.endsWith(BOT_SUFFIX_2);
}
}
19 changes: 19 additions & 0 deletions src/test/java/io/quarkus/bot/release/UsersTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.quarkus.bot.release;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;

import io.quarkus.bot.release.util.Users;

public class UsersTest {

@Test
void testIsBot() {
assertThat(Users.isBot("gsmet")).isFalse();
assertThat(Users.isBot(null)).isTrue();
assertThat(Users.isBot("quarkusbot")).isTrue();
assertThat(Users.isBot("quarkus-bot")).isTrue();
assertThat(Users.isBot("github actions [bot]")).isTrue();
}
}

0 comments on commit 95f9e3b

Please sign in to comment.