Skip to content

Migrate legacy date-time api to new date-time api #2074

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 11, 2025
27 changes: 24 additions & 3 deletions .github/workflows/maven-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -59,7 +59,27 @@ 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
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
Expand Down Expand Up @@ -88,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
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/publish_release_branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
69 changes: 64 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.kohsuke</groupId>
<artifactId>github-api</artifactId>
<artifactId>${github-api.artifactId}</artifactId>
<version>2.0-rc.2-SNAPSHOT</version>
<name>GitHub API for Java</name>
<description>GitHub API for Java</description>
Expand Down Expand Up @@ -62,6 +62,7 @@
</distributionManagement>

<properties>
<github-api.artifactId>github-api</github-api.artifactId>
<hamcrest.version>3.0</hamcrest.version>
<!-- Using this as the minimum bar for code coverage. Adding methods without covering them will fail this. -->
<jacoco.coverage.target.bundle.method>0.70</jacoco.coverage.target.bundle.method>
Expand Down Expand Up @@ -141,6 +142,10 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<dependency>
<groupId>com.infradna.tool</groupId>
<artifactId>bridge-method-annotation</artifactId>
Expand Down Expand Up @@ -302,6 +307,18 @@
</testResources>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.infradna.tool</groupId>
<artifactId>bridge-method-injector</artifactId>
<version>1.30</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
Expand All @@ -324,7 +341,10 @@
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>3.3.1</version>
</plugin>
Expand Down Expand Up @@ -511,7 +531,7 @@
<plugin>
<groupId>com.github.siom79.japicmp</groupId>
<artifactId>japicmp-maven-plugin</artifactId>
<version>0.23.0</version>
<version>0.23.1</version>
<configuration>
<parameter>
<breakBuildOnBinaryIncompatibleModifications>true</breakBuildOnBinaryIncompatibleModifications>
Expand Down Expand Up @@ -570,7 +590,7 @@
<annotationProcessorPath>
<groupId>org.jenkins-ci</groupId>
<artifactId>annotation-indexer</artifactId>
<version>1.17</version>
<version>1.18</version>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
Expand Down Expand Up @@ -619,6 +639,9 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>@{jacoco.surefire.argLine} ${surefire.argLine}</argLine>
<systemPropertyVariables>
<test.projectArtifactId>${project.artifactId}</test.projectArtifactId>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
Expand All @@ -636,7 +659,7 @@
<!--
This plugin is used to generate AOT metadata during tests so that it can be
compared against those in META-INF/native-image/org.kohsuke/github-api/*.
The tests are start with the name "Aot..."
The tests are start with the name "Aot..."
-->
<plugin>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -799,6 +822,42 @@
</plugins>
</build>
</profile>
<profile>
<id>bridged</id>
<properties>
<!-- Only fail code coverage on non-windows machines -->
<github-api.artifactId>github-api-bridged</github-api.artifactId>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.infradna.tool</groupId>
<artifactId>bridge-method-injector</artifactId>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-bridged-resources</id>
<goals>
<goal>copy-resources</goal>
</goals>
<!-- here the phase you need -->
<phase>validate</phase>
<configuration>
<outputDirectory>${basedir}/target/classes/META-INF/native-image/org.kohsuke/${github-api.artifactId}</outputDirectory>
<resources>
<resource>
<directory>src/main/resources/META-INF/native-image/org.kohsuke/github-api</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>ci-non-windows</id>
<activation>
Expand Down
21 changes: 19 additions & 2 deletions src/main/java/org/kohsuke/github/GHApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.io.IOException;
import java.net.URL;
import java.time.Instant;
import java.util.Collections;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -145,7 +146,7 @@ public PagedIterable<GHAppInstallationRequest> listInstallationRequests() {
* @see <a href="https://developer.github.com/v3/apps/#list-installations">List installations</a>
*/
public PagedIterable<GHAppInstallation> listInstallations() {
return listInstallations(null);
return listInstallations(GitHubClient.toInstantOrNull(null));
}

/**
Expand All @@ -157,11 +158,27 @@ public PagedIterable<GHAppInstallation> listInstallations() {
* - Allows users to get installations that have been updated since a given date.
* @return a list of App installations since a given time.
* @see <a href="https://developer.github.com/v3/apps/#list-installations">List installations</a>
* @deprecated use {@link #listInstallations(Instant)}
*/
@Deprecated
public PagedIterable<GHAppInstallation> listInstallations(final Date since) {
return listInstallations(since.toInstant());
}

/**
* Obtains all the installations associated with this app since a given date.
* <p>
* 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 <a href="https://developer.github.com/v3/apps/#list-installations">List installations</a>
*/
public PagedIterable<GHAppInstallation> 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);
}
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/org/kohsuke/github/GHAppInstallation.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
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;

import java.io.IOException;
import java.net.URL;
import java.time.Instant;
import java.util.Collections;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -189,8 +191,9 @@ public GHRepositorySelection getRepositorySelection() {
*
* @return the suspended at
*/
public Date getSuspendedAt() {
return GitHubClient.parseDate(suspendedAt);
@WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate")
public Instant getSuspendedAt() {
return GitHubClient.parseInstant(suspendedAt);
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/org/kohsuke/github/GHAppInstallationToken.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.kohsuke.github;

import com.infradna.tool.bridge_method_injector.WithBridgeMethods;

import java.time.Instant;
import java.util.*;

// TODO: Auto-generated Javadoc
Expand Down Expand Up @@ -66,7 +69,8 @@ public GHRepositorySelection getRepositorySelection() {
*
* @return date when this token expires
*/
public Date getExpiresAt() {
return GitHubClient.parseDate(expires_at);
@WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate")
public Instant getExpiresAt() {
return GitHubClient.parseInstant(expires_at);
}
}
7 changes: 5 additions & 2 deletions src/main/java/org/kohsuke/github/GHArtifact.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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;

import java.io.IOException;
import java.net.URL;
import java.time.Instant;
import java.util.Date;
import java.util.Objects;

Expand Down Expand Up @@ -77,8 +79,9 @@ public boolean isExpired() {
*
* @return the date of expiration
*/
public Date getExpiresAt() {
return GitHubClient.parseDate(expiresAt);
@WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate")
public Instant getExpiresAt() {
return GitHubClient.parseInstant(expiresAt);
}

/**
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/org/kohsuke/github/GHCheckRun.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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;

import java.io.IOException;
import java.net.URL;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
Expand Down Expand Up @@ -269,17 +271,19 @@ public URL getDetailsUrl() {
*
* @return Timestamp of the start time
*/
public Date getStartedAt() {
return GitHubClient.parseDate(startedAt);
@WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate")
public Instant getStartedAt() {
return GitHubClient.parseInstant(startedAt);
}

/**
* Gets the completed time of the check run in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ.
*
* @return Timestamp of the completed time
*/
public Date getCompletedAt() {
return GitHubClient.parseDate(completedAt);
@WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate")
public Instant getCompletedAt() {
return GitHubClient.parseInstant(completedAt);
}

/**
Expand Down
Loading