Skip to content

Commit 8509957

Browse files
committed
Implement getChanges() for GHEventPayload.Issue
1 parent b0aea0c commit 8509957

5 files changed

Lines changed: 422 additions & 0 deletions

File tree

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,8 @@ public static class Issue extends GHEventPayload {
522522

523523
private GHLabel label;
524524

525+
private GHIssueChanges changes;
526+
525527
/**
526528
* Gets issue.
527529
*
@@ -550,6 +552,15 @@ public GHLabel getLabel() {
550552
return label;
551553
}
552554

555+
/**
556+
* Get changes (for action="edited")
557+
*
558+
* @return changes
559+
*/
560+
public GHIssueChanges getChanges() {
561+
return changes;
562+
}
563+
553564
@Override
554565
void wrapUp(GitHub root) {
555566
super.wrapUp(root);
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 issues action="edited"
7+
*
8+
* @see GHEventPayload.Issue
9+
*/
10+
@SuppressFBWarnings("UWF_UNWRITTEN_FIELD")
11+
public class GHIssueChanges {
12+
13+
private GHFrom title;
14+
private GHFrom body;
15+
16+
/**
17+
* Old issue title.
18+
*
19+
* @return old issue title (or null if not changed)
20+
*/
21+
public GHFrom getTitle() {
22+
return title;
23+
}
24+
25+
/**
26+
* Old issue body.
27+
*
28+
* @return old issue body (or null if not changed)
29+
*/
30+
public GHFrom getBody() {
31+
return body;
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,24 @@ public void issue_unlabeled() throws Exception {
162162
assertThat(event.getLabel().getName(), is("enhancement"));
163163
}
164164

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

0 commit comments

Comments
 (0)