Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to unset the milestone of an issue #773

Merged
merged 2 commits into from
Apr 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/main/java/org/kohsuke/github/GHIssue.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,13 @@ private void edit(String key, Object value) throws IOException {
root.createRequest().with(key, value).method("PATCH").withUrlPath(getApiRoute()).send();
}

/**
* Identical to edit(), but allows null for the value.
*/
private void editNullable(String key, Object value) throws IOException {
root.createRequest().withNullable(key, value).method("PATCH").withUrlPath(getApiRoute()).send();
}

private void editIssue(String key, Object value) throws IOException {
root.createRequest().with(key, value).method("PATCH").withUrlPath(getIssuesApiRoute()).send();
}
Expand Down Expand Up @@ -277,15 +284,19 @@ public void setBody(String body) throws IOException {
}

/**
* Sets milestone.
* Sets the milestone for this issue.
*
* @param milestone
* the milestone
* The milestone to assign this issue to. Use null to remove the milestone for this issue.
* @throws IOException
* the io exception
* The io exception
*/
public void setMilestone(GHMilestone milestone) throws IOException {
edit("milestone", milestone.getNumber());
if (milestone == null) {
editNullable("milestone", null);
} else {
edit("milestone", milestone.getNumber());
}
}

/**
Expand Down
22 changes: 19 additions & 3 deletions src/test/java/org/kohsuke/github/GHMilestoneTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import java.io.IOException;
import java.util.Date;

import static org.junit.Assert.assertEquals;

/**
* @author Martin van Zijl
*/
Expand All @@ -23,7 +21,8 @@ public void cleanUp() throws Exception {
}

for (GHMilestone milestone : getRepository(getGitHubBeforeAfter()).listMilestones(GHIssueState.ALL)) {
if ("Original Title".equals(milestone.getTitle()) || "Updated Title".equals(milestone.getTitle())) {
if ("Original Title".equals(milestone.getTitle()) || "Updated Title".equals(milestone.getTitle())
|| "Unset Test Milestone".equals(milestone.getTitle())) {
milestone.delete();
}
}
Expand Down Expand Up @@ -54,6 +53,23 @@ public void testUpdateMilestone() throws Exception {
assertEquals(OUTPUT_DUE_DATE, milestone.getDueOn());
}

@Test
public void testUnsetMilestone() throws IOException {
GHRepository repo = getRepository();
GHMilestone milestone = repo.createMilestone("Unset Test Milestone", "For testUnsetMilestone");
GHIssue issue = repo.createIssue("Issue for testUnsetMilestone").create();

// set the milestone
issue.setMilestone(milestone);
issue = repo.getIssue(issue.getNumber()); // force reload
assertEquals(milestone.getNumber(), issue.getMilestone().getNumber());

// remove the milestone
issue.setMilestone(null);
issue = repo.getIssue(issue.getNumber()); // force reload
assertEquals(null, issue.getMilestone());
}

protected GHRepository getRepository() throws IOException {
return getRepository(gitHub);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"login": "github-api-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"url": "https://api.github.com/orgs/github-api-test-org",
"repos_url": "https://api.github.com/orgs/github-api-test-org/repos",
"events_url": "https://api.github.com/orgs/github-api-test-org/events",
"hooks_url": "https://api.github.com/orgs/github-api-test-org/hooks",
"issues_url": "https://api.github.com/orgs/github-api-test-org/issues",
"members_url": "https://api.github.com/orgs/github-api-test-org/members{/member}",
"public_members_url": "https://api.github.com/orgs/github-api-test-org/public_members{/member}",
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
"description": null,
"is_verified": false,
"has_organization_projects": true,
"has_repository_projects": true,
"public_repos": 25,
"public_gists": 0,
"followers": 0,
"following": 0,
"html_url": "https://github.com/github-api-test-org",
"created_at": "2014-05-10T19:39:11Z",
"updated_at": "2015-04-20T00:42:30Z",
"type": "Organization",
"total_private_repos": 0,
"owned_private_repos": 0,
"private_gists": 0,
"disk_usage": 147,
"collaborators": 0,
"billing_email": "[email protected]",
"default_repository_permission": "none",
"members_can_create_repositories": false,
"two_factor_requirement_enabled": false,
"plan": {
"name": "free",
"space": 976562499,
"private_repos": 0,
"filled_seats": 15,
"seats": 0
}
}
Loading