Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9d15cd4

Browse filesBrowse files
authored
Merge pull request #1 from kohsuke/master
catchup
2 parents d91388a + 0731f63 commit 9d15cd4
Copy full SHA for 9d15cd4

File tree

Expand file treeCollapse file tree

84 files changed

+7196
-178
lines changed
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

84 files changed

+7196
-178
lines changed

‎pom.xml

Copy file name to clipboardExpand all lines: pom.xml
+23-2Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</parent>
88

99
<artifactId>github-api</artifactId>
10-
<version>1.73-SNAPSHOT</version>
10+
<version>1.82-SNAPSHOT</version>
1111
<name>GitHub API for Java</name>
1212
<url>http://github-api.kohsuke.org/</url>
1313
<description>GitHub API for Java</description>
@@ -34,6 +34,27 @@
3434

3535
<build>
3636
<plugins>
37+
<plugin>
38+
<groupId>org.codehaus.mojo</groupId>
39+
<artifactId>animal-sniffer-maven-plugin</artifactId>
40+
<version>1.15</version>
41+
<configuration>
42+
<signature>
43+
<groupId>org.codehaus.mojo.signature</groupId>
44+
<artifactId>java15</artifactId>
45+
<version>1.0</version>
46+
</signature>
47+
</configuration>
48+
<executions>
49+
<execution>
50+
<id>ensure-java-1.5-class-library</id>
51+
<phase>test</phase>
52+
<goals>
53+
<goal>check</goal>
54+
</goals>
55+
</execution>
56+
</executions>
57+
</plugin>
3758
<plugin>
3859
<groupId>com.infradna.tool</groupId>
3960
<artifactId>bridge-method-injector</artifactId>
@@ -114,7 +135,7 @@
114135
<dependency>
115136
<groupId>com.squareup.okhttp</groupId>
116137
<artifactId>okhttp-urlconnection</artifactId>
117-
<version>2.0.0</version>
138+
<version>2.7.5</version>
118139
<optional>true</optional>
119140
</dependency>
120141
<dependency>
+63Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package org.kohsuke.github;
2+
3+
import java.io.IOException;
4+
import java.io.InterruptedIOException;
5+
import java.net.HttpURLConnection;
6+
7+
/**
8+
* Pluggable strategy to determine what to do when the API abuse limit is hit.
9+
*
10+
* @author Kohsuke Kawaguchi
11+
* @see GitHubBuilder#withAbuseLimitHandler(AbuseLimitHandler)
12+
* @see <a href="https://developer.github.com/v3/#abuse-rate-limits">documentation</a>
13+
* @see RateLimitHandler
14+
*/
15+
public abstract class AbuseLimitHandler {
16+
/**
17+
* Called when the library encounters HTTP error indicating that the API abuse limit is reached.
18+
*
19+
* <p>
20+
* Any exception thrown from this method will cause the request to fail, and the caller of github-api
21+
* will receive an exception. If this method returns normally, another request will be attempted.
22+
* For that to make sense, the implementation needs to wait for some time.
23+
*
24+
* @see <a href="https://developer.github.com/v3/#abuse-rate-limits">API documentation from GitHub</a>
25+
* @param e
26+
* Exception from Java I/O layer. If you decide to fail the processing, you can throw
27+
* this exception (or wrap this exception into another exception and throw it.)
28+
* @param uc
29+
* Connection that resulted in an error. Useful for accessing other response headers.
30+
*/
31+
public abstract void onError(IOException e, HttpURLConnection uc) throws IOException;
32+
33+
/**
34+
* Wait until the API abuse "wait time" is passed.
35+
*/
36+
public static final AbuseLimitHandler WAIT = new AbuseLimitHandler() {
37+
@Override
38+
public void onError(IOException e, HttpURLConnection uc) throws IOException {
39+
try {
40+
Thread.sleep(parseWaitTime(uc));
41+
} catch (InterruptedException _) {
42+
throw (InterruptedIOException)new InterruptedIOException().initCause(e);
43+
}
44+
}
45+
46+
private long parseWaitTime(HttpURLConnection uc) {
47+
String v = uc.getHeaderField("Retry-After");
48+
if (v==null) return 60 * 1000; // can't tell, return 1 min
49+
50+
return Math.max(1000, Long.parseLong(v)*1000);
51+
}
52+
};
53+
54+
/**
55+
* Fail immediately.
56+
*/
57+
public static final AbuseLimitHandler FAIL = new AbuseLimitHandler() {
58+
@Override
59+
public void onError(IOException e, HttpURLConnection uc) throws IOException {
60+
throw (IOException)new IOException("Abust limit reached").initCause(e);
61+
}
62+
};
63+
}
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.kohsuke.github;
2+
3+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
/**
9+
* @author Kohsuke Kawaguchi
10+
* @see GHBranch#disableProtection()
11+
*/
12+
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD", "URF_UNREAD_FIELD"}, justification = "JSON API")
13+
class BranchProtection {
14+
boolean enabled;
15+
RequiredStatusChecks requiredStatusChecks;
16+
17+
static class RequiredStatusChecks {
18+
EnforcementLevel enforcement_level;
19+
List<String> contexts = new ArrayList<String>();
20+
}
21+
}
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.kohsuke.github;
2+
3+
import java.util.Locale;
4+
5+
/**
6+
* @author Kohsuke Kawaguchi
7+
*/
8+
public enum EnforcementLevel {
9+
OFF, NON_ADMINS, EVERYONE;
10+
11+
public String toString() {
12+
return name().toLowerCase(Locale.ENGLISH);
13+
}
14+
}

