Skip to content

Commit 5db97d9

Browse files
authored
Merge pull request #899 from gastaldi/set_milestone
PullRequest.setMilestone should use the Issue API
2 parents 2b2be05 + 43063fe commit 5db97d9

21 files changed

+2147
-4
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ private void editNullable(String key, Object value) throws IOException {
239239
}
240240

241241
private void editIssue(String key, Object value) throws IOException {
242-
root.createRequest().with(key, value).method("PATCH").withUrlPath(getIssuesApiRoute()).send();
242+
root.createRequest().withNullable(key, value).method("PATCH").withUrlPath(getIssuesApiRoute()).send();
243243
}
244244

245245
/**
@@ -296,9 +296,9 @@ public void setBody(String body) throws IOException {
296296
*/
297297
public void setMilestone(GHMilestone milestone) throws IOException {
298298
if (milestone == null) {
299-
editNullable("milestone", null);
299+
editIssue("milestone", null);
300300
} else {
301-
edit("milestone", milestone.getNumber());
301+
editIssue("milestone", milestone.getNumber());
302302
}
303303
}
304304

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ public PagedIterable<GHOrganization> listOrganizations(final String since) {
532532
}
533533

534534
/**
535-
* Gets the repository object from 'user/reponame' string that GitHub calls as "repository name"
535+
* Gets the repository object from 'owner/repo' string that GitHub calls as "repository name"
536536
*
537537
* @param name
538538
* the name
@@ -543,6 +543,9 @@ public PagedIterable<GHOrganization> listOrganizations(final String since) {
543543
*/
544544
public GHRepository getRepository(String name) throws IOException {
545545
String[] tokens = name.split("/");
546+
if (tokens.length < 2) {
547+
throw new IllegalArgumentException("Repository name must be in format owner/repo");
548+
}
546549
return createRequest().withUrlPath("/repos/" + tokens[0] + '/' + tokens[1])
547550
.fetch(GHRepository.class)
548551
.wrap(this);

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,26 @@ public void testUnsetMilestone() throws IOException {
7070
assertEquals(null, issue.getMilestone());
7171
}
7272

73+
@Test
74+
public void testUnsetMilestoneFromPullRequest() throws IOException {
75+
GHRepository repo = getRepository();
76+
GHMilestone milestone = repo.createMilestone("Unset Test Milestone", "For testUnsetMilestone");
77+
GHPullRequest p = repo.createPullRequest("testUnsetMilestoneFromPullRequest",
78+
"test/stable",
79+
"master",
80+
"## test pull request");
81+
82+
// set the milestone
83+
p.setMilestone(milestone);
84+
p = repo.getPullRequest(p.getNumber()); // force reload
85+
assertEquals(milestone.getNumber(), p.getMilestone().getNumber());
86+
87+
// remove the milestone
88+
p.setMilestone(null);
89+
p = repo.getPullRequest(p.getNumber()); // force reload
90+
assertNull(p.getMilestone());
91+
}
92+
7393
protected GHRepository getRepository() throws IOException {
7494
return getRepository(gitHub);
7595
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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://avatars3.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": 12,
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+
"total_private_repos": 0,
32+
"owned_private_repos": 0,
33+
"private_gists": 0,
34+
"disk_usage": 148,
35+
"collaborators": 0,
36+
"billing_email": "[email protected]",
37+
"default_repository_permission": "none",
38+
"members_can_create_repositories": false,
39+
"two_factor_requirement_enabled": false,
40+
"plan": {
41+
"name": "free",
42+
"space": 976562499,
43+
"private_repos": 10000,
44+
"filled_seats": 19,
45+
"seats": 3
46+
}
47+
}

0 commit comments

Comments
 (0)