-
Notifications
You must be signed in to change notification settings - Fork 736
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #579 from martinvanzijl/issue_512_methods_to_updat…
…e_milestones Add methods to update and delete milestones.
- Loading branch information
Showing
20 changed files
with
1,119 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.kohsuke.github; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.Date; | ||
|
||
/** | ||
* @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(gitHubBeforeAfter).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-05T13:00:00Z"); | ||
Date OUTPUT_DUE_DATE = GitHub.parseDate("2020-10-05T07: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 time is truncated when sent to the server, but still part of the returned value | ||
// 07:00 midnight PDT | ||
assertEquals(OUTPUT_DUE_DATE, 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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package org.kohsuke.github; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.text.SimpleDateFormat; | ||
import java.time.Instant; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.Date; | ||
import java.util.TimeZone; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.CoreMatchers.not; | ||
|
||
/** | ||
* Unit test for {@link GitHub} static helpers. | ||
* | ||
* @author Liam Newman | ||
*/ | ||
public class GitHubStaticTest extends Assert { | ||
|
||
@Test | ||
public void timeRoundTrip() throws Exception { | ||
Instant instantNow = Instant.now(); | ||
|
||
Date instantSeconds = Date.from(instantNow.truncatedTo(ChronoUnit.SECONDS)); | ||
Date instantMillis = Date.from(instantNow.truncatedTo(ChronoUnit.MILLIS)); | ||
|
||
// TODO: other formats | ||
String instantFormatSlash = formatDate(instantMillis, "yyyy/MM/dd HH:mm:ss ZZZZ"); | ||
String instantFormatDash = formatDate(instantMillis, "yyyy-MM-dd'T'HH:mm:ss'Z'"); | ||
String instantFormatMillis = formatDate(instantMillis, "yyyy-MM-dd'T'HH:mm:ss.S'Z'"); | ||
String instantSecondsFormatMillis = formatDate(instantSeconds, "yyyy-MM-dd'T'HH:mm:ss.S'Z'"); | ||
String instantBadFormat = formatDate(instantMillis, "yy-MM-dd'T'HH:mm'Z'"); | ||
|
||
|
||
assertThat(GitHub.parseDate(GitHub.printDate(instantSeconds)), | ||
equalTo(GitHub.parseDate(GitHub.printDate(instantMillis)))); | ||
|
||
assertThat(instantSeconds, | ||
equalTo(GitHub.parseDate(GitHub.printDate(instantSeconds)))); | ||
|
||
assertThat(instantMillis, | ||
not(equalTo(GitHub.parseDate(GitHub.printDate(instantMillis))))); | ||
|
||
assertThat(instantSeconds, | ||
equalTo(GitHub.parseDate(instantFormatSlash))); | ||
|
||
assertThat(instantSeconds, | ||
equalTo(GitHub.parseDate(instantFormatDash))); | ||
|
||
assertThat(instantMillis, | ||
equalTo(GitHub.parseDate(instantFormatMillis))); | ||
|
||
assertThat(instantSeconds, | ||
equalTo(GitHub.parseDate(instantSecondsFormatMillis))); | ||
|
||
try { | ||
GitHub.parseDate(instantBadFormat); | ||
fail("Bad time format should throw."); | ||
} catch (IllegalStateException e) { | ||
assertThat(e.getMessage(), equalTo("Unable to parse the timestamp: " + instantBadFormat)); | ||
} | ||
} | ||
|
||
static String formatDate(Date dt, String format) { | ||
SimpleDateFormat df = new SimpleDateFormat(format); | ||
df.setTimeZone(TimeZone.getTimeZone("GMT")); | ||
return df.format(dt); | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...pdateMilestone/__files/orgs_github-api-test-org-fdbcaf38-478b-440a-851a-b5913757f6f3.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": 10, | ||
"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": 132, | ||
"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": 7, | ||
"seats": 0 | ||
} | ||
} |
Oops, something went wrong.