Skip to content

Commit

Permalink
Merge tag 'github-api-1.324' into release/v1.x-unbridged
Browse files Browse the repository at this point in the history
github-api-1.324
  • Loading branch information
bitwiseman committed Aug 19, 2024
2 parents 5184aa9 + 5fbd5a0 commit 13610e7
Show file tree
Hide file tree
Showing 52 changed files with 3,837 additions and 35 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<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-unbridged</artifactId>
<version>1.323</version>
<artifactId>github-api</artifactId>
<version>1.324</version>
<name>GitHub API for Java</name>
<url>https://github-api.kohsuke.org/</url>
<description>GitHub API for Java</description>
Expand Down
31 changes: 24 additions & 7 deletions src/main/java/org/kohsuke/github/AbuseLimitHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.HttpURLConnection;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

import javax.annotation.Nonnull;

Expand Down Expand Up @@ -86,13 +89,6 @@ public void onError(IOException e, HttpURLConnection uc) throws IOException {
}
}

private long parseWaitTime(HttpURLConnection uc) {
String v = uc.getHeaderField("Retry-After");
if (v == null)
return 60 * 1000; // can't tell, return 1 min

return Math.max(1000, Long.parseLong(v) * 1000);
}
};

/**
Expand All @@ -105,4 +101,25 @@ public void onError(IOException e, HttpURLConnection uc) throws IOException {
throw e;
}
};

/*
* Exposed for testability. Given an http response, find the retry-after header field and parse it as either a
* number or a date (the spec allows both). If no header is found, wait for a reasonably amount of time.
*/
long parseWaitTime(HttpURLConnection uc) {
String v = uc.getHeaderField("Retry-After");
if (v == null) {
// can't tell, wait for unambiguously over one minute per GitHub guidance
return 61 * 1000;
}

try {
return Math.max(1000, Long.parseLong(v) * 1000);
} catch (NumberFormatException nfe) {
// The retry-after header could be a number in seconds, or an http-date
ZonedDateTime zdt = ZonedDateTime.parse(v, DateTimeFormatter.RFC_1123_DATE_TIME);
return ChronoUnit.MILLIS.between(ZonedDateTime.now(), zdt);
}
}

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

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

/**
* The type Gh branch sync.
*/
public class GHBranchSync extends GitHubInteractiveObject {

/**
* The Repository that this branch is in.
*/
private GHRepository owner;

/**
* The message.
*/
private String message;

/**
* The merge type.
*/
private String mergeType;

/**
* The base branch.
*/
private String baseBranch;

/**
* Gets owner.
*
* @return the repository that this branch is in.
*/
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior")
public GHRepository getOwner() {
return owner;
}

/**
* Gets message.
*
* @return the message
*/
public String getMessage() {
return message;
}

/**
* Gets merge type.
*
* @return the merge type
*/
public String getMergeType() {
return mergeType;
}

/**
* Gets base branch.
*
* @return the base branch
*/
public String getBaseBranch() {
return baseBranch;
}

/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
return "GHBranchSync{" + "message='" + message + '\'' + ", mergeType='" + mergeType + '\'' + ", baseBranch='"
+ baseBranch + '\'' + '}';
}

/**
* Wrap.
*
* @param repo
* the repo
* @return the GH branch sync
*/
GHBranchSync wrap(GHRepository repo) {
this.owner = repo;
return this;
}

}
44 changes: 40 additions & 4 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ public PagedIterable<GHUser> listCollaborators(CollaboratorAffiliation affiliati

/**
* Lists all
* <a href="https://help.github.com/articles/assigning-issues-and-pull-requests-to-other-github-users/">the
* <a href= "https://help.github.com/articles/assigning-issues-and-pull-requests-to-other-github-users/">the
* available assignees</a> to which issues may be assigned.
*
* @return the paged iterable
Expand Down Expand Up @@ -1614,6 +1614,24 @@ public GHRepository fork() throws IOException {
throw new IOException(this + " was forked but can't find the new repository");
}

/**
* Sync this repository fork branch
*
* @param branch
* the branch to sync
* @return The current repository
* @throws IOException
* the io exception
*/
public GHBranchSync sync(String branch) throws IOException {
return root().createRequest()
.method("POST")
.with("branch", branch)
.withUrlPath(getApiTailUrl("merge-upstream"))
.fetch(GHBranchSync.class)
.wrap(this);
}

/**
* Forks this repository into an organization.
*
Expand Down Expand Up @@ -2222,7 +2240,7 @@ public GHCommitStatus getLastCommitStatus(String sha1) throws IOException {
* @return check runs for given ref
* @throws IOException
* the io exception
* @see <a href="https://developer.github.com/v3/checks/runs/#list-check-runs-for-a-specific-ref">List check runs
* @see <a href= "https://developer.github.com/v3/checks/runs/#list-check-runs-for-a-specific-ref">List check runs
* for a specific ref</a>
*/
public PagedIterable<GHCheckRun> getCheckRuns(String ref) throws IOException {
Expand All @@ -2242,7 +2260,7 @@ public PagedIterable<GHCheckRun> getCheckRuns(String ref) throws IOException {
* @return check runs for the given ref
* @throws IOException
* the io exception
* @see <a href="https://developer.github.com/v3/checks/runs/#list-check-runs-for-a-specific-ref">List check runs
* @see <a href= "https://developer.github.com/v3/checks/runs/#list-check-runs-for-a-specific-ref">List check runs
* for a specific ref</a>
*/
public PagedIterable<GHCheckRun> getCheckRuns(String ref, Map<String, Object> params) throws IOException {
Expand Down Expand Up @@ -3568,7 +3586,8 @@ void populate() throws IOException {

// We don't use the URL provided in the JSON because it is not reliable:
// 1. There is bug in Push event payloads that returns the wrong url.
// For Push event repository records, they take the form "https://github.com/{fullName}".
// For Push event repository records, they take the form
// "https://github.com/{fullName}".
// All other occurrences of "url" take the form "https://api.github.com/...".
// 2. For Installation event payloads, the URL is not provided at all.

Expand Down Expand Up @@ -3649,6 +3668,23 @@ public List<GHRepositoryTrafficTopReferralSources> getTopReferralSources() throw
.fetch(GHRepositoryTrafficTopReferralSources[].class));
}

/**
* Get all active rules that apply to the specified branch
* (https://docs.github.com/en/rest/repos/rules?apiVersion=2022-11-28#get-rules-for-a-branch).
*
* @param branch
* the branch
* @return the rules for branch
* @throws IOException
* the io exception
*/
public PagedIterable<GHRepositoryRule> listRulesForBranch(String branch) throws IOException {
return root().createRequest()
.method("GET")
.withUrlPath(getApiTailUrl("/rules/branches/" + branch))
.toIterable(GHRepositoryRule[].class, null);
}

/**
* A {@link GHRepositoryBuilder} that allows multiple properties to be updated per request.
*
Expand Down
Loading

0 comments on commit 13610e7

Please sign in to comment.