‎src/main/java/org/kohsuke/github/GHAuthorization.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHAuthorization.java
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,14 @@ public class GHAuthorization extends GHObject {
3636
private GitHub root;
3737
private List<String> scopes;
3838
private String token;
39+
private String token_last_eight;
40+
private String hashed_token;
3941
private App app;
4042
private String note;
4143
private String note_url;
44+
private String fingerprint;
45+
//TODO add some user class for https://developer.github.com/v3/oauth_authorizations/#check-an-authorization ?
46+
//private GHUser user;
4247

4348
public GitHub getRoot() {
4449
return root;
@@ -52,6 +57,14 @@ public String getToken() {
5257
return token;
5358
}
5459

60+
public String getTokenLastEight() {
61+
return token_last_eight;
62+
}
63+
64+
public String getHashedToken() {
65+
return hashed_token;
66+
}
67+
5568
public URL getAppUrl() {
5669
return GitHub.parseURL(app.url);
5770
}
@@ -82,6 +95,10 @@ public URL getNoteUrl() {
8295
return GitHub.parseURL(note_url);
8396
}
8497

98+
public String getFingerprint() {
99+
return fingerprint;
100+
}
101+
85102
/*package*/ GHAuthorization wrap(GitHub root) {
86103
this.root = root;
87104
return this;
@@ -92,5 +109,6 @@ public URL getNoteUrl() {
92109
private static class App {
93110
private String url;
94111
private String name;
112+
// private String client_id; not yet used
95113
}
96114
}

‎src/main/java/org/kohsuke/github/GHBranch.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHBranch.java
+46-1Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
package org.kohsuke.github;
22

33
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
4+
import org.kohsuke.github.BranchProtection.RequiredStatusChecks;
5+
6+
import java.io.IOException;
7+
import java.util.Arrays;
8+
import java.util.Collection;
9+
10+
import static org.kohsuke.github.Previews.LOKI;
411

512
/**
613
* A branch in a repository.
714
*
815
* @author Yusuke Kokubo
916
*/
1017
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
11-
"NP_UNWRITTEN_FIELD"}, justification = "JSON API")
18+
"NP_UNWRITTEN_FIELD", "URF_UNREAD_FIELD"}, justification = "JSON API")
1219
public class GHBranch {
1320
private GitHub root;
1421
private GHRepository owner;
@@ -44,6 +51,44 @@ public String getName() {
4451
public String getSHA1() {
4552
return commit.sha;
4653
}
54+
55+
/**
56+
* Disables branch protection and allows anyone with push access to push changes.
57+
*/
58+
@Preview @Deprecated
59+
public void disableProtection() throws IOException {
60+
BranchProtection bp = new BranchProtection();
61+
bp.enabled = false;
62+
setProtection(bp);
63+
}
64+
65+
/**
66+
* Enables branch protection to control what commit statuses are required to push.
67+
*
68+
* @see GHCommitStatus#getContext()
69+
*/
70+
@Preview @Deprecated
71+
public void enableProtection(EnforcementLevel level, Collection<String> contexts) throws IOException {
72+
BranchProtection bp = new BranchProtection();
73+
bp.enabled = true;
74+
bp.requiredStatusChecks = new RequiredStatusChecks();
75+
bp.requiredStatusChecks.enforcement_level = level;
76+
bp.requiredStatusChecks.contexts.addAll(contexts);
77+
setProtection(bp);
78+
}
79+
80+
@Preview @Deprecated
81+
public void enableProtection(EnforcementLevel level, String... contexts) throws IOException {
82+
enableProtection(level, Arrays.asList(contexts));
83+
}
84+
85+
private void setProtection(BranchProtection bp) throws IOException {
86+
new Requester(root).method("PATCH").withPreview(LOKI)._with("protection",bp).to(getApiRoute());
87+
}
88+
89+
String getApiRoute() {
90+
return owner.getApiTailUrl("/branches/"+name);
91+
}
4792

4893
@Override
4994
public String toString() {

‎src/main/java/org/kohsuke/github/GHCommit.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHCommit.java
+41-4Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
44
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
5-
65
import java.io.IOException;
76
import java.net.URL;
87
import java.util.AbstractList;
98
import java.util.ArrayList;
109
import java.util.Collections;
10+
import java.util.Date;
1111
import java.util.List;
1212

1313
/**
@@ -42,11 +42,19 @@ public GitUser getAuthor() {
4242
return author;
4343
}
4444

45+
public Date getAuthoredDate() {
46+
return GitHub.parseDate(author.date);
47+
}
48+
4549
@WithBridgeMethods(value = GHAuthor.class, castRequired = true)
4650
public GitUser getCommitter() {
4751
return committer;
4852
}
4953

54+
public Date getCommitDate() {
55+
return GitHub.parseDate(committer.date);
56+
}
57+
5058
/**
5159
* Commit message.
5260
*/
@@ -63,6 +71,7 @@ public int getCommentCount() {
6371
* @deprecated Use {@link GitUser} instead.
6472
*/
6573
public static class GHAuthor extends GitUser {
74+
private String date;
6675
}
6776

6877
public static class Stats {
@@ -102,7 +111,7 @@ public int getLinesDeleted() {
102111
}
103112

104113
/**
105-
* "modified", "added", or "deleted"
114+
* "modified", "added", or "removed"
106115
*/
107116
public String getStatus() {
108117
return status;
@@ -171,14 +180,16 @@ static class User {
171180
String login;
172181
}
173182

174-
String url,sha;
183+
String url,html_url,sha;
175184
List<File> files;
176185
Stats stats;
177186
List<Parent> parents;
178187
User author,committer;
179188

180189

181-
public ShortInfo getCommitShortInfo() {
190+
public ShortInfo getCommitShortInfo() throws IOException {
191+
if (commit==null)
192+
populate();
182193
return commit;
183194
}
184195

@@ -213,6 +224,13 @@ public int getLinesDeleted() throws IOException {
213224
return stats.deletions;
214225
}
215226

227+
/**
228+
* URL of this commit like "https://github.com/kohsuke/sandbox-ant/commit/8ae38db0ea5837313ab5f39d43a6f73de3bd9000"
229+
*/
230+
public URL getHtmlUrl() {
231+
return GitHub.parseURL(html_url);
232+
}
233+
216234
/**
217235
* [0-9a-f]{40} SHA1 checksum.
218236
*/
@@ -263,10 +281,29 @@ public GHUser getAuthor() throws IOException {
263281
return resolveUser(author);
264282
}
265283

284+
/**
285+
* Gets the date the change was authored on.
286+
* @return the date the change was authored on.
287+
* @throws IOException if the information was not already fetched and an attempt at fetching the information failed.
288+
*/
289+
public Date getAuthoredDate() throws IOException {
290+
return getCommitShortInfo().getAuthoredDate();
291+
}
292+
266293
public GHUser getCommitter() throws IOException {
267294
return resolveUser(committer);
268295
}
269296

297+
/**
298+
* Gets the date the change was committed on.
299+
*
300+
* @return the date the change was committed on.
301+
* @throws IOException if the information was not already fetched and an attempt at fetching the information failed.
302+
*/
303+
public Date getCommitDate() throws IOException {
304+
return getCommitShortInfo().getCommitDate();
305+
}
306+
270307
private GHUser resolveUser(User author) throws IOException {
271308
if (author==null || author.login==null) return null;
272309
return owner.root.getUser(author.login);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.