Skip to content

Commit bd19f23

Browse files
authored
Merge pull request hub4j#1087 from gsmet/label-payload
Add label payload
2 parents ee047ea + 93abb0e commit bd19f23

File tree

6 files changed

+539
-0
lines changed

6 files changed

+539
-0
lines changed

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,10 +1384,20 @@ public static class WorkflowRun extends GHEventPayload {
13841384
private GHWorkflowRun workflowRun;
13851385
private GHWorkflow workflow;
13861386

1387+
/**
1388+
* Gets the workflow run.
1389+
*
1390+
* @return the workflow run
1391+
*/
13871392
public GHWorkflowRun getWorkflowRun() {
13881393
return workflowRun;
13891394
}
13901395

1396+
/**
1397+
* Gets the associated workflow.
1398+
*
1399+
* @return the associated workflow
1400+
*/
13911401
public GHWorkflow getWorkflow() {
13921402
return workflow;
13931403
}
@@ -1407,4 +1417,35 @@ void wrapUp(GitHub root) {
14071417
workflow.wrapUp(repository);
14081418
}
14091419
}
1420+
1421+
/**
1422+
* A label was created, edited or deleted.
1423+
*
1424+
* @see <a href= "https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#label">
1425+
* label event</a>
1426+
*/
1427+
public static class Label extends GHEventPayload {
1428+
1429+
private GHLabel label;
1430+
1431+
private GHLabelChanges changes;
1432+
1433+
/**
1434+
* Gets the label.
1435+
*
1436+
* @return the label
1437+
*/
1438+
public GHLabel getLabel() {
1439+
return label;
1440+
}
1441+
1442+
/**
1443+
* Gets changes (for action="edited")
1444+
*
1445+
* @return changes
1446+
*/
1447+
public GHLabelChanges getChanges() {
1448+
return changes;
1449+
}
1450+
}
14101451
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package org.kohsuke.github;
2+
3+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
4+
5+
/**
6+
* Wrapper to define changed fields on label action="edited"
7+
*
8+
* @see GHEventPayload.Label
9+
*/
10+
@SuppressFBWarnings("UWF_UNWRITTEN_FIELD")
11+
public class GHLabelChanges {
12+
13+
private GHFrom name;
14+
private GHFrom color;
15+
16+
/**
17+
* Old label name.
18+
*
19+
* @return old label name (or null if not changed)
20+
*/
21+
public GHFrom getName() {
22+
return name;
23+
}
24+
25+
/**
26+
* Old label color.
27+
*
28+
* @return old label color (or null if not changed)
29+
*/
30+
public GHFrom getColor() {
31+
return color;
32+
}
33+
34+
/**
35+
* Wrapper for changed values.
36+
*/
37+
public static class GHFrom {
38+
private String from;
39+
40+
/**
41+
* Previous value that was changed.
42+
*
43+
* @return previous value
44+
*/
45+
public String getFrom() {
46+
return from;
47+
}
48+
}
49+
}

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,4 +805,55 @@ public void workflow_run_other_repository() throws Exception {
805805
assertThat(workflowRun.getHeadRepository().getFullName(),
806806
is("gsmet-bot-playground/quarkus-bot-java-playground"));
807807
}
808+
809+
@Test
810+
public void label_created() throws Exception {
811+
GHEventPayload.Label labelPayload = GitHub.offline()
812+
.parseEventPayload(payload.asReader(), GHEventPayload.Label.class);
813+
GHLabel label = labelPayload.getLabel();
814+
815+
assertThat(labelPayload.getAction(), is("created"));
816+
assertThat(labelPayload.getRepository().getFullName(), is("gsmet/quarkus-bot-java-playground"));
817+
assertThat(label.getId(), is(2901546662L));
818+
assertThat(label.getNodeId(), is("MDU6TGFiZWwyOTAxNTQ2NjYy"));
819+
assertThat(label.getName(), is("new-label"));
820+
assertThat(label.getColor(), is("f9d0c4"));
821+
assertThat(label.isDefault(), is(false));
822+
assertThat(label.getDescription(), is("description"));
823+
}
824+
825+
@Test
826+
public void label_edited() throws Exception {
827+
GHEventPayload.Label labelPayload = GitHub.offline()
828+
.parseEventPayload(payload.asReader(), GHEventPayload.Label.class);
829+
GHLabel label = labelPayload.getLabel();
830+
831+
assertThat(labelPayload.getAction(), is("edited"));
832+
assertThat(labelPayload.getRepository().getFullName(), is("gsmet/quarkus-bot-java-playground"));
833+
assertThat(label.getId(), is(2901546662L));
834+
assertThat(label.getNodeId(), is("MDU6TGFiZWwyOTAxNTQ2NjYy"));
835+
assertThat(label.getName(), is("new-label-updated"));
836+
assertThat(label.getColor(), is("4AE686"));
837+
assertThat(label.isDefault(), is(false));
838+
assertThat(label.getDescription(), is("description"));
839+
840+
assertThat(labelPayload.getChanges().getName().getFrom(), is("new-label"));
841+
assertThat(labelPayload.getChanges().getColor().getFrom(), is("f9d0c4"));
842+
}
843+
844+
@Test
845+
public void label_deleted() throws Exception {
846+
GHEventPayload.Label labelPayload = GitHub.offline()
847+
.parseEventPayload(payload.asReader(), GHEventPayload.Label.class);
848+
GHLabel label = labelPayload.getLabel();
849+
850+
assertThat(labelPayload.getAction(), is("deleted"));
851+
assertThat(labelPayload.getRepository().getFullName(), is("gsmet/quarkus-bot-java-playground"));
852+
assertThat(label.getId(), is(2901546662L));
853+
assertThat(label.getNodeId(), is("MDU6TGFiZWwyOTAxNTQ2NjYy"));
854+
assertThat(label.getName(), is("new-label-updated"));
855+
assertThat(label.getColor(), is("4AE686"));
856+
assertThat(label.isDefault(), is(false));
857+
assertThat(label.getDescription(), is("description"));
858+
}
808859
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
{
2+
"action": "created",
3+
"label": {
4+
"id": 2901546662,
5+
"node_id": "MDU6TGFiZWwyOTAxNTQ2NjYy",
6+
"url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/labels/new-label",
7+
"name": "new-label",
8+
"color": "f9d0c4",
9+
"default": false,
10+
"description": "description"
11+
},
12+
"repository": {
13+
"id": 313384129,
14+
"node_id": "MDEwOlJlcG9zaXRvcnkzMTMzODQxMjk=",
15+
"name": "quarkus-bot-java-playground",
16+
"full_name": "gsmet/quarkus-bot-java-playground",
17+
"private": false,
18+
"owner": {
19+
"login": "gsmet",
20+
"id": 1279749,
21+
"node_id": "MDQ6VXNlcjEyNzk3NDk=",
22+
"avatar_url": "https://avatars.githubusercontent.com/u/1279749?v=4",
23+
"gravatar_id": "",
24+
"url": "https://api.github.com/users/gsmet",
25+
"html_url": "https://github.com/gsmet",
26+
"followers_url": "https://api.github.com/users/gsmet/followers",
27+
"following_url": "https://api.github.com/users/gsmet/following{/other_user}",
28+
"gists_url": "https://api.github.com/users/gsmet/gists{/gist_id}",
29+
"starred_url": "https://api.github.com/users/gsmet/starred{/owner}{/repo}",
30+
"subscriptions_url": "https://api.github.com/users/gsmet/subscriptions",
31+
"organizations_url": "https://api.github.com/users/gsmet/orgs",
32+
"repos_url": "https://api.github.com/users/gsmet/repos",
33+
"events_url": "https://api.github.com/users/gsmet/events{/privacy}",
34+
"received_events_url": "https://api.github.com/users/gsmet/received_events",
35+
"type": "User",
36+
"site_admin": false
37+
},
38+
"html_url": "https://github.com/gsmet/quarkus-bot-java-playground",
39+
"description": null,
40+
"fork": false,
41+
"url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground",
42+
"forks_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/forks",
43+
"keys_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/keys{/key_id}",
44+
"collaborators_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/collaborators{/collaborator}",
45+
"teams_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/teams",
46+
"hooks_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/hooks",
47+
"issue_events_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/events{/number}",
48+
"events_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/events",
49+
"assignees_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/assignees{/user}",
50+
"branches_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/branches{/branch}",
51+
"tags_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/tags",
52+
"blobs_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/blobs{/sha}",
53+
"git_tags_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/tags{/sha}",
54+
"git_refs_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/refs{/sha}",
55+
"trees_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/trees{/sha}",
56+
"statuses_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/statuses/{sha}",
57+
"languages_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/languages",
58+
"stargazers_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/stargazers",
59+
"contributors_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/contributors",
60+
"subscribers_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/subscribers",
61+
"subscription_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/subscription",
62+
"commits_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/commits{/sha}",
63+
"git_commits_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/commits{/sha}",
64+
"comments_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/comments{/number}",
65+
"issue_comment_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/comments{/number}",
66+
"contents_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/contents/{+path}",
67+
"compare_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/compare/{base}...{head}",
68+
"merges_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/merges",
69+
"archive_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/{archive_format}{/ref}",
70+
"downloads_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/downloads",
71+
"issues_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues{/number}",
72+
"pulls_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/pulls{/number}",
73+
"milestones_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/milestones{/number}",
74+
"notifications_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/notifications{?since,all,participating}",
75+
"labels_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/labels{/name}",
76+
"releases_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/releases{/id}",
77+
"deployments_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/deployments",
78+
"created_at": "2020-11-16T17:55:53Z",
79+
"updated_at": "2021-04-06T17:25:43Z",
80+
"pushed_at": "2021-04-09T17:46:23Z",
81+
"git_url": "git://github.com/gsmet/quarkus-bot-java-playground.git",
82+
"ssh_url": "[email protected]:gsmet/quarkus-bot-java-playground.git",
83+
"clone_url": "https://github.com/gsmet/quarkus-bot-java-playground.git",
84+
"svn_url": "https://github.com/gsmet/quarkus-bot-java-playground",
85+
"homepage": null,
86+
"size": 42,
87+
"stargazers_count": 0,
88+
"watchers_count": 0,
89+
"language": "Java",
90+
"has_issues": true,
91+
"has_projects": true,
92+
"has_downloads": true,
93+
"has_wiki": true,
94+
"has_pages": false,
95+
"forks_count": 1,
96+
"mirror_url": null,
97+
"archived": false,
98+
"disabled": false,
99+
"open_issues_count": 31,
100+
"license": null,
101+
"forks": 1,
102+
"open_issues": 31,
103+
"watchers": 0,
104+
"default_branch": "main"
105+
},
106+
"sender": {
107+
"login": "gsmet",
108+
"id": 1279749,
109+
"node_id": "MDQ6VXNlcjEyNzk3NDk=",
110+
"avatar_url": "https://avatars.githubusercontent.com/u/1279749?v=4",
111+
"gravatar_id": "",
112+
"url": "https://api.github.com/users/gsmet",
113+
"html_url": "https://github.com/gsmet",
114+
"followers_url": "https://api.github.com/users/gsmet/followers",
115+
"following_url": "https://api.github.com/users/gsmet/following{/other_user}",
116+
"gists_url": "https://api.github.com/users/gsmet/gists{/gist_id}",
117+
"starred_url": "https://api.github.com/users/gsmet/starred{/owner}{/repo}",
118+
"subscriptions_url": "https://api.github.com/users/gsmet/subscriptions",
119+
"organizations_url": "https://api.github.com/users/gsmet/orgs",
120+
"repos_url": "https://api.github.com/users/gsmet/repos",
121+
"events_url": "https://api.github.com/users/gsmet/events{/privacy}",
122+
"received_events_url": "https://api.github.com/users/gsmet/received_events",
123+
"type": "User",
124+
"site_admin": false
125+
},
126+
"installation": {
127+
"id": 13005535,
128+
"node_id": "MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uMTMwMDU1MzU="
129+
}
130+
}

0 commit comments

Comments
 (0)