Move a few static helpers to GitHubClient

This commit is contained in:
Liam Newman
2020-02-12 23:47:44 -08:00
parent 326c627221
commit ff3136df70
51 changed files with 153 additions and 141 deletions

View File

@@ -140,7 +140,7 @@ public class GHApp extends GHObject {
}
public URL getHtmlUrl() {
return GitHub.parseURL(htmlUrl);
return GitHubClient.parseURL(htmlUrl);
}
/**

View File

@@ -42,7 +42,7 @@ public class GHAppInstallation extends GHObject {
private String htmlUrl;
public URL getHtmlUrl() {
return GitHub.parseURL(htmlUrl);
return GitHubClient.parseURL(htmlUrl);
}
/**

View File

@@ -127,7 +127,7 @@ public class GHAppInstallationToken {
*/
@WithBridgeMethods(value = String.class, adapterMethod = "expiresAtStr")
public Date getExpiresAt() throws IOException {
return GitHub.parseDate(expires_at);
return GitHubClient.parseDate(expires_at);
}
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getExpiresAt")

View File

@@ -96,7 +96,7 @@ public class GHAuthorization extends GHObject {
* @return the app url
*/
public URL getAppUrl() {
return GitHub.parseURL(app.url);
return GitHubClient.parseURL(app.url);
}
/**
@@ -115,7 +115,7 @@ public class GHAuthorization extends GHObject {
*/
@SuppressFBWarnings(value = "NM_CONFUSING", justification = "It's a part of the library API, cannot be changed")
public URL getApiURL() {
return GitHub.parseURL(url);
return GitHubClient.parseURL(url);
}
/**
@@ -141,7 +141,7 @@ public class GHAuthorization extends GHObject {
* @return the note url
*/
public URL getNoteUrl() {
return GitHub.parseURL(note_url);
return GitHubClient.parseURL(note_url);
}
/**

View File

@@ -24,7 +24,7 @@ public class GHBlob {
* @return API URL of this blob.
*/
public URL getUrl() {
return GitHub.parseURL(url);
return GitHubClient.parseURL(url);
}
/**

View File

@@ -90,7 +90,7 @@ public class GHBranch {
@Preview
@Deprecated
public URL getProtectionUrl() {
return GitHub.parseURL(protection_url);
return GitHubClient.parseURL(protection_url);
}
/**

View File

@@ -61,7 +61,7 @@ public class GHCommit {
* @return the authored date
*/
public Date getAuthoredDate() {
return GitHub.parseDate(author.date);
return GitHubClient.parseDate(author.date);
}
/**
@@ -80,7 +80,7 @@ public class GHCommit {
* @return the commit date
*/
public Date getCommitDate() {
return GitHub.parseDate(committer.date);
return GitHubClient.parseDate(committer.date);
}
/**
@@ -201,7 +201,7 @@ public class GHCommit {
* resolves to the actual content of the file.
*/
public URL getRawUrl() {
return GitHub.parseURL(raw_url);
return GitHubClient.parseURL(raw_url);
}
/**
@@ -212,7 +212,7 @@ public class GHCommit {
* that resolves to the HTML page that describes this file.
*/
public URL getBlobUrl() {
return GitHub.parseURL(blob_url);
return GitHubClient.parseURL(blob_url);
}
/**
@@ -326,7 +326,7 @@ public class GHCommit {
* "https://github.com/kohsuke/sandbox-ant/commit/8ae38db0ea5837313ab5f39d43a6f73de3bd9000"
*/
public URL getHtmlUrl() {
return GitHub.parseURL(html_url);
return GitHubClient.parseURL(html_url);
}
/**

View File

@@ -41,7 +41,7 @@ public class GHCommitComment extends GHObject implements Reactable {
* show this commit comment in a browser.
*/
public URL getHtmlUrl() {
return GitHub.parseURL(html_url);
return GitHubClient.parseURL(html_url);
}
/**

View File

@@ -83,7 +83,7 @@ public class GHCommitQueryBuilder {
* @return the gh commit query builder
*/
public GHCommitQueryBuilder since(Date dt) {
req.with("since", GitHub.printDate(dt));
req.with("since", GitHubClient.printDate(dt));
return this;
}
@@ -106,7 +106,7 @@ public class GHCommitQueryBuilder {
* @return the gh commit query builder
*/
public GHCommitQueryBuilder until(Date dt) {
req.with("until", GitHub.printDate(dt));
req.with("until", GitHubClient.printDate(dt));
return this;
}

View File

@@ -27,7 +27,7 @@ public class GHCompare {
* @return the url
*/
public URL getUrl() {
return GitHub.parseURL(url);
return GitHubClient.parseURL(url);
}
/**
@@ -36,7 +36,7 @@ public class GHCompare {
* @return the html url
*/
public URL getHtmlUrl() {
return GitHub.parseURL(html_url);
return GitHubClient.parseURL(html_url);
}
/**
@@ -45,7 +45,7 @@ public class GHCompare {
* @return the permalink url
*/
public URL getPermalinkUrl() {
return GitHub.parseURL(permalink_url);
return GitHubClient.parseURL(permalink_url);
}
/**
@@ -54,7 +54,7 @@ public class GHCompare {
* @return the diff url
*/
public URL getDiffUrl() {
return GitHub.parseURL(diff_url);
return GitHubClient.parseURL(diff_url);
}
/**
@@ -63,7 +63,7 @@ public class GHCompare {
* @return the patch url
*/
public URL getPatchUrl() {
return GitHub.parseURL(patch_url);
return GitHubClient.parseURL(patch_url);
}
/**

View File

@@ -38,7 +38,7 @@ public class GHDeployment extends GHObject {
* @return the statuses url
*/
public URL getStatusesUrl() {
return GitHub.parseURL(statuses_url);
return GitHubClient.parseURL(statuses_url);
}
/**
@@ -47,7 +47,7 @@ public class GHDeployment extends GHObject {
* @return the repository url
*/
public URL getRepositoryUrl() {
return GitHub.parseURL(repository_url);
return GitHubClient.parseURL(repository_url);
}
/**

View File

@@ -37,7 +37,7 @@ public class GHDeploymentStatus extends GHObject {
* @return the target url
*/
public URL getTargetUrl() {
return GitHub.parseURL(target_url);
return GitHubClient.parseURL(target_url);
}
/**
@@ -46,7 +46,7 @@ public class GHDeploymentStatus extends GHObject {
* @return the deployment url
*/
public URL getDeploymentUrl() {
return GitHub.parseURL(deployment_url);
return GitHubClient.parseURL(deployment_url);
}
/**
@@ -55,7 +55,7 @@ public class GHDeploymentStatus extends GHObject {
* @return the repository url
*/
public URL getRepositoryUrl() {
return GitHub.parseURL(repository_url);
return GitHubClient.parseURL(repository_url);
}
/**

View File

@@ -78,7 +78,7 @@ public class GHEventInfo {
* @return the created at
*/
public Date getCreatedAt() {
return GitHub.parseDate(created_at);
return GitHubClient.parseDate(created_at);
}
/**

View File

@@ -84,7 +84,7 @@ public class GHGist extends GHObject {
}
public URL getHtmlUrl() {
return GitHub.parseURL(html_url);
return GitHubClient.parseURL(html_url);
}
/**

View File

@@ -51,6 +51,6 @@ public class GHInvitation extends GHObject {
@Override
public URL getHtmlUrl() {
return GitHub.parseURL(html_url);
return GitHubClient.parseURL(html_url);
}
}

View File

@@ -137,7 +137,7 @@ public class GHIssue extends GHObject implements Reactable {
* The HTML page of this issue, like https://github.com/jenkinsci/jenkins/issues/100
*/
public URL getHtmlUrl() {
return GitHub.parseURL(html_url);
return GitHubClient.parseURL(html_url);
}
/**
@@ -187,7 +187,7 @@ public class GHIssue extends GHObject implements Reactable {
* @return the closed at
*/
public Date getClosedAt() {
return GitHub.parseDate(closed_at);
return GitHubClient.parseDate(closed_at);
}
/**
@@ -196,7 +196,7 @@ public class GHIssue extends GHObject implements Reactable {
* @return the api url
*/
public URL getApiURL() {
return GitHub.parseURL(url);
return GitHubClient.parseURL(url);
}
/**
@@ -677,7 +677,7 @@ public class GHIssue extends GHObject implements Reactable {
* @return the diff url
*/
public URL getDiffUrl() {
return GitHub.parseURL(diff_url);
return GitHubClient.parseURL(diff_url);
}
/**
@@ -686,7 +686,7 @@ public class GHIssue extends GHObject implements Reactable {
* @return the patch url
*/
public URL getPatchUrl() {
return GitHub.parseURL(patch_url);
return GitHubClient.parseURL(patch_url);
}
/**
@@ -695,7 +695,7 @@ public class GHIssue extends GHObject implements Reactable {
* @return the url
*/
public URL getUrl() {
return GitHub.parseURL(html_url);
return GitHubClient.parseURL(html_url);
}
}

View File

@@ -87,7 +87,7 @@ public class GHIssueComment extends GHObject implements Reactable {
@Override
public URL getHtmlUrl() {
return GitHub.parseURL(html_url);
return GitHubClient.parseURL(html_url);
}
/**

View File

@@ -90,7 +90,7 @@ public class GHIssueEvent {
* @return the created at
*/
public Date getCreatedAt() {
return GitHub.parseDate(created_at);
return GitHubClient.parseDate(created_at);
}
/**

View File

@@ -83,7 +83,7 @@ public class GHLicense extends GHObject {
*/
@WithBridgeMethods(value = String.class, adapterMethod = "urlToString")
public URL getUrl() {
return GitHub.parseURL(url);
return GitHubClient.parseURL(url);
}
/**
@@ -100,7 +100,7 @@ public class GHLicense extends GHObject {
public URL getHtmlUrl() throws IOException {
populate();
return GitHub.parseURL(html_url);
return GitHubClient.parseURL(html_url);
}
/**

View File

@@ -37,7 +37,7 @@ public class GHMarketplaceAccount {
* @return the url
*/
public URL getUrl() {
return GitHub.parseURL(url);
return GitHubClient.parseURL(url);
}
/**

View File

@@ -68,7 +68,7 @@ public class GHMarketplacePendingChange {
* @return the effective date
*/
public Date getEffectiveDate() {
return GitHub.parseDate(effectiveDate);
return GitHubClient.parseDate(effectiveDate);
}
}

View File

@@ -47,7 +47,7 @@ public class GHMarketplacePlan {
* @return the url
*/
public URL getUrl() {
return GitHub.parseURL(url);
return GitHubClient.parseURL(url);
}
/**

View File

@@ -52,7 +52,7 @@ public class GHMarketplacePurchase {
* @return the next billing date
*/
public Date getNextBillingDate() {
return GitHub.parseDate(nextBillingDate);
return GitHubClient.parseDate(nextBillingDate);
}
/**
@@ -70,7 +70,7 @@ public class GHMarketplacePurchase {
* @return the free trial ends on
*/
public Date getFreeTrialEndsOn() {
return GitHub.parseDate(freeTrialEndsOn);
return GitHubClient.parseDate(freeTrialEndsOn);
}
/**
@@ -88,7 +88,7 @@ public class GHMarketplacePurchase {
* @return the updated at
*/
public Date getUpdatedAt() {
return GitHub.parseDate(updatedAt);
return GitHubClient.parseDate(updatedAt);
}
/**

View File

@@ -54,7 +54,7 @@ public class GHMarketplaceUserPurchase {
* @return the next billing date
*/
public Date getNextBillingDate() {
return GitHub.parseDate(nextBillingDate);
return GitHubClient.parseDate(nextBillingDate);
}
/**
@@ -72,7 +72,7 @@ public class GHMarketplaceUserPurchase {
* @return the free trial ends on
*/
public Date getFreeTrialEndsOn() {
return GitHub.parseDate(freeTrialEndsOn);
return GitHubClient.parseDate(freeTrialEndsOn);
}
/**
@@ -90,7 +90,7 @@ public class GHMarketplaceUserPurchase {
* @return the updated at
*/
public Date getUpdatedAt() {
return GitHub.parseDate(updatedAt);
return GitHubClient.parseDate(updatedAt);
}
/**

View File

@@ -25,7 +25,7 @@ public class GHMembership /* extends GHObject --- but it doesn't have id, create
* @return the url
*/
public URL getUrl() {
return GitHub.parseURL(url);
return GitHubClient.parseURL(url);
}
/**

View File

@@ -56,7 +56,7 @@ public class GHMilestone extends GHObject {
public Date getDueOn() {
if (due_on == null)
return null;
return GitHub.parseDate(due_on);
return GitHubClient.parseDate(due_on);
}
/**
@@ -67,7 +67,7 @@ public class GHMilestone extends GHObject {
* the io exception
*/
public Date getClosedAt() throws IOException {
return GitHub.parseDate(closed_at);
return GitHubClient.parseDate(closed_at);
}
/**
@@ -116,7 +116,7 @@ public class GHMilestone extends GHObject {
}
public URL getHtmlUrl() {
return GitHub.parseURL(html_url);
return GitHubClient.parseURL(html_url);
}
/**
@@ -195,7 +195,7 @@ public class GHMilestone extends GHObject {
* the io exception
*/
public void setDueOn(Date dueOn) throws IOException {
edit("due_on", GitHub.printDate(dueOn));
edit("due_on", GitHubClient.printDate(dueOn));
}
/**

View File

@@ -79,7 +79,7 @@ public class GHNotificationStream implements Iterable<GHThread> {
* @return the gh notification stream
*/
public GHNotificationStream since(Date dt) {
since = GitHub.printDate(dt);
since = GitHubClient.printDate(dt);
return this;
}
@@ -234,7 +234,7 @@ public class GHNotificationStream implements Iterable<GHThread> {
public void markAsRead(long timestamp) throws IOException {
final Requester req = root.createRequest();
if (timestamp >= 0)
req.with("last_read_at", GitHub.printDate(new Date(timestamp)));
req.with("last_read_at", GitHubClient.printDate(new Date(timestamp)));
req.withUrlPath(apiUrl).fetchHttpStatusCode();
}

View File

@@ -60,7 +60,7 @@ public abstract class GHObject {
*/
@WithBridgeMethods(value = String.class, adapterMethod = "createdAtStr")
public Date getCreatedAt() throws IOException {
return GitHub.parseDate(created_at);
return GitHubClient.parseDate(created_at);
}
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getCreatedAt")
@@ -75,7 +75,7 @@ public abstract class GHObject {
*/
@WithBridgeMethods(value = String.class, adapterMethod = "urlToString")
public URL getUrl() {
return GitHub.parseURL(url);
return GitHubClient.parseURL(url);
}
/**
@@ -96,7 +96,7 @@ public abstract class GHObject {
* on error
*/
public Date getUpdatedAt() throws IOException {
return GitHub.parseDate(updated_at);
return GitHubClient.parseDate(updated_at);
}
/**

View File

@@ -264,7 +264,7 @@ public abstract class GHPerson extends GHObject {
@Override
public URL getHtmlUrl() {
return GitHub.parseURL(html_url);
return GitHubClient.parseURL(html_url);
}
/**

View File

@@ -51,7 +51,7 @@ public class GHProject extends GHObject {
@Override
public URL getHtmlUrl() throws IOException {
return GitHub.parseURL(html_url);
return GitHubClient.parseURL(html_url);
}
/**
@@ -99,7 +99,7 @@ public class GHProject extends GHObject {
* @return the owner url
*/
public URL getOwnerUrl() {
return GitHub.parseURL(owner_url);
return GitHubClient.parseURL(owner_url);
}
/**

View File

@@ -149,7 +149,7 @@ public class GHProjectCard extends GHObject {
* @return the content url
*/
public URL getContentUrl() {
return GitHub.parseURL(content_url);
return GitHubClient.parseURL(content_url);
}
/**
@@ -158,7 +158,7 @@ public class GHProjectCard extends GHObject {
* @return the project url
*/
public URL getProjectUrl() {
return GitHub.parseURL(project_url);
return GitHubClient.parseURL(project_url);
}
/**
@@ -167,7 +167,7 @@ public class GHProjectCard extends GHObject {
* @return the column url
*/
public URL getColumnUrl() {
return GitHub.parseURL(column_url);
return GitHubClient.parseURL(column_url);
}
/**

View File

@@ -90,7 +90,7 @@ public class GHProjectColumn extends GHObject {
* @return the project url
*/
public URL getProjectUrl() {
return GitHub.parseURL(project_url);
return GitHubClient.parseURL(project_url);
}
/**

View File

@@ -108,7 +108,7 @@ public class GHPullRequest extends GHIssue implements Refreshable {
* @return the patch url
*/
public URL getPatchUrl() {
return GitHub.parseURL(patch_url);
return GitHubClient.parseURL(patch_url);
}
/**
@@ -117,7 +117,7 @@ public class GHPullRequest extends GHIssue implements Refreshable {
* @return the issue url
*/
public URL getIssueUrl() {
return GitHub.parseURL(issue_url);
return GitHubClient.parseURL(issue_url);
}
/**
@@ -156,7 +156,7 @@ public class GHPullRequest extends GHIssue implements Refreshable {
* @return the diff url
*/
public URL getDiffUrl() {
return GitHub.parseURL(diff_url);
return GitHubClient.parseURL(diff_url);
}
/**
@@ -165,7 +165,7 @@ public class GHPullRequest extends GHIssue implements Refreshable {
* @return the merged at
*/
public Date getMergedAt() {
return GitHub.parseDate(merged_at);
return GitHubClient.parseDate(merged_at);
}
@Override

View File

@@ -75,7 +75,7 @@ public class GHPullRequestCommitDetail {
* @return the url
*/
public URL getUrl() {
return GitHub.parseURL(url);
return GitHubClient.parseURL(url);
}
}
@@ -125,7 +125,7 @@ public class GHPullRequestCommitDetail {
* @return the url
*/
public URL getUrl() {
return GitHub.parseURL(url);
return GitHubClient.parseURL(url);
}
/**
@@ -161,7 +161,7 @@ public class GHPullRequestCommitDetail {
* @return the url
*/
public URL getUrl() {
return GitHub.parseURL(url);
return GitHubClient.parseURL(url);
}
/**
@@ -170,7 +170,7 @@ public class GHPullRequestCommitDetail {
* @return the html url
*/
public URL getHtml_url() {
return GitHub.parseURL(html_url);
return GitHubClient.parseURL(html_url);
}
/**
@@ -214,7 +214,7 @@ public class GHPullRequestCommitDetail {
* @return the api url
*/
public URL getApiUrl() {
return GitHub.parseURL(url);
return GitHubClient.parseURL(url);
}
/**
@@ -223,7 +223,7 @@ public class GHPullRequestCommitDetail {
* @return the url
*/
public URL getUrl() {
return GitHub.parseURL(html_url);
return GitHubClient.parseURL(html_url);
}
/**
@@ -232,7 +232,7 @@ public class GHPullRequestCommitDetail {
* @return the comments url
*/
public URL getCommentsUrl() {
return GitHub.parseURL(comments_url);
return GitHubClient.parseURL(comments_url);
}
/**

View File

@@ -105,7 +105,7 @@ public class GHPullRequestFileDetail {
* @return the blob url
*/
public URL getBlobUrl() {
return GitHub.parseURL(blob_url);
return GitHubClient.parseURL(blob_url);
}
/**
@@ -114,7 +114,7 @@ public class GHPullRequestFileDetail {
* @return the raw url
*/
public URL getRawUrl() {
return GitHub.parseURL(raw_url);
return GitHubClient.parseURL(raw_url);
}
/**
@@ -123,7 +123,7 @@ public class GHPullRequestFileDetail {
* @return the contents url
*/
public URL getContentsUrl() {
return GitHub.parseURL(contents_url);
return GitHubClient.parseURL(contents_url);
}
/**

View File

@@ -122,7 +122,7 @@ public class GHPullRequestReview extends GHObject {
* the io exception
*/
public Date getSubmittedAt() throws IOException {
return GitHub.parseDate(submitted_at);
return GitHubClient.parseDate(submitted_at);
}
/**

View File

@@ -31,7 +31,7 @@ public class GHRef {
* @return the url
*/
public URL getUrl() {
return GitHub.parseURL(url);
return GitHubClient.parseURL(url);
}
/**
@@ -131,7 +131,7 @@ public class GHRef {
* @return the url
*/
public URL getUrl() {
return GitHub.parseURL(url);
return GitHubClient.parseURL(url);
}
}
}

View File

@@ -77,7 +77,7 @@ public class GHRelease extends GHObject {
}
public URL getHtmlUrl() {
return GitHub.parseURL(html_url);
return GitHubClient.parseURL(html_url);
}
/**

View File

@@ -257,7 +257,7 @@ public class GHRepository extends GHObject {
}
public URL getHtmlUrl() {
return GitHub.parseURL(html_url);
return GitHubClient.parseURL(html_url);
}
/**
@@ -696,7 +696,7 @@ public class GHRepository extends GHObject {
* @return null if the repository was never pushed at.
*/
public Date getPushedAt() {
return GitHub.parseDate(pushed_at);
return GitHubClient.parseDate(pushed_at);
}
/**

View File

@@ -47,7 +47,7 @@ public abstract class GHRepositoryTraffic implements TrafficInfo {
* @return the timestamp
*/
public Date getTimestamp() {
return GitHub.parseDate(timestamp);
return GitHubClient.parseDate(timestamp);
}
public int getCount() {

View File

@@ -32,7 +32,7 @@ public class GHStargazer {
* @return the date the stargazer was added
*/
public Date getStarredAt() {
return GitHub.parseDate(starred_at);
return GitHubClient.parseDate(starred_at);
}
/**

View File

@@ -23,7 +23,7 @@ public class GHSubscription {
* @return the created at
*/
public Date getCreatedAt() {
return GitHub.parseDate(created_at);
return GitHubClient.parseDate(created_at);
}
/**

View File

@@ -41,7 +41,7 @@ public class GHThread extends GHObject {
* @return the last read at
*/
public Date getLastReadAt() {
return GitHub.parseDate(last_read_at);
return GitHubClient.parseDate(last_read_at);
}
/**

View File

@@ -71,7 +71,7 @@ public class GHTree {
* @return the url
*/
public URL getUrl() {
return GitHub.parseURL(url);
return GitHubClient.parseURL(url);
}
GHTree wrap(GHRepository repo) {

View File

@@ -68,7 +68,7 @@ public class GHTreeEntry {
* @return the url
*/
public URL getUrl() {
return GitHub.parseURL(url);
return GitHubClient.parseURL(url);
}
/**

View File

@@ -33,11 +33,8 @@ import org.apache.commons.io.IOUtils;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Base64;
import java.util.concurrent.ConcurrentHashMap;
@@ -1398,35 +1395,6 @@ public class GitHub {
"UTF-8");
}
static URL parseURL(String s) {
try {
return s == null ? null : new URL(s);
} catch (MalformedURLException e) {
throw new IllegalStateException("Invalid URL: " + s);
}
}
static Date parseDate(String timestamp) {
if (timestamp == null)
return null;
for (String f : TIME_FORMATS) {
try {
SimpleDateFormat df = new SimpleDateFormat(f);
df.setTimeZone(TimeZone.getTimeZone("GMT"));
return df.parse(timestamp);
} catch (ParseException e) {
// try next
}
}
throw new IllegalStateException("Unable to parse the timestamp: " + timestamp);
}
static String printDate(Date dt) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
df.setTimeZone(TimeZone.getTimeZone("GMT"));
return df.format(dt);
}
static final ObjectMapper MAPPER = new ObjectMapper();
private static final String[] TIME_FORMATS = { "yyyy/MM/dd HH:mm:ss ZZZZ", "yyyy-MM-dd'T'HH:mm:ss'Z'",

View File

@@ -0,0 +1,44 @@
package org.kohsuke.github;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
class GitHubClient {
private static final String[] TIME_FORMATS = { "yyyy/MM/dd HH:mm:ss ZZZZ", "yyyy-MM-dd'T'HH:mm:ss'Z'",
"yyyy-MM-dd'T'HH:mm:ss.S'Z'" // GitHub App endpoints return a different date format
};
static URL parseURL(String s) {
try {
return s == null ? null : new URL(s);
} catch (MalformedURLException e) {
throw new IllegalStateException("Invalid URL: " + s);
}
}
static Date parseDate(String timestamp) {
if (timestamp == null)
return null;
for (String f : TIME_FORMATS) {
try {
SimpleDateFormat df = new SimpleDateFormat(f);
df.setTimeZone(TimeZone.getTimeZone("GMT"));
return df.parse(timestamp);
} catch (ParseException e) {
// try next
}
}
throw new IllegalStateException("Unable to parse the timestamp: " + timestamp);
}
static String printDate(Date dt) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
df.setTimeZone(TimeZone.getTimeZone("GMT"));
return df.format(dt);
}
}

View File

@@ -41,6 +41,6 @@ public class GitUser {
* @return This field doesn't appear to be consistently available in all the situations where this class is used.
*/
public Date getDate() {
return GitHub.parseDate(date);
return GitHubClient.parseDate(date);
}
}

View File

@@ -35,8 +35,8 @@ public class GHAppTest extends AbstractGitHubWireMockTest {
assertThat(app.getDescription(), is(""));
assertThat(app.getExternalUrl(), is("https://bogus.domain.com"));
assertThat(app.getHtmlUrl().toString(), is("https://github.com/apps/bogus-development"));
assertThat(app.getCreatedAt(), is(GitHub.parseDate("2019-06-10T04:21:41Z")));
assertThat(app.getUpdatedAt(), is(GitHub.parseDate("2019-06-10T04:21:41Z")));
assertThat(app.getCreatedAt(), is(GitHubClient.parseDate("2019-06-10T04:21:41Z")));
assertThat(app.getUpdatedAt(), is(GitHubClient.parseDate("2019-06-10T04:21:41Z")));
assertThat(app.getPermissions().size(), is(4));
assertThat(app.getEvents().size(), is(2));
assertThat(app.getInstallationsCount(), is((long) 1));
@@ -110,7 +110,7 @@ public class GHAppTest extends AbstractGitHubWireMockTest {
assertThat(installationToken.getToken(), is("bogus"));
assertThat(installation.getPermissions(), is(permissions));
assertThat(installationToken.getRepositorySelection(), is(GHRepositorySelection.SELECTED));
assertThat(installationToken.getExpiresAt(), is(GitHub.parseDate("2019-08-10T05:54:58Z")));
assertThat(installationToken.getExpiresAt(), is(GitHubClient.parseDate("2019-08-10T05:54:58Z")));
GHRepository repository = installationToken.getRepositories().get(0);
assertThat(installationToken.getRepositories().size(), is(1));
@@ -123,7 +123,7 @@ public class GHAppTest extends AbstractGitHubWireMockTest {
assertThat(installationToken2.getToken(), is("bogus"));
assertThat(installationToken2.getPermissions().size(), is(4));
assertThat(installationToken2.getRepositorySelection(), is(GHRepositorySelection.ALL));
assertThat(installationToken2.getExpiresAt(), is(GitHub.parseDate("2019-12-19T12:27:59Z")));
assertThat(installationToken2.getExpiresAt(), is(GitHubClient.parseDate("2019-12-19T12:27:59Z")));
assertNull(installationToken2.getRepositories());;
}
@@ -151,8 +151,8 @@ public class GHAppTest extends AbstractGitHubWireMockTest {
List<GHEvent> events = Arrays.asList(GHEvent.PULL_REQUEST, GHEvent.PUSH);
assertThat(appInstallation.getEvents(), containsInAnyOrder(events.toArray(new GHEvent[0])));
assertThat(appInstallation.getCreatedAt(), is(GitHub.parseDate("2019-07-04T01:19:36.000Z")));
assertThat(appInstallation.getUpdatedAt(), is(GitHub.parseDate("2019-07-30T22:48:09.000Z")));
assertThat(appInstallation.getCreatedAt(), is(GitHubClient.parseDate("2019-07-04T01:19:36.000Z")));
assertThat(appInstallation.getUpdatedAt(), is(GitHubClient.parseDate("2019-07-30T22:48:09.000Z")));
assertNull(appInstallation.getSingleFileName());
}

View File

@@ -36,8 +36,8 @@ public class GHMilestoneTest extends AbstractGitHubWireMockTest {
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");
Date NEW_DUE_DATE = GitHubClient.parseDate("2020-10-05T13:00:00Z");
Date OUTPUT_DUE_DATE = GitHubClient.parseDate("2020-10-05T07:00:00Z");
milestone.setTitle(NEW_TITLE);
milestone.setDescription(NEW_DESCRIPTION);

View File

@@ -38,25 +38,25 @@ public class GitHubStaticTest extends AbstractGitHubWireMockTest {
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(GitHubClient.parseDate(GitHubClient.printDate(instantSeconds)),
equalTo(GitHubClient.parseDate(GitHubClient.printDate(instantMillis))));
assertThat(instantSeconds, equalTo(GitHub.parseDate(GitHub.printDate(instantSeconds))));
assertThat(instantSeconds, equalTo(GitHubClient.parseDate(GitHubClient.printDate(instantSeconds))));
// printDate will truncate to the nearest second, so it should not be equal
assertThat(instantMillis, not(equalTo(GitHub.parseDate(GitHub.printDate(instantMillis)))));
assertThat(instantMillis, not(equalTo(GitHubClient.parseDate(GitHubClient.printDate(instantMillis)))));
assertThat(instantSeconds, equalTo(GitHub.parseDate(instantFormatSlash)));
assertThat(instantSeconds, equalTo(GitHubClient.parseDate(instantFormatSlash)));
assertThat(instantSeconds, equalTo(GitHub.parseDate(instantFormatDash)));
assertThat(instantSeconds, equalTo(GitHubClient.parseDate(instantFormatDash)));
// This parser does not truncate to the nearest second, so it will be equal
assertThat(instantMillis, equalTo(GitHub.parseDate(instantFormatMillis)));
assertThat(instantMillis, equalTo(GitHubClient.parseDate(instantFormatMillis)));
assertThat(instantSeconds, equalTo(GitHub.parseDate(instantSecondsFormatMillis)));
assertThat(instantSeconds, equalTo(GitHubClient.parseDate(instantSecondsFormatMillis)));
try {
GitHub.parseDate(instantBadFormat);
GitHubClient.parseDate(instantBadFormat);
fail("Bad time format should throw.");
} catch (IllegalStateException e) {
assertThat(e.getMessage(), equalTo("Unable to parse the timestamp: " + instantBadFormat));