Skip to content

Commit 551dbf2

Browse files
authored
Merge pull request #1064 from gsmet/workflow-runs
Implement GHWorkflow, GHWorkflowRun and associated payloads
2 parents e522239 + d734237 commit 551dbf2

100 files changed

Lines changed: 14324 additions & 27 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pom.xml

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -277,19 +277,6 @@
277277
<argLine>${surefire.argLine}</argLine>
278278
</configuration>
279279
</execution>
280-
<execution>
281-
<id>slow-or-flaky-test</id>
282-
<phase>test</phase>
283-
<goals>
284-
<goal>test</goal>
285-
</goals>
286-
<configuration>
287-
<rerunFailingTestsCount>2</rerunFailingTestsCount>
288-
<!-- There are some tests that take longer or are a little flaky. Run them here. -->
289-
<includesFile>src/test/resources/slow-or-flaky-tests.txt</includesFile>
290-
<argLine>${surefire.argLine}</argLine>
291-
</configuration>
292-
</execution>
293280
</executions>
294281
</plugin>
295282
<plugin>
@@ -422,6 +409,12 @@
422409
<version>4.13.2</version>
423410
<scope>test</scope>
424411
</dependency>
412+
<dependency>
413+
<groupId>org.awaitility</groupId>
414+
<artifactId>awaitility</artifactId>
415+
<version>4.0.3</version>
416+
<scope>test</scope>
417+
</dependency>
425418
<dependency>
426419
<groupId>com.fasterxml.jackson.core</groupId>
427420
<artifactId>jackson-databind</artifactId>
@@ -565,6 +558,38 @@
565558
</pluginRepository>
566559
</pluginRepositories>
567560
<profiles>
561+
<!-- only enable slow-or-flaky-test if -Dtest= is not present -->
562+
<profile>
563+
<id>slow-or-flaky-test</id>
564+
<activation>
565+
<property>
566+
<name>!test</name>
567+
</property>
568+
</activation>
569+
<build>
570+
<plugins>
571+
<plugin>
572+
<artifactId>maven-surefire-plugin</artifactId>
573+
<executions>
574+
<execution>
575+
<id>slow-or-flaky-test</id>
576+
<phase>test</phase>
577+
<goals>
578+
<goal>test</goal>
579+
</goals>
580+
<configuration>
581+
<rerunFailingTestsCount>2</rerunFailingTestsCount>
582+
<!-- There are some tests that take longer or are a little
583+
flaky. Run them here. -->
584+
<includesFile>src/test/resources/slow-or-flaky-tests.txt</includesFile>
585+
<argLine>${surefire.argLine}</argLine>
586+
</configuration>
587+
</execution>
588+
</executions>
589+
</plugin>
590+
</plugins>
591+
</build>
592+
</profile>
568593
<profile>
569594
<id>jdk11+</id>
570595
<activation>

src/main/java/org/kohsuke/github/GHCheckRun.java

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package org.kohsuke.github;
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
45
import edu.umd.cs.findbugs.annotations.NonNull;
56
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
7+
import org.kohsuke.github.GHWorkflowRun.Conclusion;
8+
import org.kohsuke.github.GHWorkflowRun.Status;
9+
import org.kohsuke.github.internal.EnumUtils;
610
import org.kohsuke.github.internal.Previews;
711

812
import java.io.IOException;
@@ -11,6 +15,7 @@
1115
import java.util.Collections;
1216
import java.util.Date;
1317
import java.util.List;
18+
import java.util.Locale;
1419

