Skip to content

Commit e7add93

Browse files
committed
Add support for workflow_job event payload
Fixes hub4j#1331
1 parent 4e103a6 commit e7add93

File tree

4 files changed

+283
-2
lines changed

4 files changed

+283
-2
lines changed

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,43 @@ void lateBind() {
15061506
}
15071507
}
15081508

1509+
/**
1510+
* A workflow job has been queued, is in progress, or has been completed.
1511+
*
1512+
* @see <a href=
1513+
* "https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#workflow_job">
1514+
* workflow job event</a>
1515+
* @see <a href="https://docs.github.com/en/rest/reference/actions#workflow-jobs">Actions Workflow Jobs</a>
1516+
*/
1517+
public static class WorkflowJob extends GHEventPayload {
1518+
1519+
private GHWorkflowJob workflowJob;
1520+
1521+
/**
1522+
* Gets the workflow job.
1523+
*
1524+
* @return the workflow job
1525+
*/
1526+
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected")
1527+
public GHWorkflowJob getWorkflowJob() {
1528+
return workflowJob;
1529+
}
1530+
1531+
@Override
1532+
void lateBind() {
1533+
if (workflowJob == null) {
1534+
throw new IllegalStateException(
1535+
"Expected workflow_job payload, but got something else. Maybe we've got another type of event?");
1536+
}
1537+
super.lateBind();
1538+
GHRepository repository = getRepository();
1539+
if (repository == null) {
1540+
throw new IllegalStateException("Repository must not be null");
1541+
}
1542+
workflowJob.wrapUp(repository);
1543+
}
1544+
}
1545+
15091546
/**
15101547
* A label was created, edited or deleted.
15111548
*

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class GHWorkflowJob extends GHObject {
3535
private String conclusion;
3636

3737
private long runId;
38+
private int runAttempt;
3839

3940
private String htmlUrl;
4041
private String checkRunUrl;
@@ -108,6 +109,15 @@ public long getRunId() {
108109
return runId;
109110
}
110111

112+
/**
113+
* Attempt number of the associated workflow run, 1 for first attempt and higher if the workflow was re-run.
114+
*
115+
* @return attempt number
116+
*/
117+
public int getRunAttempt() {
118+
return runAttempt;
119+
}
120+
111121
@Override
112122
public URL getHtmlUrl() {
113123
return GitHubClient.parseURL(htmlUrl);

src/test/java/org/kohsuke/github/GHEventPayloadTest.java

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,18 @@
1111
import java.util.List;
1212
import java.util.TimeZone;
1313

14-
import static org.hamcrest.Matchers.*;
14+
import static org.hamcrest.Matchers.aMapWithSize;
15+
import static org.hamcrest.Matchers.contains;
16+
import static org.hamcrest.Matchers.endsWith;
17+
import static org.hamcrest.Matchers.equalTo;
18+
import static org.hamcrest.Matchers.hasProperty;
19+
import static org.hamcrest.Matchers.hasToString;
20+
import static org.hamcrest.Matchers.is;
21+
import static org.hamcrest.Matchers.lessThanOrEqualTo;
22+
import static org.hamcrest.Matchers.notNullValue;
23+
import static org.hamcrest.Matchers.nullValue;
24+
import static org.hamcrest.Matchers.sameInstance;
25+
import static org.hamcrest.Matchers.startsWith;
1526
import static org.junit.Assert.assertThrows;
1627

1728
public class GHEventPayloadTest extends AbstractGitHubWireMockTest {
@@ -876,7 +887,6 @@ public void workflow_run_pull_request() throws Exception {
876887
GHPullRequest pullRequest = pullRequests.get(0);
877888
assertThat(pullRequest.getId(), is(599098265L));
878889
assertThat(pullRequest.getRepository(), sameInstance(workflowRunPayload.getRepository()));
879-
880890
}
881891

882892
@Test
@@ -892,6 +902,40 @@ public void workflow_run_other_repository() throws Exception {
892902
assertThat(workflowRunPayload.getWorkflow().getRepository(), sameInstance(workflowRunPayload.getRepository()));
893903
}
894904

905+
@Test
906+
public void workflow_job() throws Exception {
907+
final GHEventPayload.WorkflowJob workflowJobPayload = GitHub.offline()
908+
.parseEventPayload(payload.asReader(), GHEventPayload.WorkflowJob.class);
909+
910+
assertThat(workflowJobPayload.getAction(), is("completed"));
911+
assertThat(workflowJobPayload.getRepository().getFullName(), is("gsmet/quarkus-bot-java-playground"));
912+
assertThat(workflowJobPayload.getSender().getLogin(), is("gsmet"));
913+
914+
GHWorkflowJob workflowJob = workflowJobPayload.getWorkflowJob();
915+
assertThat(workflowJob.getId(), is(6653410527L));
916+
assertThat(workflowJob.getRunId(), is(2408553341L));
917+
assertThat(workflowJob.getRunAttempt(), is(1));
918+
assertThat(workflowJob.getUrl().toString(),
919+
is("https://api.github.com/repos/gsmet/quarkus-bot-java-playground/actions/jobs/6653410527"));
920+
assertThat(workflowJob.getHtmlUrl().toString(),
921+
is("https://github.com/gsmet/quarkus-bot-java-playground/runs/6653410527?check_suite_focus=true"));
922+
assertThat(workflowJob.getNodeId(), is("CR_kwDOEq3cwc8AAAABjJL83w"));
923+
assertThat(workflowJob.getHeadSha(), is("5dd2dadfbdc2a722c08a8ad42ae4e26e3e731042"));
924+
assertThat(workflowJob.getStatus(), is(GHWorkflowRun.Status.COMPLETED));
925+
assertThat(workflowJob.getConclusion(), is(GHWorkflowRun.Conclusion.FAILURE));
926+
assertThat(workflowJob.getStartedAt().getTime(), is(1653908125000L));
927+
assertThat(workflowJob.getCompletedAt().getTime(), is(1653908157000L));
928+
assertThat(workflowJob.getName(), is("JVM Tests - JDK JDK16"));
929+
assertThat(workflowJob.getSteps(),
930+
contains(hasProperty("name", is("Set up job")),
931+
hasProperty("name", is("Run actions/checkout@v2")),
932+
hasProperty("name", is("Build with Maven")),
933+
hasProperty("name", is("Post Run actions/checkout@v2")),
934+
hasProperty("name", is("Complete job"))));
935+
assertThat(workflowJob.getCheckRunUrl().toString(),
936+
is("https://api.github.com/repos/gsmet/quarkus-bot-java-playground/check-runs/6653410527"));
937+
}
938+
895939
@Test
896940
public void label_created() throws Exception {
897941
final GHEventPayload.Label labelPayload = GitHub.offline()
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
{
2+
"action": "completed",
3+
"workflow_job": {
4+
"id": 6653410527,
5+
"run_id": 2408553341,
6+
"run_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/actions/runs/2408553341",
7+
"run_attempt": 1,
8+
"node_id": "CR_kwDOEq3cwc8AAAABjJL83w",
9+
"head_sha": "5dd2dadfbdc2a722c08a8ad42ae4e26e3e731042",
10+
"url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/actions/jobs/6653410527",
11+
"html_url": "https://github.com/gsmet/quarkus-bot-java-playground/runs/6653410527?check_suite_focus=true",
12+
"status": "completed",
13+
"conclusion": "failure",
14+
"started_at": "2022-05-30T10:55:25Z",
15+
"completed_at": "2022-05-30T10:55:57Z",
16+
"name": "JVM Tests - JDK JDK16",
17+
"steps": [
18+
{
19+
"name": "Set up job",
20+
"status": "completed",
21+
"conclusion": "success",
22+
"number": 1,
23+
"started_at": "2022-05-30T10:55:25.000Z",
24+
"completed_at": "2022-05-30T10:55:27.000Z"
25+
},
26+
{
27+
"name": "Run actions/checkout@v2",
28+
"status": "completed",
29+
"conclusion": "success",
30+
"number": 2,
31+
"started_at": "2022-05-30T10:55:27.000Z",
32+
"completed_at": "2022-05-30T10:55:27.000Z"
33+
},
34+
{
35+
"name": "Build with Maven",
36+
"status": "completed",
37+
"conclusion": "failure",
38+
"number": 4,
39+
"started_at": "2022-05-30T10:55:35.000Z",
40+
"completed_at": "2022-05-30T10:55:55.000Z"
41+
},
42+
{
43+
"name": "Post Run actions/checkout@v2",
44+
"status": "completed",
45+
"conclusion": "success",
46+
"number": 10,
47+
"started_at": "2022-05-30T10:55:55.000Z",
48+
"completed_at": "2022-05-30T10:55:56.000Z"
49+
},
50+
{
51+
"name": "Complete job",
52+
"status": "completed",
53+
"conclusion": "success",
54+
"number": 11,
55+
"started_at": "2022-05-30T10:55:56.000Z",
56+
"completed_at": "2022-05-30T10:55:56.000Z"
57+
}
58+
],
59+
"check_run_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/check-runs/6653410527",
60+
"labels": [
61+
"ubuntu-latest"
62+
],
63+
"runner_id": 10,
64+
"runner_name": "GitHub Actions 10",
65+
"runner_group_id": 2,
66+
"runner_group_name": "GitHub Actions"
67+
},
68+
"repository": {
69+
"id": 313384129,
70+
"node_id": "MDEwOlJlcG9zaXRvcnkzMTMzODQxMjk=",
71+
"name": "quarkus-bot-java-playground",
72+
"full_name": "gsmet/quarkus-bot-java-playground",
73+
"private": false,
74+
"owner": {
75+
"login": "gsmet",
76+
"id": 1279749,
77+
"node_id": "MDQ6VXNlcjEyNzk3NDk=",
78+
"avatar_url": "https://avatars.githubusercontent.com/u/1279749?v=4",
79+
"gravatar_id": "",
80+
"url": "https://api.github.com/users/gsmet",
81+
"html_url": "https://github.com/gsmet",
82+
"followers_url": "https://api.github.com/users/gsmet/followers",
83+
"following_url": "https://api.github.com/users/gsmet/following{/other_user}",
84+
"gists_url": "https://api.github.com/users/gsmet/gists{/gist_id}",
85+
"starred_url": "https://api.github.com/users/gsmet/starred{/owner}{/repo}",
86+
"subscriptions_url": "https://api.github.com/users/gsmet/subscriptions",
87+
"organizations_url": "https://api.github.com/users/gsmet/orgs",
88+
"repos_url": "https://api.github.com/users/gsmet/repos",
89+
"events_url": "https://api.github.com/users/gsmet/events{/privacy}",
90+
"received_events_url": "https://api.github.com/users/gsmet/received_events",
91+
"type": "User",
92+
"site_admin": false
93+
},
94+
"html_url": "https://github.com/gsmet/quarkus-bot-java-playground",
95+
"description": null,
96+
"fork": false,
97+
"url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground",
98+
"forks_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/forks",
99+
"keys_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/keys{/key_id}",
100+
"collaborators_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/collaborators{/collaborator}",
101+
"teams_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/teams",
102+
"hooks_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/hooks",
103+
"issue_events_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/events{/number}",
104+
"events_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/events",
105+
"assignees_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/assignees{/user}",
106+
"branches_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/branches{/branch}",
107+
"tags_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/tags",
108+
"blobs_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/blobs{/sha}",
109+
"git_tags_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/tags{/sha}",
110+
"git_refs_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/refs{/sha}",
111+
"trees_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/trees{/sha}",
112+
"statuses_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/statuses/{sha}",
113+
"languages_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/languages",
114+
"stargazers_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/stargazers",
115+
"contributors_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/contributors",
116+
"subscribers_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/subscribers",
117+
"subscription_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/subscription",
118+
"commits_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/commits{/sha}",
119+
"git_commits_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/commits{/sha}",
120+
"comments_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/comments{/number}",
121+
"issue_comment_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/comments{/number}",
122+
"contents_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/contents/{+path}",
123+
"compare_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/compare/{base}...{head}",
124+
"merges_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/merges",
125+
"archive_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/{archive_format}{/ref}",
126+
"downloads_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/downloads",
127+
"issues_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues{/number}",
128+
"pulls_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/pulls{/number}",
129+
"milestones_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/milestones{/number}",
130+
"notifications_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/notifications{?since,all,participating}",
131+
"labels_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/labels{/name}",
132+
"releases_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/releases{/id}",
133+
"deployments_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/deployments",
134+
"created_at": "2020-11-16T17:55:53Z",
135+
"updated_at": "2021-12-22T17:20:52Z",
136+
"pushed_at": "2022-05-30T10:55:11Z",
137+
"git_url": "git://github.com/gsmet/quarkus-bot-java-playground.git",
138+
"ssh_url": "git@github.com:gsmet/quarkus-bot-java-playground.git",
139+
"clone_url": "https://github.com/gsmet/quarkus-bot-java-playground.git",
140+
"svn_url": "https://github.com/gsmet/quarkus-bot-java-playground",
141+
"homepage": null,
142+
"size": 88,
143+
"stargazers_count": 0,
144+
"watchers_count": 0,
145+
"language": "Java",
146+
"has_issues": true,
147+
"has_projects": true,
148+
"has_downloads": true,
149+
"has_wiki": true,
150+
"has_pages": false,
151+
"forks_count": 2,
152+
"mirror_url": null,
153+
"archived": false,
154+
"disabled": false,
155+
"open_issues_count": 36,
156+
"license": null,
157+
"allow_forking": true,
158+
"is_template": false,
159+
"topics": [],
160+
"visibility": "public",
161+
"forks": 2,
162+
"open_issues": 36,
163+
"watchers": 0,
164+
"default_branch": "main"
165+
},
166+
"sender": {
167+
"login": "gsmet",
168+
"id": 1279749,
169+
"node_id": "MDQ6VXNlcjEyNzk3NDk=",
170+
"avatar_url": "https://avatars.githubusercontent.com/u/1279749?v=4",
171+
"gravatar_id": "",
172+
"url": "https://api.github.com/users/gsmet",
173+
"html_url": "https://github.com/gsmet",
174+
"followers_url": "https://api.github.com/users/gsmet/followers",
175+
"following_url": "https://api.github.com/users/gsmet/following{/other_user}",
176+
"gists_url": "https://api.github.com/users/gsmet/gists{/gist_id}",
177+
"starred_url": "https://api.github.com/users/gsmet/starred{/owner}{/repo}",
178+
"subscriptions_url": "https://api.github.com/users/gsmet/subscriptions",
179+
"organizations_url": "https://api.github.com/users/gsmet/orgs",
180+
"repos_url": "https://api.github.com/users/gsmet/repos",
181+
"events_url": "https://api.github.com/users/gsmet/events{/privacy}",
182+
"received_events_url": "https://api.github.com/users/gsmet/received_events",
183+
"type": "User",
184+
"site_admin": false
185+
},
186+
"installation": {
187+
"id": 13005535,
188+
"node_id": "MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uMTMwMDU1MzU="
189+
}
190+
}

0 commit comments

Comments
 (0)