Skip to content

Commit b0aea0c

Browse files
committed
Expose getLabel() for GHEventPayload.Issue
It was exposed on pull requests but not issues.
1 parent 1f7f646 commit b0aea0c

4 files changed

Lines changed: 396 additions & 2 deletions

File tree

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,9 @@ public GHPullRequest getPullRequest() {
381381
}
382382

383383
/**
384-
* Gets label.
384+
* Gets the added or removed label for labeled/unlabeled events.
385385
*
386-
* @return the label
386+
* @return label the added or removed label
387387
*/
388388
public GHLabel getLabel() {
389389
return label;
@@ -520,6 +520,8 @@ void wrapUp(GitHub root) {
520520
public static class Issue extends GHEventPayload {
521521
private GHIssue issue;
522522

523+
private GHLabel label;
524+
523525
/**
524526
* Gets issue.
525527
*
@@ -539,6 +541,15 @@ public void setIssue(GHIssue issue) {
539541
this.issue = issue;
540542
}
541543

544+
/**
545+
* Gets the added or removed label for labeled/unlabeled events.
546+
*
547+
* @return label the added or removed label
548+
*/
549+
public GHLabel getLabel() {
550+
return label;
551+
}
552+
542553
@Override
543554
void wrapUp(GitHub root) {
544555
super.wrapUp(root);

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,27 @@ public void issues() throws Exception {
141141
assertThat(event.getSender().getLogin(), is("baxterthehacker"));
142142
}
143143

144+
@Test
145+
public void issue_labeled() throws Exception {
146+
GHEventPayload.Issue event = GitHub.offline().parseEventPayload(payload.asReader(), GHEventPayload.Issue.class);
147+
assertThat(event.getAction(), is("labeled"));
148+
assertThat(event.getIssue().getNumber(), is(42));
149+
assertThat(event.getIssue().getTitle(), is("Test GHEventPayload.Issue label/unlabel"));
150+
assertThat(event.getIssue().getLabels().size(), is(1));
151+
assertThat(event.getIssue().getLabels().iterator().next().getName(), is("enhancement"));
152+
assertThat(event.getLabel().getName(), is("enhancement"));
153+
}
154+
155+
@Test
156+
public void issue_unlabeled() throws Exception {
157+
GHEventPayload.Issue event = GitHub.offline().parseEventPayload(payload.asReader(), GHEventPayload.Issue.class);
158+
assertThat(event.getAction(), is("unlabeled"));
159+
assertThat(event.getIssue().getNumber(), is(42));
160+
assertThat(event.getIssue().getTitle(), is("Test GHEventPayload.Issue label/unlabel"));
161+
assertThat(event.getIssue().getLabels().size(), is(0));
162+
assertThat(event.getLabel().getName(), is("enhancement"));
163+
}
164+
144165
// TODO implement support classes and write test
145166
// @Test
146167
// public void label() throws Exception {}
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
{
2+
"action": "labeled",
3+
"issue": {
4+
"url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/42",
5+
"repository_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground",
6+
"labels_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/42/labels{/name}",
7+
"comments_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/42/comments",
8+
"events_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/42/events",
9+
"html_url": "https://github.com/gsmet/quarkus-bot-java-playground/issues/42",
10+
"id": 835908684,
11+
"node_id": "MDU6SXNzdWU4MzU5MDg2ODQ=",
12+
"number": 42,
13+
"title": "Test GHEventPayload.Issue label/unlabel",
14+
"user": {
15+
"login": "gsmet",
16+
"id": 1279749,
17+
"node_id": "MDQ6VXNlcjEyNzk3NDk=",
18+
"avatar_url": "https://avatars.githubusercontent.com/u/1279749?v=4",
19+
"gravatar_id": "",
20+
"url": "https://api.github.com/users/gsmet",
21+
"html_url": "https://github.com/gsmet",
22+
"followers_url": "https://api.github.com/users/gsmet/followers",
23+
"following_url": "https://api.github.com/users/gsmet/following{/other_user}",
24+
"gists_url": "https://api.github.com/users/gsmet/gists{/gist_id}",
25+
"starred_url": "https://api.github.com/users/gsmet/starred{/owner}{/repo}",
26+
"subscriptions_url": "https://api.github.com/users/gsmet/subscriptions",
27+
"organizations_url": "https://api.github.com/users/gsmet/orgs",
28+
"repos_url": "https://api.github.com/users/gsmet/repos",
29+
"events_url": "https://api.github.com/users/gsmet/events{/privacy}",
30+
"received_events_url": "https://api.github.com/users/gsmet/received_events",
31+
"type": "User",
32+
"site_admin": false
33+
},
34+
"labels": [
35+
{
36+
"id": 2510333772,
37+
"node_id": "MDU6TGFiZWwyNTEwMzMzNzcy",
38+
"url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/labels/enhancement",
39+
"name": "enhancement",
40+
"color": "a2eeef",
41+
"default": true,
42+
"description": "New feature or request"
43+
}
44+
],
45+
"state": "open",
46+
"locked": false,
47+
"assignee": null,
48+
"assignees": [],
49+
"milestone": null,
50+
"comments": 0,
51+
"created_at": "2021-03-19T12:02:09Z",
52+
"updated_at": "2021-03-19T12:02:31Z",
53+
"closed_at": null,
54+
"author_association": "OWNER",
55+
"active_lock_reason": null,
56+
"body": "",
57+
"performed_via_github_app": null
58+
},
59+
"label": {
60+
"id": 2510333772,
61+
"node_id": "MDU6TGFiZWwyNTEwMzMzNzcy",
62+
"url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/labels/enhancement",
63+
"name": "enhancement",
64+
"color": "a2eeef",
65+
"default": true,
66+
"description": "New feature or request"
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": true,
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": "2020-12-01T08:39:07Z",
136+
"pushed_at": "2020-12-01T08:39:05Z",
137+
"git_url": "git://github.com/gsmet/quarkus-bot-java-playground.git",
138+
"ssh_url": "[email protected]: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": 13,
143+
"stargazers_count": 0,
144+
"watchers_count": 0,
145+
"language": null,
146+
"has_issues": true,
147+
"has_projects": true,
148+
"has_downloads": true,
149+
"has_wiki": true,
150+
"has_pages": false,
151+
"forks_count": 1,
152+
"mirror_url": null,
153+
"archived": false,
154+
"disabled": false,
155+
"open_issues_count": 14,
156+
"license": null,
157+
"forks": 1,
158+
"open_issues": 14,
159+
"watchers": 0,
160+
"default_branch": "main"
161+
},
162+
"sender": {
163+
"login": "gsmet",
164+
"id": 1279749,
165+
"node_id": "MDQ6VXNlcjEyNzk3NDk=",
166+
"avatar_url": "https://avatars.githubusercontent.com/u/1279749?v=4",
167+
"gravatar_id": "",
168+
"url": "https://api.github.com/users/gsmet",
169+
"html_url": "https://github.com/gsmet",
170+
"followers_url": "https://api.github.com/users/gsmet/followers",
171+
"following_url": "https://api.github.com/users/gsmet/following{/other_user}",
172+
"gists_url": "https://api.github.com/users/gsmet/gists{/gist_id}",
173+
"starred_url": "https://api.github.com/users/gsmet/starred{/owner}{/repo}",
174+
"subscriptions_url": "https://api.github.com/users/gsmet/subscriptions",
175+
"organizations_url": "https://api.github.com/users/gsmet/orgs",
176+
"repos_url": "https://api.github.com/users/gsmet/repos",
177+
"events_url": "https://api.github.com/users/gsmet/events{/privacy}",
178+
"received_events_url": "https://api.github.com/users/gsmet/received_events",
179+
"type": "User",
180+
"site_admin": false
181+
},
182+
"installation": {
183+
"id": 13005535,
184+
"node_id": "MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uMTMwMDU1MzU="
185+
}
186+
}

0 commit comments

Comments
 (0)