Skip to content

Commit

Permalink
Merge tag 'github-api-2.0-alpha-3' into release/v2.x
Browse files Browse the repository at this point in the history
github-api-2.0-alpha-3
  • Loading branch information
bitwiseman committed Jan 25, 2025
2 parents 9fae181 + fd85f91 commit a5a9b6b
Show file tree
Hide file tree
Showing 179 changed files with 14,455 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

steps:
- name: Set up JDK
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/maven-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
name: maven-test-target-directory
path: target
- name: Codecov Report
uses: codecov/codecov-action@v4.5.0
uses: codecov/codecov-action@v5.1.2
with:
# Codecov token from https://app.codecov.io/gh/hub4j/github-api/settings
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
30 changes: 15 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.kohsuke</groupId>
<artifactId>github-api</artifactId>
<version>2.0.0-alpha-2</version>
<version>2.0-alpha-3</version>
<name>GitHub API for Java</name>
<url>https://github-api.kohsuke.org/</url>
<description>GitHub API for Java</description>
Expand Down Expand Up @@ -32,14 +32,14 @@
</distributionManagement>

<properties>
<spring.boot.version>3.3.3</spring.boot.version>
<spring.boot.version>3.3.5</spring.boot.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spotbugs-maven-plugin.version>4.8.6.3</spotbugs-maven-plugin.version>
<spotbugs-maven-plugin.version>4.8.6.4</spotbugs-maven-plugin.version>
<spotbugs.version>4.8.6</spotbugs.version>
<spotbugs-maven-plugin.failOnError>true</spotbugs-maven-plugin.failOnError>
<hamcrest.version>3.0</hamcrest.version>
<okhttp3.version>4.12.0</okhttp3.version>
<okio.version>3.9.0</okio.version>
<okio.version>3.9.1</okio.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>
<jacoco.coverage.target.class.method>0.50</jacoco.coverage.target.class.method>
Expand Down Expand Up @@ -77,16 +77,16 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.17.1</version>
<version>2.18.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-help-plugin</artifactId>
<version>3.5.0</version>
<version>3.5.1</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.0</version>
<version>3.5.2</version>
<configuration>
<!-- SUREFIRE-1226 workaround -->
<trimStackTrace>false</trimStackTrace>
Expand All @@ -100,7 +100,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.2.6</version>
<version>3.2.7</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
Expand Down Expand Up @@ -202,7 +202,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.10.0</version>
<version>3.11.1</version>
<configuration>
<source>11</source>
<release>11</release>
Expand Down Expand Up @@ -245,7 +245,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.12.1</version>
<version>3.21.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -265,7 +265,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.7.0</version>
<version>3.8.0</version>
<dependencies>
<dependency>
<groupId>org.apache.bcel</groupId>
Expand Down Expand Up @@ -419,7 +419,7 @@
<dependency>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>2.17.2</version>
<version>2.18.2</version>
<scope>import</scope>
<type>pom</type>
</dependency>
Expand Down Expand Up @@ -504,13 +504,13 @@
<dependency>
<groupId>com.infradna.tool</groupId>
<artifactId>bridge-method-annotation</artifactId>
<version>1.29</version>
<version>1.30</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.1.0-jre</version>
<version>33.4.0-jre</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -552,7 +552,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.13.0</version>
<version>5.14.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/kohsuke/github/GHApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,22 @@ public Map<String, String> getPermissions() {
return Collections.unmodifiableMap(permissions);
}

/**
* Obtains all the installation requests associated with this app.
* <p>
* You must use a JWT to access this endpoint.
*
* @return a list of App installation requests
* @see <a href=
* "https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#list-installation-requests-for-the-authenticated-app">List
* installation requests</a>
*/
public PagedIterable<GHAppInstallationRequest> listInstallationRequests() {
return root().createRequest()
.withUrlPath("/app/installation-requests")
.toIterable(GHAppInstallationRequest[].class, null);
}

/**
* Obtains all the installations associated with this app.
* <p>
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/org/kohsuke/github/GHAppInstallationRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.kohsuke.github;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* A Github App Installation Request.
*
* @author Anuj Hydrabadi
* @see GHApp#listInstallationRequests() GHApp#listInstallationRequests()
*/
public class GHAppInstallationRequest extends GHObject {
/**
* Create default GHAppInstallationRequest instance
*/
public GHAppInstallationRequest() {
}

private GHOrganization account;

private GHUser requester;

/**
* Gets the organization where the app was requested to be installed.
*
* @return the organization where the app was requested to be installed.
*/
@SuppressFBWarnings(value = { "EI_EXPOSE_REP", "UWF_UNWRITTEN_FIELD" }, justification = "Expected behavior")
public GHOrganization getAccount() {
return account;
}

/**
* Gets the user who requested the installation.
*
* @return the user who requested the installation.
*/
@SuppressFBWarnings(value = { "EI_EXPOSE_REP", "UWF_UNWRITTEN_FIELD" }, justification = "Expected behavior")
public GHUser getRequester() {
return requester;
}

}
100 changes: 100 additions & 0 deletions src/main/java/org/kohsuke/github/GHAutolink.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package org.kohsuke.github;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.io.IOException;

