Skip to content

Commit da1b8ae

Browse files
authored
Fix getLabel() nullability for unlabeled events when label was deleted (#2211)
1 parent 4e44598 commit da1b8ae

File tree

3 files changed

+195
-3
lines changed

3 files changed

+195
-3
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.annotation.JsonProperty;
44
import com.fasterxml.jackson.annotation.JsonSetter;
55
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
6+
import edu.umd.cs.findbugs.annotations.CheckForNull;
67
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
78

89
import java.io.IOException;
@@ -445,8 +446,11 @@ public GHRepositoryDiscussion getDiscussion() {
445446
/**
446447
* Gets the added or removed label for labeled/unlabeled events.
447448
*
448-
* @return label the added or removed label
449+
* May be {@code null} when the unlabeled event was triggered by deleting the label from the repository.
450+
*
451+
* @return label the added or removed label, or {@code null} if the label was deleted
449452
*/
453+
@CheckForNull
450454
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected")
451455
public GHLabel getLabel() {
452456
return label;
@@ -785,8 +789,11 @@ public GHIssue getIssue() {
785789
/**
786790
* Gets the added or removed label for labeled/unlabeled events.
787791
*
788-
* @return label the added or removed label
792+
* May be {@code null} when the unlabeled event was triggered by deleting the label from the repository.
793+
*
794+
* @return label the added or removed label, or {@code null} if the label was deleted
789795
*/
796+
@CheckForNull
790797
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected")
791798
public GHLabel getLabel() {
792799
return label;
@@ -1103,8 +1110,11 @@ public GHPullRequestChanges getChanges() {
11031110
/**
11041111
* Gets the added or removed label for labeled/unlabeled events.
11051112
*
1106-
* @return label the added or removed label
1113+
* May be {@code null} when the unlabeled event was triggered by deleting the label from the repository.
1114+
*
1115+
* @return label the added or removed label, or {@code null} if the label was deleted
11071116
*/
1117+
@CheckForNull
11081118
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected")
11091119
public GHLabel getLabel() {
11101120
return label;

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,21 @@ public void issue_unlabeled() throws Exception {
690690
assertThat(event.getLabel().getName(), is("enhancement"));
691691
}
692692

693+
/**
694+
* Issue unlabeled when label was deleted from repository.
695+
*
696+
* @throws Exception
697+
* the exception
698+
*/
699+
@Test
700+
public void issue_unlabeled_deleted_label() throws Exception {
701+
final GHEventPayload.Issue event = GitHub.offline()
702+
.parseEventPayload(payload.asReader(), GHEventPayload.Issue.class);
703+
assertThat(event.getAction(), is("unlabeled"));
704+
assertThat(event.getIssue().getNumber(), is(42));
705+
assertThat(event.getLabel(), is(nullValue()));
706+
}
707+
693708
/**
694709
* Issues.
695710
*
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
{
2+
"action": "unlabeled",
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+
"state": "open",
36+
"locked": false,
37+
"assignee": null,
38+
"assignees": [],
39+
"milestone": null,
40+
"comments": 0,
41+
"created_at": "2021-03-19T12:02:09Z",
42+
"updated_at": "2021-03-19T12:02:43Z",
43+
"closed_at": null,
44+
"author_association": "OWNER",
45+
"active_lock_reason": null,
46+
"body": "",
47+
"performed_via_github_app": null
48+
},
49+
"repository": {
50+
"id": 313384129,
51+
"node_id": "MDEwOlJlcG9zaXRvcnkzMTMzODQxMjk=",
52+
"name": "quarkus-bot-java-playground",
53+
"full_name": "gsmet/quarkus-bot-java-playground",
54+
"private": true,
55+
"owner": {
56+
"login": "gsmet",
57+
"id": 1279749,
58+
"node_id": "MDQ6VXNlcjEyNzk3NDk=",
59+
"avatar_url": "https://avatars.githubusercontent.com/u/1279749?v=4",
60+
"gravatar_id": "",
61+
"url": "https://api.github.com/users/gsmet",
62+
"html_url": "https://github.com/gsmet",
63+
"followers_url": "https://api.github.com/users/gsmet/followers",
64+
"following_url": "https://api.github.com/users/gsmet/following{/other_user}",
65+
"gists_url": "https://api.github.com/users/gsmet/gists{/gist_id}",
66+
"starred_url": "https://api.github.com/users/gsmet/starred{/owner}{/repo}",
67+
"subscriptions_url": "https://api.github.com/users/gsmet/subscriptions",
68+
"organizations_url": "https://api.github.com/users/gsmet/orgs",
69+
"repos_url": "https://api.github.com/users/gsmet/repos",
70+
"events_url": "https://api.github.com/users/gsmet/events{/privacy}",
71+
"received_events_url": "https://api.github.com/users/gsmet/received_events",
72+
"type": "User",
73+
"site_admin": false
74+
},
75+
"html_url": "https://github.com/gsmet/quarkus-bot-java-playground",
76+
"description": null,
77+
"fork": false,
78+
"url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground",
79+
"forks_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/forks",
80+
"keys_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/keys{/key_id}",
81+
"collaborators_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/collaborators{/collaborator}",
82+
"teams_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/teams",
83+
"hooks_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/hooks",
84+
"issue_events_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/events{/number}",
85+
"events_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/events",
86+
"assignees_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/assignees{/user}",
87+
"branches_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/branches{/branch}",
88+
"tags_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/tags",
89+
"blobs_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/blobs{/sha}",
90+
"git_tags_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/tags{/sha}",
91+
"git_refs_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/refs{/sha}",
92+
"trees_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/trees{/sha}",
93+
"statuses_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/statuses/{sha}",
94+
"languages_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/languages",
95+
"stargazers_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/stargazers",
96+
"contributors_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/contributors",
97+
"subscribers_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/subscribers",
98+
"subscription_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/subscription",
99+
"commits_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/commits{/sha}",
100+
"git_commits_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/commits{/sha}",
101+
"comments_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/comments{/number}",
102+
"issue_comment_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/comments{/number}",
103+
"contents_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/contents/{+path}",
104+
"compare_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/compare/{base}...{head}",
105+
"merges_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/merges",
106+
"archive_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/{archive_format}{/ref}",
107+
"downloads_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/downloads",
108+
"issues_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues{/number}",
109+
"pulls_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/pulls{/number}",
110+
"milestones_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/milestones{/number}",
111+
"notifications_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/notifications{?since,all,participating}",
112+
"labels_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/labels{/name}",
113+
"releases_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/releases{/id}",
114+
"deployments_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/deployments",
115+
"created_at": "2020-11-16T17:55:53Z",
116+
"updated_at": "2020-12-01T08:39:07Z",
117+
"pushed_at": "2020-12-01T08:39:05Z",
118+
"git_url": "git://github.com/gsmet/quarkus-bot-java-playground.git",
119+
"ssh_url": "git@github.com:gsmet/quarkus-bot-java-playground.git",
120+
"clone_url": "https://github.com/gsmet/quarkus-bot-java-playground.git",
121+
"svn_url": "https://github.com/gsmet/quarkus-bot-java-playground",
122+
"homepage": null,
123+
"size": 13,
124+
"stargazers_count": 0,
125+
"watchers_count": 0,
126+
"language": null,
127+
"has_issues": true,
128+
"has_projects": true,
129+
"has_downloads": true,
130+
"has_wiki": true,
131+
"has_pages": false,
132+
"forks_count": 1,
133+
"mirror_url": null,
134+
"archived": false,
135+
"disabled": false,
136+
"open_issues_count": 14,
137+
"license": null,
138+
"forks": 1,
139+
"open_issues": 14,
140+
"watchers": 0,
141+
"default_branch": "main"
142+
},
143+
"sender": {
144+
"login": "gsmet",
145+
"id": 1279749,
146+
"node_id": "MDQ6VXNlcjEyNzk3NDk=",
147+
"avatar_url": "https://avatars.githubusercontent.com/u/1279749?v=4",
148+
"gravatar_id": "",
149+
"url": "https://api.github.com/users/gsmet",
150+
"html_url": "https://github.com/gsmet",
151+
"followers_url": "https://api.github.com/users/gsmet/followers",
152+
"following_url": "https://api.github.com/users/gsmet/following{/other_user}",
153+
"gists_url": "https://api.github.com/users/gsmet/gists{/gist_id}",
154+
"starred_url": "https://api.github.com/users/gsmet/starred{/owner}{/repo}",
155+
"subscriptions_url": "https://api.github.com/users/gsmet/subscriptions",
156+
"organizations_url": "https://api.github.com/users/gsmet/orgs",
157+
"repos_url": "https://api.github.com/users/gsmet/repos",
158+
"events_url": "https://api.github.com/users/gsmet/events{/privacy}",
159+
"received_events_url": "https://api.github.com/users/gsmet/received_events",
160+
"type": "User",
161+
"site_admin": false
162+
},
163+
"installation": {
164+
"id": 13005535,
165+
"node_id": "MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uMTMwMDU1MzU="
166+
}
167+
}

0 commit comments

Comments
 (0)