Skip to content

Commit

Permalink
Merge pull request #15 from gsmet/rework-getting-information
Browse files Browse the repository at this point in the history
Rework getting information from description
  • Loading branch information
gsmet authored Nov 25, 2023
2 parents e21377d + e66df64 commit 2fda63b
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 31 deletions.
16 changes: 14 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
31 changes: 31 additions & 0 deletions src/main/java/io/quarkus/bot/release/GetReleaseStatusAction.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
26 changes: 0 additions & 26 deletions src/main/java/io/quarkus/bot/release/GetWorkflowRunIdAction.java

This file was deleted.

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

import java.time.Instant;
import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonCreator;
Expand All @@ -14,13 +15,15 @@ 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) {
this.status = status;
this.currentStep = currentStep;
this.currentStepStatus = currentStepStatus;
this.workflowRunId = workflowRunId;
this.date = Instant.now();
}

public Status getStatus() {
Expand All @@ -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);
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/io/quarkus/bot/release/util/Outputs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/io/quarkus/bot/release/util/UtilsProducer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
6 changes: 4 additions & 2 deletions src/test/java/io/quarkus/bot/release/IssuesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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("""
<!-- quarkus-release/release-status:
Expand All @@ -139,6 +139,7 @@ void testAppendReleaseStatus() {
currentStep: "APPROVE_CORE_RELEASE"
currentStepStatus: "STARTED"
workflowRunId: 123
date: ".*"
-->""");

assertThat(issues.appendReleaseStatus(new UpdatedIssueBody("""
Expand All @@ -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.
<!-- quarkus-release/release-information:
Expand All @@ -173,6 +174,7 @@ void testAppendReleaseStatus() {
currentStep: "CORE_RELEASE_PREPARE"
currentStepStatus: "COMPLETED"
workflowRunId: 145
date: ".*"
-->""");
}

Expand Down

0 comments on commit 2fda63b

Please sign in to comment.