From 85f14afde2250ad2cee1fc292bd36931c0ee47d6 Mon Sep 17 00:00:00 2001 From: solonovamax Date: Thu, 27 Mar 2025 16:51:55 -0400 Subject: [PATCH 01/10] Migrate legacy date-time api to new date-time api Signed-off-by: solonovamax --- pom.xml | 6 +- src/main/java/org/kohsuke/github/GHApp.java | 6 +- .../org/kohsuke/github/GHAppInstallation.java | 6 +- .../github/GHAppInstallationToken.java | 5 +- .../java/org/kohsuke/github/GHArtifact.java | 6 +- .../java/org/kohsuke/github/GHCheckRun.java | 10 +- .../org/kohsuke/github/GHCheckRunBuilder.java | 10 +- .../java/org/kohsuke/github/GHCheckSuite.java | 6 +- .../java/org/kohsuke/github/GHCommit.java | 6 +- .../org/kohsuke/github/GHCommitBuilder.java | 16 +--- .../kohsuke/github/GHCommitQueryBuilder.java | 14 +-- .../java/org/kohsuke/github/GHDeployKey.java | 10 +- .../java/org/kohsuke/github/GHEventInfo.java | 5 +- .../org/kohsuke/github/GHEventPayload.java | 10 +- .../org/kohsuke/github/GHExternalGroup.java | 6 +- src/main/java/org/kohsuke/github/GHIssue.java | 6 +- .../github/GHIssueCommentQueryBuilder.java | 8 +- .../java/org/kohsuke/github/GHIssueEvent.java | 6 +- .../kohsuke/github/GHIssueQueryBuilder.java | 8 +- .../github/GHMarketplacePendingChange.java | 6 +- .../kohsuke/github/GHMarketplacePurchase.java | 14 +-- .../github/GHMarketplaceUserPurchase.java | 14 +-- .../java/org/kohsuke/github/GHMilestone.java | 14 +-- .../kohsuke/github/GHNotificationStream.java | 12 +-- .../java/org/kohsuke/github/GHObject.java | 13 ++- .../java/org/kohsuke/github/GHPerson.java | 6 +- .../org/kohsuke/github/GHProjectsV2Item.java | 6 +- .../github/GHProjectsV2ItemChanges.java | 10 +- .../org/kohsuke/github/GHPullRequest.java | 6 +- .../kohsuke/github/GHPullRequestReview.java | 11 +-- .../java/org/kohsuke/github/GHRateLimit.java | 16 ++-- .../java/org/kohsuke/github/GHRelease.java | 10 +- .../java/org/kohsuke/github/GHRepository.java | 6 +- .../github/GHRepositoryDiscussion.java | 14 +-- .../kohsuke/github/GHRepositoryTraffic.java | 6 +- .../java/org/kohsuke/github/GHStargazer.java | 6 +- .../org/kohsuke/github/GHSubscription.java | 6 +- .../java/org/kohsuke/github/GHThread.java | 6 +- src/main/java/org/kohsuke/github/GHUser.java | 5 +- .../org/kohsuke/github/GHWorkflowJob.java | 18 ++-- .../org/kohsuke/github/GHWorkflowRun.java | 10 +- .../java/org/kohsuke/github/GitCommit.java | 6 +- .../java/org/kohsuke/github/GitHubClient.java | 26 ++--- src/main/java/org/kohsuke/github/GitUser.java | 6 +- .../org/kohsuke/github/RateLimitChecker.java | 2 +- .../AppInstallationAuthorizationProvider.java | 4 +- .../extras/authorization/JwtBuilderUtil.java | 8 ++ .../github/AbstractGitHubWireMockTest.java | 4 +- src/test/java/org/kohsuke/github/AppTest.java | 12 +-- .../java/org/kohsuke/github/CommitTest.java | 18 ++-- .../kohsuke/github/GHAppInstallationTest.java | 7 +- .../java/org/kohsuke/github/GHAppTest.java | 32 +++---- .../kohsuke/github/GHCheckRunBuilderTest.java | 22 ++--- .../github/GHContentIntegrationTest.java | 8 +- .../org/kohsuke/github/GHDeployKeyTest.java | 7 +- .../kohsuke/github/GHEventPayloadTest.java | 94 +++++++++---------- .../java/org/kohsuke/github/GHIssueTest.java | 17 ++-- .../org/kohsuke/github/GHMilestoneTest.java | 6 +- .../org/kohsuke/github/GHPullRequestTest.java | 17 ++-- .../org/kohsuke/github/GHRateLimitTest.java | 6 +- .../org/kohsuke/github/GHRepositoryTest.java | 5 +- .../org/kohsuke/github/GHTreeBuilderTest.java | 6 +- .../java/org/kohsuke/github/GHUserTest.java | 2 +- .../org/kohsuke/github/GHWorkflowRunTest.java | 9 +- .../org/kohsuke/github/GitHubStaticTest.java | 73 +++++++------- .../kohsuke/github/RateLimitCheckerTest.java | 1 + 66 files changed, 370 insertions(+), 393 deletions(-) diff --git a/pom.xml b/pom.xml index 9e42411708..f1fc1a11a3 100644 --- a/pom.xml +++ b/pom.xml @@ -141,6 +141,10 @@ com.fasterxml.jackson.core jackson-databind + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + com.infradna.tool bridge-method-annotation @@ -636,7 +640,7 @@ org.springframework.boot diff --git a/src/main/java/org/kohsuke/github/GHApp.java b/src/main/java/org/kohsuke/github/GHApp.java index 9a6ba57072..48e55b4611 100644 --- a/src/main/java/org/kohsuke/github/GHApp.java +++ b/src/main/java/org/kohsuke/github/GHApp.java @@ -5,8 +5,8 @@ import java.io.IOException; import java.net.URL; +import java.time.Instant; import java.util.Collections; -import java.util.Date; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -158,10 +158,10 @@ public PagedIterable listInstallations() { * @return a list of App installations since a given time. * @see List installations */ - public PagedIterable listInstallations(final Date since) { + public PagedIterable listInstallations(final Instant since) { Requester requester = root().createRequest().withUrlPath("/app/installations"); if (since != null) { - requester.with("since", GitHubClient.printDate(since)); + requester.with("since", GitHubClient.printInstant(since)); } return requester.toIterable(GHAppInstallation[].class, null); } diff --git a/src/main/java/org/kohsuke/github/GHAppInstallation.java b/src/main/java/org/kohsuke/github/GHAppInstallation.java index c2611e468c..3b60314c44 100644 --- a/src/main/java/org/kohsuke/github/GHAppInstallation.java +++ b/src/main/java/org/kohsuke/github/GHAppInstallation.java @@ -6,8 +6,8 @@ import java.io.IOException; import java.net.URL; +import java.time.Instant; import java.util.Collections; -import java.util.Date; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -189,8 +189,8 @@ public GHRepositorySelection getRepositorySelection() { * * @return the suspended at */ - public Date getSuspendedAt() { - return GitHubClient.parseDate(suspendedAt); + public Instant getSuspendedAt() { + return GitHubClient.parseInstant(suspendedAt); } /** diff --git a/src/main/java/org/kohsuke/github/GHAppInstallationToken.java b/src/main/java/org/kohsuke/github/GHAppInstallationToken.java index 817156a4bc..45bc622b97 100644 --- a/src/main/java/org/kohsuke/github/GHAppInstallationToken.java +++ b/src/main/java/org/kohsuke/github/GHAppInstallationToken.java @@ -1,5 +1,6 @@ package org.kohsuke.github; +import java.time.Instant; import java.util.*; // TODO: Auto-generated Javadoc @@ -66,7 +67,7 @@ public GHRepositorySelection getRepositorySelection() { * * @return date when this token expires */ - public Date getExpiresAt() { - return GitHubClient.parseDate(expires_at); + public Instant getExpiresAt() { + return GitHubClient.parseInstant(expires_at); } } diff --git a/src/main/java/org/kohsuke/github/GHArtifact.java b/src/main/java/org/kohsuke/github/GHArtifact.java index cc37a5bf4d..7ff8aa9633 100644 --- a/src/main/java/org/kohsuke/github/GHArtifact.java +++ b/src/main/java/org/kohsuke/github/GHArtifact.java @@ -7,7 +7,7 @@ import java.io.IOException; import java.net.URL; -import java.util.Date; +import java.time.Instant; import java.util.Objects; import static java.util.Objects.requireNonNull; @@ -77,8 +77,8 @@ public boolean isExpired() { * * @return the date of expiration */ - public Date getExpiresAt() { - return GitHubClient.parseDate(expiresAt); + public Instant getExpiresAt() { + return GitHubClient.parseInstant(expiresAt); } /** diff --git a/src/main/java/org/kohsuke/github/GHCheckRun.java b/src/main/java/org/kohsuke/github/GHCheckRun.java index cb12173ae4..6424e294d9 100644 --- a/src/main/java/org/kohsuke/github/GHCheckRun.java +++ b/src/main/java/org/kohsuke/github/GHCheckRun.java @@ -7,9 +7,9 @@ import java.io.IOException; import java.net.URL; +import java.time.Instant; import java.util.Arrays; import java.util.Collections; -import java.util.Date; import java.util.List; import java.util.Locale; @@ -269,8 +269,8 @@ public URL getDetailsUrl() { * * @return Timestamp of the start time */ - public Date getStartedAt() { - return GitHubClient.parseDate(startedAt); + public Instant getStartedAt() { + return GitHubClient.parseInstant(startedAt); } /** @@ -278,8 +278,8 @@ public Date getStartedAt() { * * @return Timestamp of the completed time */ - public Date getCompletedAt() { - return GitHubClient.parseDate(completedAt); + public Instant getCompletedAt() { + return GitHubClient.parseInstant(completedAt); } /** diff --git a/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java b/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java index eefe6d0235..31bd90ea7a 100644 --- a/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java @@ -30,8 +30,8 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.IOException; +import java.time.Instant; import java.util.Collections; -import java.util.Date; import java.util.LinkedList; import java.util.List; import java.util.Locale; @@ -172,9 +172,9 @@ private GHCheckRunBuilder(GHRepository repo, Requester requester) { * the started at * @return the GH check run builder */ - public @NonNull GHCheckRunBuilder withStartedAt(@CheckForNull Date startedAt) { + public @NonNull GHCheckRunBuilder withStartedAt(@CheckForNull Instant startedAt) { if (startedAt != null) { - requester.with("started_at", GitHubClient.printDate(startedAt)); + requester.with("started_at", GitHubClient.printInstant(startedAt)); } return this; } @@ -186,9 +186,9 @@ private GHCheckRunBuilder(GHRepository repo, Requester requester) { * the completed at * @return the GH check run builder */ - public @NonNull GHCheckRunBuilder withCompletedAt(@CheckForNull Date completedAt) { + public @NonNull GHCheckRunBuilder withCompletedAt(@CheckForNull Instant completedAt) { if (completedAt != null) { - requester.with("completed_at", GitHubClient.printDate(completedAt)); + requester.with("completed_at", GitHubClient.printInstant(completedAt)); } return this; } diff --git a/src/main/java/org/kohsuke/github/GHCheckSuite.java b/src/main/java/org/kohsuke/github/GHCheckSuite.java index 8c9dea61f7..2859ef03ea 100644 --- a/src/main/java/org/kohsuke/github/GHCheckSuite.java +++ b/src/main/java/org/kohsuke/github/GHCheckSuite.java @@ -5,9 +5,9 @@ import java.io.IOException; import java.net.URL; +import java.time.Instant; import java.util.Arrays; import java.util.Collections; -import java.util.Date; import java.util.List; // TODO: Auto-generated Javadoc @@ -257,8 +257,8 @@ public String getMessage() { * * @return timestamp of the commit */ - public Date getTimestamp() { - return GitHubClient.parseDate(timestamp); + public Instant getTimestamp() { + return GitHubClient.parseInstant(timestamp); } /** diff --git a/src/main/java/org/kohsuke/github/GHCommit.java b/src/main/java/org/kohsuke/github/GHCommit.java index 83ea3be00b..3b6838a538 100644 --- a/src/main/java/org/kohsuke/github/GHCommit.java +++ b/src/main/java/org/kohsuke/github/GHCommit.java @@ -4,10 +4,10 @@ import java.io.IOException; import java.net.URL; +import java.time.Instant; import java.util.AbstractList; import java.util.ArrayList; import java.util.Collections; -import java.util.Date; import java.util.List; // TODO: Auto-generated Javadoc @@ -471,7 +471,7 @@ public GHUser getAuthor() throws IOException { * @throws IOException * if the information was not already fetched and an attempt at fetching the information failed. */ - public Date getAuthoredDate() throws IOException { + public Instant getAuthoredDate() throws IOException { return getCommitShortInfo().getAuthoredDate(); } @@ -494,7 +494,7 @@ public GHUser getCommitter() throws IOException { * @throws IOException * if the information was not already fetched and an attempt at fetching the information failed. */ - public Date getCommitDate() throws IOException { + public Instant getCommitDate() throws IOException { return getCommitShortInfo().getCommitDate(); } diff --git a/src/main/java/org/kohsuke/github/GHCommitBuilder.java b/src/main/java/org/kohsuke/github/GHCommitBuilder.java index 11c382312b..3c509fa581 100644 --- a/src/main/java/org/kohsuke/github/GHCommitBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCommitBuilder.java @@ -1,12 +1,9 @@ package org.kohsuke.github; import java.io.IOException; -import java.text.DateFormat; -import java.text.SimpleDateFormat; +import java.time.Instant; import java.util.ArrayList; -import java.util.Date; import java.util.List; -import java.util.TimeZone; // TODO: Auto-generated Javadoc /** @@ -23,13 +20,10 @@ private static final class UserInfo { private final String email; private final String date; - private UserInfo(String name, String email, Date date) { + private UserInfo(String name, String email, Instant date) { this.name = name; this.email = email; - TimeZone tz = TimeZone.getTimeZone("UTC"); - DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); - df.setTimeZone(tz); - this.date = df.format((date != null) ? date : new Date()); + this.date = GitHubClient.printInstant(date); } } @@ -91,7 +85,7 @@ public GHCommitBuilder parent(String parent) { * the date * @return the gh commit builder */ - public GHCommitBuilder author(String name, String email, Date date) { + public GHCommitBuilder author(String name, String email, Instant date) { req.with("author", new UserInfo(name, email, date)); return this; } @@ -120,7 +114,7 @@ public GHCommitBuilder withSignature(String signature) { * the date * @return the gh commit builder */ - public GHCommitBuilder committer(String name, String email, Date date) { + public GHCommitBuilder committer(String name, String email, Instant date) { req.with("committer", new UserInfo(name, email, date)); return this; } diff --git a/src/main/java/org/kohsuke/github/GHCommitQueryBuilder.java b/src/main/java/org/kohsuke/github/GHCommitQueryBuilder.java index e9b8f0cca8..2e6d826b1c 100644 --- a/src/main/java/org/kohsuke/github/GHCommitQueryBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCommitQueryBuilder.java @@ -1,6 +1,6 @@ package org.kohsuke.github; -import java.util.Date; +import java.time.Instant; // TODO: Auto-generated Javadoc /** @@ -89,8 +89,8 @@ public GHCommitQueryBuilder pageSize(int pageSize) { * the dt * @return the gh commit query builder */ - public GHCommitQueryBuilder since(Date dt) { - req.with("since", GitHubClient.printDate(dt)); + public GHCommitQueryBuilder since(Instant dt) { + req.with("since", GitHubClient.printInstant(dt)); return this; } @@ -102,7 +102,7 @@ public GHCommitQueryBuilder since(Date dt) { * @return the gh commit query builder */ public GHCommitQueryBuilder since(long timestamp) { - return since(new Date(timestamp)); + return since(Instant.ofEpochMilli(timestamp)); } /** @@ -112,8 +112,8 @@ public GHCommitQueryBuilder since(long timestamp) { * the dt * @return the gh commit query builder */ - public GHCommitQueryBuilder until(Date dt) { - req.with("until", GitHubClient.printDate(dt)); + public GHCommitQueryBuilder until(Instant dt) { + req.with("until", GitHubClient.printInstant(dt)); return this; } @@ -125,7 +125,7 @@ public GHCommitQueryBuilder until(Date dt) { * @return the gh commit query builder */ public GHCommitQueryBuilder until(long timestamp) { - return until(new Date(timestamp)); + return until(Instant.ofEpochMilli(timestamp)); } /** diff --git a/src/main/java/org/kohsuke/github/GHDeployKey.java b/src/main/java/org/kohsuke/github/GHDeployKey.java index 50a7743688..c4c5048e8c 100644 --- a/src/main/java/org/kohsuke/github/GHDeployKey.java +++ b/src/main/java/org/kohsuke/github/GHDeployKey.java @@ -3,7 +3,7 @@ import org.apache.commons.lang3.builder.ToStringBuilder; import java.io.IOException; -import java.util.Date; +import java.time.Instant; // TODO: Auto-generated Javadoc /** @@ -89,8 +89,8 @@ public boolean isVerified() { * * @return the created_at */ - public Date getCreatedAt() { - return GitHubClient.parseDate(created_at); + public Instant getCreatedAt() { + return GitHubClient.parseInstant(created_at); } /** @@ -98,8 +98,8 @@ public Date getCreatedAt() { * * @return the last_used */ - public Date getLastUsedAt() { - return GitHubClient.parseDate(last_used); + public Instant getLastUsedAt() { + return GitHubClient.parseInstant(last_used); } /** diff --git a/src/main/java/org/kohsuke/github/GHEventInfo.java b/src/main/java/org/kohsuke/github/GHEventInfo.java index 050b141f31..3637189d5f 100644 --- a/src/main/java/org/kohsuke/github/GHEventInfo.java +++ b/src/main/java/org/kohsuke/github/GHEventInfo.java @@ -4,6 +4,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.IOException; +import java.time.Instant; import java.util.*; // TODO: Auto-generated Javadoc @@ -128,8 +129,8 @@ public long getId() { * * @return the created at */ - public Date getCreatedAt() { - return GitHubClient.parseDate(created_at); + public Instant getCreatedAt() { + return GitHubClient.parseInstant(created_at); } /** diff --git a/src/main/java/org/kohsuke/github/GHEventPayload.java b/src/main/java/org/kohsuke/github/GHEventPayload.java index 845b95bcaa..c091f30f5b 100644 --- a/src/main/java/org/kohsuke/github/GHEventPayload.java +++ b/src/main/java/org/kohsuke/github/GHEventPayload.java @@ -6,9 +6,9 @@ import java.io.IOException; import java.io.Reader; +import java.time.Instant; import java.util.ArrayList; import java.util.Collections; -import java.util.Date; import java.util.List; import java.util.Map; @@ -1363,8 +1363,8 @@ public List getModified() { * * @return the timestamp */ - public Date getTimestamp() { - return GitHubClient.parseDate(timestamp); + public Instant getTimestamp() { + return GitHubClient.parseInstant(timestamp); } } } @@ -1809,8 +1809,8 @@ public Star() { * * @return the date when the star is added */ - public Date getStarredAt() { - return GitHubClient.parseDate(starredAt); + public Instant getStarredAt() { + return GitHubClient.parseInstant(starredAt); } } diff --git a/src/main/java/org/kohsuke/github/GHExternalGroup.java b/src/main/java/org/kohsuke/github/GHExternalGroup.java index 50518412e1..3a2944988d 100644 --- a/src/main/java/org/kohsuke/github/GHExternalGroup.java +++ b/src/main/java/org/kohsuke/github/GHExternalGroup.java @@ -3,8 +3,8 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.IOException; +import java.time.Instant; import java.util.Collections; -import java.util.Date; import java.util.List; /** @@ -223,8 +223,8 @@ public String getName() { * * @return the date */ - public Date getUpdatedAt() { - return GitHubClient.parseDate(updatedAt); + public Instant getUpdatedAt() { + return GitHubClient.parseInstant(updatedAt); } /** diff --git a/src/main/java/org/kohsuke/github/GHIssue.java b/src/main/java/org/kohsuke/github/GHIssue.java index 4e654c7474..992931125d 100644 --- a/src/main/java/org/kohsuke/github/GHIssue.java +++ b/src/main/java/org/kohsuke/github/GHIssue.java @@ -30,11 +30,11 @@ import java.io.IOException; import java.net.URL; +import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -234,8 +234,8 @@ public Collection getLabels() { * * @return the closed at */ - public Date getClosedAt() { - return GitHubClient.parseDate(closed_at); + public Instant getClosedAt() { + return GitHubClient.parseInstant(closed_at); } /** diff --git a/src/main/java/org/kohsuke/github/GHIssueCommentQueryBuilder.java b/src/main/java/org/kohsuke/github/GHIssueCommentQueryBuilder.java index d39df0d475..221553c433 100644 --- a/src/main/java/org/kohsuke/github/GHIssueCommentQueryBuilder.java +++ b/src/main/java/org/kohsuke/github/GHIssueCommentQueryBuilder.java @@ -1,6 +1,6 @@ package org.kohsuke.github; -import java.util.Date; +import java.time.Instant; // TODO: Auto-generated Javadoc /** @@ -41,8 +41,8 @@ public class GHIssueCommentQueryBuilder { * the date * @return the query builder */ - public GHIssueCommentQueryBuilder since(Date date) { - req.with("since", GitHubClient.printDate(date)); + public GHIssueCommentQueryBuilder since(Instant date) { + req.with("since", GitHubClient.printInstant(date)); return this; } @@ -54,7 +54,7 @@ public GHIssueCommentQueryBuilder since(Date date) { * @return the query builder */ public GHIssueCommentQueryBuilder since(long timestamp) { - return since(new Date(timestamp)); + return since(Instant.ofEpochMilli(timestamp)); } /** diff --git a/src/main/java/org/kohsuke/github/GHIssueEvent.java b/src/main/java/org/kohsuke/github/GHIssueEvent.java index 726a590989..553b3343a8 100644 --- a/src/main/java/org/kohsuke/github/GHIssueEvent.java +++ b/src/main/java/org/kohsuke/github/GHIssueEvent.java @@ -2,7 +2,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import java.util.Date; +import java.time.Instant; // TODO: Auto-generated Javadoc /** @@ -105,8 +105,8 @@ public String getCommitUrl() { * * @return the created at */ - public Date getCreatedAt() { - return GitHubClient.parseDate(created_at); + public Instant getCreatedAt() { + return GitHubClient.parseInstant(created_at); } /** diff --git a/src/main/java/org/kohsuke/github/GHIssueQueryBuilder.java b/src/main/java/org/kohsuke/github/GHIssueQueryBuilder.java index cf43cb6391..af2977e158 100644 --- a/src/main/java/org/kohsuke/github/GHIssueQueryBuilder.java +++ b/src/main/java/org/kohsuke/github/GHIssueQueryBuilder.java @@ -1,7 +1,7 @@ package org.kohsuke.github; +import java.time.Instant; import java.util.ArrayList; -import java.util.Date; import java.util.List; // TODO: Auto-generated Javadoc @@ -79,8 +79,8 @@ public GHIssueQueryBuilder direction(GHDirection direction) { * the date * @return the gh issue query builder */ - public GHIssueQueryBuilder since(Date date) { - req.with("since", GitHubClient.printDate(date)); + public GHIssueQueryBuilder since(Instant date) { + req.with("since", GitHubClient.printInstant(date)); return this; } @@ -92,7 +92,7 @@ public GHIssueQueryBuilder since(Date date) { * @return the gh issue query builder */ public GHIssueQueryBuilder since(long timestamp) { - return since(new Date(timestamp)); + return since(Instant.ofEpochMilli(timestamp)); } /** diff --git a/src/main/java/org/kohsuke/github/GHMarketplacePendingChange.java b/src/main/java/org/kohsuke/github/GHMarketplacePendingChange.java index d91e6e5417..99107a0184 100644 --- a/src/main/java/org/kohsuke/github/GHMarketplacePendingChange.java +++ b/src/main/java/org/kohsuke/github/GHMarketplacePendingChange.java @@ -2,7 +2,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import java.util.Date; +import java.time.Instant; // TODO: Auto-generated Javadoc /** @@ -59,8 +59,8 @@ public GHMarketplacePlan getPlan() { * * @return the effective date */ - public Date getEffectiveDate() { - return GitHubClient.parseDate(effectiveDate); + public Instant getEffectiveDate() { + return GitHubClient.parseInstant(effectiveDate); } } diff --git a/src/main/java/org/kohsuke/github/GHMarketplacePurchase.java b/src/main/java/org/kohsuke/github/GHMarketplacePurchase.java index a0c149e159..8bdb9c5c16 100644 --- a/src/main/java/org/kohsuke/github/GHMarketplacePurchase.java +++ b/src/main/java/org/kohsuke/github/GHMarketplacePurchase.java @@ -2,7 +2,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import java.util.Date; +import java.time.Instant; // TODO: Auto-generated Javadoc /** @@ -42,8 +42,8 @@ public String getBillingCycle() { * * @return the next billing date */ - public Date getNextBillingDate() { - return GitHubClient.parseDate(nextBillingDate); + public Instant getNextBillingDate() { + return GitHubClient.parseInstant(nextBillingDate); } /** @@ -60,8 +60,8 @@ public boolean isOnFreeTrial() { * * @return the free trial ends on */ - public Date getFreeTrialEndsOn() { - return GitHubClient.parseDate(freeTrialEndsOn); + public Instant getFreeTrialEndsOn() { + return GitHubClient.parseInstant(freeTrialEndsOn); } /** @@ -78,8 +78,8 @@ public Long getUnitCount() { * * @return the updated at */ - public Date getUpdatedAt() { - return GitHubClient.parseDate(updatedAt); + public Instant getUpdatedAt() { + return GitHubClient.parseInstant(updatedAt); } /** diff --git a/src/main/java/org/kohsuke/github/GHMarketplaceUserPurchase.java b/src/main/java/org/kohsuke/github/GHMarketplaceUserPurchase.java index fb2b210512..79078fae43 100644 --- a/src/main/java/org/kohsuke/github/GHMarketplaceUserPurchase.java +++ b/src/main/java/org/kohsuke/github/GHMarketplaceUserPurchase.java @@ -2,7 +2,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import java.util.Date; +import java.time.Instant; // TODO: Auto-generated Javadoc /** @@ -44,8 +44,8 @@ public String getBillingCycle() { * * @return the next billing date */ - public Date getNextBillingDate() { - return GitHubClient.parseDate(nextBillingDate); + public Instant getNextBillingDate() { + return GitHubClient.parseInstant(nextBillingDate); } /** @@ -62,8 +62,8 @@ public boolean isOnFreeTrial() { * * @return the free trial ends on */ - public Date getFreeTrialEndsOn() { - return GitHubClient.parseDate(freeTrialEndsOn); + public Instant getFreeTrialEndsOn() { + return GitHubClient.parseInstant(freeTrialEndsOn); } /** @@ -80,8 +80,8 @@ public Long getUnitCount() { * * @return the updated at */ - public Date getUpdatedAt() { - return GitHubClient.parseDate(updatedAt); + public Instant getUpdatedAt() { + return GitHubClient.parseInstant(updatedAt); } /** diff --git a/src/main/java/org/kohsuke/github/GHMilestone.java b/src/main/java/org/kohsuke/github/GHMilestone.java index 3df476bb74..7937ab8f1b 100644 --- a/src/main/java/org/kohsuke/github/GHMilestone.java +++ b/src/main/java/org/kohsuke/github/GHMilestone.java @@ -4,7 +4,7 @@ import java.io.IOException; import java.net.URL; -import java.util.Date; +import java.time.Instant; import java.util.Locale; // TODO: Auto-generated Javadoc @@ -56,10 +56,10 @@ public GHUser getCreator() { * * @return the due on */ - public Date getDueOn() { + public Instant getDueOn() { if (due_on == null) return null; - return GitHubClient.parseDate(due_on); + return GitHubClient.parseInstant(due_on); } /** @@ -67,8 +67,8 @@ public Date getDueOn() { * * @return the closed at */ - public Date getClosedAt() { - return GitHubClient.parseDate(closed_at); + public Instant getClosedAt() { + return GitHubClient.parseInstant(closed_at); } /** @@ -200,8 +200,8 @@ public void setDescription(String description) throws IOException { * @throws IOException * the io exception */ - public void setDueOn(Date dueOn) throws IOException { - edit("due_on", GitHubClient.printDate(dueOn)); + public void setDueOn(Instant dueOn) throws IOException { + edit("due_on", GitHubClient.printInstant(dueOn)); } /** diff --git a/src/main/java/org/kohsuke/github/GHNotificationStream.java b/src/main/java/org/kohsuke/github/GHNotificationStream.java index f769907125..b74062236f 100644 --- a/src/main/java/org/kohsuke/github/GHNotificationStream.java +++ b/src/main/java/org/kohsuke/github/GHNotificationStream.java @@ -1,7 +1,7 @@ package org.kohsuke.github; import java.io.IOException; -import java.util.Date; +import java.time.Instant; import java.util.Iterator; import java.util.NoSuchElementException; @@ -75,7 +75,7 @@ public GHNotificationStream participating(boolean v) { * @return the gh notification stream */ public GHNotificationStream since(long timestamp) { - return since(new Date(timestamp)); + return since(Instant.ofEpochMilli(timestamp)); } /** @@ -85,8 +85,8 @@ public GHNotificationStream since(long timestamp) { * the dt * @return the gh notification stream */ - public GHNotificationStream since(Date dt) { - since = GitHubClient.printDate(dt); + public GHNotificationStream since(Instant dt) { + since = GitHubClient.printInstant(dt); return this; } @@ -168,7 +168,7 @@ GHThread fetch() { // if we have fetched un-returned threads, use them first while (idx >= 0) { GHThread n = threads[idx--]; - long nt = n.getUpdatedAt().getTime(); + long nt = n.getUpdatedAt().toEpochMilli(); if (nt >= lastUpdated) { lastUpdated = nt; return n; @@ -243,7 +243,7 @@ public void markAsRead() throws IOException { public void markAsRead(long timestamp) throws IOException { final Requester req = root().createRequest(); if (timestamp >= 0) - req.with("last_read_at", GitHubClient.printDate(new Date(timestamp))); + req.with("last_read_at", GitHubClient.printInstant(Instant.ofEpochMilli(timestamp))); req.withUrlPath(apiUrl).fetchHttpStatusCode(); } diff --git a/src/main/java/org/kohsuke/github/GHObject.java b/src/main/java/org/kohsuke/github/GHObject.java index 9d9b2f4fe0..4c2aa21522 100644 --- a/src/main/java/org/kohsuke/github/GHObject.java +++ b/src/main/java/org/kohsuke/github/GHObject.java @@ -6,15 +6,14 @@ import org.apache.commons.lang3.builder.ToStringStyle; import org.kohsuke.github.connector.GitHubConnectorResponse; +import javax.annotation.CheckForNull; import java.io.IOException; import java.lang.reflect.Field; import java.net.URL; -import java.util.Date; +import java.time.Instant; import java.util.List; import java.util.Map; -import javax.annotation.CheckForNull; - // TODO: Auto-generated Javadoc /** * Most (all?) domain objects in GitHub seems to have these 4 properties. @@ -78,8 +77,8 @@ public Map> getResponseHeaderFields() { * @throws IOException * on error */ - public Date getCreatedAt() throws IOException { - return GitHubClient.parseDate(createdAt); + public Instant getCreatedAt() throws IOException { + return GitHubClient.parseInstant(createdAt); } /** @@ -98,8 +97,8 @@ public URL getUrl() { * @throws IOException * on error */ - public Date getUpdatedAt() throws IOException { - return GitHubClient.parseDate(updatedAt); + public Instant getUpdatedAt() throws IOException { + return GitHubClient.parseInstant(updatedAt); } /** diff --git a/src/main/java/org/kohsuke/github/GHPerson.java b/src/main/java/org/kohsuke/github/GHPerson.java index 1b87779a6b..e2a65a4696 100644 --- a/src/main/java/org/kohsuke/github/GHPerson.java +++ b/src/main/java/org/kohsuke/github/GHPerson.java @@ -3,8 +3,8 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.net.URL; +import java.time.Instant; import java.util.Collections; -import java.util.Date; import java.util.Map; import java.util.Optional; import java.util.TreeMap; @@ -208,7 +208,7 @@ public String getTwitterUsername() throws IOException { * @throws IOException * Signals that an I/O exception has occurred. */ - public Date getCreatedAt() throws IOException { + public Instant getCreatedAt() throws IOException { populate(); return super.getCreatedAt(); } @@ -220,7 +220,7 @@ public Date getCreatedAt() throws IOException { * @throws IOException * Signals that an I/O exception has occurred. */ - public Date getUpdatedAt() throws IOException { + public Instant getUpdatedAt() throws IOException { populate(); return super.getUpdatedAt(); } diff --git a/src/main/java/org/kohsuke/github/GHProjectsV2Item.java b/src/main/java/org/kohsuke/github/GHProjectsV2Item.java index 30e0424d1c..143dd9f656 100644 --- a/src/main/java/org/kohsuke/github/GHProjectsV2Item.java +++ b/src/main/java/org/kohsuke/github/GHProjectsV2Item.java @@ -3,7 +3,7 @@ import org.kohsuke.github.internal.EnumUtils; import java.net.URL; -import java.util.Date; +import java.time.Instant; // TODO: Auto-generated Javadoc /** @@ -76,8 +76,8 @@ public GHUser getCreator() { * * @return the archived at */ - public Date getArchivedAt() { - return GitHubClient.parseDate(archivedAt); + public Instant getArchivedAt() { + return GitHubClient.parseInstant(archivedAt); } /** diff --git a/src/main/java/org/kohsuke/github/GHProjectsV2ItemChanges.java b/src/main/java/org/kohsuke/github/GHProjectsV2ItemChanges.java index d9636537ef..336642512e 100644 --- a/src/main/java/org/kohsuke/github/GHProjectsV2ItemChanges.java +++ b/src/main/java/org/kohsuke/github/GHProjectsV2ItemChanges.java @@ -3,7 +3,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.kohsuke.github.internal.EnumUtils; -import java.util.Date; +import java.time.Instant; // TODO: Auto-generated Javadoc /** @@ -138,8 +138,8 @@ public FromToDate() { * * @return the from */ - public Date getFrom() { - return GitHubClient.parseDate(from); + public Instant getFrom() { + return GitHubClient.parseInstant(from); } /** @@ -147,8 +147,8 @@ public Date getFrom() { * * @return the to */ - public Date getTo() { - return GitHubClient.parseDate(to); + public Instant getTo() { + return GitHubClient.parseInstant(to); } } diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index ac91ad8c3b..33f5f2cb6f 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -28,10 +28,10 @@ import java.io.IOException; import java.net.URL; +import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.Date; import java.util.List; import java.util.Objects; @@ -170,8 +170,8 @@ public URL getDiffUrl() { * * @return the merged at */ - public Date getMergedAt() { - return GitHubClient.parseDate(merged_at); + public Instant getMergedAt() { + return GitHubClient.parseInstant(merged_at); } /** diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReview.java b/src/main/java/org/kohsuke/github/GHPullRequestReview.java index 6c97354dfd..b6e5b3a738 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReview.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReview.java @@ -25,11 +25,10 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import javax.annotation.CheckForNull; import java.io.IOException; import java.net.URL; -import java.util.Date; - -import javax.annotation.CheckForNull; +import java.time.Instant; // TODO: Auto-generated Javadoc /** @@ -144,8 +143,8 @@ protected String getApiRoute() { * * @return the submitted at */ - public Date getSubmittedAt() { - return GitHubClient.parseDate(submitted_at); + public Instant getSubmittedAt() { + return GitHubClient.parseInstant(submitted_at); } /** @@ -156,7 +155,7 @@ public Date getSubmittedAt() { * Signals that an I/O exception has occurred. */ @Override - public Date getCreatedAt() throws IOException { + public Instant getCreatedAt() throws IOException { return getSubmittedAt(); } diff --git a/src/main/java/org/kohsuke/github/GHRateLimit.java b/src/main/java/org/kohsuke/github/GHRateLimit.java index b7ca406a72..e76f288763 100644 --- a/src/main/java/org/kohsuke/github/GHRateLimit.java +++ b/src/main/java/org/kohsuke/github/GHRateLimit.java @@ -8,10 +8,10 @@ import org.kohsuke.github.connector.GitHubConnectorResponse; import java.time.Duration; +import java.time.Instant; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; -import java.util.Date; import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Logger; @@ -131,7 +131,7 @@ static GHRateLimit fromRecord(@Nonnull Record record, @Nonnull RateLimitTarget r * @return the calculated date at which the rate limit has or will reset. */ @Nonnull - public Date getResetDate() { + public Instant getResetDate() { return getCore().getResetDate(); } @@ -416,7 +416,7 @@ public static class Record { * @see #getResetDate() */ @Nonnull - private final Date resetDate; + private final Instant resetDate; /** * Instantiates a new Record. @@ -535,7 +535,7 @@ && getRemaining() <= other.getRemaining())) { * @return reset date based on the passed date */ @Nonnull - private Date calculateResetDate(@CheckForNull String updatedAt) { + private Instant calculateResetDate(@CheckForNull String updatedAt) { long updatedAtEpochSeconds = createdAtEpochSeconds; if (!StringUtils.isBlank(updatedAt)) { try { @@ -552,7 +552,7 @@ private Date calculateResetDate(@CheckForNull String updatedAt) { // This may seem odd but it results in an accurate or slightly pessimistic reset date // based on system time rather than assuming the system time synchronized with the server long calculatedSecondsUntilReset = resetEpochSeconds - updatedAtEpochSeconds; - return new Date((createdAtEpochSeconds + calculatedSecondsUntilReset) * 1000); + return Instant.ofEpochMilli((createdAtEpochSeconds + calculatedSecondsUntilReset) * 1000); } /** @@ -595,7 +595,7 @@ public long getResetEpochSeconds() { * @return true if the rate limit reset date has passed. Otherwise false. */ public boolean isExpired() { - return getResetDate().getTime() < System.currentTimeMillis(); + return getResetDate().toEpochMilli() < System.currentTimeMillis(); } /** @@ -607,8 +607,8 @@ public boolean isExpired() { * @return the calculated date at which the rate limit has or will reset. */ @Nonnull - public Date getResetDate() { - return new Date(resetDate.getTime()); + public Instant getResetDate() { + return resetDate; } /** diff --git a/src/main/java/org/kohsuke/github/GHRelease.java b/src/main/java/org/kohsuke/github/GHRelease.java index 1c6c82851d..409ea90558 100644 --- a/src/main/java/org/kohsuke/github/GHRelease.java +++ b/src/main/java/org/kohsuke/github/GHRelease.java @@ -8,11 +8,11 @@ import java.io.InputStream; import java.net.URL; import java.net.URLEncoder; +import java.time.Instant; import java.util.Collections; -import java.util.Date; import java.util.List; -import static java.lang.String.*; +import static java.lang.String.format; // TODO: Auto-generated Javadoc /** @@ -42,7 +42,7 @@ public GHRelease() { private String body; private boolean draft; private boolean prerelease; - private Date published_at; + private Instant published_at; private String tarball_url; private String zipball_url; private String discussion_url; @@ -135,8 +135,8 @@ public boolean isPrerelease() { * * @return the published at */ - public Date getPublished_at() { - return new Date(published_at.getTime()); + public Instant getPublished_at() { + return published_at; } /** diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 65487caba9..5613f33fec 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -37,10 +37,10 @@ import java.io.InputStreamReader; import java.io.Reader; import java.net.URL; +import java.time.Instant; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; @@ -815,8 +815,8 @@ public int getSubscribersCount() { * * @return null if the repository was never pushed at. */ - public Date getPushedAt() { - return GitHubClient.parseDate(pushed_at); + public Instant getPushedAt() { + return GitHubClient.parseInstant(pushed_at); } /** diff --git a/src/main/java/org/kohsuke/github/GHRepositoryDiscussion.java b/src/main/java/org/kohsuke/github/GHRepositoryDiscussion.java index a04f234497..fb182d59e6 100644 --- a/src/main/java/org/kohsuke/github/GHRepositoryDiscussion.java +++ b/src/main/java/org/kohsuke/github/GHRepositoryDiscussion.java @@ -3,7 +3,7 @@ import org.kohsuke.github.internal.EnumUtils; import java.net.URL; -import java.util.Date; +import java.time.Instant; // TODO: Auto-generated Javadoc /** @@ -69,8 +69,8 @@ public URL getAnswerHtmlUrl() { * * @return the answer chosen at */ - public Date getAnswerChosenAt() { - return GitHubClient.parseDate(answerChosenAt); + public Instant getAnswerChosenAt() { + return GitHubClient.parseInstant(answerChosenAt); } /** @@ -269,8 +269,8 @@ public String getDescription() { * * @return the created at */ - public Date getCreatedAt() { - return GitHubClient.parseDate(createdAt); + public Instant getCreatedAt() { + return GitHubClient.parseInstant(createdAt); } /** @@ -278,8 +278,8 @@ public Date getCreatedAt() { * * @return the updated at */ - public Date getUpdatedAt() { - return GitHubClient.parseDate(updatedAt); + public Instant getUpdatedAt() { + return GitHubClient.parseInstant(updatedAt); } /** diff --git a/src/main/java/org/kohsuke/github/GHRepositoryTraffic.java b/src/main/java/org/kohsuke/github/GHRepositoryTraffic.java index 49738fceff..035e71735c 100644 --- a/src/main/java/org/kohsuke/github/GHRepositoryTraffic.java +++ b/src/main/java/org/kohsuke/github/GHRepositoryTraffic.java @@ -1,6 +1,6 @@ package org.kohsuke.github; -import java.util.Date; +import java.time.Instant; import java.util.List; // TODO: Auto-generated Javadoc @@ -68,8 +68,8 @@ public static abstract class DailyInfo implements TrafficInfo { * * @return the timestamp */ - public Date getTimestamp() { - return GitHubClient.parseDate(timestamp); + public Instant getTimestamp() { + return GitHubClient.parseInstant(timestamp); } /** diff --git a/src/main/java/org/kohsuke/github/GHStargazer.java b/src/main/java/org/kohsuke/github/GHStargazer.java index 1b9862295a..753b6ea2a2 100644 --- a/src/main/java/org/kohsuke/github/GHStargazer.java +++ b/src/main/java/org/kohsuke/github/GHStargazer.java @@ -2,7 +2,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import java.util.Date; +import java.time.Instant; // TODO: Auto-generated Javadoc /** @@ -39,8 +39,8 @@ public GHRepository getRepository() { * * @return the date the stargazer was added */ - public Date getStarredAt() { - return GitHubClient.parseDate(starred_at); + public Instant getStarredAt() { + return GitHubClient.parseInstant(starred_at); } /** diff --git a/src/main/java/org/kohsuke/github/GHSubscription.java b/src/main/java/org/kohsuke/github/GHSubscription.java index 1066d51b7b..f787036b99 100644 --- a/src/main/java/org/kohsuke/github/GHSubscription.java +++ b/src/main/java/org/kohsuke/github/GHSubscription.java @@ -3,7 +3,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.IOException; -import java.util.Date; +import java.time.Instant; // TODO: Auto-generated Javadoc /** @@ -31,8 +31,8 @@ public GHSubscription() { * * @return the created at */ - public Date getCreatedAt() { - return GitHubClient.parseDate(created_at); + public Instant getCreatedAt() { + return GitHubClient.parseInstant(created_at); } /** diff --git a/src/main/java/org/kohsuke/github/GHThread.java b/src/main/java/org/kohsuke/github/GHThread.java index 2bafc28307..dbdd4244b1 100644 --- a/src/main/java/org/kohsuke/github/GHThread.java +++ b/src/main/java/org/kohsuke/github/GHThread.java @@ -4,7 +4,7 @@ import java.io.FileNotFoundException; import java.io.IOException; -import java.util.Date; +import java.time.Instant; // TODO: Auto-generated Javadoc /** @@ -50,8 +50,8 @@ private GHThread() {// no external construction allowed * * @return the last read at */ - public Date getLastReadAt() { - return GitHubClient.parseDate(last_read_at); + public Instant getLastReadAt() { + return GitHubClient.parseInstant(last_read_at); } /** diff --git a/src/main/java/org/kohsuke/github/GHUser.java b/src/main/java/org/kohsuke/github/GHUser.java index b53da29180..8851f69270 100644 --- a/src/main/java/org/kohsuke/github/GHUser.java +++ b/src/main/java/org/kohsuke/github/GHUser.java @@ -24,6 +24,7 @@ package org.kohsuke.github; import java.io.IOException; +import java.time.Instant; import java.util.*; // TODO: Auto-generated Javadoc @@ -273,9 +274,9 @@ public Optional getLdapDn() throws IOException { * @throws IOException * on error */ - public Date getSuspendedAt() throws IOException { + public Instant getSuspendedAt() throws IOException { super.populate(); - return GitHubClient.parseDate(suspendedAt); + return GitHubClient.parseInstant(suspendedAt); } /** diff --git a/src/main/java/org/kohsuke/github/GHWorkflowJob.java b/src/main/java/org/kohsuke/github/GHWorkflowJob.java index 76a2fddaef..8aa912dcf1 100644 --- a/src/main/java/org/kohsuke/github/GHWorkflowJob.java +++ b/src/main/java/org/kohsuke/github/GHWorkflowJob.java @@ -9,9 +9,9 @@ import java.io.IOException; import java.net.URL; +import java.time.Instant; import java.util.ArrayList; import java.util.Collections; -import java.util.Date; import java.util.List; import java.util.Objects; @@ -83,8 +83,8 @@ public String getHeadSha() { * * @return start date */ - public Date getStartedAt() { - return GitHubClient.parseDate(startedAt); + public Instant getStartedAt() { + return GitHubClient.parseInstant(startedAt); } /** @@ -92,8 +92,8 @@ public Date getStartedAt() { * * @return completion date */ - public Date getCompletedAt() { - return GitHubClient.parseDate(completedAt); + public Instant getCompletedAt() { + return GitHubClient.parseInstant(completedAt); } /** @@ -302,8 +302,8 @@ public int getNumber() { * * @return start date */ - public Date getStartedAt() { - return GitHubClient.parseDate(startedAt); + public Instant getStartedAt() { + return GitHubClient.parseInstant(startedAt); } /** @@ -311,8 +311,8 @@ public Date getStartedAt() { * * @return completion date */ - public Date getCompletedAt() { - return GitHubClient.parseDate(completedAt); + public Instant getCompletedAt() { + return GitHubClient.parseInstant(completedAt); } /** diff --git a/src/main/java/org/kohsuke/github/GHWorkflowRun.java b/src/main/java/org/kohsuke/github/GHWorkflowRun.java index 04a431abbd..d62a3377b9 100644 --- a/src/main/java/org/kohsuke/github/GHWorkflowRun.java +++ b/src/main/java/org/kohsuke/github/GHWorkflowRun.java @@ -8,9 +8,9 @@ import java.io.IOException; import java.net.URL; +import java.time.Instant; import java.util.Arrays; import java.util.Collections; -import java.util.Date; import java.util.List; import java.util.Locale; import java.util.Objects; @@ -114,8 +114,8 @@ public long getRunAttempt() { * * @return run triggered */ - public Date getRunStartedAt() { - return GitHubClient.parseDate(runStartedAt); + public Instant getRunStartedAt() { + return GitHubClient.parseInstant(runStartedAt); } /** @@ -487,8 +487,8 @@ public String getMessage() { * * @return timestamp of the commit */ - public Date getTimestamp() { - return GitHubClient.parseDate(timestamp); + public Instant getTimestamp() { + return GitHubClient.parseInstant(timestamp); } /** diff --git a/src/main/java/org/kohsuke/github/GitCommit.java b/src/main/java/org/kohsuke/github/GitCommit.java index 4478edf7cc..f8b7849883 100644 --- a/src/main/java/org/kohsuke/github/GitCommit.java +++ b/src/main/java/org/kohsuke/github/GitCommit.java @@ -2,9 +2,9 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import java.time.Instant; import java.util.AbstractList; import java.util.Collections; -import java.util.Date; import java.util.List; // TODO: Auto-generated Javadoc @@ -159,7 +159,7 @@ public GitUser getAuthor() { * * @return the authored date */ - public Date getAuthoredDate() { + public Instant getAuthoredDate() { return author.getDate(); } @@ -177,7 +177,7 @@ public GitUser getCommitter() { * * @return the commit date */ - public Date getCommitDate() { + public Instant getCommitDate() { return committer.getDate(); } diff --git a/src/main/java/org/kohsuke/github/GitHubClient.java b/src/main/java/org/kohsuke/github/GitHubClient.java index 176e6cb980..750546992f 100644 --- a/src/main/java/org/kohsuke/github/GitHubClient.java +++ b/src/main/java/org/kohsuke/github/GitHubClient.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.introspect.VisibilityChecker; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import org.apache.commons.io.IOUtils; import org.kohsuke.github.authorization.AuthorizationProvider; import org.kohsuke.github.authorization.UserAuthorizationProvider; @@ -90,6 +91,7 @@ class GitHubClient { .ofPattern("yyyy/MM/dd HH:mm:ss Z"); static { + MAPPER.registerModule(new JavaTimeModule()); MAPPER.setVisibility(new VisibilityChecker.Std(NONE, NONE, NONE, NONE, ANY)); MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); MAPPER.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS, true); @@ -873,20 +875,6 @@ static URL parseURL(String s) { } } - /** - * Parses the date. - * - * @param timestamp - * the timestamp - * @return the date - */ - static Date parseDate(String timestamp) { - if (timestamp == null) - return null; - - return Date.from(parseInstant(timestamp)); - } - /** * Parses the instant. * @@ -907,14 +895,14 @@ static Instant parseInstant(String timestamp) { } /** - * Prints the date. + * Prints the instant. * - * @param dt - * the dt + * @param instant + * the instant * @return the string */ - static String printDate(Date dt) { - return DateTimeFormatter.ISO_INSTANT.format(Instant.ofEpochMilli(dt.getTime()).truncatedTo(ChronoUnit.SECONDS)); + static String printInstant(Instant instant) { + return DateTimeFormatter.ISO_INSTANT.format(instant.truncatedTo(ChronoUnit.SECONDS)); } /** diff --git a/src/main/java/org/kohsuke/github/GitUser.java b/src/main/java/org/kohsuke/github/GitUser.java index d906bc519a..9556cbe6d7 100644 --- a/src/main/java/org/kohsuke/github/GitUser.java +++ b/src/main/java/org/kohsuke/github/GitUser.java @@ -2,7 +2,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import java.util.Date; +import java.time.Instant; import javax.annotation.CheckForNull; @@ -53,8 +53,8 @@ public String getUsername() { * * @return Commit Date. */ - public Date getDate() { - return GitHubClient.parseDate(date); + public Instant getDate() { + return GitHubClient.parseInstant(date); } /** diff --git a/src/main/java/org/kohsuke/github/RateLimitChecker.java b/src/main/java/org/kohsuke/github/RateLimitChecker.java index 5b848cd17e..ebf0e1b857 100644 --- a/src/main/java/org/kohsuke/github/RateLimitChecker.java +++ b/src/main/java/org/kohsuke/github/RateLimitChecker.java @@ -79,7 +79,7 @@ protected boolean checkRateLimit(GHRateLimit.Record rateLimitRecord, long count) */ protected final boolean sleepUntilReset(GHRateLimit.Record record) throws InterruptedException { // Sleep until reset - long sleepMilliseconds = record.getResetDate().getTime() - System.currentTimeMillis(); + long sleepMilliseconds = record.getResetDate().toEpochMilli() - System.currentTimeMillis(); if (sleepMilliseconds > 0) { String message = String.format( "GitHub API - Current quota has %d remaining of %d. Waiting for quota to reset at %tT.", diff --git a/src/main/java/org/kohsuke/github/authorization/AppInstallationAuthorizationProvider.java b/src/main/java/org/kohsuke/github/authorization/AppInstallationAuthorizationProvider.java index 7ad33ede46..9d8a724cf2 100644 --- a/src/main/java/org/kohsuke/github/authorization/AppInstallationAuthorizationProvider.java +++ b/src/main/java/org/kohsuke/github/authorization/AppInstallationAuthorizationProvider.java @@ -7,8 +7,8 @@ import org.kohsuke.github.GitHub; import java.io.IOException; -import java.time.Duration; import java.time.Instant; +import java.time.temporal.ChronoUnit; import java.util.Objects; import javax.annotation.Nonnull; @@ -57,7 +57,7 @@ private String refreshToken() throws IOException { GitHub gitHub = this.gitHub(); GHAppInstallation installationByOrganization = appInstallationProvider.getAppInstallation(gitHub.getApp()); GHAppInstallationToken ghAppInstallationToken = installationByOrganization.createToken().create(); - this.validUntil = ghAppInstallationToken.getExpiresAt().toInstant().minus(Duration.ofMinutes(5)); + this.validUntil = ghAppInstallationToken.getExpiresAt().minus(5, ChronoUnit.MINUTES); return Objects.requireNonNull(ghAppInstallationToken.getToken()); } diff --git a/src/main/java/org/kohsuke/github/extras/authorization/JwtBuilderUtil.java b/src/main/java/org/kohsuke/github/extras/authorization/JwtBuilderUtil.java index 81aa4b1272..4f01efdc82 100644 --- a/src/main/java/org/kohsuke/github/extras/authorization/JwtBuilderUtil.java +++ b/src/main/java/org/kohsuke/github/extras/authorization/JwtBuilderUtil.java @@ -123,6 +123,8 @@ public String buildJwt(Instant issuedAt, Instant expiration, String applicationI SignatureAlgorithm rs256 = Jwts.SIG.RS256; JwtBuilder jwtBuilder = Jwts.builder(); + // jjwt uses the legacy java date-time api + // see https://github.com/jwtk/jjwt/issues/235 for future support for java 8 date-time api jwtBuilder = jwtBuilder.issuedAt(Date.from(issuedAt)) .expiration(Date.from(expiration)) .issuer(applicationId) @@ -148,8 +150,12 @@ private static final class ReflectionBuilderImpl implements IJwtBuilder { JwtBuilder jwtBuilder = Jwts.builder(); Class jwtReflectionClass = jwtBuilder.getClass(); + // jjwt uses the legacy java date-time api + // see https://github.com/jwtk/jjwt/issues/235 for future support for java 8 date-time api + // noinspection UseOfObsoleteDateTimeApi setIssuedAtMethod = jwtReflectionClass.getMethod("setIssuedAt", Date.class); setIssuerMethod = jwtReflectionClass.getMethod("setIssuer", String.class); + // noinspection UseOfObsoleteDateTimeApi setExpirationMethod = jwtReflectionClass.getMethod("setExpiration", Date.class); Class signatureAlgorithmClass = Class.forName("io.jsonwebtoken.SignatureAlgorithm"); rs256SignatureAlgorithm = createEnumInstance(signatureAlgorithmClass, "RS256"); @@ -186,6 +192,8 @@ private String buildJwtWithReflection(Instant issuedAt, PrivateKey privateKey) throws IllegalAccessException, InvocationTargetException { JwtBuilder jwtBuilder = Jwts.builder(); Object builderObj = jwtBuilder; + // jjwt uses the legacy java date-time api + // see https://github.com/jwtk/jjwt/issues/235 for future support for java 8 date-time api builderObj = setIssuedAtMethod.invoke(builderObj, Date.from(issuedAt)); builderObj = setExpirationMethod.invoke(builderObj, Date.from(expiration)); builderObj = setIssuerMethod.invoke(builderObj, applicationId); diff --git a/src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java b/src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java index 7d85d343eb..f963611862 100644 --- a/src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java +++ b/src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java @@ -395,6 +395,7 @@ public static void assertThat(String reason, boolean assertion) { protected static class TemplatingHelper { /** The test start date. */ + @SuppressWarnings("UseOfObsoleteDateTimeApi") public Date testStartDate = new Date(); /** @@ -409,11 +410,12 @@ public TemplatingHelper() { * @return the response template transformer */ public ResponseTemplateTransformer newResponseTransformer() { + //noinspection UnqualifiedFieldAccess testStartDate = new Date(); return ResponseTemplateTransformer.builder() .global(true) .maxCacheEntries(0L) - .helper("testStartDate", new Helper() { + .helper("testStartDate", new Helper<>() { private HandlebarsCurrentDateHelper helper = new HandlebarsCurrentDateHelper(); @Override public Object apply(final Object context, final Options options) throws IOException { diff --git a/src/test/java/org/kohsuke/github/AppTest.java b/src/test/java/org/kohsuke/github/AppTest.java index ec2938ae02..4e6f9da5d5 100755 --- a/src/test/java/org/kohsuke/github/AppTest.java +++ b/src/test/java/org/kohsuke/github/AppTest.java @@ -798,8 +798,8 @@ public void testCommit() throws Exception { assertThat(commit.getLinesChanged(), equalTo(48)); assertThat(commit.getLinesDeleted(), equalTo(8)); assertThat(commit.getParentSHA1s().size(), equalTo(1)); - assertThat(commit.getAuthoredDate(), equalTo(GitHubClient.parseDate("2012-04-24T00:16:52Z"))); - assertThat(commit.getCommitDate(), equalTo(GitHubClient.parseDate("2012-04-24T00:16:52Z"))); + assertThat(commit.getAuthoredDate(), equalTo(GitHubClient.parseInstant("2012-04-24T00:16:52Z"))); + assertThat(commit.getCommitDate(), equalTo(GitHubClient.parseInstant("2012-04-24T00:16:52Z"))); assertThat(commit.getCommitShortInfo().getCommentCount(), equalTo(0)); assertThat(commit.getCommitShortInfo().getAuthoredDate(), equalTo(commit.getAuthoredDate())); assertThat(commit.getCommitShortInfo().getCommitDate(), equalTo(commit.getCommitDate())); @@ -1009,7 +1009,7 @@ public void testEventApi() throws Exception { assertThat(ev.getActorLogin(), equalTo("pull[bot]")); assertThat(ev.getOrganization(), nullValue()); assertThat(ev.getRepository().getFullName(), equalTo("daddyfatstacksBIG/lerna")); - assertThat(ev.getCreatedAt(), equalTo(GitHubClient.parseDate("2019-10-21T21:54:52Z"))); + assertThat(ev.getCreatedAt(), equalTo(GitHubClient.parseInstant("2019-10-21T21:54:52Z"))); assertThat(ev.getType(), equalTo(GHEvent.PULL_REQUEST)); } @@ -1033,7 +1033,7 @@ public void testUserPublicEventApi() throws Exception { assertThat(ev.getActorLogin(), equalTo("PierreBtz")); assertThat(ev.getOrganization().getLogin(), equalTo("hub4j")); assertThat(ev.getRepository().getFullName(), equalTo("hub4j/github-api")); - assertThat(ev.getCreatedAt(), equalTo(GitHubClient.parseDate("2023-03-02T16:37:49Z"))); + assertThat(ev.getCreatedAt(), equalTo(GitHubClient.parseInstant("2023-03-02T16:37:49Z"))); assertThat(ev.getType(), equalTo(GHEvent.PULL_REQUEST)); } @@ -1212,9 +1212,9 @@ public void testCommitShortInfo() throws Exception { assertThat("doc", equalTo(commit.getCommitShortInfo().getMessage())); assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false)); assertThat(GHVerification.Reason.UNSIGNED, equalTo(commit.getCommitShortInfo().getVerification().getReason())); - assertThat(commit.getCommitShortInfo().getAuthor().getDate().toInstant().getEpochSecond(), + assertThat(commit.getCommitShortInfo().getAuthor().getDate().getEpochSecond(), equalTo(1271650361L)); - assertThat(commit.getCommitShortInfo().getCommitter().getDate().toInstant().getEpochSecond(), + assertThat(commit.getCommitShortInfo().getCommitter().getDate().getEpochSecond(), equalTo(1271650361L)); } diff --git a/src/test/java/org/kohsuke/github/CommitTest.java b/src/test/java/org/kohsuke/github/CommitTest.java index 746fec1e38..038e7e8be9 100644 --- a/src/test/java/org/kohsuke/github/CommitTest.java +++ b/src/test/java/org/kohsuke/github/CommitTest.java @@ -4,9 +4,9 @@ import org.junit.Test; import java.io.IOException; +import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; -import java.util.Date; import java.util.List; import static org.hamcrest.Matchers.*; @@ -123,8 +123,8 @@ public void testQueryCommits() throws Exception { commits = gitHub.getUser("jenkinsci") .getRepository("jenkins") .queryCommits() - .since(new Date(1199174400000L)) - .until(new Date(1201852800000L)) + .since(Instant.ofEpochMilli(1199174400000L)) + .until(Instant.ofEpochMilli(1201852800000L)) .path("pom.xml") .pageSize(100) .list() @@ -137,8 +137,8 @@ public void testQueryCommits() throws Exception { commits = gitHub.getUser("jenkinsci") .getRepository("jenkins") .queryCommits() - .since(new Date(1199174400000L)) - .until(new Date(1201852800000L)) + .since(Instant.ofEpochMilli(1199174400000L)) + .until(Instant.ofEpochMilli(1201852800000L)) .path("pom.xml") .from("a5259970acaec9813e2a12a91f37dfc7871a5ef5") .list() @@ -150,7 +150,7 @@ public void testQueryCommits() throws Exception { commits = gitHub.getUser("jenkinsci") .getRepository("jenkins") .queryCommits() - .until(new Date(1201852800000L)) + .until(Instant.ofEpochMilli(1201852800000L)) .path("pom.xml") .author("kohsuke") .list() @@ -161,7 +161,7 @@ public void testQueryCommits() throws Exception { commits = gitHub.getUser("jenkinsci") .getRepository("jenkins") .queryCommits() - .until(new Date(1201852800000L)) + .until(Instant.ofEpochMilli(1201852800000L)) .path("pom.xml") .pageSize(100) .author("kohsuke@71c3de6d-444a-0410-be80-ed276b4c234a") @@ -330,10 +330,10 @@ public void commitDateNotNull() throws Exception { GHRepository repo = gitHub.getRepository("hub4j/github-api"); GHCommit commit = repo.getCommit("865a49d2e86c24c5777985f0f103e975c4b765b9"); - assertThat(commit.getCommitShortInfo().getAuthoredDate().toInstant().getEpochSecond(), equalTo(1609207093L)); + assertThat(commit.getCommitShortInfo().getAuthoredDate().getEpochSecond(), equalTo(1609207093L)); assertThat(commit.getCommitShortInfo().getAuthoredDate(), equalTo(commit.getCommitShortInfo().getAuthor().getDate())); - assertThat(commit.getCommitShortInfo().getCommitDate().toInstant().getEpochSecond(), equalTo(1609207652L)); + assertThat(commit.getCommitShortInfo().getCommitDate().getEpochSecond(), equalTo(1609207652L)); assertThat(commit.getCommitShortInfo().getCommitDate(), equalTo(commit.getCommitShortInfo().getCommitter().getDate())); } diff --git a/src/test/java/org/kohsuke/github/GHAppInstallationTest.java b/src/test/java/org/kohsuke/github/GHAppInstallationTest.java index 46c51b7b64..443dc275a5 100644 --- a/src/test/java/org/kohsuke/github/GHAppInstallationTest.java +++ b/src/test/java/org/kohsuke/github/GHAppInstallationTest.java @@ -3,10 +3,10 @@ import org.junit.Test; import java.io.IOException; +import java.time.Instant; import java.time.LocalDateTime; import java.time.Month; import java.time.ZoneOffset; -import java.util.Date; import java.util.List; import static org.hamcrest.Matchers.*; @@ -85,9 +85,8 @@ public void testListSuspendedInstallation() throws IOException { final GHUser suspendedBy = appInstallation.getSuspendedBy(); assertThat(suspendedBy.getLogin(), equalTo("gilday")); - final Date suspendedAt = appInstallation.getSuspendedAt(); - final Date expectedSuspendedAt = Date - .from(LocalDateTime.of(2024, Month.FEBRUARY, 26, 2, 43, 12).toInstant(ZoneOffset.UTC)); + final Instant suspendedAt = appInstallation.getSuspendedAt(); + final Instant expectedSuspendedAt = LocalDateTime.of(2024, Month.FEBRUARY, 26, 2, 43, 12).toInstant(ZoneOffset.UTC); assertThat(suspendedAt, equalTo(expectedSuspendedAt)); } diff --git a/src/test/java/org/kohsuke/github/GHAppTest.java b/src/test/java/org/kohsuke/github/GHAppTest.java index b0369c4b99..939e8dddea 100644 --- a/src/test/java/org/kohsuke/github/GHAppTest.java +++ b/src/test/java/org/kohsuke/github/GHAppTest.java @@ -3,15 +3,15 @@ import org.junit.Test; import java.io.IOException; -import java.text.ParseException; -import java.text.SimpleDateFormat; +import java.time.Instant; +import java.time.LocalDate; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.Collections; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.TimeZone; import static org.hamcrest.Matchers.*; @@ -63,8 +63,8 @@ public void getGitHubApp() throws IOException { assertThat(app.getDescription(), is("")); assertThat(app.getExternalUrl(), is("http://localhost")); assertThat(app.getHtmlUrl().toString(), is("https://github.com/apps/ghapi-test-app-1")); - assertThat(app.getCreatedAt(), is(GitHubClient.parseDate("2020-09-30T13:40:56Z"))); - assertThat(app.getUpdatedAt(), is(GitHubClient.parseDate("2020-09-30T13:40:56Z"))); + assertThat(app.getCreatedAt(), is(GitHubClient.parseInstant("2020-09-30T13:40:56Z"))); + assertThat(app.getUpdatedAt(), is(GitHubClient.parseInstant("2020-09-30T13:40:56Z"))); assertThat(app.getPermissions().size(), is(2)); assertThat(app.getEvents().size(), is(0)); assertThat(app.getInstallationsCount(), is((long) 1)); @@ -90,7 +90,7 @@ public void listInstallationRequests() throws IOException { assertThat(appInstallation.getRequester().getId(), is((long) 195437694)); assertThat(appInstallation.getRequester().getLogin(), is("kaladinstormblessed2")); assertThat(appInstallation.getRequester().getType(), is("User")); - assertThat(appInstallation.getCreatedAt(), is(GitHubClient.parseDate("2025-01-17T15:50:51Z"))); + assertThat(appInstallation.getCreatedAt(), is(GitHubClient.parseInstant("2025-01-17T15:50:51Z"))); assertThat(appInstallation.getNodeId(), is("MDMwOkludGVncmF0aW9uSW5zdGFsbGF0aW9uUmVxdWVzdDEwMzcyMDQ=")); } @@ -116,14 +116,10 @@ public void listInstallations() throws IOException { * @throws IOException * Signals that an I/O exception has occurred. * - * @throws ParseException - * Issue parsing date string. */ @Test - public void listInstallationsSince() throws IOException, ParseException { - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); - simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); - Date localDate = simpleDateFormat.parse("2023-11-01"); + public void listInstallationsSince() throws IOException { + Instant localDate = LocalDate.parse("2023-11-01", DateTimeFormatter.ISO_LOCAL_DATE).atStartOfDay().toInstant(ZoneOffset.UTC); GHApp app = gitHub.getApp(); List installations = app.listInstallations(localDate).toList(); assertThat(installations.size(), is(1)); @@ -226,7 +222,7 @@ public void createToken() throws IOException { assertThat(installationToken.getToken(), is("bogus")); assertThat(installation.getPermissions(), is(permissions)); assertThat(installationToken.getRepositorySelection(), is(GHRepositorySelection.SELECTED)); - assertThat(installationToken.getExpiresAt(), is(GitHubClient.parseDate("2019-08-10T05:54:58Z"))); + assertThat(installationToken.getExpiresAt(), is(GitHubClient.parseInstant("2019-08-10T05:54:58Z"))); GHRepository repository = installationToken.getRepositories().get(0); assertThat(installationToken.getRepositories().size(), is(1)); @@ -239,7 +235,7 @@ public void createToken() throws IOException { assertThat(installationToken2.getToken(), is("bogus")); assertThat(installationToken2.getPermissions().size(), is(4)); assertThat(installationToken2.getRepositorySelection(), is(GHRepositorySelection.ALL)); - assertThat(installationToken2.getExpiresAt(), is(GitHubClient.parseDate("2019-12-19T12:27:59Z"))); + assertThat(installationToken2.getExpiresAt(), is(GitHubClient.parseInstant("2019-12-19T12:27:59Z"))); assertThat(installationToken2.getRepositories(), nullValue());; } @@ -263,7 +259,7 @@ public void createTokenWithRepositories() throws IOException { assertThat(installationToken.getToken(), is("bogus")); assertThat(installationToken.getPermissions().entrySet(), hasSize(4)); assertThat(installationToken.getRepositorySelection(), is(GHRepositorySelection.SELECTED)); - assertThat(installationToken.getExpiresAt(), is(GitHubClient.parseDate("2022-07-27T21:38:33Z"))); + assertThat(installationToken.getExpiresAt(), is(GitHubClient.parseInstant("2022-07-27T21:38:33Z"))); GHRepository repository = installationToken.getRepositories().get(0); assertThat(installationToken.getRepositories().size(), is(1)); @@ -295,8 +291,8 @@ private void testAppInstallation(GHAppInstallation appInstallation) throws IOExc List events = Arrays.asList(GHEvent.PULL_REQUEST, GHEvent.PUSH); assertThat(appInstallation.getEvents(), containsInAnyOrder(events.toArray(new GHEvent[0]))); - assertThat(appInstallation.getCreatedAt(), is(GitHubClient.parseDate("2019-07-04T01:19:36.000Z"))); - assertThat(appInstallation.getUpdatedAt(), is(GitHubClient.parseDate("2019-07-30T22:48:09.000Z"))); + assertThat(appInstallation.getCreatedAt(), is(GitHubClient.parseInstant("2019-07-04T01:19:36.000Z"))); + assertThat(appInstallation.getUpdatedAt(), is(GitHubClient.parseInstant("2019-07-30T22:48:09.000Z"))); assertThat(appInstallation.getSingleFileName(), nullValue()); } diff --git a/src/test/java/org/kohsuke/github/GHCheckRunBuilderTest.java b/src/test/java/org/kohsuke/github/GHCheckRunBuilderTest.java index a52e07e3a4..cf02d8059f 100644 --- a/src/test/java/org/kohsuke/github/GHCheckRunBuilderTest.java +++ b/src/test/java/org/kohsuke/github/GHCheckRunBuilderTest.java @@ -29,7 +29,7 @@ import org.kohsuke.github.GHCheckRun.Status; import java.io.IOException; -import java.util.Date; +import java.time.Instant; import static org.hamcrest.Matchers.*; @@ -71,8 +71,8 @@ public void createCheckRun() throws Exception { .withConclusion(GHCheckRun.Conclusion.SUCCESS) .withDetailsURL("http://nowhere.net/stuff") .withExternalID("whatever") - .withStartedAt(new Date(999_999_000)) - .withCompletedAt(new Date(999_999_999)) + .withStartedAt(Instant.ofEpochMilli(999_999_000)) + .withCompletedAt(Instant.ofEpochMilli(999_999_999)) .add(new GHCheckRunBuilder.Output("Some Title", "what happened…").withText("Hello Text!") .add(new GHCheckRunBuilder.Annotation("stuff.txt", 1, @@ -185,7 +185,7 @@ public void updateCheckRun() throws Exception { GHCheckRun checkRun = getInstallationGithub().getRepository("hub4j-test-org/test-checks") .createCheckRun("foo", "89a9ae301e35e667756034fdc933b1fc94f63fc1") .withStatus(GHCheckRun.Status.IN_PROGRESS) - .withStartedAt(new Date(999_999_000)) + .withStartedAt(Instant.ofEpochMilli(999_999_000)) .add(new GHCheckRunBuilder.Output("Some Title", "what happened…") .add(new GHCheckRunBuilder.Annotation("stuff.txt", 1, @@ -195,9 +195,9 @@ public void updateCheckRun() throws Exception { GHCheckRun updated = checkRun.update() .withStatus(GHCheckRun.Status.COMPLETED) .withConclusion(GHCheckRun.Conclusion.SUCCESS) - .withCompletedAt(new Date(999_999_999)) + .withCompletedAt(Instant.ofEpochMilli(999_999_999)) .create(); - assertThat(new Date(999_999_000), equalTo(updated.getStartedAt())); + assertThat(Instant.ofEpochMilli(999_999_000), equalTo(updated.getStartedAt())); assertThat("foo", equalTo(updated.getName())); assertThat(checkRun.getOutput().getAnnotationsCount(), equalTo(1)); } @@ -213,7 +213,7 @@ public void updateCheckRunWithName() throws Exception { GHCheckRun checkRun = getInstallationGithub().getRepository("hub4j-test-org/test-checks") .createCheckRun("foo", "89a9ae301e35e667756034fdc933b1fc94f63fc1") .withStatus(GHCheckRun.Status.IN_PROGRESS) - .withStartedAt(new Date(999_999_000)) + .withStartedAt(Instant.ofEpochMilli(999_999_000)) .add(new GHCheckRunBuilder.Output("Some Title", "what happened…") .add(new GHCheckRunBuilder.Annotation("stuff.txt", 1, @@ -223,10 +223,10 @@ public void updateCheckRunWithName() throws Exception { GHCheckRun updated = checkRun.update() .withStatus(GHCheckRun.Status.COMPLETED) .withConclusion(GHCheckRun.Conclusion.SUCCESS) - .withCompletedAt(new Date(999_999_999)) + .withCompletedAt(Instant.ofEpochMilli(999_999_999)) .withName("bar", checkRun.getName()) .create(); - assertThat(new Date(999_999_000), equalTo(updated.getStartedAt())); + assertThat(Instant.ofEpochMilli(999_999_000), equalTo(updated.getStartedAt())); assertThat("bar", equalTo(updated.getName())); assertThat(checkRun.getOutput().getAnnotationsCount(), equalTo(1)); } @@ -243,7 +243,7 @@ public void updateCheckRunWithNameException() throws Exception { GHCheckRun checkRun = getInstallationGithub().getRepository("hub4j-test-org/test-checks") .createCheckRun("foo", "89a9ae301e35e667756034fdc933b1fc94f63fc1") .withStatus(GHCheckRun.Status.IN_PROGRESS) - .withStartedAt(new Date(999_999_000)) + .withStartedAt(Instant.ofEpochMilli(999_999_000)) .add(new GHCheckRunBuilder.Output("Some Title", "what happened…") .add(new GHCheckRunBuilder.Annotation("stuff.txt", 1, @@ -254,7 +254,7 @@ public void updateCheckRunWithNameException() throws Exception { () -> checkRun.update() .withStatus(GHCheckRun.Status.COMPLETED) .withConclusion(GHCheckRun.Conclusion.SUCCESS) - .withCompletedAt(new Date(999_999_999)) + .withCompletedAt(Instant.ofEpochMilli(999_999_999)) .withName("bar", null) .create()); } diff --git a/src/test/java/org/kohsuke/github/GHContentIntegrationTest.java b/src/test/java/org/kohsuke/github/GHContentIntegrationTest.java index 719382faed..785d531f34 100644 --- a/src/test/java/org/kohsuke/github/GHContentIntegrationTest.java +++ b/src/test/java/org/kohsuke/github/GHContentIntegrationTest.java @@ -245,8 +245,8 @@ int checkCreatedCommits(GitCommit gitCommit, GHCommit ghCommit, int expectedRequ assertThat(mockGitHub.getRequestCount(), equalTo(expectedRequestCount)); assertThat(gitCommit.getMessage(), equalTo("Creating a file for integration tests.")); - assertThat(gitCommit.getAuthoredDate(), equalTo(GitHubClient.parseDate("2021-06-28T20:37:49Z"))); - assertThat(gitCommit.getCommitDate(), equalTo(GitHubClient.parseDate("2021-06-28T20:37:49Z"))); + assertThat(gitCommit.getAuthoredDate(), equalTo(GitHubClient.parseInstant("2021-06-28T20:37:49Z"))); + assertThat(gitCommit.getCommitDate(), equalTo(GitHubClient.parseInstant("2021-06-28T20:37:49Z"))); assertThat(ghCommit.getCommitShortInfo().getMessage(), equalTo("Creating a file for integration tests.")); assertThat("Message already resolved", mockGitHub.getRequestCount(), equalTo(expectedRequestCount)); @@ -296,8 +296,8 @@ int checkUpdatedContentResponseCommits(GitCommit gitCommit, GHCommit ghCommit, i assertThat(mockGitHub.getRequestCount(), equalTo(expectedRequestCount)); assertThat(gitCommit.getMessage(), equalTo("Updated file for integration tests.")); - assertThat(gitCommit.getAuthoredDate(), equalTo(GitHubClient.parseDate("2021-06-28T20:37:51Z"))); - assertThat(gitCommit.getCommitDate(), equalTo(GitHubClient.parseDate("2021-06-28T20:37:51Z"))); + assertThat(gitCommit.getAuthoredDate(), equalTo(GitHubClient.parseInstant("2021-06-28T20:37:51Z"))); + assertThat(gitCommit.getCommitDate(), equalTo(GitHubClient.parseInstant("2021-06-28T20:37:51Z"))); assertThat(ghCommit.getCommitShortInfo().getMessage(), equalTo("Updated file for integration tests.")); assertThat("Message already resolved", mockGitHub.getRequestCount(), equalTo(expectedRequestCount)); diff --git a/src/test/java/org/kohsuke/github/GHDeployKeyTest.java b/src/test/java/org/kohsuke/github/GHDeployKeyTest.java index bc3bb229ab..090af40044 100644 --- a/src/test/java/org/kohsuke/github/GHDeployKeyTest.java +++ b/src/test/java/org/kohsuke/github/GHDeployKeyTest.java @@ -4,7 +4,6 @@ import java.io.IOException; import java.time.Instant; -import java.util.Date; import java.util.List; import java.util.Optional; @@ -47,13 +46,13 @@ public void testGetDeployKeys() throws IOException { assertThat("The key exists", ed25519Key, isPresent()); assertThat("The key was created at the specified date", ed25519Key.get().getCreatedAt(), - is(Date.from(Instant.parse("2023-02-08T10:00:15.00Z")))); + is(Instant.parse("2023-02-08T10:00:15.00Z"))); assertThat("The key is created by " + KEY_CREATOR_USERNAME, ed25519Key.get().getAdded_by(), is(KEY_CREATOR_USERNAME)); assertThat("The key has a last_used value", ed25519Key.get().getLastUsedAt(), - is(Date.from(Instant.parse("2023-02-08T10:02:11.00Z")))); + is(Instant.parse("2023-02-08T10:02:11.00Z"))); assertThat("The key only has read access", ed25519Key.get().isRead_only(), is(true)); assertThat("Object has a toString()", ed25519Key.get().toString(), is(notNullValue())); @@ -63,7 +62,7 @@ public void testGetDeployKeys() throws IOException { assertThat("The key exists", rsa_4096Key, isPresent()); assertThat("The key was created at the specified date", rsa_4096Key.get().getCreatedAt(), - is(Date.from(Instant.parse("2023-01-26T14:12:12.00Z")))); + is(Instant.parse("2023-01-26T14:12:12.00Z"))); assertThat("The key is created by " + KEY_CREATOR_USERNAME, rsa_4096Key.get().getAdded_by(), is(KEY_CREATOR_USERNAME)); diff --git a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java index 638e60f18b..179bd51929 100644 --- a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java +++ b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java @@ -9,10 +9,8 @@ import org.kohsuke.github.GHTeam.Privacy; import java.io.IOException; -import java.text.SimpleDateFormat; import java.util.Collections; import java.util.List; -import java.util.TimeZone; import static org.hamcrest.Matchers.aMapWithSize; import static org.hamcrest.Matchers.contains; @@ -622,9 +620,7 @@ public void push() throws Exception { assertThat(event.getHeadCommit().getModified().get(0), is("README.md")); assertThat(event.getHeadCommit().getMessage(), is("Update README.md")); - SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); - formatter.setTimeZone(TimeZone.getTimeZone("UTC")); - assertThat(formatter.format(event.getCommits().get(0).getTimestamp()), is("2015-05-05T23:40:15Z")); + assertThat(GitHubClient.printInstant(event.getCommits().get(0).getTimestamp()), is("2015-05-05T23:40:15Z")); assertThat(event.getRepository().getName(), is("public-repo")); assertThat(event.getRepository().getOwnerName(), is("baxterthehacker")); assertThat(event.getRepository().getUrl().toExternalForm(), @@ -887,10 +883,8 @@ private GHCheckRun verifyBasicCheckRunEvent(final GHEventPayload.CheckRun event) assertThat(checkRun.getNodeId(), is("MDg6Q2hlY2tSdW4xMjg2MjAyMjg=")); assertThat(checkRun.getExternalId(), is("")); - SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); - formatter.setTimeZone(TimeZone.getTimeZone("UTC")); - assertThat(formatter.format(checkRun.getStartedAt()), is("2019-05-15T15:21:12Z")); - assertThat(formatter.format(checkRun.getCompletedAt()), is("2019-05-15T20:22:22Z")); + assertThat(GitHubClient.printInstant(checkRun.getStartedAt()), is("2019-05-15T15:21:12Z")); + assertThat(GitHubClient.printInstant(checkRun.getCompletedAt()), is("2019-05-15T20:22:22Z")); assertThat(checkRun.getConclusion(), is(Conclusion.SUCCESS)); assertThat(checkRun.getUrl().toString(), endsWith("/repos/Codertocat/Hello-World/check-runs/128620228")); @@ -969,9 +963,7 @@ private GHCheckSuite verifyBasicCheckSuiteEvent(final GHEventPayload.CheckSuite assertThat(checkSuite.getHeadCommit().getAuthor().getName(), is("Codertocat")); assertThat(checkSuite.getHeadCommit().getCommitter().getName(), is("Codertocat")); - SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); - formatter.setTimeZone(TimeZone.getTimeZone("UTC")); - assertThat(formatter.format(checkSuite.getHeadCommit().getTimestamp()), is("2019-05-15T15:20:30Z")); + assertThat(GitHubClient.printInstant(checkSuite.getHeadCommit().getTimestamp()), is("2019-05-15T15:20:30Z")); assertThat(checkSuite.getApp().getId(), is(29310L)); @@ -1138,14 +1130,14 @@ public void workflow_run() throws Exception { is("https://api.github.com/repos/gsmet/quarkus-bot-java-playground/actions/runs/680604745/rerun")); assertThat(workflowRun.getWorkflowUrl().toString(), is("https://api.github.com/repos/gsmet/quarkus-bot-java-playground/actions/workflows/7087581")); - assertThat(workflowRun.getCreatedAt().getTime(), is(1616524526000L)); - assertThat(workflowRun.getUpdatedAt().getTime(), is(1616524543000L)); + assertThat(workflowRun.getCreatedAt().toEpochMilli(), is(1616524526000L)); + assertThat(workflowRun.getUpdatedAt().toEpochMilli(), is(1616524543000L)); assertThat(workflowRun.getRunAttempt(), is(1L)); - assertThat(workflowRun.getRunStartedAt().getTime(), is(1616524526000L)); + assertThat(workflowRun.getRunStartedAt().toEpochMilli(), is(1616524526000L)); assertThat(workflowRun.getHeadCommit().getId(), is("dbea8d8b6ed2cf764dfd84a215f3f9040b3d4423")); assertThat(workflowRun.getHeadCommit().getTreeId(), is("b17089e6a2574ec1002566fe980923e62dce3026")); assertThat(workflowRun.getHeadCommit().getMessage(), is("Update main.yml")); - assertThat(workflowRun.getHeadCommit().getTimestamp().getTime(), is(1616523390000L)); + assertThat(workflowRun.getHeadCommit().getTimestamp().toEpochMilli(), is(1616523390000L)); assertThat(workflowRun.getHeadCommit().getAuthor().getName(), is("Guillaume Smet")); assertThat(workflowRun.getHeadCommit().getAuthor().getEmail(), is("guillaume.smet@gmail.com")); assertThat(workflowRun.getHeadCommit().getCommitter().getName(), is("GitHub")); @@ -1219,8 +1211,8 @@ public void workflow_job() throws Exception { assertThat(workflowJob.getHeadSha(), is("5dd2dadfbdc2a722c08a8ad42ae4e26e3e731042")); assertThat(workflowJob.getStatus(), is(GHWorkflowRun.Status.COMPLETED)); assertThat(workflowJob.getConclusion(), is(GHWorkflowRun.Conclusion.FAILURE)); - assertThat(workflowJob.getStartedAt().getTime(), is(1653908125000L)); - assertThat(workflowJob.getCompletedAt().getTime(), is(1653908157000L)); + assertThat(workflowJob.getStartedAt().toEpochMilli(), is(1653908125000L)); + assertThat(workflowJob.getCompletedAt().toEpochMilli(), is(1653908157000L)); assertThat(workflowJob.getName(), is("JVM Tests - JDK JDK16")); assertThat(workflowJob.getSteps(), contains(hasProperty("name", is("Set up job")), @@ -1325,8 +1317,8 @@ public void discussion_created() throws Exception { assertThat(category.getEmoji(), is(":pray:")); assertThat(category.getName(), is("Q&A")); assertThat(category.getDescription(), is("Ask the community for help")); - assertThat(category.getCreatedAt().getTime(), is(1636991431000L)); - assertThat(category.getUpdatedAt().getTime(), is(1636991431000L)); + assertThat(category.getCreatedAt().toEpochMilli(), is(1636991431000L)); + assertThat(category.getUpdatedAt().toEpochMilli(), is(1636991431000L)); assertThat(category.getSlug(), is("q-a")); assertThat(category.isAnswerable(), is(true)); @@ -1348,8 +1340,8 @@ public void discussion_created() throws Exception { assertThat(discussion.getState(), is(GHRepositoryDiscussion.State.OPEN)); assertThat(discussion.isLocked(), is(false)); assertThat(discussion.getComments(), is(0)); - assertThat(discussion.getCreatedAt().getTime(), is(1637584949000L)); - assertThat(discussion.getUpdatedAt().getTime(), is(1637584949000L)); + assertThat(discussion.getCreatedAt().toEpochMilli(), is(1637584949000L)); + assertThat(discussion.getUpdatedAt().toEpochMilli(), is(1637584949000L)); assertThat(discussion.getAuthorAssociation(), is(GHCommentAuthorAssociation.OWNER)); assertThat(discussion.getActiveLockReason(), is(nullValue())); assertThat(discussion.getBody(), is("Body of discussion.")); @@ -1379,14 +1371,14 @@ public void discussion_answered() throws Exception { assertThat(category.getEmoji(), is(":pray:")); assertThat(category.getName(), is("Q&A")); assertThat(category.getDescription(), is("Ask the community for help")); - assertThat(category.getCreatedAt().getTime(), is(1636991431000L)); - assertThat(category.getUpdatedAt().getTime(), is(1636991431000L)); + assertThat(category.getCreatedAt().toEpochMilli(), is(1636991431000L)); + assertThat(category.getUpdatedAt().toEpochMilli(), is(1636991431000L)); assertThat(category.getSlug(), is("q-a")); assertThat(category.isAnswerable(), is(true)); assertThat(discussion.getAnswerHtmlUrl().toString(), is("https://github.com/gsmet/quarkus-bot-java-playground/discussions/78#discussioncomment-1681242")); - assertThat(discussion.getAnswerChosenAt().getTime(), is(1637585047000L)); + assertThat(discussion.getAnswerChosenAt().toEpochMilli(), is(1637585047000L)); assertThat(discussion.getAnswerChosenBy().getLogin(), is("gsmet")); assertThat(discussion.getHtmlUrl().toString(), @@ -1403,8 +1395,8 @@ public void discussion_answered() throws Exception { assertThat(discussion.getState(), is(GHRepositoryDiscussion.State.OPEN)); assertThat(discussion.isLocked(), is(false)); assertThat(discussion.getComments(), is(1)); - assertThat(discussion.getCreatedAt().getTime(), is(1637584949000L)); - assertThat(discussion.getUpdatedAt().getTime(), is(1637585047000L)); + assertThat(discussion.getCreatedAt().toEpochMilli(), is(1637584949000L)); + assertThat(discussion.getUpdatedAt().toEpochMilli(), is(1637585047000L)); assertThat(discussion.getAuthorAssociation(), is(GHCommentAuthorAssociation.OWNER)); assertThat(discussion.getActiveLockReason(), is(nullValue())); assertThat(discussion.getBody(), is("Body of discussion.")); @@ -1434,8 +1426,8 @@ public void discussion_labeled() throws Exception { assertThat(category.getEmoji(), is(":pray:")); assertThat(category.getName(), is("Q&A")); assertThat(category.getDescription(), is("Ask the community for help")); - assertThat(category.getCreatedAt().getTime(), is(1636991431000L)); - assertThat(category.getUpdatedAt().getTime(), is(1636991431000L)); + assertThat(category.getCreatedAt().toEpochMilli(), is(1636991431000L)); + assertThat(category.getUpdatedAt().toEpochMilli(), is(1636991431000L)); assertThat(category.getSlug(), is("q-a")); assertThat(category.isAnswerable(), is(true)); @@ -1457,8 +1449,8 @@ public void discussion_labeled() throws Exception { assertThat(discussion.getState(), is(GHRepositoryDiscussion.State.OPEN)); assertThat(discussion.isLocked(), is(false)); assertThat(discussion.getComments(), is(0)); - assertThat(discussion.getCreatedAt().getTime(), is(1637584949000L)); - assertThat(discussion.getUpdatedAt().getTime(), is(1637584961000L)); + assertThat(discussion.getCreatedAt().toEpochMilli(), is(1637584949000L)); + assertThat(discussion.getUpdatedAt().toEpochMilli(), is(1637584961000L)); assertThat(discussion.getAuthorAssociation(), is(GHCommentAuthorAssociation.OWNER)); assertThat(discussion.getActiveLockReason(), is(nullValue())); assertThat(discussion.getBody(), is("Body of discussion.")); @@ -1498,8 +1490,8 @@ public void discussion_comment_created() throws Exception { assertThat(category.getEmoji(), is(":pray:")); assertThat(category.getName(), is("Q&A")); assertThat(category.getDescription(), is("Ask the community for help")); - assertThat(category.getCreatedAt().getTime(), is(1636991431000L)); - assertThat(category.getUpdatedAt().getTime(), is(1636991431000L)); + assertThat(category.getCreatedAt().toEpochMilli(), is(1636991431000L)); + assertThat(category.getUpdatedAt().toEpochMilli(), is(1636991431000L)); assertThat(category.getSlug(), is("q-a")); assertThat(category.isAnswerable(), is(true)); @@ -1521,8 +1513,8 @@ public void discussion_comment_created() throws Exception { assertThat(discussion.getState(), is(GHRepositoryDiscussion.State.OPEN)); assertThat(discussion.isLocked(), is(false)); assertThat(discussion.getComments(), is(1)); - assertThat(discussion.getCreatedAt().getTime(), is(1705586390000L)); - assertThat(discussion.getUpdatedAt().getTime(), is(1705586399000L)); + assertThat(discussion.getCreatedAt().toEpochMilli(), is(1705586390000L)); + assertThat(discussion.getUpdatedAt().toEpochMilli(), is(1705586399000L)); assertThat(discussion.getAuthorAssociation(), is(GHCommentAuthorAssociation.OWNER)); assertThat(discussion.getActiveLockReason(), is(nullValue())); assertThat(discussion.getBody(), is("Test question")); @@ -1534,8 +1526,8 @@ public void discussion_comment_created() throws Exception { assertThat(comment.getId(), is(8169669L)); assertThat(comment.getNodeId(), is("DC_kwDOEq3cwc4AfKjF")); assertThat(comment.getAuthorAssociation(), is(GHCommentAuthorAssociation.OWNER)); - assertThat(comment.getCreatedAt().getTime(), is(1705586398000L)); - assertThat(comment.getUpdatedAt().getTime(), is(1705586399000L)); + assertThat(comment.getCreatedAt().toEpochMilli(), is(1705586398000L)); + assertThat(comment.getUpdatedAt().toEpochMilli(), is(1705586399000L)); assertThat(comment.getBody(), is("Test comment.")); assertThat(comment.getUser().getLogin(), is("gsmet")); assertThat(comment.getUser().getId(), is(1279749L)); @@ -1558,7 +1550,7 @@ public void starred() throws Exception { assertThat(starPayload.getAction(), is("created")); assertThat(starPayload.getRepository().getFullName(), is("gsmet/quarkus-bot-java-playground")); assertThat(starPayload.getSender().getLogin(), is("gsmet")); - assertThat(starPayload.getStarredAt().getTime(), is(1654017876000L)); + assertThat(starPayload.getStarredAt().toEpochMilli(), is(1654017876000L)); } /** @@ -1581,8 +1573,8 @@ public void projectsv2item_created() throws Exception { assertThat(projectsV2ItemPayload.getProjectsV2Item().getContentType(), is(ContentType.ISSUE)); assertThat(projectsV2ItemPayload.getProjectsV2Item().getCreator().getLogin(), is("gsmet")); assertThat(projectsV2ItemPayload.getProjectsV2Item().getCreator().getNodeId(), is("MDQ6VXNlcjEyNzk3NDk=")); - assertThat(projectsV2ItemPayload.getProjectsV2Item().getCreatedAt().getTime(), is(1659532028000L)); - assertThat(projectsV2ItemPayload.getProjectsV2Item().getUpdatedAt().getTime(), is(1659532028000L)); + assertThat(projectsV2ItemPayload.getProjectsV2Item().getCreatedAt().toEpochMilli(), is(1659532028000L)); + assertThat(projectsV2ItemPayload.getProjectsV2Item().getUpdatedAt().toEpochMilli(), is(1659532028000L)); assertThat(projectsV2ItemPayload.getProjectsV2Item().getArchivedAt(), is(nullValue())); assertThat(projectsV2ItemPayload.getOrganization().getLogin(), is("gsmet-bot-playground")); @@ -1612,8 +1604,8 @@ public void projectsv2item_edited() throws Exception { assertThat(projectsV2ItemPayload.getAction(), is("edited")); assertThat(projectsV2ItemPayload.getProjectsV2Item().getId(), is(8083254L)); - assertThat(projectsV2ItemPayload.getProjectsV2Item().getCreatedAt().getTime(), is(1659532028000L)); - assertThat(projectsV2ItemPayload.getProjectsV2Item().getUpdatedAt().getTime(), is(1659532033000L)); + assertThat(projectsV2ItemPayload.getProjectsV2Item().getCreatedAt().toEpochMilli(), is(1659532028000L)); + assertThat(projectsV2ItemPayload.getProjectsV2Item().getUpdatedAt().toEpochMilli(), is(1659532033000L)); assertThat(projectsV2ItemPayload.getProjectsV2Item().getArchivedAt(), is(nullValue())); assertThat(projectsV2ItemPayload.getChanges().getFieldValue().getFieldNodeId(), @@ -1635,12 +1627,12 @@ public void projectsv2item_archived() throws Exception { assertThat(projectsV2ItemPayload.getAction(), is("archived")); assertThat(projectsV2ItemPayload.getProjectsV2Item().getId(), is(8083794L)); - assertThat(projectsV2ItemPayload.getProjectsV2Item().getCreatedAt().getTime(), is(1659532431000L)); - assertThat(projectsV2ItemPayload.getProjectsV2Item().getUpdatedAt().getTime(), is(1660086629000L)); - assertThat(projectsV2ItemPayload.getProjectsV2Item().getArchivedAt().getTime(), is(1660086629000L)); + assertThat(projectsV2ItemPayload.getProjectsV2Item().getCreatedAt().toEpochMilli(), is(1659532431000L)); + assertThat(projectsV2ItemPayload.getProjectsV2Item().getUpdatedAt().toEpochMilli(), is(1660086629000L)); + assertThat(projectsV2ItemPayload.getProjectsV2Item().getArchivedAt().toEpochMilli(), is(1660086629000L)); assertThat(projectsV2ItemPayload.getChanges().getArchivedAt().getFrom(), is(nullValue())); - assertThat(projectsV2ItemPayload.getChanges().getArchivedAt().getTo().getTime(), is(1660086629000L)); + assertThat(projectsV2ItemPayload.getChanges().getArchivedAt().getTo().toEpochMilli(), is(1660086629000L)); } /** @@ -1657,11 +1649,11 @@ public void projectsv2item_restored() throws Exception { assertThat(projectsV2ItemPayload.getAction(), is("restored")); assertThat(projectsV2ItemPayload.getProjectsV2Item().getId(), is(8083254L)); - assertThat(projectsV2ItemPayload.getProjectsV2Item().getCreatedAt().getTime(), is(1659532028000L)); - assertThat(projectsV2ItemPayload.getProjectsV2Item().getUpdatedAt().getTime(), is(1659532419000L)); + assertThat(projectsV2ItemPayload.getProjectsV2Item().getCreatedAt().toEpochMilli(), is(1659532028000L)); + assertThat(projectsV2ItemPayload.getProjectsV2Item().getUpdatedAt().toEpochMilli(), is(1659532419000L)); assertThat(projectsV2ItemPayload.getProjectsV2Item().getArchivedAt(), is(nullValue())); - assertThat(projectsV2ItemPayload.getChanges().getArchivedAt().getFrom().getTime(), is(1659532142000L)); + assertThat(projectsV2ItemPayload.getChanges().getArchivedAt().getFrom().toEpochMilli(), is(1659532142000L)); assertThat(projectsV2ItemPayload.getChanges().getArchivedAt().getTo(), is(nullValue())); } @@ -1679,8 +1671,8 @@ public void projectsv2item_reordered() throws Exception { assertThat(projectsV2ItemPayload.getAction(), is("reordered")); assertThat(projectsV2ItemPayload.getProjectsV2Item().getId(), is(8083794L)); - assertThat(projectsV2ItemPayload.getProjectsV2Item().getCreatedAt().getTime(), is(1659532431000L)); - assertThat(projectsV2ItemPayload.getProjectsV2Item().getUpdatedAt().getTime(), is(1659532439000L)); + assertThat(projectsV2ItemPayload.getProjectsV2Item().getCreatedAt().toEpochMilli(), is(1659532431000L)); + assertThat(projectsV2ItemPayload.getProjectsV2Item().getUpdatedAt().toEpochMilli(), is(1659532439000L)); assertThat(projectsV2ItemPayload.getProjectsV2Item().getArchivedAt(), is(nullValue())); assertThat(projectsV2ItemPayload.getChanges().getPreviousProjectsV2ItemNodeId().getFrom(), diff --git a/src/test/java/org/kohsuke/github/GHIssueTest.java b/src/test/java/org/kohsuke/github/GHIssueTest.java index 5b1a45f3d6..705f4ed75d 100644 --- a/src/test/java/org/kohsuke/github/GHIssueTest.java +++ b/src/test/java/org/kohsuke/github/GHIssueTest.java @@ -5,9 +5,8 @@ import org.junit.Test; import java.io.IOException; -import java.time.temporal.ChronoUnit; +import java.time.Instant; import java.util.Collection; -import java.util.Date; import java.util.List; import static org.hamcrest.Matchers.contains; @@ -86,9 +85,8 @@ public void issueComment() throws Exception { assertThat(comments, hasSize(0)); GHIssueComment firstComment = issue.comment("First comment"); - Date firstCommentCreatedAt = firstComment.getCreatedAt(); - Date firstCommentCreatedAtPlus1Second = Date - .from(firstComment.getCreatedAt().toInstant().plus(1, ChronoUnit.SECONDS)); + Instant firstCommentCreatedAt = firstComment.getCreatedAt(); + Instant firstCommentCreatedAtPlus1Second = firstComment.getCreatedAt().plusSeconds(1); comments = issue.listComments().toList(); assertThat(comments, hasSize(1)); @@ -112,13 +110,12 @@ public void issueComment() throws Exception { Thread.sleep(2000); GHIssueComment secondComment = issue.comment("Second comment"); - Date secondCommentCreatedAt = secondComment.getCreatedAt(); - Date secondCommentCreatedAtPlus1Second = Date - .from(secondComment.getCreatedAt().toInstant().plus(1, ChronoUnit.SECONDS)); + Instant secondCommentCreatedAt = secondComment.getCreatedAt(); + Instant secondCommentCreatedAtPlus1Second = secondComment.getCreatedAt().plusSeconds(1); assertThat( "There's an error in the setup of this test; please fix it." + " The second comment should be created at least one second after the first one.", - firstCommentCreatedAtPlus1Second.getTime() <= secondCommentCreatedAt.getTime()); + firstCommentCreatedAtPlus1Second.isBefore(secondCommentCreatedAt)); comments = issue.listComments().toList(); assertThat(comments, hasSize(2)); @@ -147,7 +144,7 @@ public void issueComment() throws Exception { assertThat(comments, hasSize(0)); // Test "since" with timestamp instead of Date - comments = issue.queryComments().since(secondCommentCreatedAt.getTime()).list().toList(); + comments = issue.queryComments().since(secondCommentCreatedAt.toEpochMilli()).list().toList(); assertThat(comments, hasSize(1)); assertThat(comments, contains(hasProperty("body", equalTo("Second comment")))); } diff --git a/src/test/java/org/kohsuke/github/GHMilestoneTest.java b/src/test/java/org/kohsuke/github/GHMilestoneTest.java index 78867c4cd3..7d8cdc60dc 100644 --- a/src/test/java/org/kohsuke/github/GHMilestoneTest.java +++ b/src/test/java/org/kohsuke/github/GHMilestoneTest.java @@ -5,7 +5,7 @@ import org.junit.Test; import java.io.IOException; -import java.util.Date; +import java.time.Instant; import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.containsString; @@ -59,8 +59,8 @@ public void testUpdateMilestone() throws Exception { String NEW_TITLE = "Updated Title"; String NEW_DESCRIPTION = "Updated Description"; - Date NEW_DUE_DATE = GitHubClient.parseDate("2020-10-05T13:00:00Z"); - Date OUTPUT_DUE_DATE = GitHubClient.parseDate("2020-10-05T07:00:00Z"); + Instant NEW_DUE_DATE = GitHubClient.parseInstant("2020-10-05T13:00:00Z"); + Instant OUTPUT_DUE_DATE = GitHubClient.parseInstant("2020-10-05T07:00:00Z"); milestone.setTitle(NEW_TITLE); milestone.setDescription(NEW_DESCRIPTION); diff --git a/src/test/java/org/kohsuke/github/GHPullRequestTest.java b/src/test/java/org/kohsuke/github/GHPullRequestTest.java index 3beddb2769..09c47f5a6f 100644 --- a/src/test/java/org/kohsuke/github/GHPullRequestTest.java +++ b/src/test/java/org/kohsuke/github/GHPullRequestTest.java @@ -6,10 +6,9 @@ import org.kohsuke.github.GHPullRequest.AutoMerge; import java.io.IOException; -import java.time.temporal.ChronoUnit; +import java.time.Instant; import java.util.Collection; import java.util.Collections; -import java.util.Date; import java.util.List; import java.util.Optional; @@ -135,9 +134,8 @@ public void pullRequestComment() throws Exception { assertThat(comments, hasSize(0)); GHIssueComment firstComment = p.comment("First comment"); - Date firstCommentCreatedAt = firstComment.getCreatedAt(); - Date firstCommentCreatedAtPlus1Second = Date - .from(firstComment.getCreatedAt().toInstant().plus(1, ChronoUnit.SECONDS)); + Instant firstCommentCreatedAt = firstComment.getCreatedAt(); + Instant firstCommentCreatedAtPlus1Second = firstComment.getCreatedAt().plusSeconds(1); comments = p.listComments().toList(); assertThat(comments, hasSize(1)); @@ -160,13 +158,12 @@ public void pullRequestComment() throws Exception { Thread.sleep(2000); GHIssueComment secondComment = p.comment("Second comment"); - Date secondCommentCreatedAt = secondComment.getCreatedAt(); - Date secondCommentCreatedAtPlus1Second = Date - .from(secondComment.getCreatedAt().toInstant().plus(1, ChronoUnit.SECONDS)); + Instant secondCommentCreatedAt = secondComment.getCreatedAt(); + Instant secondCommentCreatedAtPlus1Second = secondComment.getCreatedAt().plusSeconds(1); assertThat( "There's an error in the setup of this test; please fix it." + " The second comment should be created at least one second after the first one.", - firstCommentCreatedAtPlus1Second.getTime() <= secondCommentCreatedAt.getTime()); + firstCommentCreatedAtPlus1Second.isBefore(secondCommentCreatedAt)); comments = p.listComments().toList(); assertThat(comments, hasSize(2)); @@ -195,7 +192,7 @@ public void pullRequestComment() throws Exception { assertThat(comments, hasSize(0)); // Test "since" with timestamp instead of Date - comments = p.queryComments().since(secondCommentCreatedAt.getTime()).list().toList(); + comments = p.queryComments().since(secondCommentCreatedAt.toEpochMilli()).list().toList(); assertThat(comments, hasSize(1)); assertThat(comments, contains(hasProperty("body", equalTo("Second comment")))); } diff --git a/src/test/java/org/kohsuke/github/GHRateLimitTest.java b/src/test/java/org/kohsuke/github/GHRateLimitTest.java index b7c8c807a4..01e8ac5372 100644 --- a/src/test/java/org/kohsuke/github/GHRateLimitTest.java +++ b/src/test/java/org/kohsuke/github/GHRateLimitTest.java @@ -7,7 +7,7 @@ import java.io.IOException; import java.time.Duration; -import java.util.Date; +import java.time.Instant; import java.util.HashMap; import static org.hamcrest.CoreMatchers.equalTo; @@ -231,7 +231,7 @@ private void verifyRateLimitValues(GHRateLimit previousLimit, int remaining, boo assertThat(rateLimit.getRemaining(), equalTo(remaining)); // Check that the reset date of the current limit is not older than the previous one - long diffMillis = rateLimit.getResetDate().getTime() - previousLimit.getResetDate().getTime(); + long diffMillis = rateLimit.getResetDate().toEpochMilli() - previousLimit.getResetDate().toEpochMilli(); assertThat(diffMillis, greaterThanOrEqualTo(0L)); if (changedResetDate) { @@ -262,7 +262,7 @@ public void testGitHubEnterpriseDoesNotHaveRateLimit() throws Exception { assertThat(mockGitHub.getRequestCount(), equalTo(0)); GHRateLimit rateLimit = null; - Date lastReset = new Date(System.currentTimeMillis() / 1000L); + Instant lastReset = Instant.ofEpochMilli(System.currentTimeMillis() / 1000L); // Give this a moment Thread.sleep(1500); diff --git a/src/test/java/org/kohsuke/github/GHRepositoryTest.java b/src/test/java/org/kohsuke/github/GHRepositoryTest.java index 0d1f6e4590..2eaa197aea 100644 --- a/src/test/java/org/kohsuke/github/GHRepositoryTest.java +++ b/src/test/java/org/kohsuke/github/GHRepositoryTest.java @@ -15,6 +15,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.time.Instant; import java.time.LocalDate; import java.util.*; import java.util.stream.Collectors; @@ -262,7 +263,7 @@ public void listStargazers() throws IOException { repository = gitHub.getOrganization("hub4j").getRepository("github-api"); Iterable stargazers = repository.listStargazers2(); GHStargazer stargazer = stargazers.iterator().next(); - assertThat(stargazer.getStarredAt(), equalTo(new Date(1271650383000L))); + assertThat(stargazer.getStarredAt(), equalTo(Instant.ofEpochMilli(1271650383000L))); assertThat(stargazer.getUser().getLogin(), equalTo("nielswind")); assertThat(stargazer.getRepository(), sameInstance(repository)); } @@ -314,7 +315,7 @@ public void subscription() throws Exception { assertThat(s.getUrl().toString(), containsString("/repos/hub4j-test-org/github-api/subscription")); assertThat(s.getReason(), nullValue()); - assertThat(s.getCreatedAt(), equalTo(new Date(1611377286000L))); + assertThat(s.getCreatedAt(), equalTo(Instant.ofEpochMilli(1611377286000L))); } finally { s.delete(); } diff --git a/src/test/java/org/kohsuke/github/GHTreeBuilderTest.java b/src/test/java/org/kohsuke/github/GHTreeBuilderTest.java index 2f3ea77fb4..94405fe045 100644 --- a/src/test/java/org/kohsuke/github/GHTreeBuilderTest.java +++ b/src/test/java/org/kohsuke/github/GHTreeBuilderTest.java @@ -5,8 +5,8 @@ import org.junit.Test; import java.io.IOException; +import java.time.Instant; import java.util.Arrays; -import java.util.Date; import static org.hamcrest.Matchers.*; @@ -146,8 +146,8 @@ private GHCommit updateTree() throws IOException { String treeSha = treeBuilder.create().getSha(); GHCommit commit = new GHCommitBuilder(repo).message("Add files") .tree(treeSha) - .author("author", "author@author.com", new Date(1611433225969L)) - .committer("committer", "committer@committer.com", new Date(1611433225968L)) + .author("author", "author@author.com", Instant.ofEpochMilli(1611433225969L)) + .committer("committer", "committer@committer.com", Instant.ofEpochMilli(1611433225968L)) .parent(mainRef.getObject().getSha()) .create(); diff --git a/src/test/java/org/kohsuke/github/GHUserTest.java b/src/test/java/org/kohsuke/github/GHUserTest.java index bf47fb252e..0b16911a06 100644 --- a/src/test/java/org/kohsuke/github/GHUserTest.java +++ b/src/test/java/org/kohsuke/github/GHUserTest.java @@ -247,7 +247,7 @@ public void verifySuspendedAt() throws IOException { assertThat(normal.getSuspendedAt(), is(nullValue())); GHUser suspended = gitHub.getUser("suspended"); - Date suspendedAt = new Date(Instant.parse("2024-08-08T00:00:00Z").toEpochMilli()); + Instant suspendedAt = Instant.ofEpochMilli(Instant.parse("2024-08-08T00:00:00Z").toEpochMilli()); assertThat(suspended.getSuspendedAt(), equalTo(suspendedAt)); } } diff --git a/src/test/java/org/kohsuke/github/GHWorkflowRunTest.java b/src/test/java/org/kohsuke/github/GHWorkflowRunTest.java index 2d9d63dd32..67f77c5e3d 100644 --- a/src/test/java/org/kohsuke/github/GHWorkflowRunTest.java +++ b/src/test/java/org/kohsuke/github/GHWorkflowRunTest.java @@ -14,7 +14,6 @@ import java.time.Duration; import java.time.Instant; import java.util.ArrayList; -import java.util.Date; import java.util.List; import java.util.Optional; import java.util.Scanner; @@ -290,26 +289,26 @@ public void testSearchOnCreatedAndHeadSha() throws IOException { assertThat(mainBranchHeadShaWorkflowRuns, everyItem(hasProperty("headSha", equalTo(mainBranchHeadSha)))); // Ideally, we would use everyItem() but the bridge method is in the way for (GHWorkflowRun workflowRun : mainBranchHeadShaWorkflowRuns) { - assertThat(workflowRun.getCreatedAt(), greaterThanOrEqualTo(Date.from(before))); + assertThat(workflowRun.getCreatedAt(), greaterThanOrEqualTo(before)); } assertThat(secondBranchHeadShaWorkflowRuns, hasSize(greaterThanOrEqualTo(1))); assertThat(secondBranchHeadShaWorkflowRuns, everyItem(hasProperty("headSha", equalTo(secondBranchHeadSha)))); // Ideally, we would use everyItem() but the bridge method is in the way for (GHWorkflowRun workflowRun : secondBranchHeadShaWorkflowRuns) { - assertThat(workflowRun.getCreatedAt(), greaterThanOrEqualTo(Date.from(before))); + assertThat(workflowRun.getCreatedAt(), greaterThanOrEqualTo(before)); } List mainBranchHeadShaWorkflowRunsBefore = repo.queryWorkflowRuns() .headSha(repo.getBranch(MAIN_BRANCH).getSHA1()) - .created("<" + before.toString()) + .created("<" + before) .list() .toList(); // Ideally, we would use that but the bridge method is causing issues // assertThat(mainBranchHeadShaWorkflowRunsBefore, everyItem(hasProperty("createdAt", // lessThan(Date.from(before))))); for (GHWorkflowRun workflowRun : mainBranchHeadShaWorkflowRunsBefore) { - assertThat(workflowRun.getCreatedAt(), lessThan(Date.from(before))); + assertThat(workflowRun.getCreatedAt(), lessThan(before)); } } diff --git a/src/test/java/org/kohsuke/github/GitHubStaticTest.java b/src/test/java/org/kohsuke/github/GitHubStaticTest.java index 5c4e9b68eb..904a7674b6 100644 --- a/src/test/java/org/kohsuke/github/GitHubStaticTest.java +++ b/src/test/java/org/kohsuke/github/GitHubStaticTest.java @@ -6,13 +6,13 @@ import java.net.MalformedURLException; import java.net.URL; -import java.text.SimpleDateFormat; import java.time.Duration; import java.time.Instant; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import java.time.temporal.ChronoUnit; -import java.util.Date; -import java.util.TimeZone; +import java.util.Locale; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.Matchers.containsString; @@ -82,54 +82,54 @@ public void timeRoundTrip() { final long stableInstantEpochMilli = 1533721222255L; Instant instantNow = Instant.ofEpochMilli(stableInstantEpochMilli); - Date instantSeconds = Date.from(instantNow.truncatedTo(ChronoUnit.SECONDS)); - Date instantMillis = Date.from(instantNow.truncatedTo(ChronoUnit.MILLIS)); + Instant instantSeconds = instantNow.truncatedTo(ChronoUnit.SECONDS); + Instant instantMillis = instantNow.truncatedTo(ChronoUnit.MILLIS); - String instantFormatSlash = formatZonedDate(instantMillis, "yyyy/MM/dd HH:mm:ss ZZZZ", "PST"); + String instantFormatSlash = formatZonedInstant(instantMillis, "yyyy/MM/dd HH:mm:ss Z", "PST"); assertThat(instantFormatSlash, equalTo("2018/08/08 02:40:22 -0700")); - String instantFormatDash = formatDate(instantMillis, "yyyy-MM-dd'T'HH:mm:ss'Z'"); + String instantFormatDash = formatInstant(instantMillis, "yyyy-MM-dd'T'HH:mm:ss'Z'"); assertThat(instantFormatDash, equalTo("2018-08-08T09:40:22Z")); - String instantFormatMillis = formatDate(instantMillis, "yyyy-MM-dd'T'HH:mm:ss.S'Z'"); + String instantFormatMillis = formatInstant(instantMillis, "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); assertThat(instantFormatMillis, equalTo("2018-08-08T09:40:22.255Z")); - String instantFormatMillisZoned = formatZonedDate(instantMillis, "yyyy-MM-dd'T'HH:mm:ss.SXXX", "PST"); + String instantFormatMillisZoned = formatZonedInstant(instantMillis, "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ", "PST"); assertThat(instantFormatMillisZoned, equalTo("2018-08-08T02:40:22.255-07:00")); - String instantSecondsFormatMillis = formatDate(instantSeconds, "yyyy-MM-dd'T'HH:mm:ss.S'Z'"); + String instantSecondsFormatMillis = formatInstant(instantSeconds, "yyyy-MM-dd'T'HH:mm:ss.S'Z'"); assertThat(instantSecondsFormatMillis, equalTo("2018-08-08T09:40:22.0Z")); - String instantSecondsFormatMillisZoned = formatZonedDate(instantSeconds, "yyyy-MM-dd'T'HH:mm:ss.SSSXXX", "PST"); + String instantSecondsFormatMillisZoned = formatZonedInstant(instantSeconds, "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ", "PST"); assertThat(instantSecondsFormatMillisZoned, equalTo("2018-08-08T02:40:22.000-07:00")); - String instantBadFormat = formatDate(instantMillis, "yy-MM-dd'T'HH:mm'Z'"); + String instantBadFormat = formatInstant(instantMillis, "yy-MM-dd'T'HH:mm'Z'"); assertThat(instantBadFormat, equalTo("18-08-08T09:40Z")); - assertThat(GitHubClient.parseDate(GitHubClient.printDate(instantSeconds)), - equalTo(GitHubClient.parseDate(GitHubClient.printDate(instantMillis)))); - assertThat(GitHubClient.printDate(instantSeconds), equalTo("2018-08-08T09:40:22Z")); - assertThat(GitHubClient.printDate(GitHubClient.parseDate(instantFormatMillisZoned)), + assertThat(GitHubClient.parseInstant(GitHubClient.printInstant(instantSeconds)), + equalTo(GitHubClient.parseInstant(GitHubClient.printInstant(instantMillis)))); + assertThat(GitHubClient.printInstant(instantSeconds), equalTo("2018-08-08T09:40:22Z")); + assertThat(GitHubClient.printInstant(GitHubClient.parseInstant(instantFormatMillisZoned)), equalTo("2018-08-08T09:40:22Z")); - assertThat(instantSeconds, equalTo(GitHubClient.parseDate(GitHubClient.printDate(instantSeconds)))); + assertThat(instantSeconds, equalTo(GitHubClient.parseInstant(GitHubClient.printInstant(instantSeconds)))); // printDate will truncate to the nearest second, so it should not be equal - assertThat(instantMillis, not(equalTo(GitHubClient.parseDate(GitHubClient.printDate(instantMillis))))); + assertThat(instantMillis, not(equalTo(GitHubClient.parseInstant(GitHubClient.printInstant(instantMillis))))); - assertThat(instantSeconds, equalTo(GitHubClient.parseDate(instantFormatSlash))); + assertThat(instantSeconds, equalTo(GitHubClient.parseInstant(instantFormatSlash))); - assertThat(instantSeconds, equalTo(GitHubClient.parseDate(instantFormatDash))); + assertThat(instantSeconds, equalTo(GitHubClient.parseInstant(instantFormatDash))); // This parser does not truncate to the nearest second, so it will be equal - assertThat(instantMillis, equalTo(GitHubClient.parseDate(instantFormatMillis))); - assertThat(instantMillis, equalTo(GitHubClient.parseDate(instantFormatMillisZoned))); + assertThat(instantMillis, equalTo(GitHubClient.parseInstant(instantFormatMillis))); + assertThat(instantMillis, equalTo(GitHubClient.parseInstant(instantFormatMillisZoned))); - assertThat(instantSeconds, equalTo(GitHubClient.parseDate(instantSecondsFormatMillis))); - assertThat(instantSeconds, equalTo(GitHubClient.parseDate(instantSecondsFormatMillisZoned))); + assertThat(instantSeconds, equalTo(GitHubClient.parseInstant(instantSecondsFormatMillis))); + assertThat(instantSeconds, equalTo(GitHubClient.parseInstant(instantSecondsFormatMillisZoned))); try { - GitHubClient.parseDate(instantBadFormat); + GitHubClient.parseInstant(instantBadFormat); fail("Bad time format should throw."); } catch (DateTimeParseException e) { assertThat(e.getMessage(), equalTo("Text '" + instantBadFormat + "' could not be parsed at index 0")); @@ -417,33 +417,32 @@ public void testGitHubRequest_getApiURL() { } /** - * Format date. + * Format instant. * - * @param dt - * the dt + * @param instant + * the instant * @param format * the format * @return the string */ - static String formatDate(Date dt, String format) { - return formatZonedDate(dt, format, "GMT"); + static String formatInstant(Instant instant, String format) { + return formatZonedInstant(instant, format, "GMT"); } /** - * Format zoned date. + * Format zoned instant. * - * @param dt - * the dt + * @param instant + * the instant * @param format * the format * @param timeZone * the time zone * @return the string */ - static String formatZonedDate(Date dt, String format, String timeZone) { - SimpleDateFormat df = new SimpleDateFormat(format); - df.setTimeZone(TimeZone.getTimeZone(timeZone)); - return df.format(dt); + static String formatZonedInstant(Instant instant, String format, String timeZone) { + return DateTimeFormatter.ofPattern(format, Locale.ENGLISH) + .format(instant.atZone(ZoneId.of(timeZone, ZoneId.SHORT_IDS))); } } diff --git a/src/test/java/org/kohsuke/github/RateLimitCheckerTest.java b/src/test/java/org/kohsuke/github/RateLimitCheckerTest.java index 8192ce0359..55b5fd1076 100644 --- a/src/test/java/org/kohsuke/github/RateLimitCheckerTest.java +++ b/src/test/java/org/kohsuke/github/RateLimitCheckerTest.java @@ -57,6 +57,7 @@ public void testGitHubRateLimit() throws Exception { // Give this a moment Thread.sleep(1000); + //noinspection UseOfObsoleteDateTimeApi templating.testStartDate = new Date(); // ------------------------------------------------------------- // /user gets response with rate limit information From 6c400a0a4bf011afa0bd3fd5e17260a2feb888c2 Mon Sep 17 00:00:00 2001 From: solonovamax Date: Thu, 27 Mar 2025 17:09:05 -0400 Subject: [PATCH 02/10] Apply spotless fixes Signed-off-by: solonovamax --- src/main/java/org/kohsuke/github/GHObject.java | 3 ++- src/main/java/org/kohsuke/github/GHPullRequestReview.java | 3 ++- .../java/org/kohsuke/github/AbstractGitHubWireMockTest.java | 2 +- src/test/java/org/kohsuke/github/AppTest.java | 6 ++---- src/test/java/org/kohsuke/github/GHAppInstallationTest.java | 3 ++- src/test/java/org/kohsuke/github/GHAppTest.java | 4 +++- src/test/java/org/kohsuke/github/GitHubStaticTest.java | 4 +++- src/test/java/org/kohsuke/github/RateLimitCheckerTest.java | 2 +- 8 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHObject.java b/src/main/java/org/kohsuke/github/GHObject.java index 4c2aa21522..1c1fd41695 100644 --- a/src/main/java/org/kohsuke/github/GHObject.java +++ b/src/main/java/org/kohsuke/github/GHObject.java @@ -6,7 +6,6 @@ import org.apache.commons.lang3.builder.ToStringStyle; import org.kohsuke.github.connector.GitHubConnectorResponse; -import javax.annotation.CheckForNull; import java.io.IOException; import java.lang.reflect.Field; import java.net.URL; @@ -14,6 +13,8 @@ import java.util.List; import java.util.Map; +import javax.annotation.CheckForNull; + // TODO: Auto-generated Javadoc /** * Most (all?) domain objects in GitHub seems to have these 4 properties. diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReview.java b/src/main/java/org/kohsuke/github/GHPullRequestReview.java index b6e5b3a738..6237c801c5 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReview.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReview.java @@ -25,11 +25,12 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import javax.annotation.CheckForNull; import java.io.IOException; import java.net.URL; import java.time.Instant; +import javax.annotation.CheckForNull; + // TODO: Auto-generated Javadoc /** * Review to a pull request. diff --git a/src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java b/src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java index f963611862..79f28c0dea 100644 --- a/src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java +++ b/src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java @@ -410,7 +410,7 @@ public TemplatingHelper() { * @return the response template transformer */ public ResponseTemplateTransformer newResponseTransformer() { - //noinspection UnqualifiedFieldAccess + // noinspection UnqualifiedFieldAccess testStartDate = new Date(); return ResponseTemplateTransformer.builder() .global(true) diff --git a/src/test/java/org/kohsuke/github/AppTest.java b/src/test/java/org/kohsuke/github/AppTest.java index 4e6f9da5d5..dcb2fd151c 100755 --- a/src/test/java/org/kohsuke/github/AppTest.java +++ b/src/test/java/org/kohsuke/github/AppTest.java @@ -1212,10 +1212,8 @@ public void testCommitShortInfo() throws Exception { assertThat("doc", equalTo(commit.getCommitShortInfo().getMessage())); assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false)); assertThat(GHVerification.Reason.UNSIGNED, equalTo(commit.getCommitShortInfo().getVerification().getReason())); - assertThat(commit.getCommitShortInfo().getAuthor().getDate().getEpochSecond(), - equalTo(1271650361L)); - assertThat(commit.getCommitShortInfo().getCommitter().getDate().getEpochSecond(), - equalTo(1271650361L)); + assertThat(commit.getCommitShortInfo().getAuthor().getDate().getEpochSecond(), equalTo(1271650361L)); + assertThat(commit.getCommitShortInfo().getCommitter().getDate().getEpochSecond(), equalTo(1271650361L)); } /** diff --git a/src/test/java/org/kohsuke/github/GHAppInstallationTest.java b/src/test/java/org/kohsuke/github/GHAppInstallationTest.java index 443dc275a5..5b9a000d5f 100644 --- a/src/test/java/org/kohsuke/github/GHAppInstallationTest.java +++ b/src/test/java/org/kohsuke/github/GHAppInstallationTest.java @@ -86,7 +86,8 @@ public void testListSuspendedInstallation() throws IOException { assertThat(suspendedBy.getLogin(), equalTo("gilday")); final Instant suspendedAt = appInstallation.getSuspendedAt(); - final Instant expectedSuspendedAt = LocalDateTime.of(2024, Month.FEBRUARY, 26, 2, 43, 12).toInstant(ZoneOffset.UTC); + final Instant expectedSuspendedAt = LocalDateTime.of(2024, Month.FEBRUARY, 26, 2, 43, 12) + .toInstant(ZoneOffset.UTC); assertThat(suspendedAt, equalTo(expectedSuspendedAt)); } diff --git a/src/test/java/org/kohsuke/github/GHAppTest.java b/src/test/java/org/kohsuke/github/GHAppTest.java index 939e8dddea..60cd18ebda 100644 --- a/src/test/java/org/kohsuke/github/GHAppTest.java +++ b/src/test/java/org/kohsuke/github/GHAppTest.java @@ -119,7 +119,9 @@ public void listInstallations() throws IOException { */ @Test public void listInstallationsSince() throws IOException { - Instant localDate = LocalDate.parse("2023-11-01", DateTimeFormatter.ISO_LOCAL_DATE).atStartOfDay().toInstant(ZoneOffset.UTC); + Instant localDate = LocalDate.parse("2023-11-01", DateTimeFormatter.ISO_LOCAL_DATE) + .atStartOfDay() + .toInstant(ZoneOffset.UTC); GHApp app = gitHub.getApp(); List installations = app.listInstallations(localDate).toList(); assertThat(installations.size(), is(1)); diff --git a/src/test/java/org/kohsuke/github/GitHubStaticTest.java b/src/test/java/org/kohsuke/github/GitHubStaticTest.java index 904a7674b6..3ff351994e 100644 --- a/src/test/java/org/kohsuke/github/GitHubStaticTest.java +++ b/src/test/java/org/kohsuke/github/GitHubStaticTest.java @@ -100,7 +100,9 @@ public void timeRoundTrip() { String instantSecondsFormatMillis = formatInstant(instantSeconds, "yyyy-MM-dd'T'HH:mm:ss.S'Z'"); assertThat(instantSecondsFormatMillis, equalTo("2018-08-08T09:40:22.0Z")); - String instantSecondsFormatMillisZoned = formatZonedInstant(instantSeconds, "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ", "PST"); + String instantSecondsFormatMillisZoned = formatZonedInstant(instantSeconds, + "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ", + "PST"); assertThat(instantSecondsFormatMillisZoned, equalTo("2018-08-08T02:40:22.000-07:00")); String instantBadFormat = formatInstant(instantMillis, "yy-MM-dd'T'HH:mm'Z'"); diff --git a/src/test/java/org/kohsuke/github/RateLimitCheckerTest.java b/src/test/java/org/kohsuke/github/RateLimitCheckerTest.java index 55b5fd1076..0c0a1d9b51 100644 --- a/src/test/java/org/kohsuke/github/RateLimitCheckerTest.java +++ b/src/test/java/org/kohsuke/github/RateLimitCheckerTest.java @@ -57,7 +57,7 @@ public void testGitHubRateLimit() throws Exception { // Give this a moment Thread.sleep(1000); - //noinspection UseOfObsoleteDateTimeApi + // noinspection UseOfObsoleteDateTimeApi templating.testStartDate = new Date(); // ------------------------------------------------------------- // /user gets response with rate limit information From 0543261210b026b71a8e3d832ac538f5cb974d9a Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Sat, 5 Apr 2025 18:15:06 -0700 Subject: [PATCH 03/10] Add bridge methods for Data backward compatibility --- pom.xml | 16 ++++- src/main/java/org/kohsuke/github/GHApp.java | 19 +++++- .../org/kohsuke/github/GHAppInstallation.java | 3 + .../github/GHAppInstallationToken.java | 3 + .../java/org/kohsuke/github/GHArtifact.java | 3 + .../java/org/kohsuke/github/GHCheckRun.java | 4 ++ .../org/kohsuke/github/GHCheckRunBuilder.java | 23 +++++++ .../java/org/kohsuke/github/GHCheckSuite.java | 5 +- .../java/org/kohsuke/github/GHCommit.java | 4 ++ .../org/kohsuke/github/GHCommitBuilder.java | 35 ++++++++++ .../kohsuke/github/GHCommitQueryBuilder.java | 27 ++++++++ .../java/org/kohsuke/github/GHDeployKey.java | 4 ++ .../java/org/kohsuke/github/GHEventInfo.java | 2 + .../org/kohsuke/github/GHEventPayload.java | 5 ++ .../org/kohsuke/github/GHExternalGroup.java | 3 + src/main/java/org/kohsuke/github/GHIssue.java | 3 + .../github/GHIssueCommentQueryBuilder.java | 12 ++++ .../java/org/kohsuke/github/GHIssueEvent.java | 3 + .../kohsuke/github/GHIssueQueryBuilder.java | 12 ++++ .../github/GHMarketplacePendingChange.java | 3 + .../kohsuke/github/GHMarketplacePurchase.java | 5 ++ .../github/GHMarketplaceUserPurchase.java | 5 ++ .../java/org/kohsuke/github/GHMilestone.java | 16 +++++ .../kohsuke/github/GHNotificationStream.java | 14 ++++ .../java/org/kohsuke/github/GHObject.java | 4 ++ .../java/org/kohsuke/github/GHPerson.java | 5 ++ .../org/kohsuke/github/GHProjectsV2Item.java | 3 + .../github/GHProjectsV2ItemChanges.java | 6 +- .../org/kohsuke/github/GHPullRequest.java | 3 + .../kohsuke/github/GHPullRequestReview.java | 4 ++ .../java/org/kohsuke/github/GHRateLimit.java | 64 +++++++++++++------ .../java/org/kohsuke/github/GHRelease.java | 16 ++++- .../java/org/kohsuke/github/GHRepository.java | 3 + .../github/GHRepositoryDiscussion.java | 7 +- .../kohsuke/github/GHRepositoryTraffic.java | 6 +- .../java/org/kohsuke/github/GHStargazer.java | 5 +- .../org/kohsuke/github/GHSubscription.java | 3 + .../java/org/kohsuke/github/GHThread.java | 5 +- src/main/java/org/kohsuke/github/GHUser.java | 3 + .../org/kohsuke/github/GHWorkflowJob.java | 8 ++- .../org/kohsuke/github/GHWorkflowRun.java | 6 +- .../java/org/kohsuke/github/GitCommit.java | 6 +- .../github/GitHubBridgeAdapterObject.java | 25 ++++++++ .../java/org/kohsuke/github/GitHubClient.java | 28 ++++++++ .../github/GitHubInteractiveObject.java | 2 +- src/main/java/org/kohsuke/github/GitUser.java | 5 +- .../org/kohsuke/github/RateLimitChecker.java | 5 +- .../org/kohsuke/github/BridgeMethodTest.java | 57 ++++++++++++++++- .../org/kohsuke/github/GHRateLimitTest.java | 20 +++--- 49 files changed, 479 insertions(+), 49 deletions(-) create mode 100644 src/main/java/org/kohsuke/github/GitHubBridgeAdapterObject.java diff --git a/pom.xml b/pom.xml index f1fc1a11a3..0afdabc0be 100644 --- a/pom.xml +++ b/pom.xml @@ -515,7 +515,7 @@ com.github.siom79.japicmp japicmp-maven-plugin - 0.23.0 + 0.23.1 true @@ -563,6 +563,18 @@ + + com.infradna.tool + bridge-method-injector + 1.30 + + + + process + + + + maven-compiler-plugin 3.13.0 @@ -574,7 +586,7 @@ org.jenkins-ci annotation-indexer - 1.17 + 1.18 diff --git a/src/main/java/org/kohsuke/github/GHApp.java b/src/main/java/org/kohsuke/github/GHApp.java index 48e55b4611..de202aa2d5 100644 --- a/src/main/java/org/kohsuke/github/GHApp.java +++ b/src/main/java/org/kohsuke/github/GHApp.java @@ -7,6 +7,7 @@ import java.net.URL; import java.time.Instant; import java.util.Collections; +import java.util.Date; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -145,7 +146,23 @@ public PagedIterable listInstallationRequests() { * @see List installations */ public PagedIterable listInstallations() { - return listInstallations(null); + return listInstallations(GitHubClient.toInstantOrNull(null)); + } + + /** + * Obtains all the installations associated with this app since a given date. + *

+ * You must use a JWT to access this endpoint. + * + * @param since + * - Allows users to get installations that have been updated since a given date. + * @return a list of App installations since a given time. + * @see List installations + * @deprecated use {@link #listInstallations(Instant)} + */ + @Deprecated + public PagedIterable listInstallations(final Date since) { + return listInstallations(since.toInstant()); } /** diff --git a/src/main/java/org/kohsuke/github/GHAppInstallation.java b/src/main/java/org/kohsuke/github/GHAppInstallation.java index 3b60314c44..7764458d5a 100644 --- a/src/main/java/org/kohsuke/github/GHAppInstallation.java +++ b/src/main/java/org/kohsuke/github/GHAppInstallation.java @@ -1,6 +1,7 @@ package org.kohsuke.github; import com.fasterxml.jackson.annotation.JsonProperty; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.kohsuke.github.internal.EnumUtils; @@ -8,6 +9,7 @@ import java.net.URL; import java.time.Instant; import java.util.Collections; +import java.util.Date; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -189,6 +191,7 @@ public GHRepositorySelection getRepositorySelection() { * * @return the suspended at */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getSuspendedAt() { return GitHubClient.parseInstant(suspendedAt); } diff --git a/src/main/java/org/kohsuke/github/GHAppInstallationToken.java b/src/main/java/org/kohsuke/github/GHAppInstallationToken.java index 45bc622b97..339d80cdd2 100644 --- a/src/main/java/org/kohsuke/github/GHAppInstallationToken.java +++ b/src/main/java/org/kohsuke/github/GHAppInstallationToken.java @@ -1,5 +1,7 @@ package org.kohsuke.github; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; + import java.time.Instant; import java.util.*; @@ -67,6 +69,7 @@ public GHRepositorySelection getRepositorySelection() { * * @return date when this token expires */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getExpiresAt() { return GitHubClient.parseInstant(expires_at); } diff --git a/src/main/java/org/kohsuke/github/GHArtifact.java b/src/main/java/org/kohsuke/github/GHArtifact.java index 7ff8aa9633..c9af104ed0 100644 --- a/src/main/java/org/kohsuke/github/GHArtifact.java +++ b/src/main/java/org/kohsuke/github/GHArtifact.java @@ -1,6 +1,7 @@ package org.kohsuke.github; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.apache.commons.lang3.StringUtils; import org.kohsuke.github.function.InputStreamFunction; @@ -8,6 +9,7 @@ import java.io.IOException; import java.net.URL; import java.time.Instant; +import java.util.Date; import java.util.Objects; import static java.util.Objects.requireNonNull; @@ -77,6 +79,7 @@ public boolean isExpired() { * * @return the date of expiration */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getExpiresAt() { return GitHubClient.parseInstant(expiresAt); } diff --git a/src/main/java/org/kohsuke/github/GHCheckRun.java b/src/main/java/org/kohsuke/github/GHCheckRun.java index 6424e294d9..8befbba46b 100644 --- a/src/main/java/org/kohsuke/github/GHCheckRun.java +++ b/src/main/java/org/kohsuke/github/GHCheckRun.java @@ -1,6 +1,7 @@ package org.kohsuke.github; import com.fasterxml.jackson.annotation.JsonProperty; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.kohsuke.github.internal.EnumUtils; @@ -10,6 +11,7 @@ import java.time.Instant; import java.util.Arrays; import java.util.Collections; +import java.util.Date; import java.util.List; import java.util.Locale; @@ -269,6 +271,7 @@ public URL getDetailsUrl() { * * @return Timestamp of the start time */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getStartedAt() { return GitHubClient.parseInstant(startedAt); } @@ -278,6 +281,7 @@ public Instant getStartedAt() { * * @return Timestamp of the completed time */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getCompletedAt() { return GitHubClient.parseInstant(completedAt); } diff --git a/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java b/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java index 31bd90ea7a..642ab2db36 100644 --- a/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java @@ -32,6 +32,7 @@ import java.io.IOException; import java.time.Instant; import java.util.Collections; +import java.util.Date; import java.util.LinkedList; import java.util.List; import java.util.Locale; @@ -165,6 +166,17 @@ private GHCheckRunBuilder(GHRepository repo, Requester requester) { return this; } + /** + * With started at. + * + * @param startedAt + * the started at + * @return the GH check run builder + */ + public @NonNull GHCheckRunBuilder withStartedAt(@CheckForNull Date startedAt) { + return withStartedAt(GitHubClient.toInstantOrNull(startedAt)); + } + /** * With started at. * @@ -179,6 +191,17 @@ private GHCheckRunBuilder(GHRepository repo, Requester requester) { return this; } + /** + * With completed at. + * + * @param completedAt + * the completed at + * @return the GH check run builder + */ + public @NonNull GHCheckRunBuilder withCompletedAt(@CheckForNull Date completedAt) { + return withCompletedAt(GitHubClient.toInstantOrNull(completedAt)); + } + /** * With completed at. * diff --git a/src/main/java/org/kohsuke/github/GHCheckSuite.java b/src/main/java/org/kohsuke/github/GHCheckSuite.java index 2859ef03ea..f6595fa031 100644 --- a/src/main/java/org/kohsuke/github/GHCheckSuite.java +++ b/src/main/java/org/kohsuke/github/GHCheckSuite.java @@ -1,6 +1,7 @@ package org.kohsuke.github; import com.fasterxml.jackson.annotation.JsonProperty; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.IOException; @@ -8,6 +9,7 @@ import java.time.Instant; import java.util.Arrays; import java.util.Collections; +import java.util.Date; import java.util.List; // TODO: Auto-generated Javadoc @@ -210,7 +212,7 @@ public List getPullRequests() throws IOException { /** * The Class HeadCommit. */ - public static class HeadCommit { + public static class HeadCommit extends GitHubBridgeAdapterObject { /** * Create default HeadCommit instance @@ -257,6 +259,7 @@ public String getMessage() { * * @return timestamp of the commit */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getTimestamp() { return GitHubClient.parseInstant(timestamp); } diff --git a/src/main/java/org/kohsuke/github/GHCommit.java b/src/main/java/org/kohsuke/github/GHCommit.java index 3b6838a538..e3d6582f78 100644 --- a/src/main/java/org/kohsuke/github/GHCommit.java +++ b/src/main/java/org/kohsuke/github/GHCommit.java @@ -1,5 +1,6 @@ package org.kohsuke.github; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.IOException; @@ -8,6 +9,7 @@ import java.util.AbstractList; import java.util.ArrayList; import java.util.Collections; +import java.util.Date; import java.util.List; // TODO: Auto-generated Javadoc @@ -471,6 +473,7 @@ public GHUser getAuthor() throws IOException { * @throws IOException * if the information was not already fetched and an attempt at fetching the information failed. */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getAuthoredDate() throws IOException { return getCommitShortInfo().getAuthoredDate(); } @@ -494,6 +497,7 @@ public GHUser getCommitter() throws IOException { * @throws IOException * if the information was not already fetched and an attempt at fetching the information failed. */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getCommitDate() throws IOException { return getCommitShortInfo().getCommitDate(); } diff --git a/src/main/java/org/kohsuke/github/GHCommitBuilder.java b/src/main/java/org/kohsuke/github/GHCommitBuilder.java index 3c509fa581..7dfb40e148 100644 --- a/src/main/java/org/kohsuke/github/GHCommitBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCommitBuilder.java @@ -3,6 +3,7 @@ import java.io.IOException; import java.time.Instant; import java.util.ArrayList; +import java.util.Date; import java.util.List; // TODO: Auto-generated Javadoc @@ -74,6 +75,23 @@ public GHCommitBuilder parent(String parent) { return this; } + /** + * Configures the author of this commit. + * + * @param name + * the name + * @param email + * the email + * @param date + * the date + * @return the gh commit builder + * @deprecated use {@link #author(String, String, Instant)} instead + */ + @Deprecated + public GHCommitBuilder author(String name, String email, Date date) { + return author(name, email, GitHubClient.toInstantOrNull(date)); + } + /** * Configures the author of this commit. * @@ -103,6 +121,23 @@ public GHCommitBuilder withSignature(String signature) { return this; } + /** + * Configures the committer of this commit. + * + * @param name + * the name + * @param email + * the email + * @param date + * the date + * @return the gh commit builder + * @deprecated use {@link #committer(String, String, Instant)} instead + */ + @Deprecated + public GHCommitBuilder committer(String name, String email, Date date) { + return committer(name, email, GitHubClient.toInstantOrNull(date)); + } + /** * Configures the committer of this commit. * diff --git a/src/main/java/org/kohsuke/github/GHCommitQueryBuilder.java b/src/main/java/org/kohsuke/github/GHCommitQueryBuilder.java index 2e6d826b1c..dd4738421d 100644 --- a/src/main/java/org/kohsuke/github/GHCommitQueryBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCommitQueryBuilder.java @@ -1,6 +1,7 @@ package org.kohsuke.github; import java.time.Instant; +import java.util.Date; // TODO: Auto-generated Javadoc /** @@ -82,6 +83,19 @@ public GHCommitQueryBuilder pageSize(int pageSize) { return this; } + /** + * Only commits after this date will be returned. + * + * @param dt + * the dt + * @return the gh commit query builder + * @deprecated use {@link #since(Instant)} + */ + @Deprecated + public GHCommitQueryBuilder since(Date dt) { + return since(GitHubClient.toInstantOrNull(dt)); + } + /** * Only commits after this date will be returned. * @@ -105,6 +119,19 @@ public GHCommitQueryBuilder since(long timestamp) { return since(Instant.ofEpochMilli(timestamp)); } + /** + * Only commits before this date will be returned. + * + * @param dt + * the dt + * @return the gh commit query builder + * @deprecated use {@link #until(Instant)} + */ + @Deprecated + public GHCommitQueryBuilder until(Date dt) { + return until(GitHubClient.toInstantOrNull(dt)); + } + /** * Only commits before this date will be returned. * diff --git a/src/main/java/org/kohsuke/github/GHDeployKey.java b/src/main/java/org/kohsuke/github/GHDeployKey.java index c4c5048e8c..7cd64c8e02 100644 --- a/src/main/java/org/kohsuke/github/GHDeployKey.java +++ b/src/main/java/org/kohsuke/github/GHDeployKey.java @@ -1,9 +1,11 @@ package org.kohsuke.github; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import org.apache.commons.lang3.builder.ToStringBuilder; import java.io.IOException; import java.time.Instant; +import java.util.Date; // TODO: Auto-generated Javadoc /** @@ -89,6 +91,7 @@ public boolean isVerified() { * * @return the created_at */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getCreatedAt() { return GitHubClient.parseInstant(created_at); } @@ -98,6 +101,7 @@ public Instant getCreatedAt() { * * @return the last_used */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getLastUsedAt() { return GitHubClient.parseInstant(last_used); } diff --git a/src/main/java/org/kohsuke/github/GHEventInfo.java b/src/main/java/org/kohsuke/github/GHEventInfo.java index 3637189d5f..8238f04a06 100644 --- a/src/main/java/org/kohsuke/github/GHEventInfo.java +++ b/src/main/java/org/kohsuke/github/GHEventInfo.java @@ -1,6 +1,7 @@ package org.kohsuke.github; import com.fasterxml.jackson.databind.node.ObjectNode; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.IOException; @@ -129,6 +130,7 @@ public long getId() { * * @return the created at */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getCreatedAt() { return GitHubClient.parseInstant(created_at); } diff --git a/src/main/java/org/kohsuke/github/GHEventPayload.java b/src/main/java/org/kohsuke/github/GHEventPayload.java index c091f30f5b..592a04e28f 100644 --- a/src/main/java/org/kohsuke/github/GHEventPayload.java +++ b/src/main/java/org/kohsuke/github/GHEventPayload.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonSetter; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.IOException; @@ -9,6 +10,7 @@ import java.time.Instant; import java.util.ArrayList; import java.util.Collections; +import java.util.Date; import java.util.List; import java.util.Map; @@ -1363,9 +1365,11 @@ public List getModified() { * * @return the timestamp */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getTimestamp() { return GitHubClient.parseInstant(timestamp); } + } } @@ -1809,6 +1813,7 @@ public Star() { * * @return the date when the star is added */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getStarredAt() { return GitHubClient.parseInstant(starredAt); } diff --git a/src/main/java/org/kohsuke/github/GHExternalGroup.java b/src/main/java/org/kohsuke/github/GHExternalGroup.java index 3a2944988d..c40608d0f5 100644 --- a/src/main/java/org/kohsuke/github/GHExternalGroup.java +++ b/src/main/java/org/kohsuke/github/GHExternalGroup.java @@ -1,10 +1,12 @@ package org.kohsuke.github; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.IOException; import java.time.Instant; import java.util.Collections; +import java.util.Date; import java.util.List; /** @@ -223,6 +225,7 @@ public String getName() { * * @return the date */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getUpdatedAt() { return GitHubClient.parseInstant(updatedAt); } diff --git a/src/main/java/org/kohsuke/github/GHIssue.java b/src/main/java/org/kohsuke/github/GHIssue.java index 992931125d..668a74b4d0 100644 --- a/src/main/java/org/kohsuke/github/GHIssue.java +++ b/src/main/java/org/kohsuke/github/GHIssue.java @@ -24,6 +24,7 @@ package org.kohsuke.github; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.apache.commons.lang3.StringUtils; import org.kohsuke.github.internal.EnumUtils; @@ -35,6 +36,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -234,6 +236,7 @@ public Collection getLabels() { * * @return the closed at */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getClosedAt() { return GitHubClient.parseInstant(closed_at); } diff --git a/src/main/java/org/kohsuke/github/GHIssueCommentQueryBuilder.java b/src/main/java/org/kohsuke/github/GHIssueCommentQueryBuilder.java index 221553c433..b75a6deefe 100644 --- a/src/main/java/org/kohsuke/github/GHIssueCommentQueryBuilder.java +++ b/src/main/java/org/kohsuke/github/GHIssueCommentQueryBuilder.java @@ -1,6 +1,7 @@ package org.kohsuke.github; import java.time.Instant; +import java.util.Date; // TODO: Auto-generated Javadoc /** @@ -34,6 +35,17 @@ public class GHIssueCommentQueryBuilder { this.req = issue.root().createRequest().withUrlPath(issue.getIssuesApiRoute() + "/comments"); } + /** + * Only comments created/updated after this date will be returned. + * + * @param date + * the date + * @return the query builder + */ + public GHIssueCommentQueryBuilder since(Date date) { + return since(GitHubClient.toInstantOrNull(date)); + } + /** * Only comments created/updated after this date will be returned. * diff --git a/src/main/java/org/kohsuke/github/GHIssueEvent.java b/src/main/java/org/kohsuke/github/GHIssueEvent.java index 553b3343a8..11193e2634 100644 --- a/src/main/java/org/kohsuke/github/GHIssueEvent.java +++ b/src/main/java/org/kohsuke/github/GHIssueEvent.java @@ -1,8 +1,10 @@ package org.kohsuke.github; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.time.Instant; +import java.util.Date; // TODO: Auto-generated Javadoc /** @@ -105,6 +107,7 @@ public String getCommitUrl() { * * @return the created at */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getCreatedAt() { return GitHubClient.parseInstant(created_at); } diff --git a/src/main/java/org/kohsuke/github/GHIssueQueryBuilder.java b/src/main/java/org/kohsuke/github/GHIssueQueryBuilder.java index af2977e158..5de811d117 100644 --- a/src/main/java/org/kohsuke/github/GHIssueQueryBuilder.java +++ b/src/main/java/org/kohsuke/github/GHIssueQueryBuilder.java @@ -2,6 +2,7 @@ import java.time.Instant; import java.util.ArrayList; +import java.util.Date; import java.util.List; // TODO: Auto-generated Javadoc @@ -72,6 +73,17 @@ public GHIssueQueryBuilder direction(GHDirection direction) { return this; } + /** + * Only issues after this date will be returned. + * + * @param date + * the date + * @return the gh issue query builder + */ + public GHIssueQueryBuilder since(Date date) { + return since(GitHubClient.toInstantOrNull(date)); + } + /** * Only issues after this date will be returned. * diff --git a/src/main/java/org/kohsuke/github/GHMarketplacePendingChange.java b/src/main/java/org/kohsuke/github/GHMarketplacePendingChange.java index 99107a0184..1dcb83a43e 100644 --- a/src/main/java/org/kohsuke/github/GHMarketplacePendingChange.java +++ b/src/main/java/org/kohsuke/github/GHMarketplacePendingChange.java @@ -1,8 +1,10 @@ package org.kohsuke.github; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.time.Instant; +import java.util.Date; // TODO: Auto-generated Javadoc /** @@ -59,6 +61,7 @@ public GHMarketplacePlan getPlan() { * * @return the effective date */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getEffectiveDate() { return GitHubClient.parseInstant(effectiveDate); } diff --git a/src/main/java/org/kohsuke/github/GHMarketplacePurchase.java b/src/main/java/org/kohsuke/github/GHMarketplacePurchase.java index 8bdb9c5c16..25a06c0ef0 100644 --- a/src/main/java/org/kohsuke/github/GHMarketplacePurchase.java +++ b/src/main/java/org/kohsuke/github/GHMarketplacePurchase.java @@ -1,8 +1,10 @@ package org.kohsuke.github; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.time.Instant; +import java.util.Date; // TODO: Auto-generated Javadoc /** @@ -42,6 +44,7 @@ public String getBillingCycle() { * * @return the next billing date */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getNextBillingDate() { return GitHubClient.parseInstant(nextBillingDate); } @@ -60,6 +63,7 @@ public boolean isOnFreeTrial() { * * @return the free trial ends on */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getFreeTrialEndsOn() { return GitHubClient.parseInstant(freeTrialEndsOn); } @@ -78,6 +82,7 @@ public Long getUnitCount() { * * @return the updated at */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getUpdatedAt() { return GitHubClient.parseInstant(updatedAt); } diff --git a/src/main/java/org/kohsuke/github/GHMarketplaceUserPurchase.java b/src/main/java/org/kohsuke/github/GHMarketplaceUserPurchase.java index 79078fae43..cd981ef0ec 100644 --- a/src/main/java/org/kohsuke/github/GHMarketplaceUserPurchase.java +++ b/src/main/java/org/kohsuke/github/GHMarketplaceUserPurchase.java @@ -1,8 +1,10 @@ package org.kohsuke.github; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.time.Instant; +import java.util.Date; // TODO: Auto-generated Javadoc /** @@ -44,6 +46,7 @@ public String getBillingCycle() { * * @return the next billing date */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getNextBillingDate() { return GitHubClient.parseInstant(nextBillingDate); } @@ -62,6 +65,7 @@ public boolean isOnFreeTrial() { * * @return the free trial ends on */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getFreeTrialEndsOn() { return GitHubClient.parseInstant(freeTrialEndsOn); } @@ -80,6 +84,7 @@ public Long getUnitCount() { * * @return the updated at */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getUpdatedAt() { return GitHubClient.parseInstant(updatedAt); } diff --git a/src/main/java/org/kohsuke/github/GHMilestone.java b/src/main/java/org/kohsuke/github/GHMilestone.java index 7937ab8f1b..453d17f4fc 100644 --- a/src/main/java/org/kohsuke/github/GHMilestone.java +++ b/src/main/java/org/kohsuke/github/GHMilestone.java @@ -1,10 +1,12 @@ package org.kohsuke.github; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.IOException; import java.net.URL; import java.time.Instant; +import java.util.Date; import java.util.Locale; // TODO: Auto-generated Javadoc @@ -56,6 +58,7 @@ public GHUser getCreator() { * * @return the due on */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getDueOn() { if (due_on == null) return null; @@ -67,6 +70,7 @@ public Instant getDueOn() { * * @return the closed at */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getClosedAt() { return GitHubClient.parseInstant(closed_at); } @@ -192,6 +196,18 @@ public void setDescription(String description) throws IOException { edit("description", description); } + /** + * Sets due on. + * + * @param dueOn + * the due on + * @throws IOException + * the io exception + */ + public void setDueOn(Date dueOn) throws IOException { + setDueOn(GitHubClient.toInstantOrNull(dueOn)); + } + /** * Sets due on. * diff --git a/src/main/java/org/kohsuke/github/GHNotificationStream.java b/src/main/java/org/kohsuke/github/GHNotificationStream.java index b74062236f..c5a355a935 100644 --- a/src/main/java/org/kohsuke/github/GHNotificationStream.java +++ b/src/main/java/org/kohsuke/github/GHNotificationStream.java @@ -2,6 +2,7 @@ import java.io.IOException; import java.time.Instant; +import java.util.Date; import java.util.Iterator; import java.util.NoSuchElementException; @@ -78,6 +79,19 @@ public GHNotificationStream since(long timestamp) { return since(Instant.ofEpochMilli(timestamp)); } + /** + * Since gh notification stream. + * + * @param dt + * the dt + * @return the gh notification stream + * @deprecated {@link #since(Instant)} + */ + @Deprecated + public GHNotificationStream since(Date dt) { + return since(GitHubClient.toInstantOrNull(dt)); + } + /** * Since gh notification stream. * diff --git a/src/main/java/org/kohsuke/github/GHObject.java b/src/main/java/org/kohsuke/github/GHObject.java index 1c1fd41695..ebd24372ad 100644 --- a/src/main/java/org/kohsuke/github/GHObject.java +++ b/src/main/java/org/kohsuke/github/GHObject.java @@ -1,6 +1,7 @@ package org.kohsuke.github; import com.fasterxml.jackson.annotation.JacksonInject; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; @@ -10,6 +11,7 @@ import java.lang.reflect.Field; import java.net.URL; import java.time.Instant; +import java.util.Date; import java.util.List; import java.util.Map; @@ -78,6 +80,7 @@ public Map> getResponseHeaderFields() { * @throws IOException * on error */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getCreatedAt() throws IOException { return GitHubClient.parseInstant(createdAt); } @@ -98,6 +101,7 @@ public URL getUrl() { * @throws IOException * on error */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getUpdatedAt() throws IOException { return GitHubClient.parseInstant(updatedAt); } diff --git a/src/main/java/org/kohsuke/github/GHPerson.java b/src/main/java/org/kohsuke/github/GHPerson.java index e2a65a4696..a2ed44c047 100644 --- a/src/main/java/org/kohsuke/github/GHPerson.java +++ b/src/main/java/org/kohsuke/github/GHPerson.java @@ -1,10 +1,13 @@ package org.kohsuke.github; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; + import java.io.FileNotFoundException; import java.io.IOException; import java.net.URL; import java.time.Instant; import java.util.Collections; +import java.util.Date; import java.util.Map; import java.util.Optional; import java.util.TreeMap; @@ -208,6 +211,7 @@ public String getTwitterUsername() throws IOException { * @throws IOException * Signals that an I/O exception has occurred. */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getCreatedAt() throws IOException { populate(); return super.getCreatedAt(); @@ -220,6 +224,7 @@ public Instant getCreatedAt() throws IOException { * @throws IOException * Signals that an I/O exception has occurred. */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getUpdatedAt() throws IOException { populate(); return super.getUpdatedAt(); diff --git a/src/main/java/org/kohsuke/github/GHProjectsV2Item.java b/src/main/java/org/kohsuke/github/GHProjectsV2Item.java index 143dd9f656..6e6075e18c 100644 --- a/src/main/java/org/kohsuke/github/GHProjectsV2Item.java +++ b/src/main/java/org/kohsuke/github/GHProjectsV2Item.java @@ -1,9 +1,11 @@ package org.kohsuke.github; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import org.kohsuke.github.internal.EnumUtils; import java.net.URL; import java.time.Instant; +import java.util.Date; // TODO: Auto-generated Javadoc /** @@ -76,6 +78,7 @@ public GHUser getCreator() { * * @return the archived at */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getArchivedAt() { return GitHubClient.parseInstant(archivedAt); } diff --git a/src/main/java/org/kohsuke/github/GHProjectsV2ItemChanges.java b/src/main/java/org/kohsuke/github/GHProjectsV2ItemChanges.java index 336642512e..e703cb6577 100644 --- a/src/main/java/org/kohsuke/github/GHProjectsV2ItemChanges.java +++ b/src/main/java/org/kohsuke/github/GHProjectsV2ItemChanges.java @@ -1,9 +1,11 @@ package org.kohsuke.github; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.kohsuke.github.internal.EnumUtils; import java.time.Instant; +import java.util.Date; // TODO: Auto-generated Javadoc /** @@ -12,7 +14,7 @@ * Note that this is best effort only as nothing is documented in the GitHub documentation. */ @SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD" }, justification = "JSON API") -public class GHProjectsV2ItemChanges { +public class GHProjectsV2ItemChanges extends GitHubBridgeAdapterObject { /** * Create default GHProjectsV2ItemChanges instance @@ -138,6 +140,7 @@ public FromToDate() { * * @return the from */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getFrom() { return GitHubClient.parseInstant(from); } @@ -147,6 +150,7 @@ public Instant getFrom() { * * @return the to */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getTo() { return GitHubClient.parseInstant(to); } diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index 33f5f2cb6f..28920f58e5 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -23,6 +23,7 @@ */ package org.kohsuke.github; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.apache.commons.lang3.StringUtils; @@ -32,6 +33,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.Date; import java.util.List; import java.util.Objects; @@ -170,6 +172,7 @@ public URL getDiffUrl() { * * @return the merged at */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getMergedAt() { return GitHubClient.parseInstant(merged_at); } diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReview.java b/src/main/java/org/kohsuke/github/GHPullRequestReview.java index 6237c801c5..6e1bbab3cc 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReview.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReview.java @@ -23,11 +23,13 @@ */ package org.kohsuke.github; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.IOException; import java.net.URL; import java.time.Instant; +import java.util.Date; import javax.annotation.CheckForNull; @@ -144,6 +146,7 @@ protected String getApiRoute() { * * @return the submitted at */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getSubmittedAt() { return GitHubClient.parseInstant(submitted_at); } @@ -156,6 +159,7 @@ public Instant getSubmittedAt() { * Signals that an I/O exception has occurred. */ @Override + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getCreatedAt() throws IOException { return getSubmittedAt(); } diff --git a/src/main/java/org/kohsuke/github/GHRateLimit.java b/src/main/java/org/kohsuke/github/GHRateLimit.java index e76f288763..9fcb290d28 100644 --- a/src/main/java/org/kohsuke/github/GHRateLimit.java +++ b/src/main/java/org/kohsuke/github/GHRateLimit.java @@ -12,6 +12,7 @@ import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; +import java.util.Date; import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Logger; @@ -129,9 +130,11 @@ static GHRateLimit fromRecord(@Nonnull Record record, @Nonnull RateLimitTarget r * Returns the date at which the Core API rate limit will reset. * * @return the calculated date at which the rate limit has or will reset. + * @deprecated use {@link #getCore()} */ @Nonnull - public Instant getResetDate() { + @Deprecated + public Date getResetDate() { return getCore().getResetDate(); } @@ -140,7 +143,9 @@ public Instant getResetDate() { * * @return an integer * @since 1.100 + * @deprecated use {@link #getCore()} */ + @Deprecated public int getRemaining() { return getCore().getRemaining(); } @@ -150,7 +155,9 @@ public int getRemaining() { * * @return an integer * @since 1.100 + * @deprecated use {@link #getCore()} */ + @Deprecated public int getLimit() { return getCore().getLimit(); } @@ -160,7 +167,9 @@ public int getLimit() { * * @return a long * @since 1.100 + * @deprecated use {@link #getCore()} */ + @Deprecated public long getResetEpochSeconds() { return getCore().getResetEpochSeconds(); } @@ -170,7 +179,9 @@ public long getResetEpochSeconds() { * * @return true if the rate limit reset date has passed. Otherwise false. * @since 1.100 + * @deprecated use {@link #getCore()} */ + @Deprecated public boolean isExpired() { return getCore().isExpired(); } @@ -412,11 +423,11 @@ public static class Record { * The date at which the rate limit will reset, adjusted to local machine time if the local machine's clock not * synchronized with to the same clock as the GitHub server. * - * @see #calculateResetDate(String) - * @see #getResetDate() + * @see #calculateResetInstant(String) + * @see #getResetInstant() */ @Nonnull - private final Instant resetDate; + private final Instant resetInstant; /** * Instantiates a new Record. @@ -458,7 +469,7 @@ public Record(@JsonProperty(value = "limit", required = true) int limit, if (connectorResponse != null) { updatedAt = connectorResponse.header("Date"); } - this.resetDate = calculateResetDate(updatedAt); + this.resetInstant = calculateResetInstant(updatedAt); } /** @@ -508,11 +519,11 @@ && getRemaining() <= other.getRemaining())) { } /** - * Recalculates the {@link #resetDate} relative to the local machine clock. + * Recalculates the {@link #resetInstant} relative to the local machine clock. *

- * {@link RateLimitChecker}s and {@link RateLimitHandler}s use {@link #getResetDate()} to make decisions about - * how long to wait for until for the rate limit to reset. That means that {@link #getResetDate()} needs to be - * calculated based on the local machine clock. + * {@link RateLimitChecker}s and {@link RateLimitHandler}s use {@link #getResetInstant()} to make decisions + * about how long to wait for until for the rate limit to reset. That means that {@link #getResetInstant()} + * needs to be calculated based on the local machine clock. *

*

* When we say that the clock on two machines is "synchronized", we mean that the UTC time returned from @@ -535,7 +546,7 @@ && getRemaining() <= other.getRemaining())) { * @return reset date based on the passed date */ @Nonnull - private Instant calculateResetDate(@CheckForNull String updatedAt) { + private Instant calculateResetInstant(@CheckForNull String updatedAt) { long updatedAtEpochSeconds = createdAtEpochSeconds; if (!StringUtils.isBlank(updatedAt)) { try { @@ -578,10 +589,10 @@ public int getLimit() { * * This is the raw value returned by the server. This value is not adjusted if local machine time is not * synchronized with server time. If attempting to check when the rate limit will reset, use - * {@link #getResetDate()} or implement a {@link RateLimitChecker} instead. + * {@link #getResetInstant()} or implement a {@link RateLimitChecker} instead. * * @return a long representing the time in epoch seconds when the rate limit will reset - * @see #getResetDate() + * @see #getResetInstant() */ public long getResetEpochSeconds() { return resetEpochSeconds; @@ -595,7 +606,7 @@ public long getResetEpochSeconds() { * @return true if the rate limit reset date has passed. Otherwise false. */ public boolean isExpired() { - return getResetDate().toEpochMilli() < System.currentTimeMillis(); + return getResetInstant().toEpochMilli() < System.currentTimeMillis(); } /** @@ -605,10 +616,25 @@ public boolean isExpired() { * If attempting to wait for the rate limit to reset, consider implementing a {@link RateLimitChecker} instead. * * @return the calculated date at which the rate limit has or will reset. + * @deprecated Use {@link #getResetInstant()} */ @Nonnull - public Instant getResetDate() { - return resetDate; + @Deprecated + public Date getResetDate() { + return Date.from(getResetInstant()); + } + + /** + * The Instant at which the rate limit will reset, adjusted to local machine time if the local machine's clock + * not synchronized with to the same clock as the GitHub server. + * + * If attempting to wait for the rate limit to reset, consider implementing a {@link RateLimitChecker} instead. + * + * @return the calculated date at which the rate limit has or will reset. + */ + @Nonnull + public Instant getResetInstant() { + return resetInstant; } /** @@ -618,8 +644,8 @@ public Instant getResetDate() { */ @Override public String toString() { - return "{" + "remaining=" + getRemaining() + ", limit=" + getLimit() + ", resetDate=" + getResetDate() - + '}'; + return "{" + "remaining=" + getRemaining() + ", limit=" + getLimit() + ", resetDate=" + + GitHubClient.printInstant(getResetInstant()) + '}'; } /** @@ -640,7 +666,7 @@ public boolean equals(Object o) { Record record = (Record) o; return getRemaining() == record.getRemaining() && getLimit() == record.getLimit() && getResetEpochSeconds() == record.getResetEpochSeconds() - && getResetDate().equals(record.getResetDate()); + && getResetInstant().equals(record.getResetInstant()); } /** @@ -650,7 +676,7 @@ && getResetEpochSeconds() == record.getResetEpochSeconds() */ @Override public int hashCode() { - return Objects.hash(getRemaining(), getLimit(), getResetEpochSeconds(), getResetDate()); + return Objects.hash(getRemaining(), getLimit(), getResetEpochSeconds(), getResetInstant()); } } diff --git a/src/main/java/org/kohsuke/github/GHRelease.java b/src/main/java/org/kohsuke/github/GHRelease.java index 409ea90558..5647191bde 100644 --- a/src/main/java/org/kohsuke/github/GHRelease.java +++ b/src/main/java/org/kohsuke/github/GHRelease.java @@ -10,6 +10,7 @@ import java.net.URLEncoder; import java.time.Instant; import java.util.Collections; +import java.util.Date; import java.util.List; import static java.lang.String.format; @@ -42,7 +43,7 @@ public GHRelease() { private String body; private boolean draft; private boolean prerelease; - private Instant published_at; + private String published_at; private String tarball_url; private String zipball_url; private String discussion_url; @@ -135,8 +136,17 @@ public boolean isPrerelease() { * * @return the published at */ - public Instant getPublished_at() { - return published_at; + public Date getPublished_at() { + return Date.from(getPublishedAt()); + } + + /** + * Gets published at. + * + * @return the published at + */ + public Instant getPublishedAt() { + return GitHubClient.parseInstant(published_at); } /** diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 5613f33fec..baa02bbd09 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -24,6 +24,7 @@ package org.kohsuke.github; import com.fasterxml.jackson.annotation.JsonProperty; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.CheckForNull; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @@ -41,6 +42,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; @@ -815,6 +817,7 @@ public int getSubscribersCount() { * * @return null if the repository was never pushed at. */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getPushedAt() { return GitHubClient.parseInstant(pushed_at); } diff --git a/src/main/java/org/kohsuke/github/GHRepositoryDiscussion.java b/src/main/java/org/kohsuke/github/GHRepositoryDiscussion.java index fb182d59e6..7c1195114c 100644 --- a/src/main/java/org/kohsuke/github/GHRepositoryDiscussion.java +++ b/src/main/java/org/kohsuke/github/GHRepositoryDiscussion.java @@ -1,9 +1,11 @@ package org.kohsuke.github; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import org.kohsuke.github.internal.EnumUtils; import java.net.URL; import java.time.Instant; +import java.util.Date; // TODO: Auto-generated Javadoc /** @@ -69,6 +71,7 @@ public URL getAnswerHtmlUrl() { * * @return the answer chosen at */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getAnswerChosenAt() { return GitHubClient.parseInstant(answerChosenAt); } @@ -191,7 +194,7 @@ public String getTimelineUrl() { * "https://docs.github.com/en/graphql/guides/using-the-graphql-api-for-discussions#discussioncategory">The * GraphQL API for Discussions */ - public static class Category { + public static class Category extends GitHubBridgeAdapterObject { /** * Create default Category instance @@ -269,6 +272,7 @@ public String getDescription() { * * @return the created at */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getCreatedAt() { return GitHubClient.parseInstant(createdAt); } @@ -278,6 +282,7 @@ public Instant getCreatedAt() { * * @return the updated at */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getUpdatedAt() { return GitHubClient.parseInstant(updatedAt); } diff --git a/src/main/java/org/kohsuke/github/GHRepositoryTraffic.java b/src/main/java/org/kohsuke/github/GHRepositoryTraffic.java index 035e71735c..63bd6bcc98 100644 --- a/src/main/java/org/kohsuke/github/GHRepositoryTraffic.java +++ b/src/main/java/org/kohsuke/github/GHRepositoryTraffic.java @@ -1,13 +1,16 @@ package org.kohsuke.github; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; + import java.time.Instant; +import java.util.Date; import java.util.List; // TODO: Auto-generated Javadoc /** * The type GHRepositoryTraffic. */ -public abstract class GHRepositoryTraffic implements TrafficInfo { +public abstract class GHRepositoryTraffic extends GitHubBridgeAdapterObject implements TrafficInfo { private int count; private int uniques; @@ -68,6 +71,7 @@ public static abstract class DailyInfo implements TrafficInfo { * * @return the timestamp */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getTimestamp() { return GitHubClient.parseInstant(timestamp); } diff --git a/src/main/java/org/kohsuke/github/GHStargazer.java b/src/main/java/org/kohsuke/github/GHStargazer.java index 753b6ea2a2..1f41a4e0e2 100644 --- a/src/main/java/org/kohsuke/github/GHStargazer.java +++ b/src/main/java/org/kohsuke/github/GHStargazer.java @@ -1,8 +1,10 @@ package org.kohsuke.github; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.time.Instant; +import java.util.Date; // TODO: Auto-generated Javadoc /** @@ -11,7 +13,7 @@ * @author noctarius */ @SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" }, justification = "JSON API") -public class GHStargazer { +public class GHStargazer extends GitHubBridgeAdapterObject { /** * Create default GHStargazer instance @@ -39,6 +41,7 @@ public GHRepository getRepository() { * * @return the date the stargazer was added */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getStarredAt() { return GitHubClient.parseInstant(starred_at); } diff --git a/src/main/java/org/kohsuke/github/GHSubscription.java b/src/main/java/org/kohsuke/github/GHSubscription.java index f787036b99..d2bac440c8 100644 --- a/src/main/java/org/kohsuke/github/GHSubscription.java +++ b/src/main/java/org/kohsuke/github/GHSubscription.java @@ -1,9 +1,11 @@ package org.kohsuke.github; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.IOException; import java.time.Instant; +import java.util.Date; // TODO: Auto-generated Javadoc /** @@ -31,6 +33,7 @@ public GHSubscription() { * * @return the created at */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getCreatedAt() { return GitHubClient.parseInstant(created_at); } diff --git a/src/main/java/org/kohsuke/github/GHThread.java b/src/main/java/org/kohsuke/github/GHThread.java index dbdd4244b1..5666ba056e 100644 --- a/src/main/java/org/kohsuke/github/GHThread.java +++ b/src/main/java/org/kohsuke/github/GHThread.java @@ -1,10 +1,12 @@ package org.kohsuke.github; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.FileNotFoundException; import java.io.IOException; import java.time.Instant; +import java.util.Date; // TODO: Auto-generated Javadoc /** @@ -27,7 +29,7 @@ public class GHThread extends GHObject { /** * The Class Subject. */ - static class Subject { + static class Subject extends GitHubBridgeAdapterObject { /** The title. */ String title; @@ -50,6 +52,7 @@ private GHThread() {// no external construction allowed * * @return the last read at */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getLastReadAt() { return GitHubClient.parseInstant(last_read_at); } diff --git a/src/main/java/org/kohsuke/github/GHUser.java b/src/main/java/org/kohsuke/github/GHUser.java index 8851f69270..376238188f 100644 --- a/src/main/java/org/kohsuke/github/GHUser.java +++ b/src/main/java/org/kohsuke/github/GHUser.java @@ -23,6 +23,8 @@ */ package org.kohsuke.github; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; + import java.io.IOException; import java.time.Instant; import java.util.*; @@ -274,6 +276,7 @@ public Optional getLdapDn() throws IOException { * @throws IOException * on error */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getSuspendedAt() throws IOException { super.populate(); return GitHubClient.parseInstant(suspendedAt); diff --git a/src/main/java/org/kohsuke/github/GHWorkflowJob.java b/src/main/java/org/kohsuke/github/GHWorkflowJob.java index 8aa912dcf1..9b0a4956ec 100644 --- a/src/main/java/org/kohsuke/github/GHWorkflowJob.java +++ b/src/main/java/org/kohsuke/github/GHWorkflowJob.java @@ -1,6 +1,7 @@ package org.kohsuke.github; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.apache.commons.lang3.StringUtils; import org.kohsuke.github.GHWorkflowRun.Conclusion; @@ -12,6 +13,7 @@ import java.time.Instant; import java.util.ArrayList; import java.util.Collections; +import java.util.Date; import java.util.List; import java.util.Objects; @@ -83,6 +85,7 @@ public String getHeadSha() { * * @return start date */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getStartedAt() { return GitHubClient.parseInstant(startedAt); } @@ -92,6 +95,7 @@ public Instant getStartedAt() { * * @return completion date */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getCompletedAt() { return GitHubClient.parseInstant(completedAt); } @@ -262,7 +266,7 @@ GHWorkflowJob wrapUp(GHRepository owner) { /** * The Class Step. */ - public static class Step { + public static class Step extends GitHubBridgeAdapterObject { /** * Create default Step instance @@ -302,6 +306,7 @@ public int getNumber() { * * @return start date */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getStartedAt() { return GitHubClient.parseInstant(startedAt); } @@ -311,6 +316,7 @@ public Instant getStartedAt() { * * @return completion date */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getCompletedAt() { return GitHubClient.parseInstant(completedAt); } diff --git a/src/main/java/org/kohsuke/github/GHWorkflowRun.java b/src/main/java/org/kohsuke/github/GHWorkflowRun.java index d62a3377b9..760cffcb26 100644 --- a/src/main/java/org/kohsuke/github/GHWorkflowRun.java +++ b/src/main/java/org/kohsuke/github/GHWorkflowRun.java @@ -1,6 +1,7 @@ package org.kohsuke.github; import com.fasterxml.jackson.annotation.JsonProperty; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.apache.commons.lang3.StringUtils; import org.kohsuke.github.function.InputStreamFunction; @@ -11,6 +12,7 @@ import java.time.Instant; import java.util.Arrays; import java.util.Collections; +import java.util.Date; import java.util.List; import java.util.Locale; import java.util.Objects; @@ -114,6 +116,7 @@ public long getRunAttempt() { * * @return run triggered */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getRunStartedAt() { return GitHubClient.parseInstant(runStartedAt); } @@ -440,7 +443,7 @@ GHWorkflowRun wrapUp(GitHub root) { /** * The Class HeadCommit. */ - public static class HeadCommit { + public static class HeadCommit extends GitHubBridgeAdapterObject { /** * Create default HeadCommit instance @@ -487,6 +490,7 @@ public String getMessage() { * * @return timestamp of the commit */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getTimestamp() { return GitHubClient.parseInstant(timestamp); } diff --git a/src/main/java/org/kohsuke/github/GitCommit.java b/src/main/java/org/kohsuke/github/GitCommit.java index f8b7849883..d7a2768973 100644 --- a/src/main/java/org/kohsuke/github/GitCommit.java +++ b/src/main/java/org/kohsuke/github/GitCommit.java @@ -1,10 +1,12 @@ package org.kohsuke.github; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.time.Instant; import java.util.AbstractList; import java.util.Collections; +import java.util.Date; import java.util.List; // TODO: Auto-generated Javadoc @@ -16,7 +18,7 @@ */ @SuppressFBWarnings(value = { "NP_UNWRITTEN_FIELD", "UWF_UNWRITTEN_FIELD" }, justification = "JSON API") -public class GitCommit { +public class GitCommit extends GitHubBridgeAdapterObject { private GHRepository owner; private String sha, node_id, url, html_url; private GitUser author; @@ -159,6 +161,7 @@ public GitUser getAuthor() { * * @return the authored date */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getAuthoredDate() { return author.getDate(); } @@ -177,6 +180,7 @@ public GitUser getCommitter() { * * @return the commit date */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getCommitDate() { return committer.getDate(); } diff --git a/src/main/java/org/kohsuke/github/GitHubBridgeAdapterObject.java b/src/main/java/org/kohsuke/github/GitHubBridgeAdapterObject.java new file mode 100644 index 0000000000..3477c96013 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GitHubBridgeAdapterObject.java @@ -0,0 +1,25 @@ +package org.kohsuke.github; + +import java.time.Instant; +import java.util.Date; + +/** + * Defines a base class that holds bridge adapter methods. + * + * @author Liam Newman + */ +abstract class GitHubBridgeAdapterObject { + /** + * Instantiates a new git hub bridge adapter object. + */ + GitHubBridgeAdapterObject() { + } + + // Used by bridge method to convert Instant to Date + Object instantToDate(Instant value, Class type) { + if (value == null) + return null; + + return Date.from(value); + } +} diff --git a/src/main/java/org/kohsuke/github/GitHubClient.java b/src/main/java/org/kohsuke/github/GitHubClient.java index 750546992f..76826083cf 100644 --- a/src/main/java/org/kohsuke/github/GitHubClient.java +++ b/src/main/java/org/kohsuke/github/GitHubClient.java @@ -875,6 +875,34 @@ static URL parseURL(String s) { } } + /** + * Parses the date. + * + * @param timestamp + * the timestamp + * @return the date + */ + static Date parseDate(String timestamp) { + if (timestamp == null) + return null; + + return Date.from(parseInstant(timestamp)); + } + + /** + * Parses the date. + * + * @param timestamp + * the timestamp + * @return the date + */ + static Instant toInstantOrNull(Date date) { + if (date == null) + return null; + + return date.toInstant(); + } + /** * Parses the instant. * diff --git a/src/main/java/org/kohsuke/github/GitHubInteractiveObject.java b/src/main/java/org/kohsuke/github/GitHubInteractiveObject.java index a34f6485e7..97f9dcbe21 100644 --- a/src/main/java/org/kohsuke/github/GitHubInteractiveObject.java +++ b/src/main/java/org/kohsuke/github/GitHubInteractiveObject.java @@ -15,7 +15,7 @@ * * @author Liam Newman */ -abstract class GitHubInteractiveObject { +abstract class GitHubInteractiveObject extends GitHubBridgeAdapterObject { @JacksonInject @CheckForNull private transient final GitHub root; diff --git a/src/main/java/org/kohsuke/github/GitUser.java b/src/main/java/org/kohsuke/github/GitUser.java index 9556cbe6d7..f6cb1c95e4 100644 --- a/src/main/java/org/kohsuke/github/GitUser.java +++ b/src/main/java/org/kohsuke/github/GitUser.java @@ -1,8 +1,10 @@ package org.kohsuke.github; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.time.Instant; +import java.util.Date; import javax.annotation.CheckForNull; @@ -17,7 +19,7 @@ */ @SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" }, justification = "JSON API") -public class GitUser { +public class GitUser extends GitHubBridgeAdapterObject { private String name, email, date, username; /** @@ -53,6 +55,7 @@ public String getUsername() { * * @return Commit Date. */ + @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getDate() { return GitHubClient.parseInstant(date); } diff --git a/src/main/java/org/kohsuke/github/RateLimitChecker.java b/src/main/java/org/kohsuke/github/RateLimitChecker.java index ebf0e1b857..05c3c6f060 100644 --- a/src/main/java/org/kohsuke/github/RateLimitChecker.java +++ b/src/main/java/org/kohsuke/github/RateLimitChecker.java @@ -1,5 +1,6 @@ package org.kohsuke.github; +import java.util.Date; import java.util.logging.Level; import java.util.logging.Logger; @@ -79,13 +80,13 @@ protected boolean checkRateLimit(GHRateLimit.Record rateLimitRecord, long count) */ protected final boolean sleepUntilReset(GHRateLimit.Record record) throws InterruptedException { // Sleep until reset - long sleepMilliseconds = record.getResetDate().toEpochMilli() - System.currentTimeMillis(); + long sleepMilliseconds = record.getResetInstant().toEpochMilli() - System.currentTimeMillis(); if (sleepMilliseconds > 0) { String message = String.format( "GitHub API - Current quota has %d remaining of %d. Waiting for quota to reset at %tT.", record.getRemaining(), record.getLimit(), - record.getResetDate()); + Date.from(record.getResetInstant())); LOGGER.log(Level.INFO, message); diff --git a/src/test/java/org/kohsuke/github/BridgeMethodTest.java b/src/test/java/org/kohsuke/github/BridgeMethodTest.java index a3f25adea8..acb7fe27f1 100644 --- a/src/test/java/org/kohsuke/github/BridgeMethodTest.java +++ b/src/test/java/org/kohsuke/github/BridgeMethodTest.java @@ -4,7 +4,9 @@ import org.junit.Test; import java.lang.reflect.Method; +import java.time.Instant; import java.util.ArrayList; +import java.util.Date; import java.util.List; import javax.annotation.Nonnull; @@ -38,8 +40,59 @@ public void testBridgeMethods() { // verifyBridgeMethods(new GHCommit(), "getAuthor", GHCommit.GHAuthor.class, GitUser.class); // verifyBridgeMethods(new GHCommit(), "getCommitter", GHCommit.GHAuthor.class, GitUser.class); - // verifyBridgeMethods(GitHub.class, "getMyself", GHMyself.class, GHUser.class); - + verifyBridgeMethods(GHAppInstallation.class, "getSuspendedAt", Date.class, Instant.class); + verifyBridgeMethods(GHAppInstallationToken.class, "getExpiresAt", Date.class, Instant.class); + verifyBridgeMethods(GHArtifact.class, "getExpiresAt", Date.class, Instant.class); + verifyBridgeMethods(GHCheckRun.class, "getStartedAt", Date.class, Instant.class); + verifyBridgeMethods(GHCheckRun.class, "getCompletedAt", Date.class, Instant.class); + verifyBridgeMethods(GHCheckSuite.HeadCommit.class, "getTimestamp", Date.class, Instant.class); + verifyBridgeMethods(GHCommit.class, "getAuthoredDate", Date.class, Instant.class); + verifyBridgeMethods(GHCommit.class, "getCommitDate", Date.class, Instant.class); + verifyBridgeMethods(GHDeployKey.class, "getCreatedAt", Date.class, Instant.class); + verifyBridgeMethods(GHDeployKey.class, "getLastUsedAt", Date.class, Instant.class); + verifyBridgeMethods(GHEventInfo.class, "getCreatedAt", Date.class, Instant.class); + verifyBridgeMethods(GHEventPayload.Push.PushCommit.class, "getTimestamp", Date.class, Instant.class); + verifyBridgeMethods(GHEventPayload.Star.class, "getStarredAt", Date.class, Instant.class); + verifyBridgeMethods(GHExternalGroup.class, "getUpdatedAt", Date.class, Instant.class); + verifyBridgeMethods(GHIssue.class, "getClosedAt", Date.class, Instant.class); + verifyBridgeMethods(GHIssueEvent.class, "getCreatedAt", Date.class, Instant.class); + verifyBridgeMethods(GHMarketplacePendingChange.class, "getEffectiveDate", Date.class, Instant.class); + verifyBridgeMethods(GHMarketplacePurchase.class, "getNextBillingDate", Date.class, Instant.class); + verifyBridgeMethods(GHMarketplacePurchase.class, "getFreeTrialEndsOn", Date.class, Instant.class); + verifyBridgeMethods(GHMarketplacePurchase.class, "getUpdatedAt", Date.class, Instant.class); + verifyBridgeMethods(GHMarketplaceUserPurchase.class, "getNextBillingDate", Date.class, Instant.class); + verifyBridgeMethods(GHMarketplaceUserPurchase.class, "getFreeTrialEndsOn", Date.class, Instant.class); + verifyBridgeMethods(GHMarketplaceUserPurchase.class, "getUpdatedAt", Date.class, Instant.class); + verifyBridgeMethods(GHMilestone.class, "getDueOn", Date.class, Instant.class); + verifyBridgeMethods(GHMilestone.class, "getClosedAt", Date.class, Instant.class); + verifyBridgeMethods(GHObject.class, "getCreatedAt", Date.class, Instant.class); + verifyBridgeMethods(GHObject.class, "getUpdatedAt", Date.class, Instant.class); + verifyBridgeMethods(GHPerson.class, "getCreatedAt", Date.class, Instant.class); + verifyBridgeMethods(GHPerson.class, "getUpdatedAt", Date.class, Instant.class); + verifyBridgeMethods(GHProjectsV2Item.class, "getArchivedAt", Date.class, Instant.class); + verifyBridgeMethods(GHProjectsV2ItemChanges.FromToDate.class, "getFrom", Date.class, Instant.class); + verifyBridgeMethods(GHProjectsV2ItemChanges.FromToDate.class, "getTo", Date.class, Instant.class); + verifyBridgeMethods(GHPullRequest.class, "getMergedAt", Date.class, Instant.class); + verifyBridgeMethods(GHPullRequestReview.class, "getSubmittedAt", Date.class, Instant.class); + verifyBridgeMethods(GHPullRequestReview.class, "getCreatedAt", Date.class, Instant.class); + verifyBridgeMethods(GHRepository.class, "getPushedAt", Date.class, Instant.class); + verifyBridgeMethods(GHRepositoryDiscussion.class, "getAnswerChosenAt", Date.class, Instant.class); + verifyBridgeMethods(GHRepositoryDiscussion.class, "getCreatedAt", Date.class, Instant.class); + verifyBridgeMethods(GHRepositoryDiscussion.class, "getUpdatedAt", Date.class, Instant.class); + verifyBridgeMethods(GHRepositoryTraffic.DailyInfo.class, "getTimestamp", Date.class, Instant.class); + verifyBridgeMethods(GHStargazer.class, "getStarredAt", Date.class, Instant.class); + verifyBridgeMethods(GHSubscription.class, "getCreatedAt", Date.class, Instant.class); + verifyBridgeMethods(GHThread.class, "getLastReadAt", Date.class, Instant.class); + verifyBridgeMethods(GHUser.class, "getSuspendedAt", Date.class, Instant.class); + verifyBridgeMethods(GHWorkflowJob.class, "getStartedAt", Date.class, Instant.class); + verifyBridgeMethods(GHWorkflowJob.class, "getCompletedAt", Date.class, Instant.class); + verifyBridgeMethods(GHWorkflowJob.class, "getStartedAt", Date.class, Instant.class); + verifyBridgeMethods(GHWorkflowJob.class, "getCompletedAt", Date.class, Instant.class); + verifyBridgeMethods(GHWorkflowRun.class, "getRunStartedAt", Date.class, Instant.class); + verifyBridgeMethods(GHWorkflowRun.HeadCommit.class, "getTimestamp", Date.class, Instant.class); + verifyBridgeMethods(GitCommit.class, "getAuthoredDate", Date.class, Instant.class); + verifyBridgeMethods(GitCommit.class, "getCommitDate", Date.class, Instant.class); + verifyBridgeMethods(GitUser.class, "getDate", Date.class, Instant.class); } /** diff --git a/src/test/java/org/kohsuke/github/GHRateLimitTest.java b/src/test/java/org/kohsuke/github/GHRateLimitTest.java index 01e8ac5372..30ce63a73d 100644 --- a/src/test/java/org/kohsuke/github/GHRateLimitTest.java +++ b/src/test/java/org/kohsuke/github/GHRateLimitTest.java @@ -8,6 +8,7 @@ import java.io.IOException; import java.time.Duration; import java.time.Instant; +import java.util.Date; import java.util.HashMap; import static org.hamcrest.CoreMatchers.equalTo; @@ -231,7 +232,8 @@ private void verifyRateLimitValues(GHRateLimit previousLimit, int remaining, boo assertThat(rateLimit.getRemaining(), equalTo(remaining)); // Check that the reset date of the current limit is not older than the previous one - long diffMillis = rateLimit.getResetDate().toEpochMilli() - previousLimit.getResetDate().toEpochMilli(); + long diffMillis = rateLimit.getCore().getResetInstant().toEpochMilli() + - previousLimit.getCore().getResetInstant().toEpochMilli(); assertThat(diffMillis, greaterThanOrEqualTo(0L)); if (changedResetDate) { @@ -279,8 +281,8 @@ public void testGitHubEnterpriseDoesNotHaveRateLimit() throws Exception { assertThat(rateLimit.getCore(), instanceOf(GHRateLimit.UnknownLimitRecord.class)); assertThat(rateLimit.getLimit(), equalTo(GHRateLimit.UnknownLimitRecord.unknownLimit)); assertThat(rateLimit.getRemaining(), equalTo(GHRateLimit.UnknownLimitRecord.unknownRemaining)); - assertThat(rateLimit.getResetDate().compareTo(lastReset), equalTo(1)); - lastReset = rateLimit.getResetDate(); + assertThat(rateLimit.getResetDate().compareTo(Date.from(lastReset)), equalTo(1)); + lastReset = rateLimit.getCore().getResetInstant(); assertThat(mockGitHub.getRequestCount(), equalTo(1)); @@ -306,8 +308,8 @@ public void testGitHubEnterpriseDoesNotHaveRateLimit() throws Exception { assertThat(rateLimit.getLimit(), equalTo(GHRateLimit.UnknownLimitRecord.unknownLimit)); assertThat(rateLimit.getRemaining(), equalTo(GHRateLimit.UnknownLimitRecord.unknownRemaining)); // Same unknown instance is reused for a while - assertThat(rateLimit.getResetDate().compareTo(lastReset), equalTo(0)); - lastReset = rateLimit.getResetDate(); + assertThat(rateLimit.getResetDate().compareTo(Date.from(lastReset)), equalTo(0)); + lastReset = rateLimit.getCore().getResetInstant(); assertThat(mockGitHub.getRequestCount(), equalTo(3)); @@ -326,7 +328,7 @@ public void testGitHubEnterpriseDoesNotHaveRateLimit() throws Exception { assertThat(rateLimit.getLimit(), equalTo(GHRateLimit.UnknownLimitRecord.unknownLimit)); assertThat(rateLimit.getRemaining(), equalTo(GHRateLimit.UnknownLimitRecord.unknownRemaining)); // When not expired, unknowns do not replace each other so last reset remains unchanged - assertThat(rateLimit.getResetDate().compareTo(lastReset), equalTo(0)); + assertThat(rateLimit.getResetDate().compareTo(Date.from(lastReset)), equalTo(0)); // Give this a moment Thread.sleep(1500); @@ -348,8 +350,8 @@ public void testGitHubEnterpriseDoesNotHaveRateLimit() throws Exception { assertThat(rateLimit, notNullValue()); assertThat(rateLimit.getLimit(), equalTo(5000)); assertThat(rateLimit.getRemaining(), equalTo(4978)); - assertThat(rateLimit.getResetDate().compareTo(lastReset), equalTo(1)); - lastReset = rateLimit.getResetDate(); + assertThat(rateLimit.getResetDate().compareTo(Date.from(lastReset)), equalTo(1)); + lastReset = rateLimit.getCore().getResetInstant(); // When getting only header updates, the unknowns are also expired assertThat(rateLimit.getSearch().isExpired(), is(true)); @@ -383,7 +385,7 @@ public void testGitHubEnterpriseDoesNotHaveRateLimit() throws Exception { // 11 requests since previous api call // This verifies that header rate limit info is recorded even for /rate_limit endpoint and 404 response assertThat(rateLimit.getRemaining(), equalTo(4967)); - assertThat(rateLimit.getResetDate().compareTo(lastReset), equalTo(0)); + assertThat(rateLimit.getResetDate().compareTo(Date.from(lastReset)), equalTo(0)); // getRateLimit() uses headerRateLimit if /rate_limit returns a 404 // and headerRateLimit is available and not expired From 89681980904397a0e698f89b3dea83fff4ad5584 Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Sat, 5 Apr 2025 18:29:39 -0700 Subject: [PATCH 04/10] Fixup reflect tests --- .../graphql/response/GHGraphQLResponse.java | 15 ++++++++- .../github-api/reflect-config.json | 31 +++++++++++++++++++ .../github-api/serialization-config.json | 6 ++++ .../GitHubConnectorResponseTest.java | 6 ++++ .../no-reflect-and-serialization-list | 1 - 5 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/kohsuke/github/internal/graphql/response/GHGraphQLResponse.java b/src/main/java/org/kohsuke/github/internal/graphql/response/GHGraphQLResponse.java index 54960aa556..2e3469a37e 100644 --- a/src/main/java/org/kohsuke/github/internal/graphql/response/GHGraphQLResponse.java +++ b/src/main/java/org/kohsuke/github/internal/graphql/response/GHGraphQLResponse.java @@ -24,6 +24,8 @@ public class GHGraphQLResponse { private final List errors; /** + * GHGraphQLResponse constructor + * * @param data * GraphQL success response * @param errors @@ -40,6 +42,8 @@ public GHGraphQLResponse(@JsonProperty("data") T data, @JsonProperty("errors") L } /** + * Is response succesful. + * * @return request is succeeded. True when error list is empty. */ public boolean isSuccessful() { @@ -47,6 +51,8 @@ public boolean isSuccessful() { } /** + * Get response data. + * * @return GraphQL success response */ public T getData() { @@ -58,6 +64,8 @@ public T getData() { } /** + * Get response error message. + * * @return GraphQL error messages from Github Response. Empty list when no errors occurred. */ public List getErrorMessages() { @@ -82,7 +90,12 @@ public String getMessage() { */ public static class ObjectResponse extends GHGraphQLResponse { /** - * {@inheritDoc} + * ObjectResponse constructor. + * + * @param data + * GraphQL success response + * @param errors + * GraphQL failure response, This will be empty if not fail */ @JsonCreator @SuppressFBWarnings(value = { "EI_EXPOSE_REP2" }, justification = "Spotbugs also doesn't like this") diff --git a/src/main/resources/META-INF/native-image/org.kohsuke/github-api/reflect-config.json b/src/main/resources/META-INF/native-image/org.kohsuke/github-api/reflect-config.json index 24935c34be..30be262b74 100644 --- a/src/main/resources/META-INF/native-image/org.kohsuke/github-api/reflect-config.json +++ b/src/main/resources/META-INF/native-image/org.kohsuke/github-api/reflect-config.json @@ -6793,5 +6793,36 @@ "allDeclaredMethods": true, "allPublicClasses": true, "allDeclaredClasses": true + }, + { + "name": "org.kohsuke.github.GHAutolink", + "allPublicFields": true, + "allDeclaredFields": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredConstructors": true, + "queryAllPublicMethods": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredMethods": true, + "allPublicClasses": true, + "allDeclaredClasses": true + }, + { + "name": "org.kohsuke.github.GitHubBridgeAdapterObject", + "allPublicFields": true, + "allDeclaredFields": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredConstructors": true, + "queryAllPublicMethods": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredMethods": true, + "allPublicClasses": true, + "allDeclaredClasses": true } + ] diff --git a/src/main/resources/META-INF/native-image/org.kohsuke/github-api/serialization-config.json b/src/main/resources/META-INF/native-image/org.kohsuke/github-api/serialization-config.json index 0bb21a1624..412aa47e18 100644 --- a/src/main/resources/META-INF/native-image/org.kohsuke/github-api/serialization-config.json +++ b/src/main/resources/META-INF/native-image/org.kohsuke/github-api/serialization-config.json @@ -1360,5 +1360,11 @@ }, { "name": "org.kohsuke.github.internal.graphql.response.GHGraphQLResponse$ObjectResponse" + }, + { + "name": "org.kohsuke.github.GHAutolink" + }, + { + "name": "org.kohsuke.github.GitHubBridgeAdapterObject" } ] diff --git a/src/test/java/org/kohsuke/github/connector/GitHubConnectorResponseTest.java b/src/test/java/org/kohsuke/github/connector/GitHubConnectorResponseTest.java index fbc2098902..218cf26c4f 100644 --- a/src/test/java/org/kohsuke/github/connector/GitHubConnectorResponseTest.java +++ b/src/test/java/org/kohsuke/github/connector/GitHubConnectorResponseTest.java @@ -27,6 +27,12 @@ */ public class GitHubConnectorResponseTest extends AbstractGitHubWireMockTest { + /** + * Instantiates a new GitHubConnectorResponseTest. + */ + public GitHubConnectorResponseTest() { + } + /** * Test basic body stream. * diff --git a/src/test/resources/no-reflect-and-serialization-list b/src/test/resources/no-reflect-and-serialization-list index 4e248c490c..4ad893272c 100644 --- a/src/test/resources/no-reflect-and-serialization-list +++ b/src/test/resources/no-reflect-and-serialization-list @@ -82,6 +82,5 @@ org.kohsuke.github.internal.DefaultGitHubConnector org.kohsuke.github.internal.EnumUtils org.kohsuke.github.internal.Previews org.kohsuke.github.EnterpriseManagedSupport -org.kohsuke.github.GHAutolink org.kohsuke.github.GHAutolinkBuilder org.kohsuke.github.GHRepositoryForkBuilder \ No newline at end of file From 977ff7a70c158ed1ed1394b33911d11484d82add Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Sat, 5 Apr 2025 23:55:53 -0700 Subject: [PATCH 05/10] Add build for artifact with bridge methods --- .github/workflows/maven-build.yml | 20 ++++++ pom.xml | 71 +++++++++++++++---- .../kohsuke/github/AotIntegrationTest.java | 12 ++-- .../org/kohsuke/github/BridgeMethodTest.java | 4 ++ ...ction-and-serialization-test-error-message | 14 +++- 5 files changed, 102 insertions(+), 19 deletions(-) diff --git a/.github/workflows/maven-build.yml b/.github/workflows/maven-build.yml index f6973dae09..48e5fb4966 100644 --- a/.github/workflows/maven-build.yml +++ b/.github/workflows/maven-build.yml @@ -60,6 +60,26 @@ jobs: # running install site seems to more closely imitate real site deployment, # more likely to prevent failed deployment run: mvn -B clean install site -DskipTests --file pom.xml + test-bridged: + name: build-and-test Bridged (Java 17) + # Does not require build output, but orders execution to prevent launching test workflows when simple build fails + needs: build + runs-on: ubuntu-latest + strategy: + fail-fast: true + steps: + - uses: actions/checkout@v4 + - name: Set up JDK + uses: actions/setup-java@v4 + with: + java-version: 17 + distribution: 'temurin' + cache: 'maven' + - name: Maven Install (skipTests) + env: + MAVEN_OPTS: ${{ env.JAVA_11_PLUS_MAVEN_OPTS }} + #skipping japicmp check for bridged artifact until after next release + run: mvn -B clean install -Djapicmp.skip=true -Pbridged -D enable-ci --file pom.xml "-Dsurefire.argLine=--add-opens java.base/java.net=ALL-UNNAMED" test: name: test (${{ matrix.os }}, Java ${{ matrix.java }}) # Does not require build output, but orders execution to prevent launching test workflows when simple build fails diff --git a/pom.xml b/pom.xml index 0afdabc0be..895f0fd73e 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 org.kohsuke - github-api + ${github-api.artifactId} 2.0-rc.2-SNAPSHOT GitHub API for Java GitHub API for Java @@ -62,6 +62,7 @@ + github-api 3.0 0.70 @@ -306,6 +307,18 @@ + + com.infradna.tool + bridge-method-injector + 1.30 + + + + process + + + + org.apache.maven.plugins maven-gpg-plugin @@ -328,7 +341,10 @@ - org.apache.maven.plugins + maven-resources-plugin + 3.3.1 + + maven-source-plugin 3.3.1 @@ -563,18 +579,6 @@ - - com.infradna.tool - bridge-method-injector - 1.30 - - - - process - - - - maven-compiler-plugin 3.13.0 @@ -635,6 +639,9 @@ maven-surefire-plugin @{jacoco.surefire.argLine} ${surefire.argLine} + + ${project.artifactId} + @@ -815,6 +822,42 @@ + + bridged + + + github-api-bridged + + + + + com.infradna.tool + bridge-method-injector + + + maven-resources-plugin + + + copy-bridged-resources + + copy-resources + + + validate + + ${basedir}/target/classes/META-INF/native-image/org.kohsuke/${github-api.artifactId} + + + src/main/resources/META-INF/native-image/org.kohsuke/github-api + + + + + + + + + ci-non-windows diff --git a/src/test/java/org/kohsuke/github/AotIntegrationTest.java b/src/test/java/org/kohsuke/github/AotIntegrationTest.java index 8605d8aa46..a8b458f792 100644 --- a/src/test/java/org/kohsuke/github/AotIntegrationTest.java +++ b/src/test/java/org/kohsuke/github/AotIntegrationTest.java @@ -39,12 +39,14 @@ public AotIntegrationTest() { */ @Test public void testIfAllRequiredClassesAreRegisteredForAot() throws IOException { + String artifactId = System.getProperty("test.projectArtifactId", "default"); + Stream providedReflectionConfigStreamOfNames = readAotConfigToStreamOfClassNames( - "./target/classes/META-INF/native-image/org.kohsuke/github-api/reflect-config.json"); + "./target/classes/META-INF/native-image/org.kohsuke/" + artifactId + "/reflect-config.json"); Stream providedNoReflectStreamOfNames = Files .lines(Path.of("./target/test-classes/no-reflect-and-serialization-list")); Stream providedSerializationStreamOfNames = readAotConfigToStreamOfClassNames( - "./target/classes/META-INF/native-image/org.kohsuke/github-api/serialization-config.json"); + "./target/classes/META-INF/native-image/org.kohsuke/" + artifactId + "/serialization-config.json"); Stream providedAotConfigClassNamesPart = Stream .concat(providedSerializationStreamOfNames, Stream.concat(providedReflectionConfigStreamOfNames, providedNoReflectStreamOfNames)) @@ -53,9 +55,11 @@ public void testIfAllRequiredClassesAreRegisteredForAot() throws IOException { .collect(Collectors.toList()); Stream generatedReflectConfigStreamOfClassNames = readAotConfigToStreamOfClassNames( - "./target/spring-aot/test/resources/META-INF/native-image/org.kohsuke/github-api/reflect-config.json"); + "./target/spring-aot/test/resources/META-INF/native-image/org.kohsuke/" + artifactId + + "/reflect-config.json"); Stream generatedSerializationStreamOfNames = readAotConfigToStreamOfClassNames( - "./target/spring-aot/test/resources/META-INF/native-image/org.kohsuke/github-api/serialization-config.json"); + "./target/spring-aot/test/resources/META-INF/native-image/org.kohsuke/" + artifactId + + "/serialization-config.json"); Stream generatedAotConfigClassNames = Stream.concat(generatedReflectConfigStreamOfClassNames, generatedSerializationStreamOfNames); diff --git a/src/test/java/org/kohsuke/github/BridgeMethodTest.java b/src/test/java/org/kohsuke/github/BridgeMethodTest.java index acb7fe27f1..1960b3073c 100644 --- a/src/test/java/org/kohsuke/github/BridgeMethodTest.java +++ b/src/test/java/org/kohsuke/github/BridgeMethodTest.java @@ -40,6 +40,10 @@ public void testBridgeMethods() { // verifyBridgeMethods(new GHCommit(), "getAuthor", GHCommit.GHAuthor.class, GitUser.class); // verifyBridgeMethods(new GHCommit(), "getCommitter", GHCommit.GHAuthor.class, GitUser.class); + String artifactId = System.getProperty("test.projectArtifactId", "default"); + // Only run these tests when building the "bridged" artifact + org.junit.Assume.assumeThat(artifactId, equalTo("github-api-bridged")); + verifyBridgeMethods(GHAppInstallation.class, "getSuspendedAt", Date.class, Instant.class); verifyBridgeMethods(GHAppInstallationToken.class, "getExpiresAt", Date.class, Instant.class); verifyBridgeMethods(GHArtifact.class, "getExpiresAt", Date.class, Instant.class); diff --git a/src/test/resources/reflection-and-serialization-test-error-message b/src/test/resources/reflection-and-serialization-test-error-message index a56576c62c..a60293d3e6 100644 --- a/src/test/resources/reflection-and-serialization-test-error-message +++ b/src/test/resources/reflection-and-serialization-test-error-message @@ -1,5 +1,15 @@ The class "%1$s" needs to be configured or excluded for reflection / serialization and was not mentioned in one of the following resources: +Please do one of the following: +1. add "%1$s" to serialization.json and / or reflect-config.json +2. add "%1$s" to no-reflect-and-serialization-list + +DO NOT do both. + +Option 1: +The class is serialized or reflected over. Includes "GH*" classes the are populated using Jackson. +Does not include Builders and other classes that are only used locally. + src/main/resources/META-INF/reflect-config.json - example: { @@ -24,10 +34,12 @@ src/main/resources/META-INF/serialization.json - example: "name": "%1$s" } +Option 2: +The class is not serialized or reflected over. This is less common. + src/test/resources/no-reflect-and-serialization-list - example: %1$s -Please add it to either no-reflect-and-serialization-list or to serialization.json and / or reflect-config.json From 114e0e4e685a538b0e9986929f23b806699e8554 Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Sun, 6 Apr 2025 00:06:28 -0700 Subject: [PATCH 06/10] Disable japicmp temporarily --- .github/workflows/maven-build.yml | 7 ++++--- .github/workflows/publish_release_branch.yml | 8 ++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/maven-build.yml b/.github/workflows/maven-build.yml index 48e5fb4966..fa455bcce6 100644 --- a/.github/workflows/maven-build.yml +++ b/.github/workflows/maven-build.yml @@ -35,7 +35,7 @@ jobs: - name: Maven Install (skipTests) env: MAVEN_OPTS: ${{ env.JAVA_11_PLUS_MAVEN_OPTS }} - run: mvn -B clean install -DskipTests --file pom.xml + run: mvn -B clean install -Djapicmp.skip=true -DskipTests --file pom.xml - uses: actions/upload-artifact@v4 with: name: maven-target-directory @@ -59,7 +59,7 @@ jobs: MAVEN_OPTS: ${{ env.JAVA_11_PLUS_MAVEN_OPTS }} # running install site seems to more closely imitate real site deployment, # more likely to prevent failed deployment - run: mvn -B clean install site -DskipTests --file pom.xml + run: mvn -B clean install site -Djapicmp.skip=true -DskipTests --file pom.xml test-bridged: name: build-and-test Bridged (Java 17) # Does not require build output, but orders execution to prevent launching test workflows when simple build fails @@ -108,7 +108,8 @@ jobs: if: matrix.os != 'windows' env: MAVEN_OPTS: ${{ env.JAVA_11_PLUS_MAVEN_OPTS }} - run: mvn -B clean install -D enable-ci --file pom.xml "-Dsurefire.argLine=--add-opens java.base/java.net=ALL-UNNAMED" + # Disable japicmp until next release + run: mvn -B clean install -Djapicmp.skip=true -D enable-ci --file pom.xml "-Dsurefire.argLine=--add-opens java.base/java.net=ALL-UNNAMED" - name: Save coverage data if: matrix.os == 'ubuntu' && matrix.java == '17' uses: actions/upload-artifact@v4 diff --git a/.github/workflows/publish_release_branch.yml b/.github/workflows/publish_release_branch.yml index 6e3041a436..72e5c21a0f 100644 --- a/.github/workflows/publish_release_branch.yml +++ b/.github/workflows/publish_release_branch.yml @@ -56,6 +56,14 @@ jobs: MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN_PASSWORD }} MAVEN_GPG_PASSPHRASE: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSPHRASE }} + - name: Publish package with bridge methods + run: mvn -B clean deploy -DskipTests -Prelease -Pbridged + env: + MAVEN_OPTS: ${{ env.JAVA_11_PLUS_MAVEN_OPTS }} + MAVEN_USERNAME: ${{ secrets.OSSRH_TOKEN_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN_PASSWORD }} + MAVEN_GPG_PASSPHRASE: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSPHRASE }} + publish_gh_pages: runs-on: ubuntu-latest needs: build From 8ffd6eec383740ee54e488f230c57cfc0a329778 Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Sun, 6 Apr 2025 12:44:44 -0700 Subject: [PATCH 07/10] Improve code coverage --- src/test/java/org/kohsuke/github/CommitTest.java | 14 +++++++------- src/test/java/org/kohsuke/github/GHAppTest.java | 15 ++++++++++++--- .../org/kohsuke/github/GHCheckRunBuilderTest.java | 9 +++++---- src/test/java/org/kohsuke/github/GHIssueTest.java | 3 ++- .../java/org/kohsuke/github/GHMilestoneTest.java | 4 ++-- .../org/kohsuke/github/GHTreeBuilderTest.java | 6 +++--- 6 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/test/java/org/kohsuke/github/CommitTest.java b/src/test/java/org/kohsuke/github/CommitTest.java index 038e7e8be9..f7dc656945 100644 --- a/src/test/java/org/kohsuke/github/CommitTest.java +++ b/src/test/java/org/kohsuke/github/CommitTest.java @@ -4,9 +4,9 @@ import org.junit.Test; import java.io.IOException; -import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; +import java.util.Date; import java.util.List; import static org.hamcrest.Matchers.*; @@ -123,8 +123,8 @@ public void testQueryCommits() throws Exception { commits = gitHub.getUser("jenkinsci") .getRepository("jenkins") .queryCommits() - .since(Instant.ofEpochMilli(1199174400000L)) - .until(Instant.ofEpochMilli(1201852800000L)) + .since(new Date(1199174400000L)) + .until(new Date(1201852800000L)) .path("pom.xml") .pageSize(100) .list() @@ -137,8 +137,8 @@ public void testQueryCommits() throws Exception { commits = gitHub.getUser("jenkinsci") .getRepository("jenkins") .queryCommits() - .since(Instant.ofEpochMilli(1199174400000L)) - .until(Instant.ofEpochMilli(1201852800000L)) + .since(new Date(1199174400000L)) + .until(new Date(1201852800000L)) .path("pom.xml") .from("a5259970acaec9813e2a12a91f37dfc7871a5ef5") .list() @@ -150,7 +150,7 @@ public void testQueryCommits() throws Exception { commits = gitHub.getUser("jenkinsci") .getRepository("jenkins") .queryCommits() - .until(Instant.ofEpochMilli(1201852800000L)) + .until(new Date(1201852800000L)) .path("pom.xml") .author("kohsuke") .list() @@ -161,7 +161,7 @@ public void testQueryCommits() throws Exception { commits = gitHub.getUser("jenkinsci") .getRepository("jenkins") .queryCommits() - .until(Instant.ofEpochMilli(1201852800000L)) + .until(new Date(1201852800000L)) .path("pom.xml") .pageSize(100) .author("kohsuke@71c3de6d-444a-0410-be80-ed276b4c234a") diff --git a/src/test/java/org/kohsuke/github/GHAppTest.java b/src/test/java/org/kohsuke/github/GHAppTest.java index 60cd18ebda..8e3392409b 100644 --- a/src/test/java/org/kohsuke/github/GHAppTest.java +++ b/src/test/java/org/kohsuke/github/GHAppTest.java @@ -3,15 +3,19 @@ import org.junit.Test; import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.time.Instant; import java.time.LocalDate; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.Collections; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.TimeZone; import static org.hamcrest.Matchers.*; @@ -115,11 +119,16 @@ public void listInstallations() throws IOException { * * @throws IOException * Signals that an I/O exception has occurred. + * @throws ParseException + * Signals that a ParseException has occurred. * */ @Test - public void listInstallationsSince() throws IOException { - Instant localDate = LocalDate.parse("2023-11-01", DateTimeFormatter.ISO_LOCAL_DATE) + public void listInstallationsSince() throws IOException, ParseException { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); + simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); + Date localDate = simpleDateFormat.parse("2023-11-01"); + Instant localInstant = LocalDate.parse("2023-11-01", DateTimeFormatter.ISO_LOCAL_DATE) .atStartOfDay() .toInstant(ZoneOffset.UTC); GHApp app = gitHub.getApp(); @@ -293,7 +302,7 @@ private void testAppInstallation(GHAppInstallation appInstallation) throws IOExc List events = Arrays.asList(GHEvent.PULL_REQUEST, GHEvent.PUSH); assertThat(appInstallation.getEvents(), containsInAnyOrder(events.toArray(new GHEvent[0]))); - assertThat(appInstallation.getCreatedAt(), is(GitHubClient.parseInstant("2019-07-04T01:19:36.000Z"))); + assertThat(appInstallation.getCreatedAt(), is(GitHubClient.parseDate("2019-07-04T01:19:36.000Z").toInstant())); assertThat(appInstallation.getUpdatedAt(), is(GitHubClient.parseInstant("2019-07-30T22:48:09.000Z"))); assertThat(appInstallation.getSingleFileName(), nullValue()); } diff --git a/src/test/java/org/kohsuke/github/GHCheckRunBuilderTest.java b/src/test/java/org/kohsuke/github/GHCheckRunBuilderTest.java index cf02d8059f..ada5f1f4cd 100644 --- a/src/test/java/org/kohsuke/github/GHCheckRunBuilderTest.java +++ b/src/test/java/org/kohsuke/github/GHCheckRunBuilderTest.java @@ -30,6 +30,7 @@ import java.io.IOException; import java.time.Instant; +import java.util.Date; import static org.hamcrest.Matchers.*; @@ -71,8 +72,8 @@ public void createCheckRun() throws Exception { .withConclusion(GHCheckRun.Conclusion.SUCCESS) .withDetailsURL("http://nowhere.net/stuff") .withExternalID("whatever") - .withStartedAt(Instant.ofEpochMilli(999_999_000)) - .withCompletedAt(Instant.ofEpochMilli(999_999_999)) + .withStartedAt(new Date(999_999_000)) + .withCompletedAt(new Date(999_999_999)) .add(new GHCheckRunBuilder.Output("Some Title", "what happened…").withText("Hello Text!") .add(new GHCheckRunBuilder.Annotation("stuff.txt", 1, @@ -195,7 +196,7 @@ public void updateCheckRun() throws Exception { GHCheckRun updated = checkRun.update() .withStatus(GHCheckRun.Status.COMPLETED) .withConclusion(GHCheckRun.Conclusion.SUCCESS) - .withCompletedAt(Instant.ofEpochMilli(999_999_999)) + .withCompletedAt(new Date(999_999_999)) .create(); assertThat(Instant.ofEpochMilli(999_999_000), equalTo(updated.getStartedAt())); assertThat("foo", equalTo(updated.getName())); @@ -254,7 +255,7 @@ public void updateCheckRunWithNameException() throws Exception { () -> checkRun.update() .withStatus(GHCheckRun.Status.COMPLETED) .withConclusion(GHCheckRun.Conclusion.SUCCESS) - .withCompletedAt(Instant.ofEpochMilli(999_999_999)) + .withCompletedAt(new Date(999_999_999)) .withName("bar", null) .create()); } diff --git a/src/test/java/org/kohsuke/github/GHIssueTest.java b/src/test/java/org/kohsuke/github/GHIssueTest.java index 705f4ed75d..c3618f0cf3 100644 --- a/src/test/java/org/kohsuke/github/GHIssueTest.java +++ b/src/test/java/org/kohsuke/github/GHIssueTest.java @@ -7,6 +7,7 @@ import java.io.IOException; import java.time.Instant; import java.util.Collection; +import java.util.Date; import java.util.List; import static org.hamcrest.Matchers.contains; @@ -137,7 +138,7 @@ public void issueComment() throws Exception { comments = issue.queryComments().since(firstCommentCreatedAtPlus1Second).list().toList(); assertThat(comments, hasSize(1)); assertThat(comments, contains(hasProperty("body", equalTo("Second comment")))); - comments = issue.queryComments().since(secondCommentCreatedAt).list().toList(); + comments = issue.queryComments().since(Date.from(secondCommentCreatedAt)).list().toList(); assertThat(comments, hasSize(1)); assertThat(comments, contains(hasProperty("body", equalTo("Second comment")))); comments = issue.queryComments().since(secondCommentCreatedAtPlus1Second).list().toList(); diff --git a/src/test/java/org/kohsuke/github/GHMilestoneTest.java b/src/test/java/org/kohsuke/github/GHMilestoneTest.java index 7d8cdc60dc..c50d02eeea 100644 --- a/src/test/java/org/kohsuke/github/GHMilestoneTest.java +++ b/src/test/java/org/kohsuke/github/GHMilestoneTest.java @@ -6,9 +6,9 @@ import java.io.IOException; import java.time.Instant; +import java.util.Date; import static org.hamcrest.Matchers.*; -import static org.hamcrest.Matchers.containsString; // TODO: Auto-generated Javadoc /** @@ -59,7 +59,7 @@ public void testUpdateMilestone() throws Exception { String NEW_TITLE = "Updated Title"; String NEW_DESCRIPTION = "Updated Description"; - Instant NEW_DUE_DATE = GitHubClient.parseInstant("2020-10-05T13:00:00Z"); + Date NEW_DUE_DATE = GitHubClient.parseDate("2020-10-05T13:00:00Z"); Instant OUTPUT_DUE_DATE = GitHubClient.parseInstant("2020-10-05T07:00:00Z"); milestone.setTitle(NEW_TITLE); diff --git a/src/test/java/org/kohsuke/github/GHTreeBuilderTest.java b/src/test/java/org/kohsuke/github/GHTreeBuilderTest.java index 94405fe045..2f3ea77fb4 100644 --- a/src/test/java/org/kohsuke/github/GHTreeBuilderTest.java +++ b/src/test/java/org/kohsuke/github/GHTreeBuilderTest.java @@ -5,8 +5,8 @@ import org.junit.Test; import java.io.IOException; -import java.time.Instant; import java.util.Arrays; +import java.util.Date; import static org.hamcrest.Matchers.*; @@ -146,8 +146,8 @@ private GHCommit updateTree() throws IOException { String treeSha = treeBuilder.create().getSha(); GHCommit commit = new GHCommitBuilder(repo).message("Add files") .tree(treeSha) - .author("author", "author@author.com", Instant.ofEpochMilli(1611433225969L)) - .committer("committer", "committer@committer.com", Instant.ofEpochMilli(1611433225968L)) + .author("author", "author@author.com", new Date(1611433225969L)) + .committer("committer", "committer@committer.com", new Date(1611433225968L)) .parent(mainRef.getObject().getSha()) .create(); From fd3fdb5ddf2ac45db0e431ae8aec311b26072ef3 Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Tue, 8 Apr 2025 10:25:53 -0700 Subject: [PATCH 08/10] Increase code coverage --- .../org/kohsuke/github/GHIssueQueryBuilder.java | 2 +- .../java/org/kohsuke/github/GHMilestone.java | 2 -- src/main/java/org/kohsuke/github/GHRelease.java | 16 ++++------------ .../java/org/kohsuke/github/GHMilestoneTest.java | 1 + .../java/org/kohsuke/github/GHReleaseTest.java | 5 +++++ .../org/kohsuke/github/GitHubStaticTest.java | 7 +++++++ src/test/java/org/kohsuke/github/GitHubTest.java | 4 ++++ 7 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHIssueQueryBuilder.java b/src/main/java/org/kohsuke/github/GHIssueQueryBuilder.java index 5de811d117..a4fcd5622e 100644 --- a/src/main/java/org/kohsuke/github/GHIssueQueryBuilder.java +++ b/src/main/java/org/kohsuke/github/GHIssueQueryBuilder.java @@ -104,7 +104,7 @@ public GHIssueQueryBuilder since(Instant date) { * @return the gh issue query builder */ public GHIssueQueryBuilder since(long timestamp) { - return since(Instant.ofEpochMilli(timestamp)); + return since(new Date(timestamp)); } /** diff --git a/src/main/java/org/kohsuke/github/GHMilestone.java b/src/main/java/org/kohsuke/github/GHMilestone.java index 453d17f4fc..25fd14a47f 100644 --- a/src/main/java/org/kohsuke/github/GHMilestone.java +++ b/src/main/java/org/kohsuke/github/GHMilestone.java @@ -60,8 +60,6 @@ public GHUser getCreator() { */ @WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate") public Instant getDueOn() { - if (due_on == null) - return null; return GitHubClient.parseInstant(due_on); } diff --git a/src/main/java/org/kohsuke/github/GHRelease.java b/src/main/java/org/kohsuke/github/GHRelease.java index 5647191bde..e0b8b0853c 100644 --- a/src/main/java/org/kohsuke/github/GHRelease.java +++ b/src/main/java/org/kohsuke/github/GHRelease.java @@ -43,7 +43,7 @@ public GHRelease() { private String body; private boolean draft; private boolean prerelease; - private String published_at; + private String publishedAt; private String tarball_url; private String zipball_url; private String discussion_url; @@ -102,16 +102,6 @@ public String getName() { return name; } - /** - * Sets name. - * - * @param name - * the name - */ - public void setName(String name) { - this.name = name; - } - /** * Gets owner. * @@ -135,7 +125,9 @@ public boolean isPrerelease() { * Gets published at. * * @return the published at + * @deprecated Use #getPublishedAt() */ + @Deprecated public Date getPublished_at() { return Date.from(getPublishedAt()); } @@ -146,7 +138,7 @@ public Date getPublished_at() { * @return the published at */ public Instant getPublishedAt() { - return GitHubClient.parseInstant(published_at); + return GitHubClient.parseInstant(publishedAt); } /** diff --git a/src/test/java/org/kohsuke/github/GHMilestoneTest.java b/src/test/java/org/kohsuke/github/GHMilestoneTest.java index c50d02eeea..50fffd76e1 100644 --- a/src/test/java/org/kohsuke/github/GHMilestoneTest.java +++ b/src/test/java/org/kohsuke/github/GHMilestoneTest.java @@ -75,6 +75,7 @@ public void testUpdateMilestone() throws Exception { // The time is truncated when sent to the server, but still part of the returned value // 07:00 midnight PDT assertThat(milestone.getDueOn(), equalTo(OUTPUT_DUE_DATE)); + assertThat(milestone.getClosedAt(), nullValue()); assertThat(milestone.getHtmlUrl().toString(), containsString("/hub4j-test-org/github-api/milestone/")); assertThat(milestone.getUrl().toString(), containsString("/repos/hub4j-test-org/github-api/milestones/")); assertThat(milestone.getClosedIssues(), equalTo(0)); diff --git a/src/test/java/org/kohsuke/github/GHReleaseTest.java b/src/test/java/org/kohsuke/github/GHReleaseTest.java index 7d907c4335..044074d299 100644 --- a/src/test/java/org/kohsuke/github/GHReleaseTest.java +++ b/src/test/java/org/kohsuke/github/GHReleaseTest.java @@ -36,7 +36,12 @@ public void testCreateSimpleRelease() throws Exception { assertThat(releaseCheck, notNullValue()); assertThat(releaseCheck.getTagName(), is(tagName)); assertThat(releaseCheck.isPrerelease(), is(false)); + assertThat(releaseCheck.isDraft(), is(false)); + assertThat(releaseCheck.getAssetsUrl(), endsWith("/assets")); assertThat(releaseCheck.getDiscussionUrl(), notNullValue()); + assertThat(releaseCheck.getCreatedAt(), equalTo(GitHubClient.parseInstant("2021-06-02T21:59:14Z"))); + assertThat(releaseCheck.getPublishedAt(), equalTo(GitHubClient.parseInstant("2021-06-11T06:56:52Z"))); + } finally { release.delete(); assertThat(repo.getRelease(release.getId()), nullValue()); diff --git a/src/test/java/org/kohsuke/github/GitHubStaticTest.java b/src/test/java/org/kohsuke/github/GitHubStaticTest.java index 3ff351994e..cc6daaf790 100644 --- a/src/test/java/org/kohsuke/github/GitHubStaticTest.java +++ b/src/test/java/org/kohsuke/github/GitHubStaticTest.java @@ -12,6 +12,7 @@ import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import java.time.temporal.ChronoUnit; +import java.util.Date; import java.util.Locale; import static org.hamcrest.CoreMatchers.*; @@ -136,6 +137,12 @@ public void timeRoundTrip() { } catch (DateTimeParseException e) { assertThat(e.getMessage(), equalTo("Text '" + instantBadFormat + "' could not be parsed at index 0")); } + + final GitHubBridgeAdapterObject bridge = new GitHubBridgeAdapterObject() { + }; + assertThat(bridge.instantToDate(null, null), nullValue()); + assertThat(bridge.instantToDate(Instant.ofEpochMilli(stableInstantEpochMilli), null), + equalTo(Date.from(instantNow))); } /** diff --git a/src/test/java/org/kohsuke/github/GitHubTest.java b/src/test/java/org/kohsuke/github/GitHubTest.java index 2c26f48daf..8e27f8844a 100644 --- a/src/test/java/org/kohsuke/github/GitHubTest.java +++ b/src/test/java/org/kohsuke/github/GitHubTest.java @@ -336,6 +336,10 @@ public void getMyMarketplacePurchases() throws IOException { assertThat(userPurchase.isOnFreeTrial(), is(false)); assertThat(userPurchase.getFreeTrialEndsOn(), nullValue()); assertThat(userPurchase.getBillingCycle(), equalTo("monthly")); + assertThat(userPurchase.getNextBillingDate(), + equalTo(GitHubClient.parseInstant("2020-01-01T00:00:00.000+13:00"))); + assertThat(userPurchase.getUpdatedAt(), + equalTo(GitHubClient.parseInstant("2019-12-02T00:00:00.000+13:00"))); GHMarketplacePlan plan = userPurchase.getPlan(); // GHMarketplacePlan - Non-nullable fields From 0489b31d85bdffa218d56ff9fadb41af1c115f36 Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Wed, 9 Apr 2025 14:36:06 -0700 Subject: [PATCH 09/10] Add Deprecated and more coverage --- .../org/kohsuke/github/GHCheckRunBuilder.java | 4 ++++ .../github/GHIssueCommentQueryBuilder.java | 2 ++ .../kohsuke/github/GHIssueQueryBuilder.java | 2 ++ .../java/org/kohsuke/github/GHMilestone.java | 2 ++ .../kohsuke/github/GHNotificationStream.java | 2 +- .../java/org/kohsuke/github/GitHubClient.java | 20 +++---------------- src/test/java/org/kohsuke/github/AppTest.java | 4 ++++ .../java/org/kohsuke/github/GHAppTest.java | 2 +- .../org/kohsuke/github/GHIssueEventTest.java | 17 +++++++++++++++- .../org/kohsuke/github/GHMilestoneTest.java | 2 +- .../org/kohsuke/github/GHReleaseTest.java | 4 ++++ .../java/org/kohsuke/github/GHUserTest.java | 4 +++- 12 files changed, 43 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java b/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java index 642ab2db36..2165b3e264 100644 --- a/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java @@ -172,7 +172,9 @@ private GHCheckRunBuilder(GHRepository repo, Requester requester) { * @param startedAt * the started at * @return the GH check run builder + * @deprecated Use {@link #withStartedAt(Instant)} */ + @Deprecated public @NonNull GHCheckRunBuilder withStartedAt(@CheckForNull Date startedAt) { return withStartedAt(GitHubClient.toInstantOrNull(startedAt)); } @@ -197,7 +199,9 @@ private GHCheckRunBuilder(GHRepository repo, Requester requester) { * @param completedAt * the completed at * @return the GH check run builder + * @deprecated Use {@link #withCompletedAt(Instant)} */ + @Deprecated public @NonNull GHCheckRunBuilder withCompletedAt(@CheckForNull Date completedAt) { return withCompletedAt(GitHubClient.toInstantOrNull(completedAt)); } diff --git a/src/main/java/org/kohsuke/github/GHIssueCommentQueryBuilder.java b/src/main/java/org/kohsuke/github/GHIssueCommentQueryBuilder.java index b75a6deefe..9cc43b35b3 100644 --- a/src/main/java/org/kohsuke/github/GHIssueCommentQueryBuilder.java +++ b/src/main/java/org/kohsuke/github/GHIssueCommentQueryBuilder.java @@ -41,7 +41,9 @@ public class GHIssueCommentQueryBuilder { * @param date * the date * @return the query builder + * @deprecated Use {@link #since(Instant)} */ + @Deprecated public GHIssueCommentQueryBuilder since(Date date) { return since(GitHubClient.toInstantOrNull(date)); } diff --git a/src/main/java/org/kohsuke/github/GHIssueQueryBuilder.java b/src/main/java/org/kohsuke/github/GHIssueQueryBuilder.java index a4fcd5622e..72e9bba12e 100644 --- a/src/main/java/org/kohsuke/github/GHIssueQueryBuilder.java +++ b/src/main/java/org/kohsuke/github/GHIssueQueryBuilder.java @@ -79,7 +79,9 @@ public GHIssueQueryBuilder direction(GHDirection direction) { * @param date * the date * @return the gh issue query builder + * @deprecated Use {@link #since(Instant)} */ + @Deprecated public GHIssueQueryBuilder since(Date date) { return since(GitHubClient.toInstantOrNull(date)); } diff --git a/src/main/java/org/kohsuke/github/GHMilestone.java b/src/main/java/org/kohsuke/github/GHMilestone.java index 25fd14a47f..c0dbc6792b 100644 --- a/src/main/java/org/kohsuke/github/GHMilestone.java +++ b/src/main/java/org/kohsuke/github/GHMilestone.java @@ -201,7 +201,9 @@ public void setDescription(String description) throws IOException { * the due on * @throws IOException * the io exception + * @deprecated Use {@link #setDueOn(Instant)} */ + @Deprecated public void setDueOn(Date dueOn) throws IOException { setDueOn(GitHubClient.toInstantOrNull(dueOn)); } diff --git a/src/main/java/org/kohsuke/github/GHNotificationStream.java b/src/main/java/org/kohsuke/github/GHNotificationStream.java index c5a355a935..cc5b2e7e86 100644 --- a/src/main/java/org/kohsuke/github/GHNotificationStream.java +++ b/src/main/java/org/kohsuke/github/GHNotificationStream.java @@ -76,7 +76,7 @@ public GHNotificationStream participating(boolean v) { * @return the gh notification stream */ public GHNotificationStream since(long timestamp) { - return since(Instant.ofEpochMilli(timestamp)); + return since(new Date(timestamp)); } /** diff --git a/src/main/java/org/kohsuke/github/GitHubClient.java b/src/main/java/org/kohsuke/github/GitHubClient.java index 76826083cf..b6f6b6522b 100644 --- a/src/main/java/org/kohsuke/github/GitHubClient.java +++ b/src/main/java/org/kohsuke/github/GitHubClient.java @@ -876,24 +876,10 @@ static URL parseURL(String s) { } /** - * Parses the date. + * Convert Date to Instant or null. * - * @param timestamp - * the timestamp - * @return the date - */ - static Date parseDate(String timestamp) { - if (timestamp == null) - return null; - - return Date.from(parseInstant(timestamp)); - } - - /** - * Parses the date. - * - * @param timestamp - * the timestamp + * @param date + * the date * @return the date */ static Instant toInstantOrNull(Date date) { diff --git a/src/test/java/org/kohsuke/github/AppTest.java b/src/test/java/org/kohsuke/github/AppTest.java index dcb2fd151c..40b2d93eee 100755 --- a/src/test/java/org/kohsuke/github/AppTest.java +++ b/src/test/java/org/kohsuke/github/AppTest.java @@ -1731,6 +1731,10 @@ public void checkToString() throws Exception { public void reactions() throws Exception { GHIssue i = gitHub.getRepository("hub4j/github-api").getIssue(311); + // cover issue methods + assertThat(i.getClosedAt(), equalTo(GitHubClient.parseInstant("2016-11-17T02:40:11Z"))); + assertThat(i.getHtmlUrl().toString(), endsWith("github-api/issues/311")); + List l; // retrieval l = i.listReactions().toList(); diff --git a/src/test/java/org/kohsuke/github/GHAppTest.java b/src/test/java/org/kohsuke/github/GHAppTest.java index 8e3392409b..66eacd58d2 100644 --- a/src/test/java/org/kohsuke/github/GHAppTest.java +++ b/src/test/java/org/kohsuke/github/GHAppTest.java @@ -302,7 +302,7 @@ private void testAppInstallation(GHAppInstallation appInstallation) throws IOExc List events = Arrays.asList(GHEvent.PULL_REQUEST, GHEvent.PUSH); assertThat(appInstallation.getEvents(), containsInAnyOrder(events.toArray(new GHEvent[0]))); - assertThat(appInstallation.getCreatedAt(), is(GitHubClient.parseDate("2019-07-04T01:19:36.000Z").toInstant())); + assertThat(appInstallation.getCreatedAt(), is(GitHubClient.parseInstant("2019-07-04T01:19:36.000Z"))); assertThat(appInstallation.getUpdatedAt(), is(GitHubClient.parseInstant("2019-07-30T22:48:09.000Z"))); assertThat(appInstallation.getSingleFileName(), nullValue()); } diff --git a/src/test/java/org/kohsuke/github/GHIssueEventTest.java b/src/test/java/org/kohsuke/github/GHIssueEventTest.java index 5ac4c2b1df..ea141029fb 100644 --- a/src/test/java/org/kohsuke/github/GHIssueEventTest.java +++ b/src/test/java/org/kohsuke/github/GHIssueEventTest.java @@ -81,6 +81,10 @@ public void testIssueReviewRequestedEvent() throws Exception { assertThat(event.getReviewRequester().getLogin(), equalTo("t0m4uk1991")); assertThat(event.getRequestedReviewer(), notNullValue()); assertThat(event.getRequestedReviewer().getLogin(), equalTo("bitwiseman")); + assertThat(event.getNodeId(), equalTo("MDIwOlJldmlld1JlcXVlc3RlZEV2ZW50NTA2NDM2MzE3OQ==")); + assertThat(event.getCommitId(), nullValue()); + assertThat(event.getCommitUrl(), nullValue()); + assertThat(event.toString(), equalTo("Issue 434 was review_requested by t0m4uk1991 on 2021-07-24T20:28:28Z")); // Close the PR. pullRequest.close(); @@ -139,11 +143,22 @@ public void testRepositoryEvents() throws Exception { assertThat(list, is(not(empty()))); int i = 0; + int successfulChecks = 0; for (GHIssueEvent event : list) { + + if ("merged".equals(event.getEvent()) + && "ecec449372b1e8270524a35c1a5aa8fdaf0e6676".equals(event.getCommitId())) { + assertThat(event.getCommitUrl(), endsWith("/ecec449372b1e8270524a35c1a5aa8fdaf0e6676")); + assertThat(event.getActor().getLogin(), equalTo("bitwiseman")); + assertThat(event.getActor().getLogin(), equalTo("bitwiseman")); + assertThat(event.getIssue().getPullRequest().getUrl().toString(), endsWith("/github-api/pull/267")); + successfulChecks++; + } assertThat(event.getIssue(), notNullValue()); - if (i++ > 10) + if (i++ > 100) break; } + assertThat("All issue checks must be found and passed", successfulChecks, equalTo(1)); } /** diff --git a/src/test/java/org/kohsuke/github/GHMilestoneTest.java b/src/test/java/org/kohsuke/github/GHMilestoneTest.java index 50fffd76e1..2426eb8d2e 100644 --- a/src/test/java/org/kohsuke/github/GHMilestoneTest.java +++ b/src/test/java/org/kohsuke/github/GHMilestoneTest.java @@ -59,7 +59,7 @@ public void testUpdateMilestone() throws Exception { String NEW_TITLE = "Updated Title"; String NEW_DESCRIPTION = "Updated Description"; - Date NEW_DUE_DATE = GitHubClient.parseDate("2020-10-05T13:00:00Z"); + Date NEW_DUE_DATE = Date.from(GitHubClient.parseInstant("2020-10-05T13:00:00Z")); Instant OUTPUT_DUE_DATE = GitHubClient.parseInstant("2020-10-05T07:00:00Z"); milestone.setTitle(NEW_TITLE); diff --git a/src/test/java/org/kohsuke/github/GHReleaseTest.java b/src/test/java/org/kohsuke/github/GHReleaseTest.java index 044074d299..2b088253bb 100644 --- a/src/test/java/org/kohsuke/github/GHReleaseTest.java +++ b/src/test/java/org/kohsuke/github/GHReleaseTest.java @@ -3,6 +3,8 @@ import org.junit.Test; import org.kohsuke.github.GHReleaseBuilder.MakeLatest; +import java.util.Date; + import static org.hamcrest.Matchers.*; import static org.junit.Assert.assertThrows; @@ -40,6 +42,8 @@ public void testCreateSimpleRelease() throws Exception { assertThat(releaseCheck.getAssetsUrl(), endsWith("/assets")); assertThat(releaseCheck.getDiscussionUrl(), notNullValue()); assertThat(releaseCheck.getCreatedAt(), equalTo(GitHubClient.parseInstant("2021-06-02T21:59:14Z"))); + assertThat(releaseCheck.getPublished_at(), + equalTo(Date.from(GitHubClient.parseInstant("2021-06-11T06:56:52Z")))); assertThat(releaseCheck.getPublishedAt(), equalTo(GitHubClient.parseInstant("2021-06-11T06:56:52Z"))); } finally { diff --git a/src/test/java/org/kohsuke/github/GHUserTest.java b/src/test/java/org/kohsuke/github/GHUserTest.java index 0b16911a06..a0fc8494de 100644 --- a/src/test/java/org/kohsuke/github/GHUserTest.java +++ b/src/test/java/org/kohsuke/github/GHUserTest.java @@ -214,13 +214,15 @@ public void verifyBioAndHireable() throws IOException { GHUser u = gitHub.getUser("Chew"); assertThat(u.getBio(), equalTo("I like to program things and I hope to program something cool one day :D")); assertThat(u.isHireable(), is(true)); - assertThat(u.getTwitterUsername(), notNullValue()); + assertThat(u.getTwitterUsername(), equalTo("ChewCraft")); assertThat(u.getBlog(), equalTo("https://chew.pw")); assertThat(u.getCompany(), equalTo("@Memerator")); assertThat(u.getFollowersCount(), equalTo(29)); assertThat(u.getFollowingCount(), equalTo(3)); assertThat(u.getPublicGistCount(), equalTo(4)); assertThat(u.getPublicRepoCount(), equalTo(96)); + assertThat(u.getCreatedAt(), equalTo(GitHubClient.parseInstant("2014-07-26T23:41:36Z"))); + assertThat(u.getUpdatedAt(), equalTo(GitHubClient.parseInstant("2020-06-06T20:16:06Z"))); } /** From b2d1420d16d37c94b0aa514ec6b92ff96d2c1f6f Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Wed, 9 Apr 2025 15:48:25 -0700 Subject: [PATCH 10/10] More code coverage --- src/test/java/org/kohsuke/github/AppTest.java | 23 +++++++++++++++---- .../kohsuke/github/RepositoryTrafficTest.java | 4 ++++ .../mappings/10-notifications.json | 4 ++-- .../mappings/11-notifications.json | 4 ++-- .../mappings/12-notifications.json | 4 ++-- .../mappings/13-notifications.json | 4 ++-- .../mappings/14-notifications.json | 4 ++-- .../mappings/15-notifications.json | 4 ++-- .../mappings/16-notifications.json | 4 ++-- .../mappings/17-notifications.json | 4 ++-- .../mappings/18-notifications.json | 4 ++-- .../mappings/19-notifications.json | 4 ++-- .../mappings/2-notifications.json | 4 ++-- .../mappings/20-notifications.json | 4 ++-- .../mappings/21-notifications.json | 4 ++-- .../mappings/22-notifications.json | 4 ++-- .../mappings/23-notifications.json | 4 ++-- .../mappings/24-notifications.json | 4 ++-- .../mappings/3-notifications.json | 4 ++-- .../mappings/4-notifications.json | 4 ++-- .../mappings/5-notifications.json | 4 ++-- .../mappings/6-notifications.json | 4 ++-- .../mappings/7-notifications.json | 4 ++-- .../mappings/8-notifications.json | 4 ++-- .../mappings/9-notifications.json | 4 ++-- 25 files changed, 69 insertions(+), 50 deletions(-) diff --git a/src/test/java/org/kohsuke/github/AppTest.java b/src/test/java/org/kohsuke/github/AppTest.java index 40b2d93eee..48ae46dbc9 100755 --- a/src/test/java/org/kohsuke/github/AppTest.java +++ b/src/test/java/org/kohsuke/github/AppTest.java @@ -1005,16 +1005,23 @@ public void tryHook() throws Exception { public void testEventApi() throws Exception { for (GHEventInfo ev : gitHub.getEvents()) { if (ev.getType() == GHEvent.PULL_REQUEST) { + GHEventPayload.PullRequest pr = ev.getPayload(GHEventPayload.PullRequest.class); + assertThat(pr.getNumber(), is(pr.getPullRequest().getNumber())); + + assertThat(pr.getPullRequest().getClosedBy(), nullValue()); + assertThat(pr.getPullRequest().getPullRequest(), nullValue()); + if (ev.getId() == 10680625394L) { assertThat(ev.getActorLogin(), equalTo("pull[bot]")); assertThat(ev.getOrganization(), nullValue()); assertThat(ev.getRepository().getFullName(), equalTo("daddyfatstacksBIG/lerna")); assertThat(ev.getCreatedAt(), equalTo(GitHubClient.parseInstant("2019-10-21T21:54:52Z"))); assertThat(ev.getType(), equalTo(GHEvent.PULL_REQUEST)); + assertThat(pr.getPullRequest().getMergedAt(), + equalTo(GitHubClient.parseInstant("2019-10-21T21:54:52Z"))); + assertThat(pr.getPullRequest().getPatchUrl().toString(), endsWith("lerna/pull/20.patch")); + assertThat(pr.getPullRequest().getDiffUrl().toString(), endsWith("lerna/pull/20.diff")); } - - GHEventPayload.PullRequest pr = ev.getPayload(GHEventPayload.PullRequest.class); - assertThat(pr.getNumber(), is(pr.getPullRequest().getNumber())); } } } @@ -1040,6 +1047,14 @@ public void testUserPublicEventApi() throws Exception { GHEventPayload.PullRequest pr = ev.getPayload(GHEventPayload.PullRequest.class); assertThat(pr.getNumber(), is(pr.getPullRequest().getNumber())); } + if (ev.getType() == GHEvent.PULL_REQUEST_REVIEW) { + if (ev.getId() == 27468578706L) { + GHEventPayload.PullRequestReview prr = ev.getPayload(GHEventPayload.PullRequestReview.class); + assertThat(prr.getReview().getSubmittedAt(), + equalTo(GitHubClient.parseInstant("2023-03-03T10:51:48Z"))); + assertThat(prr.getReview().getCreatedAt(), equalTo(prr.getReview().getSubmittedAt())); + } + } } } @@ -1674,7 +1689,7 @@ public void testSubscribers() throws IOException { @Test public void notifications() throws Exception { boolean found = false; - for (GHThread t : gitHub.listNotifications().nonBlocking(true).read(true)) { + for (GHThread t : gitHub.listNotifications().since(0).nonBlocking(true).read(true)) { if (!found) { found = true; // both read and unread are included diff --git a/src/test/java/org/kohsuke/github/RepositoryTrafficTest.java b/src/test/java/org/kohsuke/github/RepositoryTrafficTest.java index 2fd49958b6..fb2485cd81 100644 --- a/src/test/java/org/kohsuke/github/RepositoryTrafficTest.java +++ b/src/test/java/org/kohsuke/github/RepositoryTrafficTest.java @@ -9,6 +9,8 @@ import java.util.Iterator; import java.util.List; +import static org.hamcrest.CoreMatchers.equalTo; + // TODO: Auto-generated Javadoc /** * The Class RepositoryTrafficTest. @@ -95,6 +97,8 @@ public void testGetClones() throws IOException { snapshotNotAllowed(); GHRepository repository = getRepository(gitHub); + assertThat(repository.getPushedAt(), equalTo(GitHubClient.parseInstant("2020-02-21T21:17:31Z"))); + GHRepositoryCloneTraffic clones = repository.getCloneTraffic(); GHRepositoryCloneTraffic expectedResult = new GHRepositoryCloneTraffic(128, diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/10-notifications.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/10-notifications.json index b16ad3007a..7304188eb8 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/10-notifications.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/10-notifications.json @@ -2,7 +2,7 @@ "id": "a979348d-c6be-4cb7-8877-7c42a6f013ae", "name": "notifications", "request": { - "url": "/notifications?all=true&page=9", + "url": "/notifications?all=true&since=1970-01-01T00%3A00%3A00Z&page=9", "method": "GET", "headers": { "Accept": { @@ -41,7 +41,7 @@ "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", "X-GitHub-Request-Id": "CB13:833E:A1F628:BFE1F0:5DB3A14D", - "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" + "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" } }, "uuid": "a979348d-c6be-4cb7-8877-7c42a6f013ae", diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/11-notifications.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/11-notifications.json index 85f3b573c0..c02ba6ccd0 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/11-notifications.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/11-notifications.json @@ -2,7 +2,7 @@ "id": "89714ed3-235b-4914-86a8-44ad66d59f30", "name": "notifications", "request": { - "url": "/notifications?all=true&page=10", + "url": "/notifications?all=true&since=1970-01-01T00%3A00%3A00Z&page=10", "method": "GET", "headers": { "Accept": { @@ -41,7 +41,7 @@ "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", "X-GitHub-Request-Id": "CB13:833E:A1F646:BFE217:5DB3A14D", - "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" + "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" } }, "uuid": "89714ed3-235b-4914-86a8-44ad66d59f30", diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/12-notifications.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/12-notifications.json index 8907d54645..84c0a42873 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/12-notifications.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/12-notifications.json @@ -2,7 +2,7 @@ "id": "2b718339-36d3-4c6b-9484-79cdd79a79e4", "name": "notifications", "request": { - "url": "/notifications?all=true&page=11", + "url": "/notifications?all=true&since=1970-01-01T00%3A00%3A00Z&page=11", "method": "GET", "headers": { "Accept": { @@ -41,7 +41,7 @@ "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", "X-GitHub-Request-Id": "CB13:833E:A1F657:BFE22B:5DB3A14D", - "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" + "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" } }, "uuid": "2b718339-36d3-4c6b-9484-79cdd79a79e4", diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/13-notifications.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/13-notifications.json index e6b46f7ecb..3481d18741 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/13-notifications.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/13-notifications.json @@ -2,7 +2,7 @@ "id": "989db4b3-8dde-4065-b4ef-6a2d90a2753a", "name": "notifications", "request": { - "url": "/notifications?all=true&page=12", + "url": "/notifications?all=true&since=1970-01-01T00%3A00%3A00Z&page=12", "method": "GET", "headers": { "Accept": { @@ -41,7 +41,7 @@ "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", "X-GitHub-Request-Id": "CB13:833E:A1F661:BFE238:5DB3A14E", - "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" + "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" } }, "uuid": "989db4b3-8dde-4065-b4ef-6a2d90a2753a", diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/14-notifications.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/14-notifications.json index bd27626d4e..08f647fcad 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/14-notifications.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/14-notifications.json @@ -2,7 +2,7 @@ "id": "50b907ef-a983-4cc9-bfd2-e2ba76eae729", "name": "notifications", "request": { - "url": "/notifications?all=true&page=13", + "url": "/notifications?all=true&since=1970-01-01T00%3A00%3A00Z&page=13", "method": "GET", "headers": { "Accept": { @@ -41,7 +41,7 @@ "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", "X-GitHub-Request-Id": "CB13:833E:A1F66D:BFE242:5DB3A14E", - "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" + "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" } }, "uuid": "50b907ef-a983-4cc9-bfd2-e2ba76eae729", diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/15-notifications.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/15-notifications.json index 2086a8fdbd..139228796a 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/15-notifications.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/15-notifications.json @@ -2,7 +2,7 @@ "id": "f2648b73-4af1-4be3-a2a4-9edc712c5d59", "name": "notifications", "request": { - "url": "/notifications?all=true&page=14", + "url": "/notifications?all=true&since=1970-01-01T00%3A00%3A00Z&page=14", "method": "GET", "headers": { "Accept": { @@ -41,7 +41,7 @@ "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", "X-GitHub-Request-Id": "CB13:833E:A1F679:BFE254:5DB3A14E", - "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" + "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" } }, "uuid": "f2648b73-4af1-4be3-a2a4-9edc712c5d59", diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/16-notifications.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/16-notifications.json index 60d836dec6..596d062a2b 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/16-notifications.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/16-notifications.json @@ -2,7 +2,7 @@ "id": "ee5a6c9f-da3a-47e7-a393-b403e82ae5d9", "name": "notifications", "request": { - "url": "/notifications?all=true&page=15", + "url": "/notifications?all=true&since=1970-01-01T00%3A00%3A00Z&page=15", "method": "GET", "headers": { "Accept": { @@ -41,7 +41,7 @@ "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", "X-GitHub-Request-Id": "CB13:833E:A1F689:BFE266:5DB3A14E", - "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" + "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" } }, "uuid": "ee5a6c9f-da3a-47e7-a393-b403e82ae5d9", diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/17-notifications.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/17-notifications.json index 25cf77ff48..2b3fcaa99d 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/17-notifications.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/17-notifications.json @@ -2,7 +2,7 @@ "id": "a41aeecf-7097-4ac6-b857-ab14797afe0a", "name": "notifications", "request": { - "url": "/notifications?all=true&page=16", + "url": "/notifications?all=true&since=1970-01-01T00%3A00%3A00Z&page=16", "method": "GET", "headers": { "Accept": { @@ -41,7 +41,7 @@ "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", "X-GitHub-Request-Id": "CB13:833E:A1F69E:BFE27A:5DB3A14F", - "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" + "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" } }, "uuid": "a41aeecf-7097-4ac6-b857-ab14797afe0a", diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/18-notifications.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/18-notifications.json index 42c582816a..3e04973df2 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/18-notifications.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/18-notifications.json @@ -2,7 +2,7 @@ "id": "e1d519f7-9bd2-4fcd-a288-2391944ec7ca", "name": "notifications", "request": { - "url": "/notifications?all=true&page=17", + "url": "/notifications?all=true&since=1970-01-01T00%3A00%3A00Z&page=17", "method": "GET", "headers": { "Accept": { @@ -41,7 +41,7 @@ "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", "X-GitHub-Request-Id": "CB13:833E:A1F6B4:BFE291:5DB3A14F", - "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" + "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" } }, "uuid": "e1d519f7-9bd2-4fcd-a288-2391944ec7ca", diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/19-notifications.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/19-notifications.json index 5bc7d00622..a2bc722b01 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/19-notifications.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/19-notifications.json @@ -2,7 +2,7 @@ "id": "1b694852-8043-418c-a76e-39370f22db96", "name": "notifications", "request": { - "url": "/notifications?all=true&page=18", + "url": "/notifications?all=true&since=1970-01-01T00%3A00%3A00Z&page=18", "method": "GET", "headers": { "Accept": { @@ -41,7 +41,7 @@ "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", "X-GitHub-Request-Id": "CB13:833E:A1F6CA:BFE2B2:5DB3A14F", - "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" + "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" } }, "uuid": "1b694852-8043-418c-a76e-39370f22db96", diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/2-notifications.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/2-notifications.json index 1b160a9c8b..46240a1d92 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/2-notifications.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/2-notifications.json @@ -2,7 +2,7 @@ "id": "d85867b0-1efe-43f5-bdf4-1b9aef03ef55", "name": "notifications", "request": { - "url": "/notifications?all=true", + "url": "/notifications?all=true&since=1970-01-01T00%3A00%3A00Z", "method": "GET", "headers": { "Accept": { @@ -41,7 +41,7 @@ "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", "X-GitHub-Request-Id": "CB13:833E:A1F5C2:BFE16E:5DB3A14B", - "Link": "; rel=\"next\", ; rel=\"last\"" + "Link": "; rel=\"next\", ; rel=\"last\"" } }, "uuid": "d85867b0-1efe-43f5-bdf4-1b9aef03ef55", diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/20-notifications.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/20-notifications.json index d99f71b368..5d4bc6c3df 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/20-notifications.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/20-notifications.json @@ -2,7 +2,7 @@ "id": "48908278-ce2f-4cec-8662-6f4ca3d81226", "name": "notifications", "request": { - "url": "/notifications?all=true&page=19", + "url": "/notifications?all=true&since=1970-01-01T00%3A00%3A00Z&page=19", "method": "GET", "headers": { "Accept": { @@ -41,7 +41,7 @@ "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", "X-GitHub-Request-Id": "CB13:833E:A1F6E4:BFE2D4:5DB3A150", - "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" + "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" } }, "uuid": "48908278-ce2f-4cec-8662-6f4ca3d81226", diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/21-notifications.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/21-notifications.json index 0d01191175..6e011fce6f 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/21-notifications.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/21-notifications.json @@ -2,7 +2,7 @@ "id": "42be6527-0570-4353-b42f-d0cae80258e3", "name": "notifications", "request": { - "url": "/notifications?all=true&page=20", + "url": "/notifications?all=true&since=1970-01-01T00%3A00%3A00Z&page=20", "method": "GET", "headers": { "Accept": { @@ -41,7 +41,7 @@ "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", "X-GitHub-Request-Id": "CB13:833E:A1F70C:BFE300:5DB3A150", - "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" + "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" } }, "uuid": "42be6527-0570-4353-b42f-d0cae80258e3", diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/22-notifications.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/22-notifications.json index 0578186986..bcaf874f82 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/22-notifications.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/22-notifications.json @@ -2,7 +2,7 @@ "id": "5720c49c-c69b-495b-b7e6-b885d88c10b1", "name": "notifications", "request": { - "url": "/notifications?all=true&page=21", + "url": "/notifications?all=true&since=1970-01-01T00%3A00%3A00Z&page=21", "method": "GET", "headers": { "Accept": { @@ -41,7 +41,7 @@ "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", "X-GitHub-Request-Id": "CB13:833E:A1F71C:BFE311:5DB3A150", - "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" + "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" } }, "uuid": "5720c49c-c69b-495b-b7e6-b885d88c10b1", diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/23-notifications.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/23-notifications.json index 28bdd8d595..11e575c017 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/23-notifications.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/23-notifications.json @@ -2,7 +2,7 @@ "id": "045c369a-0818-455a-afe1-3ae9ec919af2", "name": "notifications", "request": { - "url": "/notifications?all=true&page=22", + "url": "/notifications?all=true&since=1970-01-01T00%3A00%3A00Z&page=22", "method": "GET", "headers": { "Accept": { @@ -41,7 +41,7 @@ "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", "X-GitHub-Request-Id": "CB13:833E:A1F731:BFE31F:5DB3A151", - "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" + "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" } }, "uuid": "045c369a-0818-455a-afe1-3ae9ec919af2", diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/24-notifications.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/24-notifications.json index fb5ac17e0f..450bd8797d 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/24-notifications.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/24-notifications.json @@ -2,7 +2,7 @@ "id": "bfc7733f-6dff-4675-81e9-926103c40b83", "name": "notifications", "request": { - "url": "/notifications?all=true&page=23", + "url": "/notifications?all=true&since=1970-01-01T00%3A00%3A00Z&page=23", "method": "GET", "headers": { "Accept": { @@ -41,7 +41,7 @@ "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", "X-GitHub-Request-Id": "CB13:833E:A1F73A:BFE332:5DB3A151", - "Link": "; rel=\"prev\", ; rel=\"first\"" + "Link": "; rel=\"prev\", ; rel=\"first\"" } }, "uuid": "bfc7733f-6dff-4675-81e9-926103c40b83", diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/3-notifications.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/3-notifications.json index 686668959e..963a173b9a 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/3-notifications.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/3-notifications.json @@ -2,7 +2,7 @@ "id": "d9617266-1ca6-44b2-b495-52c1f3be4b91", "name": "notifications", "request": { - "url": "/notifications?all=true&page=2", + "url": "/notifications?all=true&since=1970-01-01T00%3A00%3A00Z&page=2", "method": "GET", "headers": { "Accept": { @@ -41,7 +41,7 @@ "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", "X-GitHub-Request-Id": "CB13:833E:A1F5D0:BFE187:5DB3A14B", - "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" + "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" } }, "uuid": "d9617266-1ca6-44b2-b495-52c1f3be4b91", diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/4-notifications.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/4-notifications.json index 590392dc5a..bfd2be216d 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/4-notifications.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/4-notifications.json @@ -2,7 +2,7 @@ "id": "6dea5253-3aa2-4484-b97a-effcad5c6ebd", "name": "notifications", "request": { - "url": "/notifications?all=true&page=3", + "url": "/notifications?all=true&since=1970-01-01T00%3A00%3A00Z&page=3", "method": "GET", "headers": { "Accept": { @@ -41,7 +41,7 @@ "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", "X-GitHub-Request-Id": "CB13:833E:A1F5DC:BFE198:5DB3A14B", - "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" + "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" } }, "uuid": "6dea5253-3aa2-4484-b97a-effcad5c6ebd", diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/5-notifications.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/5-notifications.json index a12e55a622..4f60ae1eb3 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/5-notifications.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/5-notifications.json @@ -2,7 +2,7 @@ "id": "a8e9449d-b78c-4e46-801e-59fc459920d3", "name": "notifications", "request": { - "url": "/notifications?all=true&page=4", + "url": "/notifications?all=true&since=1970-01-01T00%3A00%3A00Z&page=4", "method": "GET", "headers": { "Accept": { @@ -41,7 +41,7 @@ "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", "X-GitHub-Request-Id": "CB13:833E:A1F5E4:BFE1A3:5DB3A14C", - "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" + "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" } }, "uuid": "a8e9449d-b78c-4e46-801e-59fc459920d3", diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/6-notifications.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/6-notifications.json index 4c448dd5ba..c6b6c09cb9 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/6-notifications.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/6-notifications.json @@ -2,7 +2,7 @@ "id": "2658e99a-6619-4b0b-b70f-814a0841839e", "name": "notifications", "request": { - "url": "/notifications?all=true&page=5", + "url": "/notifications?all=true&since=1970-01-01T00%3A00%3A00Z&page=5", "method": "GET", "headers": { "Accept": { @@ -41,7 +41,7 @@ "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", "X-GitHub-Request-Id": "CB13:833E:A1F5F0:BFE1B4:5DB3A14C", - "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" + "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" } }, "uuid": "2658e99a-6619-4b0b-b70f-814a0841839e", diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/7-notifications.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/7-notifications.json index 038b30ff7b..7f78aac737 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/7-notifications.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/7-notifications.json @@ -2,7 +2,7 @@ "id": "f2524684-5156-4db6-97fa-10dedac5f779", "name": "notifications", "request": { - "url": "/notifications?all=true&page=6", + "url": "/notifications?all=true&since=1970-01-01T00%3A00%3A00Z&page=6", "method": "GET", "headers": { "Accept": { @@ -41,7 +41,7 @@ "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", "X-GitHub-Request-Id": "CB13:833E:A1F5FD:BFE1C1:5DB3A14C", - "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" + "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" } }, "uuid": "f2524684-5156-4db6-97fa-10dedac5f779", diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/8-notifications.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/8-notifications.json index 4a245443ff..6b084811db 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/8-notifications.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/8-notifications.json @@ -2,7 +2,7 @@ "id": "9437189d-2f1b-47de-898d-66fde88ef05b", "name": "notifications", "request": { - "url": "/notifications?all=true&page=7", + "url": "/notifications?all=true&since=1970-01-01T00%3A00%3A00Z&page=7", "method": "GET", "headers": { "Accept": { @@ -41,7 +41,7 @@ "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", "X-GitHub-Request-Id": "CB13:833E:A1F60A:BFE1CD:5DB3A14C", - "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" + "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" } }, "uuid": "9437189d-2f1b-47de-898d-66fde88ef05b", diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/9-notifications.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/9-notifications.json index 3a479236b2..b2c14fe37e 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/9-notifications.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/9-notifications.json @@ -2,7 +2,7 @@ "id": "1de52522-e900-4b19-90cd-758573c2349a", "name": "notifications", "request": { - "url": "/notifications?all=true&page=8", + "url": "/notifications?all=true&since=1970-01-01T00%3A00%3A00Z&page=8", "method": "GET", "headers": { "Accept": { @@ -41,7 +41,7 @@ "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", "X-GitHub-Request-Id": "CB13:833E:A1F612:BFE1D9:5DB3A14C", - "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" + "Link": "; rel=\"prev\", ; rel=\"next\", ; rel=\"last\", ; rel=\"first\"" } }, "uuid": "1de52522-e900-4b19-90cd-758573c2349a",