Skip to content

Commit c602aa5

Browse files
committed
Merge tag 'github-api-1.324' into release/v1.x
github-api-1.324
2 parents eeff849 + 5fbd5a0 commit c602aa5

File tree

52 files changed

+3836
-34
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3836
-34
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>org.kohsuke</groupId>
44
<artifactId>github-api</artifactId>
5-
<version>1.323</version>
5+
<version>1.324</version>
66
<name>GitHub API for Java</name>
77
<url>https://github-api.kohsuke.org/</url>
88
<description>GitHub API for Java</description>

src/main/java/org/kohsuke/github/AbuseLimitHandler.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import java.io.IOException;
66
import java.io.InterruptedIOException;
77
import java.net.HttpURLConnection;
8+
import java.time.ZonedDateTime;
9+
import java.time.format.DateTimeFormatter;
10+
import java.time.temporal.ChronoUnit;
811

912
import javax.annotation.Nonnull;
1013

@@ -86,13 +89,6 @@ public void onError(IOException e, HttpURLConnection uc) throws IOException {
8689
}
8790
}
8891

89-
private long parseWaitTime(HttpURLConnection uc) {
90-
String v = uc.getHeaderField("Retry-After");
91-
if (v == null)
92-
return 60 * 1000; // can't tell, return 1 min
93-
94-
return Math.max(1000, Long.parseLong(v) * 1000);
95-
}
9692
};
9793

9894
/**
@@ -105,4 +101,25 @@ public void onError(IOException e, HttpURLConnection uc) throws IOException {
105101
throw e;
106102
}
107103
};
104+
105+
/*
106+
* Exposed for testability. Given an http response, find the retry-after header field and parse it as either a
107+
* number or a date (the spec allows both). If no header is found, wait for a reasonably amount of time.
108+
*/
109+
long parseWaitTime(HttpURLConnection uc) {
110+
String v = uc.getHeaderField("Retry-After");
111+
if (v == null) {
112+
// can't tell, wait for unambiguously over one minute per GitHub guidance
113+
return 61 * 1000;
114+
}
115+
116+
try {
117+
return Math.max(1000, Long.parseLong(v) * 1000);
118+
} catch (NumberFormatException nfe) {
119+
// The retry-after header could be a number in seconds, or an http-date
120+
ZonedDateTime zdt = ZonedDateTime.parse(v, DateTimeFormatter.RFC_1123_DATE_TIME);
121+
return ChronoUnit.MILLIS.between(ZonedDateTime.now(), zdt);
122+
}
123+
}
124+
108125
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package org.kohsuke.github;
2+
3+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
4+
5+
/**
6+
* The type Gh branch sync.
7+
*/
8+
public class GHBranchSync extends GitHubInteractiveObject {
9+
10+
/**
11+
* The Repository that this branch is in.
12+
*/
13+
private GHRepository owner;
14+
15+
/**
16+
* The message.
17+
*/
18+
private String message;
19+
20+
/**
21+
* The merge type.
22+
*/
23+
private String mergeType;
24+
25+
/**
26+
* The base branch.
27+
*/
28+
private String baseBranch;
29+
30+
/**
31+
* Gets owner.
32+
*
33+
* @return the repository that this branch is in.
34+
*/
35+
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior")
36+
public GHRepository getOwner() {
37+
return owner;
38+
}
39+
40+
/**
41+
* Gets message.
42+
*
43+
* @return the message
44+
*/
45+
public String getMessage() {
46+
return message;
47+
}
48+
49+
/**
50+
* Gets merge type.
51+
*
52+
* @return the merge type
53+
*/
54+
public String getMergeType() {
55+
return mergeType;
56+
}
57+
58+
/**
59+
* Gets base branch.
60+
*
61+
* @return the base branch
62+
*/
63+
public String getBaseBranch() {
64+
return baseBranch;
65+
}
66+
67+
/**
68+
* To string.
69+
*
70+
* @return the string
71+
*/
72+
@Override
73+
public String toString() {
74+
return "GHBranchSync{" + "message='" + message + '\'' + ", mergeType='" + mergeType + '\'' + ", baseBranch='"
75+
+ baseBranch + '\'' + '}';
76+
}
77+
78+
/**
79+
* Wrap.
80+
*
81+
* @param repo
82+
* the repo
83+
* @return the GH branch sync
84+
*/
85+
GHBranchSync wrap(GHRepository repo) {
86+
this.owner = repo;
87+
return this;
88+
}
89+
90+
}

src/main/java/org/kohsuke/github/GHRepository.java

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ public PagedIterable<GHUser> listCollaborators(CollaboratorAffiliation affiliati
10071007

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

1617+
/**
1618+
* Sync this repository fork branch
1619+
*
1620+
* @param branch
1621+
* the branch to sync
1622+
* @return The current repository
1623+
* @throws IOException
1624+
* the io exception
1625+
*/
1626+
public GHBranchSync sync(String branch) throws IOException {
1627+
return root().createRequest()
1628+
.method("POST")
1629+
.with("branch", branch)
1630+
.withUrlPath(getApiTailUrl("merge-upstream"))
1631+
.fetch(GHBranchSync.class)
1632+
.wrap(this);
1633+
}
1634+
16171635
/**
16181636
* Forks this repository into an organization.
16191637
*
@@ -2222,7 +2240,7 @@ public GHCommitStatus getLastCommitStatus(String sha1) throws IOException {
22222240
* @return check runs for given ref
22232241
* @throws IOException
22242242
* the io exception
2225-
* @see <a href="https://developer.github.com/v3/checks/runs/#list-check-runs-for-a-specific-ref">List check runs
2243+
* @see <a href= "https://developer.github.com/v3/checks/runs/#list-check-runs-for-a-specific-ref">List check runs
22262244
* for a specific ref</a>
22272245
*/
22282246
public PagedIterable<GHCheckRun> getCheckRuns(String ref) throws IOException {
@@ -2242,7 +2260,7 @@ public PagedIterable<GHCheckRun> getCheckRuns(String ref) throws IOException {
22422260
* @return check runs for the given ref
22432261
* @throws IOException
22442262
* the io exception
2245-
* @see <a href="https://developer.github.com/v3/checks/runs/#list-check-runs-for-a-specific-ref">List check runs
2263+
* @see <a href= "https://developer.github.com/v3/checks/runs/#list-check-runs-for-a-specific-ref">List check runs
22462264
* for a specific ref</a>
22472265
*/
22482266
public PagedIterable<GHCheckRun> getCheckRuns(String ref, Map<String, Object> params) throws IOException {
@@ -3568,7 +3586,8 @@ void populate() throws IOException {
35683586

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

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

3671+
/**
3672+
* Get all active rules that apply to the specified branch
3673+
* (https://docs.github.com/en/rest/repos/rules?apiVersion=2022-11-28#get-rules-for-a-branch).
3674+
*
3675+
* @param branch
3676+
* the branch
3677+
* @return the rules for branch
3678+
* @throws IOException
3679+
* the io exception
3680+
*/
3681+
public PagedIterable<GHRepositoryRule> listRulesForBranch(String branch) throws IOException {
3682+
return root().createRequest()
3683+
.method("GET")
3684+
.withUrlPath(getApiTailUrl("/rules/branches/" + branch))
3685+
.toIterable(GHRepositoryRule[].class, null);
3686+
}
3687+
36523688
/**
36533689
* A {@link GHRepositoryBuilder} that allows multiple properties to be updated per request.
36543690
*

0 commit comments

Comments
 (0)