From adaa8ece89ae8d6652d8f3c2b934af5caf7bb2bd Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Sat, 15 Aug 2015 07:19:25 -0700 Subject: [PATCH 01/26] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 6650872541..60299712b2 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ github-api - 1.70 + 1.71-SNAPSHOT GitHub API for Java http://github-api.kohsuke.org/ GitHub API for Java @@ -16,7 +16,7 @@ scm:git:git@github.com/kohsuke/${project.artifactId}.git scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git http://${project.artifactId}.kohsuke.org/ - github-api-1.70 + HEAD From e0b109cba6faa84813a528880dbf3923c1b86058 Mon Sep 17 00:00:00 2001 From: Rob Schoening Date: Tue, 1 Sep 2015 00:00:46 -0700 Subject: [PATCH 02/26] fix read() failure with private repos reorder buildRequest() --- src/main/java/org/kohsuke/github/Requester.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index 78ead072d9..12fd96fa66 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -271,8 +271,12 @@ public InputStream asStream(String tailApiUrl) throws IOException { while (true) {// loop while API rate limit is hit setupConnection(root.getApiURL(tailApiUrl)); - buildRequest(); - + + // if the download link is encoded with a token on the query string, the default behavior of POST will fail + uc.setRequestMethod("GET"); + + buildRequest(); + try { return wrapStream(uc.getInputStream()); } catch (IOException e) { From b0687dbeb59f5c9202f9b1c9cff0aceb4d760a55 Mon Sep 17 00:00:00 2001 From: Rob Schoening Date: Sun, 6 Sep 2015 08:45:42 -0700 Subject: [PATCH 03/26] Fix compilation errror: The constructor ArrayList(List) is undefined --- src/main/java/org/kohsuke/github/GHHooks.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHHooks.java b/src/main/java/org/kohsuke/github/GHHooks.java index 1a6154aa6d..4ee939c5a8 100644 --- a/src/main/java/org/kohsuke/github/GHHooks.java +++ b/src/main/java/org/kohsuke/github/GHHooks.java @@ -21,8 +21,9 @@ private Context(GitHub root) { } public List getHooks() throws IOException { - List list = new ArrayList(Arrays.asList( - root.retrieve().to(collection(), collectionClass()))); + + GHHook [] hookArray = root.retrieve().to(collection(),collectionClass()); // jdk/eclipse bug requires this to be on separate line + List list = new ArrayList(Arrays.asList(hookArray)); for (GHHook h : list) wrap(h); return list; From 025b6cbfb799fdbbd4aefb4b09953054d4c35831 Mon Sep 17 00:00:00 2001 From: dblevins Date: Mon, 14 Sep 2015 10:53:07 -0700 Subject: [PATCH 04/26] Support Milestone closed_at date --- src/main/java/org/kohsuke/github/GHMilestone.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/kohsuke/github/GHMilestone.java b/src/main/java/org/kohsuke/github/GHMilestone.java index 146c92abb3..0d1b43224e 100644 --- a/src/main/java/org/kohsuke/github/GHMilestone.java +++ b/src/main/java/org/kohsuke/github/GHMilestone.java @@ -17,6 +17,7 @@ public class GHMilestone extends GHObject { GHUser creator; private String state, due_on, title, description, html_url; private int closed_issues, open_issues, number; + protected String closed_at; public GitHub getRoot() { return root; @@ -34,7 +35,14 @@ public Date getDueOn() { if (due_on == null) return null; return GitHub.parseDate(due_on); } - + + /** + * When was this milestone closed? + */ + public Date getClosedAt() throws IOException { + return GitHub.parseDate(closed_at); + } + public String getTitle() { return title; } From 512c921a814e2700b1bb8926fdbf0949cfe3137c Mon Sep 17 00:00:00 2001 From: Rob Schoening Date: Sun, 20 Sep 2015 21:20:57 -0700 Subject: [PATCH 05/26] enable cross fork compare --- .../java/org/kohsuke/github/GHRepository.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 54acc2c8c3..8f45a5b92a 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -682,7 +682,23 @@ public GHCompare getCompare(GHCommit id1, GHCommit id2) throws IOException { } public GHCompare getCompare(GHBranch id1, GHBranch id2) throws IOException { - return getCompare(id1.getName(),id2.getName()); + + GHRepository owner1 = id1.getOwner(); + GHRepository owner2 = id2.getOwner(); + + // If the owner of the branches is different, we have a cross-fork compare. + if (owner1!=null && owner2!=null) { + String ownerName1 = owner1.getOwnerName(); + String ownerName2 = owner2.getOwnerName(); + if (!StringUtils.equals(ownerName1, ownerName2)) { + String qualifiedName1 = String.format("%s:%s", ownerName1, id1.getName()); + String qualifiedName2 = String.format("%s:%s", ownerName2, id2.getName()); + return getCompare(qualifiedName1, qualifiedName2); + } + } + + return getCompare(id1.getName(), id2.getName()); + } /** From 092e9062c814da19f1ab2d3f18292c5dd131104f Mon Sep 17 00:00:00 2001 From: Ruben Dijkstra Date: Tue, 6 Oct 2015 09:33:29 +0200 Subject: [PATCH 06/26] Remove trailing slash when requesting directory content --- src/main/java/org/kohsuke/github/GHRepository.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 54acc2c8c3..f48abbd311 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -1094,6 +1094,9 @@ public List getDirectoryContent(String path) throws IOException { public List getDirectoryContent(String path, String ref) throws IOException { Requester requester = root.retrieve(); + while (path.endsWith("/")) { + path = path.substring(0, path.length() - 1); + } String target = getApiTailUrl("contents/" + path); GHContent[] files = requester.with("ref",ref).to(target, GHContent[].class); From 5dc83cf2bf1ba8e945986a7e9fb156332ab138ee Mon Sep 17 00:00:00 2001 From: Ruben Dijkstra Date: Wed, 7 Oct 2015 09:38:48 +0200 Subject: [PATCH 07/26] Overzealous FindBugs changes. Charsets that are standard on the JRE are try-lookuped, bridge methods were removed and a stream that would be closed later is closed explicitly --- src/main/java/org/kohsuke/github/GHObject.java | 15 +++++++++++++++ src/main/java/org/kohsuke/github/GHRelease.java | 9 ++------- src/main/java/org/kohsuke/github/GitHub.java | 8 ++------ src/main/java/org/kohsuke/github/Requester.java | 4 +++- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHObject.java b/src/main/java/org/kohsuke/github/GHObject.java index 50aa0a6a86..270ac1fcc5 100644 --- a/src/main/java/org/kohsuke/github/GHObject.java +++ b/src/main/java/org/kohsuke/github/GHObject.java @@ -29,6 +29,11 @@ public Date getCreatedAt() throws IOException { return GitHub.parseDate(created_at); } + @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getCreatedAt") + private Object createdAtStr(Date id, Class type) { + return created_at; + } + /** * API URL of this object. */ @@ -57,4 +62,14 @@ public Date getUpdatedAt() throws IOException { public int getId() { return id; } + + @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getId") + private Object intToString(int id, Class type) { + return String.valueOf(id); + } + + @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getHtmlUrl") + private Object urlToString(URL url, Class type) { + return url==null ? null : url.toString(); + } } diff --git a/src/main/java/org/kohsuke/github/GHRelease.java b/src/main/java/org/kohsuke/github/GHRelease.java index 901bb8f359..b61dc62b38 100644 --- a/src/main/java/org/kohsuke/github/GHRelease.java +++ b/src/main/java/org/kohsuke/github/GHRelease.java @@ -129,14 +129,9 @@ public GHAsset uploadAsset(File file, String contentType) throws IOException { String url = format("https://uploads.github.com%s/releases/%d/assets?name=%s", owner.getApiTailUrl(""), getId(), file.getName()); - FileInputStream istream = new FileInputStream(file); - try { - return builder.contentType(contentType) - .with(istream) + return builder.contentType(contentType) + .with(new FileInputStream(file)) .to(url, GHAsset.class).wrap(this); - } finally { - istream.close(); - } } public List getAssets() throws IOException { diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 9e638bb4aa..2eaef53ceb 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -47,6 +47,7 @@ import java.util.TimeZone; import java.util.concurrent.TimeUnit; +import org.apache.commons.codec.Charsets; import org.apache.commons.codec.binary.Base64; import com.fasterxml.jackson.databind.DeserializationFeature; @@ -129,12 +130,7 @@ public class GitHub { } else { if (password!=null) { String authorization = (login + ':' + password); - final Charset charset; - try { - charset = Charset.forName("UTF-8"); - } catch (Exception ex) { - throw new IOException("UTF-8 encoding is not supported", ex); - } + Charset charset = Charsets.UTF_8; encodedAuthorization = "Basic "+new String(Base64.encodeBase64(authorization.getBytes(charset)), charset); } else {// anonymous access encodedAuthorization = null; diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index 78ead072d9..b8b53b78cd 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -53,6 +53,8 @@ import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; +import javax.annotation.WillClose; + import static java.util.Arrays.asList; import static org.kohsuke.github.GitHub.*; @@ -143,7 +145,7 @@ public Requester with(String key, Map value) { return _with(key, value); } - public Requester with(InputStream body) { + public Requester with(@WillClose/*later*/ InputStream body) { this.body = body; return this; } From 75b9184a0011a5d900698e1d119105b2543a5047 Mon Sep 17 00:00:00 2001 From: Ruben Dijkstra Date: Fri, 9 Oct 2015 12:31:08 +0200 Subject: [PATCH 08/26] Check builder result to either be a token or a user Currently, a `user` property is always required (it not having content is also fine). This adds support for only having the `oauth` key in the property file/environment. --- src/main/java/org/kohsuke/github/GitHubBuilder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GitHubBuilder.java b/src/main/java/org/kohsuke/github/GitHubBuilder.java index c0ecaffda5..9160976640 100644 --- a/src/main/java/org/kohsuke/github/GitHubBuilder.java +++ b/src/main/java/org/kohsuke/github/GitHubBuilder.java @@ -51,7 +51,7 @@ public static GitHubBuilder fromCredentials() throws IOException { try { builder = fromPropertyFile(); - if (builder.user != null) + if (builder.oauthToken != null || builder.user != null) return builder; } catch (FileNotFoundException e) { // fall through @@ -60,7 +60,7 @@ public static GitHubBuilder fromCredentials() throws IOException { builder = fromEnvironment(); - if (builder.user != null) + if (builder.oauthToken != null || builder.user != null) return builder; else throw (IOException)new IOException("Failed to resolve credentials from ~/.github or the environment.").initCause(cause); From bafddf4bafc9f897f2c0dbb9d4e42de244e08ead Mon Sep 17 00:00:00 2001 From: Manuel Recena Date: Sat, 14 Nov 2015 12:11:24 +0100 Subject: [PATCH 09/26] Initial source code modifications --- src/main/java/org/kohsuke/github/GHPullRequest.java | 12 +++++++++--- .../java/org/kohsuke/github/PullRequestTest.java | 9 +++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index 909110b727..42cc38992e 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -50,6 +50,7 @@ public class GHPullRequest extends GHIssue { private int deletions; private String mergeable_state; private int changed_files; + private String merge_commit_sha; /** * GitHub doesn't return some properties of {@link GHIssue} when requesting the GET on the 'pulls' API @@ -142,9 +143,9 @@ public PullRequest getPullRequest() { } // -// details that are only available via get with ID -// -// + // details that are only available via get with ID + // + public GHUser getMergedBy() throws IOException { populate(); return merged_by; @@ -185,6 +186,11 @@ public int getChangedFiles() throws IOException { return changed_files; } + public String getMergeCommitSha() throws IOException { + populate(); + return merge_commit_sha; + } + /** * Fully populate the data by retrieving missing data. * diff --git a/src/test/java/org/kohsuke/github/PullRequestTest.java b/src/test/java/org/kohsuke/github/PullRequestTest.java index 9fc55f7519..9ef582cb79 100644 --- a/src/test/java/org/kohsuke/github/PullRequestTest.java +++ b/src/test/java/org/kohsuke/github/PullRequestTest.java @@ -49,6 +49,15 @@ public void testPullRequestReviewComments() throws Exception { assertTrue(comments.isEmpty()); } + @Test + public void testMergeCommitSHA() throws Exception { + String name = rnd.next(); + GHRepository repo = gitHub.getMyself().getRepository("website"); + GHPullRequest p = repo.createPullRequest(name, "feature5", "master", "## test"); + GHRef ref = repo.getRef("pull/" + p.getNumber() + "/merge"); + assertTrue(ref.getObject().getSha() == p.getMergeCommitSha()); + } + @Test // Requires push access to the test repo to pass public void setLabels() throws Exception { From 08be8eb4f8ae4b202c7ab74de51958c632a13223 Mon Sep 17 00:00:00 2001 From: Manuel Recena Date: Sun, 15 Nov 2015 11:46:18 +0100 Subject: [PATCH 10/26] Added a new test testMergeCommitSHA() --- src/test/java/org/kohsuke/github/PullRequestTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/kohsuke/github/PullRequestTest.java b/src/test/java/org/kohsuke/github/PullRequestTest.java index 9ef582cb79..4ed9dd5b0f 100644 --- a/src/test/java/org/kohsuke/github/PullRequestTest.java +++ b/src/test/java/org/kohsuke/github/PullRequestTest.java @@ -52,10 +52,10 @@ public void testPullRequestReviewComments() throws Exception { @Test public void testMergeCommitSHA() throws Exception { String name = rnd.next(); - GHRepository repo = gitHub.getMyself().getRepository("website"); - GHPullRequest p = repo.createPullRequest(name, "feature5", "master", "## test"); - GHRef ref = repo.getRef("pull/" + p.getNumber() + "/merge"); - assertTrue(ref.getObject().getSha() == p.getMergeCommitSha()); + GHPullRequest p = getRepository().createPullRequest(name, "stable", "master", "## test"); + GHPullRequest updated = getRepository().getPullRequest(p.getNumber()); + GHCommit commit = getRepository().getCommit(updated.getMergeCommitSha()); + assertNotNull(commit); } @Test From b0789a7ce72b6e1773b47d4e778535f839863480 Mon Sep 17 00:00:00 2001 From: Manuel Recena Date: Sun, 15 Nov 2015 11:50:13 +0100 Subject: [PATCH 11/26] Set merge_commit_sha as deprecated --- src/main/java/org/kohsuke/github/GHPullRequest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index 42cc38992e..b9078d9c30 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -50,6 +50,8 @@ public class GHPullRequest extends GHIssue { private int deletions; private String mergeable_state; private int changed_files; + + @Deprecated private String merge_commit_sha; /** @@ -186,6 +188,10 @@ public int getChangedFiles() throws IOException { return changed_files; } + /** + * FYI: https://developer.github.com/changes/2013-04-25-deprecating-merge-commit-sha + */ + @Deprecated public String getMergeCommitSha() throws IOException { populate(); return merge_commit_sha; From a371892409621e50a9d9c5c11d8045cfc1396d34 Mon Sep 17 00:00:00 2001 From: Manuel Recena Date: Sun, 15 Nov 2015 16:36:27 +0100 Subject: [PATCH 12/26] Added a new method to validate the GitHub API URL --- pom.xml | 3 +-- .../java/org/kohsuke/github/GHApiInfo.java | 14 ++++++++++ src/main/java/org/kohsuke/github/GitHub.java | 26 +++++++++++++++++++ .../java/org/kohsuke/github/GitHubTest.java | 7 +++++ 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/kohsuke/github/GHApiInfo.java diff --git a/pom.xml b/pom.xml index 60299712b2..02b788b6a4 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ UTF-8 - 3.0.1 + 3.0.2 true @@ -52,7 +52,6 @@ ${findbugs-maven-plugin.version} true - true ${findbugs-maven-plugin.failOnError} diff --git a/src/main/java/org/kohsuke/github/GHApiInfo.java b/src/main/java/org/kohsuke/github/GHApiInfo.java new file mode 100644 index 0000000000..131e0de647 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHApiInfo.java @@ -0,0 +1,14 @@ +package org.kohsuke.github; + +/** + * Represents information about Github API. + */ +public class GHApiInfo { + + private String rate_limit_url; + + public String getRateLimitUrl() { + return rate_limit_url; + } + +} diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 9e638bb4aa..1ca5ed968e 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -204,6 +204,15 @@ public static GitHub connectAnonymously() throws IOException { return new GitHubBuilder().build(); } + /** + * Connects to GitHub Enterprise anonymously. + * + * All operations that requires authentication will fail. + */ + public static GitHub connectToEnterpriseAnonymously(String apiUrl) throws IOException { + return new GitHubBuilder().withEndpoint(apiUrl).build(); + } + /** * Is this an anonymous connection * @return {@code true} if operations that require authentication will fail. @@ -446,6 +455,23 @@ public boolean isCredentialValid() throws IOException { } } + /** + * Ensures that the API URL is valid. + */ + public boolean isApiUrlValid() throws IOException { + try { + GHApiInfo apiInfo = retrieve().to("/", GHApiInfo.class); + try { + new URL(apiInfo.getRateLimitUrl()); + return true; + } catch (MalformedURLException mue) { + return false; + } + } catch (IOException e) { + return false; + } + } + /** * Search issues. */ diff --git a/src/test/java/org/kohsuke/github/GitHubTest.java b/src/test/java/org/kohsuke/github/GitHubTest.java index 54ce6e35d7..5c5ee982fe 100644 --- a/src/test/java/org/kohsuke/github/GitHubTest.java +++ b/src/test/java/org/kohsuke/github/GitHubTest.java @@ -12,6 +12,7 @@ import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; @@ -119,4 +120,10 @@ public void testGitHubEnterpriseDoesNotHaveRateLimit() throws IOException { GHRateLimit rateLimit = github.getRateLimit(); assertThat(rateLimit.getResetDate(), notNullValue()); } + + @Test + public void testGitHubIsApiUrlValid() throws IOException { + GitHub github = GitHub.connectAnonymously(); + assertTrue(github.isApiUrlValid()); + } } From 354969d5fae984af50a648cded5300e04cf3d512 Mon Sep 17 00:00:00 2001 From: Manuel Recena Date: Mon, 16 Nov 2015 11:16:58 +0100 Subject: [PATCH 13/26] Javadoc comment reviewed --- src/main/java/org/kohsuke/github/GHPullRequest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index b9078d9c30..8d1f0cab2f 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -189,7 +189,7 @@ public int getChangedFiles() throws IOException { } /** - * FYI: https://developer.github.com/changes/2013-04-25-deprecating-merge-commit-sha + * See GitHub blog post */ @Deprecated public String getMergeCommitSha() throws IOException { From a1e79d305037afebc0aefbcefd7598814083051a Mon Sep 17 00:00:00 2001 From: Ruben Dijkstra Date: Mon, 16 Nov 2015 18:33:51 +0100 Subject: [PATCH 14/26] Add unit test to cover the truncation of ?ref --- .../java/org/kohsuke/github/GHContentIntegrationTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/java/org/kohsuke/github/GHContentIntegrationTest.java b/src/test/java/org/kohsuke/github/GHContentIntegrationTest.java index 39f8545aaa..7848143a86 100644 --- a/src/test/java/org/kohsuke/github/GHContentIntegrationTest.java +++ b/src/test/java/org/kohsuke/github/GHContentIntegrationTest.java @@ -43,6 +43,14 @@ public void testGetDirectoryContent() throws Exception { assertTrue(entries.size() == 3); } + @Test + public void testGetDirectoryContentTrailingSlash() throws Exception { + //Used to truncate the ?ref=master, see gh-224 https://github.com/kohsuke/github-api/pull/224 + List entries = repo.getDirectoryContent("ghcontent-ro/a-dir-with-3-entries/", "master"); + + assertTrue(entries.get(0).getUrl().endsWith("?ref=master")); + } + @Test public void testCRUDContent() throws Exception { GHContentUpdateResponse created = repo.createContent("this is an awesome file I created\n", "Creating a file for integration tests.", createdFilename); From b037f75fb0e897046360f6333f0cbbc2763ba4e8 Mon Sep 17 00:00:00 2001 From: Vitaly Parfonov Date: Thu, 19 Nov 2015 12:09:34 +0200 Subject: [PATCH 15/26] Add information about mirror url if it exist. Like https://github.com/apache/tomee --- src/main/java/org/kohsuke/github/GHRepository.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 54acc2c8c3..f77ac6e2e8 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -54,7 +54,7 @@ public class GHRepository extends GHObject { private String description, homepage, name, full_name; private String html_url; // this is the UI - private String git_url, ssh_url, clone_url, svn_url; + private String git_url, ssh_url, clone_url, svn_url, mirror_url; private GHUser owner; // not fully populated. beware. private boolean has_issues, has_wiki, fork, has_downloads; @JsonProperty("private") @@ -159,6 +159,14 @@ public String getSvnUrl() { return svn_url; } + /** + * Gets the Mirror URL to access this repository: https://github.com/apache/tomee + * mirrored from git://git.apache.org/tomee.git + */ + public String getMirrorUrl() { + return mirror_url; + } + /** * Gets the SSH URL to access this repository, such as git@github.com:rails/rails.git */ From c6d2b1a22257f15963d3e4bd79929af10670b918 Mon Sep 17 00:00:00 2001 From: Manuel Recena Date: Mon, 23 Nov 2015 09:33:32 +0100 Subject: [PATCH 16/26] @deprecated annotations were removed --- src/main/java/org/kohsuke/github/GHPullRequest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index 8d1f0cab2f..5604d2355e 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -50,8 +50,6 @@ public class GHPullRequest extends GHIssue { private int deletions; private String mergeable_state; private int changed_files; - - @Deprecated private String merge_commit_sha; /** @@ -191,7 +189,6 @@ public int getChangedFiles() throws IOException { /** * See GitHub blog post */ - @Deprecated public String getMergeCommitSha() throws IOException { populate(); return merge_commit_sha; From acbafee02afcb4f46f6f379c2dbe65742c140c63 Mon Sep 17 00:00:00 2001 From: Manuel Recena Date: Mon, 23 Nov 2015 10:25:41 +0100 Subject: [PATCH 17/26] Removed unrelated changes. @KostyaSha's suggestion --- pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 02b788b6a4..60299712b2 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ UTF-8 - 3.0.2 + 3.0.1 true @@ -52,6 +52,7 @@ ${findbugs-maven-plugin.version} true + true ${findbugs-maven-plugin.failOnError} From aab21c5b170d24f1cca0010803e19677718e8b73 Mon Sep 17 00:00:00 2001 From: Manuel Recena Date: Mon, 23 Nov 2015 10:29:04 +0100 Subject: [PATCH 18/26] findbugs plugin has been upgraded --- pom.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 60299712b2..02b788b6a4 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ UTF-8 - 3.0.1 + 3.0.2 true @@ -52,7 +52,6 @@ ${findbugs-maven-plugin.version} true - true ${findbugs-maven-plugin.failOnError} From 75a40815498fa370e81ad3bc60fb769eb8c7ce1f Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 1 Dec 2015 14:57:30 +0100 Subject: [PATCH 19/26] Follow up to PR #216 --- src/main/java/org/kohsuke/github/Requester.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index 92f069bdfe..81fe507d8b 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -259,6 +259,8 @@ public int asHttpStatusCode(String tailApiUrl) throws IOException { while (true) {// loop while API rate limit is hit setupConnection(root.getApiURL(tailApiUrl)); + uc.setRequestMethod("GET"); + buildRequest(); try { @@ -273,7 +275,6 @@ public InputStream asStream(String tailApiUrl) throws IOException { while (true) {// loop while API rate limit is hit setupConnection(root.getApiURL(tailApiUrl)); - // if the download link is encoded with a token on the query string, the default behavior of POST will fail uc.setRequestMethod("GET"); From 832e4f3c37e58b2c36195c899d50b69686f12c77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Gond=C5=BEa?= Date: Tue, 1 Dec 2015 14:58:46 +0100 Subject: [PATCH 20/26] Use default timeouts for URLConnections --- src/main/java/org/kohsuke/github/GitHubBuilder.java | 5 ++++- src/main/java/org/kohsuke/github/HttpConnector.java | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GitHubBuilder.java b/src/main/java/org/kohsuke/github/GitHubBuilder.java index c0ecaffda5..0056b87987 100644 --- a/src/main/java/org/kohsuke/github/GitHubBuilder.java +++ b/src/main/java/org/kohsuke/github/GitHubBuilder.java @@ -186,7 +186,10 @@ public GitHubBuilder withRateLimitHandler(RateLimitHandler handler) { public GitHubBuilder withProxy(final Proxy p) { return withConnector(new HttpConnector() { public HttpURLConnection connect(URL url) throws IOException { - return (HttpURLConnection) url.openConnection(p); + HttpURLConnection con = (HttpURLConnection) url.openConnection(p); + con.setConnectTimeout(HttpConnector.HTTP_CONNECT_TIMEOUT); + con.setReadTimeout(HttpConnector.HTTP_READ_TIMEOUT); + return con; } }); } diff --git a/src/main/java/org/kohsuke/github/HttpConnector.java b/src/main/java/org/kohsuke/github/HttpConnector.java index 6cff72dc53..555fba34fb 100644 --- a/src/main/java/org/kohsuke/github/HttpConnector.java +++ b/src/main/java/org/kohsuke/github/HttpConnector.java @@ -3,6 +3,7 @@ import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; +import java.util.concurrent.TimeUnit; /** * Pluggability for customizing HTTP request behaviors or using altogether different library. @@ -23,7 +24,13 @@ public interface HttpConnector { */ HttpConnector DEFAULT = new HttpConnector() { public HttpURLConnection connect(URL url) throws IOException { - return (HttpURLConnection) url.openConnection(); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.setConnectTimeout(HTTP_CONNECT_TIMEOUT); + con.setReadTimeout(HTTP_READ_TIMEOUT); + return con; } }; + + int HTTP_CONNECT_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(10); + int HTTP_READ_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(10); } From 261a7a34e36964e8bffdd60cd4ceaf8b79d93628 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 1 Dec 2015 15:17:54 +0100 Subject: [PATCH 21/26] Consolidated timeout handling --- .../org/kohsuke/github/GitHubBuilder.java | 10 ++-- .../org/kohsuke/github/HttpConnector.java | 14 ++--- .../github/extras/ImpatientHttpConnector.java | 54 +++++++++++++++++++ 3 files changed, 63 insertions(+), 15 deletions(-) create mode 100644 src/main/java/org/kohsuke/github/extras/ImpatientHttpConnector.java diff --git a/src/main/java/org/kohsuke/github/GitHubBuilder.java b/src/main/java/org/kohsuke/github/GitHubBuilder.java index 0056b87987..0b85871eaf 100644 --- a/src/main/java/org/kohsuke/github/GitHubBuilder.java +++ b/src/main/java/org/kohsuke/github/GitHubBuilder.java @@ -1,6 +1,7 @@ package org.kohsuke.github; import org.apache.commons.io.IOUtils; +import org.kohsuke.github.extras.ImpatientHttpConnector; import java.io.File; import java.io.FileInputStream; @@ -184,14 +185,11 @@ public GitHubBuilder withRateLimitHandler(RateLimitHandler handler) { * the system default one. */ public GitHubBuilder withProxy(final Proxy p) { - return withConnector(new HttpConnector() { + return withConnector(new ImpatientHttpConnector(new HttpConnector() { public HttpURLConnection connect(URL url) throws IOException { - HttpURLConnection con = (HttpURLConnection) url.openConnection(p); - con.setConnectTimeout(HttpConnector.HTTP_CONNECT_TIMEOUT); - con.setReadTimeout(HttpConnector.HTTP_READ_TIMEOUT); - return con; + return (HttpURLConnection) url.openConnection(p); } - }); + })); } public GitHub build() throws IOException { diff --git a/src/main/java/org/kohsuke/github/HttpConnector.java b/src/main/java/org/kohsuke/github/HttpConnector.java index 555fba34fb..5496268561 100644 --- a/src/main/java/org/kohsuke/github/HttpConnector.java +++ b/src/main/java/org/kohsuke/github/HttpConnector.java @@ -1,5 +1,7 @@ package org.kohsuke.github; +import org.kohsuke.github.extras.ImpatientHttpConnector; + import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; @@ -22,15 +24,9 @@ public interface HttpConnector { /** * Default implementation that uses {@link URL#openConnection()}. */ - HttpConnector DEFAULT = new HttpConnector() { + HttpConnector DEFAULT = new ImpatientHttpConnector(new HttpConnector() { public HttpURLConnection connect(URL url) throws IOException { - HttpURLConnection con = (HttpURLConnection) url.openConnection(); - con.setConnectTimeout(HTTP_CONNECT_TIMEOUT); - con.setReadTimeout(HTTP_READ_TIMEOUT); - return con; + return (HttpURLConnection) url.openConnection(); } - }; - - int HTTP_CONNECT_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(10); - int HTTP_READ_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(10); + }); } diff --git a/src/main/java/org/kohsuke/github/extras/ImpatientHttpConnector.java b/src/main/java/org/kohsuke/github/extras/ImpatientHttpConnector.java new file mode 100644 index 0000000000..e0e18fc962 --- /dev/null +++ b/src/main/java/org/kohsuke/github/extras/ImpatientHttpConnector.java @@ -0,0 +1,54 @@ +package org.kohsuke.github.extras; + +import org.kohsuke.github.HttpConnector; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.concurrent.TimeUnit; + +/** + * {@link HttpConnector} wrapper that sets timeout + * + * @author Kohsuke Kawaguchi + */ +public class ImpatientHttpConnector implements HttpConnector { + private final HttpConnector base; + private final int readTimeout, connectTimeout; + + /** + * @param connectTimeout + * HTTP connection timeout in milliseconds + * @param readTimeout + * HTTP read timeout in milliseconds + */ + public ImpatientHttpConnector(HttpConnector base, int connectTimeout, int readTimeout) { + this.base = base; + this.connectTimeout = connectTimeout; + this.readTimeout = readTimeout; + } + + public ImpatientHttpConnector(HttpConnector base, int timeout) { + this(base,timeout,timeout); + } + + public ImpatientHttpConnector(HttpConnector base) { + this(base,CONNECT_TIMEOUT,READ_TIMEOUT); + } + + public HttpURLConnection connect(URL url) throws IOException { + HttpURLConnection con = base.connect(url); + con.setConnectTimeout(connectTimeout); + con.setReadTimeout(readTimeout); + return con; + } + + /** + * Default connection timeout in milliseconds + */ + public static int CONNECT_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(10); + /** + * Default read timeout in milliseconds + */ + public static int READ_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(10); +} From 0397d7ab53fa6c7489115de024f3dc0c40c80484 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 1 Dec 2015 15:39:19 +0100 Subject: [PATCH 22/26] Fixing a test problem --- .../org/kohsuke/github/PullRequestTest.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/kohsuke/github/PullRequestTest.java b/src/test/java/org/kohsuke/github/PullRequestTest.java index 4ed9dd5b0f..c7ce77d289 100644 --- a/src/test/java/org/kohsuke/github/PullRequestTest.java +++ b/src/test/java/org/kohsuke/github/PullRequestTest.java @@ -52,10 +52,21 @@ public void testPullRequestReviewComments() throws Exception { @Test public void testMergeCommitSHA() throws Exception { String name = rnd.next(); - GHPullRequest p = getRepository().createPullRequest(name, "stable", "master", "## test"); - GHPullRequest updated = getRepository().getPullRequest(p.getNumber()); - GHCommit commit = getRepository().getCommit(updated.getMergeCommitSha()); - assertNotNull(commit); + GHPullRequest p = getRepository().createPullRequest(name, "mergeable-branch", "master", "## test"); + for (int i=0; i<100; i++) { + GHPullRequest updated = getRepository().getPullRequest(p.getNumber()); + if (updated.getMergeCommitSha()!=null) { + // make sure commit exists + GHCommit commit = getRepository().getCommit(updated.getMergeCommitSha()); + assertNotNull(commit); + return; + } + + // mergeability computation takes time. give it more chance + Thread.sleep(100); + } + // hmm? + fail(); } @Test From 0f45d03c51975eac7c96731537a1cffc78cf6dcc Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 1 Dec 2015 16:01:01 +0100 Subject: [PATCH 23/26] Reworked this change a bit. - GHApiInfo need not be public because it's not publicly exposed. - Throwing an exception is better IMO as it allows richer error message, including the differentiation between unreachable host name vs wrong URL, and reporting the API endpoint URL that was actually tried. --- .../java/org/kohsuke/github/GHApiInfo.java | 14 --------- src/main/java/org/kohsuke/github/GitHub.java | 30 +++++++++++-------- .../java/org/kohsuke/github/GitHubTest.java | 2 +- 3 files changed, 19 insertions(+), 27 deletions(-) delete mode 100644 src/main/java/org/kohsuke/github/GHApiInfo.java diff --git a/src/main/java/org/kohsuke/github/GHApiInfo.java b/src/main/java/org/kohsuke/github/GHApiInfo.java deleted file mode 100644 index 131e0de647..0000000000 --- a/src/main/java/org/kohsuke/github/GHApiInfo.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.kohsuke.github; - -/** - * Represents information about Github API. - */ -public class GHApiInfo { - - private String rate_limit_url; - - public String getRateLimitUrl() { - return rate_limit_url; - } - -} diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 1ca5ed968e..6b434fe2a5 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -455,21 +455,27 @@ public boolean isCredentialValid() throws IOException { } } + private static class GHApiInfo { + private String rate_limit_url; + + void check(String apiUrl) throws IOException { + if (rate_limit_url==null) + throw new IOException(apiUrl+" doesn't look like GitHub API URL"); + + // make sure that the URL is legitimate + new URL(rate_limit_url); + } + } + /** * Ensures that the API URL is valid. + * + *

