Skip to content

Commit 05e63f5

Browse files
authored
Merge pull request #1175 from t0m4uk1991/issue_rename_event_add_from_to_metadata
Add mapping for from/to fields in issue rename event
2 parents 3ced4fc + 2c06ed0 commit 05e63f5

23 files changed

+1338
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class GHIssueEvent extends GitHubInteractiveObject {
2121
private GHMilestone milestone;
2222
private GHLabel label;
2323
private GHUser assignee;
24+
private GHIssueRename rename;
2425

2526
private GHIssue issue;
2627

@@ -144,6 +145,16 @@ public GHUser getAssignee() {
144145
return assignee;
145146
}
146147

148+
/**
149+
* Get the {@link GHIssueRename} that contains information about issue old and new name. Only present for event
150+
* "renamed", <code>null</code> otherwise.
151+
*
152+
* @return the GHIssueRename
153+
*/
154+
public GHIssueRename getRename() {
155+
return this.rename;
156+
}
157+
147158
GHIssueEvent wrapUp(GitHub root) {
148159
this.root = root;
149160
return this;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.kohsuke.github;
2+
3+
/**
4+
* The type GHIssueRename.
5+
*
6+
* @see <a href="https://docs.github.com/en/developers/webhooks-and-events/events/issue-event-types#renamed">Github
7+
* documentation for renamed event</a>
8+
*
9+
* @author Andrii Tomchuk
10+
*/
11+
public class GHIssueRename {
12+
private String from = "";
13+
private String to = "";
14+
15+
/**
16+
* Old issue name.
17+
*
18+
* @return old issue name
19+
*/
20+
public String getFrom() {
21+
return this.from;
22+
}
23+
24+
/**
25+
* New issue name.
26+
*
27+
* @return new issue name
28+
*/
29+
public String getTo() {
30+
return this.to;
31+
}
32+
}

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,40 @@ public void testEventsForSingleIssue() throws Exception {
3939
issue.close();
4040
}
4141

42+
@Test
43+
public void testEventsForIssueRename() throws Exception {
44+
// Create the issue.
45+
GHRepository repo = getRepository();
46+
GHIssueBuilder builder = repo.createIssue("Some invalid issue name");
47+
GHIssue issue = builder.create();
48+
49+
// Generate rename event.
50+
issue.setTitle("Fixed issue name");
51+
52+
// Test that the event is present.
53+
List<GHIssueEvent> list = issue.listEvents().toList();
54+
assertThat(list.size(), equalTo(1));
55+
56+
GHIssueEvent event = list.get(0);
57+
assertThat(event.getIssue().getNumber(), equalTo(issue.getNumber()));
58+
assertThat(event.getEvent(), equalTo("renamed"));
59+
assertThat(event.getRename(), notNullValue());
60+
assertThat(event.getRename().getFrom(), equalTo("Some invalid issue name"));
61+
assertThat(event.getRename().getTo(), equalTo("Fixed issue name"));
62+
63+
// Test that we can get a single event directly.
64+
GHIssueEvent eventFromRepo = repo.getIssueEvent(event.getId());
65+
assertThat(eventFromRepo.getId(), equalTo(event.getId()));
66+
assertThat(eventFromRepo.getCreatedAt(), equalTo(event.getCreatedAt()));
67+
assertThat(eventFromRepo.getEvent(), equalTo("renamed"));
68+
assertThat(eventFromRepo.getRename(), notNullValue());
69+
assertThat(eventFromRepo.getRename().getFrom(), equalTo("Some invalid issue name"));
70+
assertThat(eventFromRepo.getRename().getTo(), equalTo("Fixed issue name"));
71+
72+
// Close the issue.
73+
issue.close();
74+
}
75+
4276
@Test
4377
public void testRepositoryEvents() throws Exception {
4478
GHRepository repo = getRepository();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"login": "hub4j-test-org",
3+
"id": 7544739,
4+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
5+
"url": "https://api.github.com/orgs/hub4j-test-org",
6+
"repos_url": "https://api.github.com/orgs/hub4j-test-org/repos",
7+
"events_url": "https://api.github.com/orgs/hub4j-test-org/events",
8+
"hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks",
9+
"issues_url": "https://api.github.com/orgs/hub4j-test-org/issues",
10+
"members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}",
11+
"public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}",
12+
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
13+
"description": "Hub4j Test Org Description (this could be null or blank too)",
14+
"name": "Hub4j Test Org Name (this could be null or blank too)",
15+
"company": null,
16+
"blog": "https://hub4j.url.io/could/be/null",
17+
"location": "Hub4j Test Org Location (this could be null or blank too)",
18+
"email": "[email protected]",
19+
"twitter_username": null,
20+
"is_verified": false,
21+
"has_organization_projects": true,
22+
"has_repository_projects": true,
23+
"public_repos": 18,
24+
"public_gists": 0,
25+
"followers": 0,
26+
"following": 0,
27+
"html_url": "https://github.com/hub4j-test-org",
28+
"created_at": "2014-05-10T19:39:11Z",
29+
"updated_at": "2020-06-04T05:56:10Z",
30+
"type": "Organization"
31+
}

0 commit comments

Comments
 (0)