/**
* Represents a GitHub repository autolink reference.
*
* @author Alaurant
* @see GHAutolinkBuilder
* @see GHRepository#listAutolinks() GHRepository#listAutolinks()
* @see <a href="https://docs.github.com/en/rest/repos/autolinks">Repository autolinks API</a>
*/
public class GHAutolink {

private int id;
private String key_prefix;
private String url_template;
private boolean is_alphanumeric;
private GHRepository owner;

/**
* Instantiates a new Gh autolink.
*/
public GHAutolink() {
}

/**
* Gets the autolink ID
*
* @return the id
*/
public int getId() {
return id;
}

/**
* Gets the key prefix used to identify issues/PR references
*
* @return the key prefix string
*/
public String getKeyPrefix() {
return key_prefix;
}

/**
* Gets the URL template that will be used for matching
*
* @return the URL template string
*/
public String getUrlTemplate() {
return url_template;
}

/**
* Checks if the autolink uses alphanumeric values
*
* @return true if alphanumeric, false otherwise
*/
public boolean isAlphanumeric() {
return is_alphanumeric;
}

/**
* Gets the repository that owns this autolink
*
* @return the repository instance
*/
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior")
public GHRepository getOwner() {
return owner;
}

/**
* Deletes this autolink
*
* @throws IOException
* if the deletion fails
*/
public void delete() throws IOException {
owner.root()
.createRequest()
.method("DELETE")
.withUrlPath(String.format("/repos/%s/%s/autolinks/%d", owner.getOwnerName(), owner.getName(), getId()))
.send();
}

/**
* Wraps this autolink with its owner repository.
*
* @param owner
* the repository that owns this autolink
* @return this instance
*/
GHAutolink lateBind(GHRepository owner) {
this.owner = owner;
return this;
}
}
90 changes: 90 additions & 0 deletions src/main/java/org/kohsuke/github/GHAutolinkBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package org.kohsuke.github;

import java.io.IOException;

// TODO: Auto-generated Javadoc
/**
* The type Gh autolink builder.
*
* @see GHRepository#createAutolink()
* @see GHAutolink
*/
public class GHAutolinkBuilder {

private final GHRepository repo;
private final Requester req;
private String keyPrefix;
private String urlTemplate;
private Boolean isAlphanumeric;

/**
* Instantiates a new Gh autolink builder.
*
* @param repo
* the repo
*/
GHAutolinkBuilder(GHRepository repo) {
this.repo = repo;
req = repo.root().createRequest();
}

/**
* With key prefix gh autolink builder.
*
* @param keyPrefix
* the key prefix
* @return the gh autolink builder
*/
public GHAutolinkBuilder withKeyPrefix(String keyPrefix) {
this.keyPrefix = keyPrefix;
return this;
}

/**
* With url template gh autolink builder.
*
* @param urlTemplate
* the url template
* @return the gh autolink builder
*/
public GHAutolinkBuilder withUrlTemplate(String urlTemplate) {
this.urlTemplate = urlTemplate;
return this;
}

/**
* With is alphanumeric gh autolink builder.
*
* @param isAlphanumeric
* the is alphanumeric
* @return the gh autolink builder
*/
public GHAutolinkBuilder withIsAlphanumeric(boolean isAlphanumeric) {
this.isAlphanumeric = isAlphanumeric;
return this;
}

private String getApiTail() {
return String.format("/repos/%s/%s/autolinks", repo.getOwnerName(), repo.getName());
}

/**
* Create gh autolink.
*
* @return the gh autolink
* @throws IOException
* the io exception
*/
public GHAutolink create() throws IOException {
GHAutolink autolink = req.method("POST")
.with("key_prefix", keyPrefix)
.with("url_template", urlTemplate)
.with("is_alphanumeric", isAlphanumeric)
.withHeader("Accept", "application/vnd.github+json")
.withUrlPath(getApiTail())
.fetch(GHAutolink.class);

return autolink.lateBind(repo);
}

}
Loading

0 comments on commit a5a9b6b

Please sign in to comment.