1520
/**
1621
* Represents a check run.
@@ -80,12 +85,27 @@ GHPullRequest[] wrap() {
8085
* @return Status of the check run
8186
* @see Status
8287
*/
83-
public String getStatus() {
88+
@WithBridgeMethods(value = String.class, adapterMethod = "statusAsStr")
89+
public Status getStatus() {
90+
return Status.from(status);
91+
}
92+
93+
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getStatus")
94+
private Object statusAsStr(Status status, Class type) {
8495
return status;
8596
}
8697

8798
public static enum Status {
88-
QUEUED, IN_PROGRESS, COMPLETED
99+
QUEUED, IN_PROGRESS, COMPLETED, UNKNOWN;
100+
101+
public static Status from(String value) {
102+
return EnumUtils.getNullableEnumOrDefault(Status.class, value, Status.UNKNOWN);
103+
}
104+
105+
@Override
106+
public String toString() {
107+
return name().toLowerCase(Locale.ROOT);
108+
}
89109
}
90110

91111
/**
@@ -94,7 +114,13 @@ public static enum Status {
94114
* @return Status of the check run
95115
* @see Conclusion
96116
*/
97-
public String getConclusion() {
117+
@WithBridgeMethods(value = String.class, adapterMethod = "conclusionAsStr")
118+
public Conclusion getConclusion() {
119+
return Conclusion.from(conclusion);
120+
}
121+
122+
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getConclusion")
123+
private Object conclusionAsStr(Conclusion conclusion, Class type) {
98124
return conclusion;
99125
}
100126

@@ -105,7 +131,16 @@ public String getConclusion() {
105131
* Parameters - <code>conclusion</code></a>.
106132
*/
107133
public static enum Conclusion {
108-
SUCCESS, FAILURE, NEUTRAL, CANCELLED, TIMED_OUT, ACTION_REQUIRED, SKIPPED
134+
ACTION_REQUIRED, CANCELLED, FAILURE, NEUTRAL, SUCCESS, SKIPPED, STALE, TIMED_OUT, UNKNOWN;
135+
136+
public static Conclusion from(String value) {
137+
return EnumUtils.getNullableEnumOrDefault(Conclusion.class, value, Conclusion.UNKNOWN);
138+
}
139+
140+
@Override
141+
public String toString() {
142+
return name().toLowerCase(Locale.ROOT);
143+
}
109144
}
110145

111146
/**

src/main/java/org/kohsuke/github/GHEventPayload.java

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.io.Reader;
88
import java.util.Date;
99
import java.util.List;
10+
import java.util.Map;
1011

1112
/**
1213
* Base type for types used in databinding of the event payload.
@@ -1326,4 +1327,86 @@ void wrapUp(GitHub root) {
13261327
}
13271328
}
13281329
}
1330+
1331+
/**
1332+
* Occurs when someone triggered a workflow run or sends a POST request to the "Create a workflow dispatch event"
1333+
* endpoint.
1334+
*
1335+
* @see <a href=
1336+
* "https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#workflow_dispatch">
1337+
* workflow dispatch event</a>
1338+
* @see <a href=
1339+
* "https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_dispatch">Events that
1340+
* trigger workflows</a>
1341+
*/
1342+
public static class WorkflowDispatch extends GHEventPayload {
1343+
private Map<String, Object> inputs;
1344+
private String ref;
1345+
private String workflow;
1346+
1347+
/**
1348+
* Gets the map of input parameters passed to the workflow.
1349+
*
1350+
* @return the map of input parameters
1351+
*/
1352+
public Map<String, Object> getInputs() {
1353+
return inputs;
1354+
}
1355+
1356+
/**
1357+
* Gets the ref of the branch (e.g. refs/heads/main)
1358+
*
1359+
* @return the ref of the branch
1360+
*/
1361+
public String getRef() {
1362+
return ref;
1363+
}
1364+
1365+
/**
1366+
* Gets the path of the workflow file (e.g. .github/workflows/hello-world-workflow.yml).
1367+
*
1368+
* @return the path of the workflow file
1369+
*/
1370+
public String getWorkflow() {
1371+
return workflow;
1372+
}
1373+
}
1374+
1375+
/**
1376+
* A workflow run was requested or completed.
1377+
*
1378+
* @see <a href=
1379+
* "https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#workflow_run">
1380+
* workflow run event</a>
1381+
* @see <a href="https://docs.github.com/en/rest/reference/actions#workflow-runs">Actions Workflow Runs</a>
1382+
*/
1383+
public static class WorkflowRun extends GHEventPayload {
1384+
private GHWorkflowRun workflowRun;
1385+
private GHWorkflow workflow;
1386+
1387+
public GHWorkflowRun getWorkflowRun() {
1388+
return workflowRun;
1389+
}
1390+
1391+
public GHWorkflow getWorkflow() {
1392+
return workflow;
1393+
}
1394+
1395+
@Override
1396+
void wrapUp(GitHub root) {
1397+
super.wrapUp(root);
1398+
if (workflowRun == null || workflow == null) {
1399+
throw new IllegalStateException(
1400+
"Expected workflow and workflow_run payload, but got something else. Maybe we've got another type of event?");
1401+
}
1402+
GHRepository repository = getRepository();
1403+
if (repository != null) {
1404+
workflowRun.wrapUp(repository);
1405+
workflow.wrapUp(repository);
1406+
} else {
1407+
workflowRun.wrapUp(root);
1408+
workflow.wrapUp(root);
1409+
}
1410+
}
1411+
}
13291412
}

src/main/java/org/kohsuke/github/GHRepository.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2898,6 +2898,71 @@ public GHIssueEvent getIssueEvent(long id) throws IOException {
28982898
.wrapUp(root);
28992899
}
29002900

2901+
/**
2902+
* Lists all the workflows of this repository.
2903+
*
2904+
* @return the paged iterable
2905+
*/
2906+
public PagedIterable<GHWorkflow> listWorkflows() {
2907+
return root.createRequest()
2908+
.withUrlPath(getApiTailUrl("actions/workflows"))
2909+
.toIterable(GHWorkflow[].class, item -> item.wrapUp(root));
2910+
}
2911+
2912+
/**
2913+
* Gets a workflow by id.
2914+
*
2915+
* @param id
2916+
* the id of the workflow run
2917+
* @return the workflow run
2918+
* @throws IOException
2919+
* the io exception
2920+
*/
2921+
public GHWorkflow getWorkflow(long id) throws IOException {
2922+
return getWorkflow(String.valueOf(id));
2923+
}
2924+
2925+
/**
2926+
* Gets a workflow by name of the file.
2927+
*
2928+
* @param nameOrId
2929+
* either the name of the file (e.g. my-workflow.yml) or the id as a string
2930+
* @return the workflow run
2931+
* @throws IOException
2932+
* the io exception
2933+
*/
2934+
public GHWorkflow getWorkflow(String nameOrId) throws IOException {
2935+
return root.createRequest()
2936+
.withUrlPath(getApiTailUrl("actions/workflows"), nameOrId)
2937+
.fetch(GHWorkflow.class)
2938+
.wrapUp(this);
2939+
}
2940+
2941+
/**
2942+
* Retrieves workflow runs.
2943+
*
2944+
* @return the workflow run query builder
2945+
*/
2946+
public GHWorkflowRunQueryBuilder queryWorkflowRuns() {
2947+
return new GHWorkflowRunQueryBuilder(this);
2948+
}
2949+
2950+
/**
2951+
* Gets a workflow run.
2952+
*
2953+
* @param id
2954+
* the id of the workflow run
2955+
* @return the workflow run
2956+
* @throws IOException
2957+
* the io exception
2958+
*/
2959+
public GHWorkflowRun getWorkflowRun(long id) throws IOException {
2960+
return root.createRequest()
2961+
.withUrlPath(getApiTailUrl("actions/runs"), String.valueOf(id))
2962+
.fetch(GHWorkflowRun.class)
2963+
.wrapUp(this);
2964+
}
2965+
29012966
// Only used within listTopics().
29022967
private static class Topics {
29032968
public List<String> names;

0 commit comments

Comments
 (0)