+ * This method returns normally if the endpoint is reachable and verified to be GitHub API URL. + * Otherwise this method throws {@link IOException} to indicate the problem. */ - public boolean isApiUrlValid() throws IOException { - try { - GHApiInfo apiInfo = retrieve().to("/", GHApiInfo.class); - try { - new URL(apiInfo.getRateLimitUrl()); - return true; - } catch (MalformedURLException mue) { - return false; - } - } catch (IOException e) { - return false; - } + public void checkApiUrlValidity() throws IOException { + retrieve().to("/", GHApiInfo.class).check(apiUrl); } /** diff --git a/src/test/java/org/kohsuke/github/GitHubTest.java b/src/test/java/org/kohsuke/github/GitHubTest.java index 5c5ee982fe..1663d24144 100644 --- a/src/test/java/org/kohsuke/github/GitHubTest.java +++ b/src/test/java/org/kohsuke/github/GitHubTest.java @@ -124,6 +124,6 @@ public void testGitHubEnterpriseDoesNotHaveRateLimit() throws IOException { @Test public void testGitHubIsApiUrlValid() throws IOException { GitHub github = GitHub.connectAnonymously(); - assertTrue(github.isApiUrlValid()); + github.checkApiUrlValidity(); } } From e33bdd7e62663756ebb76796c141ff806d495070 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 1 Dec 2015 16:17:03 +0100 Subject: [PATCH 24/26] Two teams now. I assume this is because 'owner' is now a team. --- src/test/java/org/kohsuke/github/AppTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/kohsuke/github/AppTest.java b/src/test/java/org/kohsuke/github/AppTest.java index d2b68e112c..5d5e0a5fef 100755 --- a/src/test/java/org/kohsuke/github/AppTest.java +++ b/src/test/java/org/kohsuke/github/AppTest.java @@ -286,7 +286,8 @@ public void testOrgFork() throws Exception { @Test public void testGetTeamsForRepo() throws Exception { kohsuke(); - assertEquals(1, gitHub.getOrganization("github-api-test-org").getRepository("testGetTeamsForRepo").getTeams().size()); + // 'Core Developers' and 'Owners' + assertEquals(2, gitHub.getOrganization("github-api-test-org").getRepository("testGetTeamsForRepo").getTeams().size()); } @Test From c2f2d0f8af83b187417bce9cee776086a9c323c6 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 1 Dec 2015 16:23:51 +0100 Subject: [PATCH 25/26] Making FindBugs happy --- .../org/kohsuke/github/extras/ImpatientHttpConnector.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/org/kohsuke/github/extras/ImpatientHttpConnector.java b/src/main/java/org/kohsuke/github/extras/ImpatientHttpConnector.java index e0e18fc962..740b9a037d 100644 --- a/src/main/java/org/kohsuke/github/extras/ImpatientHttpConnector.java +++ b/src/main/java/org/kohsuke/github/extras/ImpatientHttpConnector.java @@ -1,5 +1,6 @@ package org.kohsuke.github.extras; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.kohsuke.github.HttpConnector; import java.io.IOException; @@ -46,9 +47,12 @@ public HttpURLConnection connect(URL url) throws IOException { /** * Default connection timeout in milliseconds */ + @SuppressFBWarnings("MS_SHOULD_BE_FINAL") public static int CONNECT_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(10); + /** * Default read timeout in milliseconds */ + @SuppressFBWarnings("MS_SHOULD_BE_FINAL") public static int READ_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(10); } From b24fcb18af6bd3f00302371cafd0335de7c756e6 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 1 Dec 2015 16:27:24 +0100 Subject: [PATCH 26/26] [maven-release-plugin] prepare release github-api-1.71 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 02b788b6a4..4847f4885c 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ github-api - 1.71-SNAPSHOT + 1.71 GitHub API for Java http://github-api.kohsuke.org/ GitHub API for Java @@ -16,7 +16,7 @@ scm:git:git@github.com/kohsuke/${project.artifactId}.git scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git http://${project.artifactId}.kohsuke.org/ - HEAD + github-api-1.71