mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-10 08:21:21 +00:00
@@ -85,10 +85,29 @@ public class GHMilestone extends GHObject {
|
||||
edit("state", "open");
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes this milestone.
|
||||
*/
|
||||
public void delete() throws IOException {
|
||||
root.retrieve().method("DELETE").to(getApiRoute());
|
||||
}
|
||||
|
||||
private void edit(String key, Object value) throws IOException {
|
||||
new Requester(root)._with(key, value).method("PATCH").to(getApiRoute());
|
||||
}
|
||||
|
||||
public void setTitle(String title) throws IOException {
|
||||
edit("title", title);
|
||||
}
|
||||
|
||||
public void setDescription(String description) throws IOException {
|
||||
edit("description", description);
|
||||
}
|
||||
|
||||
public void setDueOn(Date dueOn) throws IOException {
|
||||
edit("due_on", GitHub.printDate(dueOn));
|
||||
}
|
||||
|
||||
protected String getApiRoute() {
|
||||
return "/repos/"+owner.getOwnerName()+"/"+owner.getName()+"/milestones/"+number;
|
||||
}
|
||||
|
||||
63
src/test/java/org/kohsuke/github/GHMilestoneTest.java
Normal file
63
src/test/java/org/kohsuke/github/GHMilestoneTest.java
Normal file
@@ -0,0 +1,63 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Martin van Zijl
|
||||
*/
|
||||
public class GHMilestoneTest extends AbstractGitHubWireMockTest {
|
||||
|
||||
@Before
|
||||
@After
|
||||
public void cleanUp() throws Exception {
|
||||
// Cleanup is only needed when proxying
|
||||
if (!mockGitHub.isUseProxy()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (GHMilestone milestone : getRepository().listMilestones(GHIssueState.ALL)) {
|
||||
if ("Original Title".equals(milestone.getTitle()) ||
|
||||
"Updated Title".equals(milestone.getTitle())) {
|
||||
milestone.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateMilestone() throws Exception {
|
||||
GHRepository repo = getRepository();
|
||||
GHMilestone milestone = repo.createMilestone("Original Title",
|
||||
"To test the update methods");
|
||||
|
||||
String NEW_TITLE = "Updated Title";
|
||||
String NEW_DESCRIPTION = "Updated Description";
|
||||
Date NEW_DUE_DATE = GitHub.parseDate("2020-10-01T17:00:00Z");
|
||||
|
||||
milestone.setTitle(NEW_TITLE);
|
||||
milestone.setDescription(NEW_DESCRIPTION);
|
||||
milestone.setDueOn(NEW_DUE_DATE);
|
||||
|
||||
// Force reload.
|
||||
milestone = repo.getMilestone(milestone.getNumber());
|
||||
|
||||
assertEquals(NEW_TITLE, milestone.getTitle());
|
||||
assertEquals(NEW_DESCRIPTION, milestone.getDescription());
|
||||
// The dates never seem to match exactly...
|
||||
//assertEquals(NEW_DUE_DATE, milestone.getDueOn());
|
||||
assertNotNull(milestone.getDueOn());
|
||||
}
|
||||
|
||||
protected GHRepository getRepository() throws IOException {
|
||||
return getRepository(gitHub);
|
||||
}
|
||||
|
||||
private GHRepository getRepository(GitHub gitHub) throws IOException {
|
||||
return gitHub.getOrganization("github-api-test-org").getRepository("github-api");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user