From e66df646896e92b14b422329b1ead891b5a08d07 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Sat, 25 Nov 2023 17:08:33 +0100 Subject: [PATCH] Rework getting information from description Also add date in status as it can be useful. --- action.yml | 16 +++++++- .../release/GetReleaseInformationAction.java | 39 +++++++++++++++++++ .../bot/release/GetReleaseStatusAction.java | 31 +++++++++++++++ .../bot/release/GetWorkflowRunIdAction.java | 26 ------------- .../io/quarkus/bot/release/ReleaseStatus.java | 7 ++++ .../io/quarkus/bot/release/util/Outputs.java | 11 +++++- .../bot/release/util/UtilsProducer.java | 4 ++ .../io/quarkus/bot/release/IssuesTest.java | 6 ++- 8 files changed, 109 insertions(+), 31 deletions(-) create mode 100644 src/main/java/io/quarkus/bot/release/GetReleaseInformationAction.java create mode 100644 src/main/java/io/quarkus/bot/release/GetReleaseStatusAction.java delete mode 100644 src/main/java/io/quarkus/bot/release/GetWorkflowRunIdAction.java diff --git a/action.yml b/action.yml index 18dff49..c237042 100644 --- a/action.yml +++ b/action.yml @@ -11,12 +11,24 @@ inputs: description: 'Optional interaction comment' required: false outputs: + branch: + value: ${{ steps.action.outputs.branch }} + qualifier: + value: ${{ steps.action.outputs.qualifier }} + major: + value: ${{ steps.action.outputs.major }} + version: + value: ${{ steps.action.outputs.version }} + status: + value: ${{ steps.action.outputs.status }} + current-step: + value: ${{ steps.action.outputs.current-step }} + current-step-status: + value: ${{ steps.action.outputs.current-step-status }} workflow-run-id: value: ${{ steps.action.outputs.workflow-run-id }} interaction-comment: value: ${{ steps.action.outputs.interaction-comment }} - version: - value: ${{ steps.action.outputs.version }} runs: using: "composite" steps: diff --git a/src/main/java/io/quarkus/bot/release/GetReleaseInformationAction.java b/src/main/java/io/quarkus/bot/release/GetReleaseInformationAction.java new file mode 100644 index 0000000..7c02ab9 --- /dev/null +++ b/src/main/java/io/quarkus/bot/release/GetReleaseInformationAction.java @@ -0,0 +1,39 @@ +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; +import io.quarkus.bot.release.util.UpdatedIssueBody; + +public class GetReleaseInformationAction { + + @Inject + Issues issues; + + @Action("get-release-information") + void getReleaseInformation(Commands commands, @IssueComment.Created GHEventPayload.IssueComment issueCommentPayload) { + ReleaseInformation releaseInformation; + + try { + UpdatedIssueBody updatedIssueBody = new UpdatedIssueBody(issueCommentPayload.getIssue().getBody()); + releaseInformation = issues.extractReleaseInformation(updatedIssueBody); + } catch (Exception e) { + releaseInformation = issues.extractReleaseInformationFromForm(issueCommentPayload.getIssue().getBody()); + } + + commands.setOutput(Outputs.BRANCH, releaseInformation.getBranch()); + if (releaseInformation.getQualifier() != null) { + commands.setOutput(Outputs.QUALIFIER, releaseInformation.getQualifier()); + } + commands.setOutput(Outputs.MAJOR, Boolean.toString(releaseInformation.isMajor())); + if (releaseInformation.getVersion() != null) { + commands.setOutput(Outputs.VERSION, releaseInformation.getVersion()); + } + } +} diff --git a/src/main/java/io/quarkus/bot/release/GetReleaseStatusAction.java b/src/main/java/io/quarkus/bot/release/GetReleaseStatusAction.java new file mode 100644 index 0000000..092bbc3 --- /dev/null +++ b/src/main/java/io/quarkus/bot/release/GetReleaseStatusAction.java @@ -0,0 +1,31 @@ +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; +import io.quarkus.bot.release.util.UpdatedIssueBody; + +public class GetReleaseStatusAction { + + @Inject + Issues issues; + + @Action("get-release-status") + void getReleaseStatus(Commands commands, @IssueComment.Created GHEventPayload.IssueComment issueCommentPayload) { + UpdatedIssueBody updatedIssueBody = new UpdatedIssueBody(issueCommentPayload.getIssue().getBody()); + + ReleaseStatus releaseStatus = issues.extractReleaseStatus(updatedIssueBody); + + commands.setOutput(Outputs.STATUS, releaseStatus.getStatus().name()); + commands.setOutput(Outputs.CURRENT_STEP, releaseStatus.getCurrentStep().name()); + commands.setOutput(Outputs.CURRENT_STEP_STATUS, releaseStatus.getCurrentStepStatus().name()); + commands.setOutput(Outputs.WORKFLOW_RUN_ID, releaseStatus.getWorkflowRunId().toString()); + commands.setOutput(Outputs.DATE, releaseStatus.getDate().toString()); + } +} diff --git a/src/main/java/io/quarkus/bot/release/GetWorkflowRunIdAction.java b/src/main/java/io/quarkus/bot/release/GetWorkflowRunIdAction.java deleted file mode 100644 index ced742a..0000000 --- a/src/main/java/io/quarkus/bot/release/GetWorkflowRunIdAction.java +++ /dev/null @@ -1,26 +0,0 @@ -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; -import io.quarkus.bot.release.util.UpdatedIssueBody; - -public class GetWorkflowRunIdAction { - - @Inject - Issues issues; - - @Action("get-workflow-run-id") - void getWorkflowRunId(Commands commands, @IssueComment.Created GHEventPayload.IssueComment issueCommentPayload) { - UpdatedIssueBody updatedIssueBody = new UpdatedIssueBody(issueCommentPayload.getIssue().getBody()); - - commands.setOutput(Outputs.WORKFLOW_RUN_ID, - issues.extractReleaseStatus(updatedIssueBody).getWorkflowRunId().toString()); - } -} diff --git a/src/main/java/io/quarkus/bot/release/ReleaseStatus.java b/src/main/java/io/quarkus/bot/release/ReleaseStatus.java index c5ffb55..fbb991b 100644 --- a/src/main/java/io/quarkus/bot/release/ReleaseStatus.java +++ b/src/main/java/io/quarkus/bot/release/ReleaseStatus.java @@ -1,5 +1,6 @@ package io.quarkus.bot.release; +import java.time.Instant; import java.util.Objects; import com.fasterxml.jackson.annotation.JsonCreator; @@ -14,6 +15,7 @@ public class ReleaseStatus { private final Step currentStep; private final StepStatus currentStepStatus; private final Long workflowRunId; + private final Instant date; @JsonCreator public ReleaseStatus(Status status, Step currentStep, StepStatus currentStepStatus, Long workflowRunId) { @@ -21,6 +23,7 @@ public ReleaseStatus(Status status, Step currentStep, StepStatus currentStepStat this.currentStep = currentStep; this.currentStepStatus = currentStepStatus; this.workflowRunId = workflowRunId; + this.date = Instant.now(); } public Status getStatus() { @@ -39,6 +42,10 @@ public Long getWorkflowRunId() { return workflowRunId; } + public Instant getDate() { + return date; + } + @JsonIgnore public ReleaseStatus progress(Long workflowRunId) { return new ReleaseStatus(this.status, this.currentStep, this.currentStepStatus, workflowRunId); diff --git a/src/main/java/io/quarkus/bot/release/util/Outputs.java b/src/main/java/io/quarkus/bot/release/util/Outputs.java index 81690c6..38994f2 100644 --- a/src/main/java/io/quarkus/bot/release/util/Outputs.java +++ b/src/main/java/io/quarkus/bot/release/util/Outputs.java @@ -2,9 +2,18 @@ public final class Outputs { + public static final String BRANCH = "branch"; + public static final String VERSION = "version"; + public static final String QUALIFIER = "qualifier"; + public static final String MAJOR = "major"; + + public static final String STATUS = "status"; + public static final String CURRENT_STEP = "current-step"; + public static final String CURRENT_STEP_STATUS = "current-step-status"; public static final String WORKFLOW_RUN_ID = "workflow-run-id"; + public static final String DATE = "date"; + public static final String INTERACTION_COMMENT = "interaction-comment"; - public static final String VERSION = "version"; private Outputs() { } diff --git a/src/main/java/io/quarkus/bot/release/util/UtilsProducer.java b/src/main/java/io/quarkus/bot/release/util/UtilsProducer.java index 6938f26..78e2925 100644 --- a/src/main/java/io/quarkus/bot/release/util/UtilsProducer.java +++ b/src/main/java/io/quarkus/bot/release/util/UtilsProducer.java @@ -16,7 +16,9 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.fasterxml.jackson.module.paramnames.ParameterNamesModule; @Singleton @@ -28,6 +30,8 @@ public class UtilsProducer { public ObjectMapper yamlObjectMapper() { ObjectMapper yamlObjectMapper = new ObjectMapper(new YAMLFactory()); yamlObjectMapper.registerModule(new ParameterNamesModule()); + yamlObjectMapper.registerModule(new JavaTimeModule()); + yamlObjectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); yamlObjectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); return yamlObjectMapper; } diff --git a/src/test/java/io/quarkus/bot/release/IssuesTest.java b/src/test/java/io/quarkus/bot/release/IssuesTest.java index 5e97b2b..1f6c44d 100644 --- a/src/test/java/io/quarkus/bot/release/IssuesTest.java +++ b/src/test/java/io/quarkus/bot/release/IssuesTest.java @@ -130,7 +130,7 @@ void testExtractReleaseInformation() { @Test void testAppendReleaseStatus() { - assertThat(issues.appendReleaseStatus(new UpdatedIssueBody(""), new ReleaseStatus(Status.STARTED, Step.APPROVE_CORE_RELEASE, StepStatus.STARTED, 123L))).isEqualTo(""" + assertThat(issues.appendReleaseStatus(new UpdatedIssueBody(""), new ReleaseStatus(Status.STARTED, Step.APPROVE_CORE_RELEASE, StepStatus.STARTED, 123L))).matches(""" """); assertThat(issues.appendReleaseStatus(new UpdatedIssueBody(""" @@ -157,7 +158,7 @@ void testAppendReleaseStatus() { currentStep: "APPROVE_CORE_RELEASE" currentStepStatus: "STARTED" workflowRunId: 123 - -->"""), new ReleaseStatus(Status.COMPLETED, Step.CORE_RELEASE_PREPARE, StepStatus.COMPLETED, 145L))).isEqualTo(""" + -->"""), new ReleaseStatus(Status.COMPLETED, Step.CORE_RELEASE_PREPARE, StepStatus.COMPLETED, 145L))).matches(""" This is a comment. """); }