From 1b55b5fa3c1aa182b42feea2bc11b4ba206d2813 Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Wed, 20 Nov 2019 19:10:12 -0800 Subject: [PATCH 1/7] Move array population to single iterator code path This remove a second code path throught pagination. --- .../java/org/kohsuke/github/Requester.java | 115 ++++++++++-------- .../mappings/notifications-10-a97934.json | 2 +- .../mappings/notifications-11-89714e.json | 2 +- .../mappings/notifications-12-2b7183.json | 2 +- .../mappings/notifications-13-989db4.json | 2 +- .../mappings/notifications-14-50b907.json | 2 +- .../mappings/notifications-15-f2648b.json | 2 +- .../mappings/notifications-16-ee5a6c.json | 2 +- .../mappings/notifications-17-a41aee.json | 2 +- .../mappings/notifications-18-e1d519.json | 2 +- .../mappings/notifications-19-1b6948.json | 2 +- .../mappings/notifications-20-489082.json | 2 +- .../mappings/notifications-21-42be65.json | 2 +- .../mappings/notifications-22-5720c4.json | 2 +- .../mappings/notifications-23-045c36.json | 2 +- .../mappings/notifications-24-bfc773.json | 2 +- .../mappings/notifications-3-d96172.json | 2 +- .../mappings/notifications-4-6dea52.json | 2 +- .../mappings/notifications-5-a8e944.json | 2 +- .../mappings/notifications-6-2658e9.json | 2 +- .../mappings/notifications-7-f25246.json | 2 +- .../mappings/notifications-8-943718.json | 2 +- .../mappings/notifications-9-1de525.json | 2 +- 23 files changed, 84 insertions(+), 75 deletions(-) diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index 1fe3bab8bb..c2ecf983d0 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -24,7 +24,6 @@ package org.kohsuke.github; import com.fasterxml.jackson.databind.JsonMappingException; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; @@ -55,8 +54,6 @@ import java.util.NoSuchElementException; import java.util.function.Consumer; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; import javax.annotation.CheckForNull; @@ -370,46 +367,31 @@ public T to(String tailApiUrl, T existingInstance) throws IOException { return _to(tailApiUrl, null, existingInstance); } - @SuppressFBWarnings("SBSC_USE_STRINGBUFFER_CONCATENATION") private T _to(String tailApiUrl, Class type, T instance) throws IOException { - if (!isMethodWithBody() && !args.isEmpty()) { - boolean questionMarkFound = tailApiUrl.indexOf('?') != -1; - tailApiUrl += questionMarkFound ? '&' : '?'; - for (Iterator it = args.listIterator(); it.hasNext();) { - Entry arg = it.next(); - tailApiUrl += arg.key + '=' + URLEncoder.encode(arg.value.toString(), "UTF-8"); - if (it.hasNext()) { - tailApiUrl += '&'; - } + T result; + + if (type != null && type.isArray()) { + // for arrays we might have to loop for pagination + // use the iterator to handle it + List pages = new ArrayList<>(); + int totalSize = 0; + for (Iterator iterator = asIterator(tailApiUrl, type, 0); iterator.hasNext();) { + T nextResult = iterator.next(); + totalSize += Array.getLength(nextResult); + pages.add(nextResult); } - } - while (true) {// loop while API rate limit is hit - setupConnection(root.getApiURL(tailApiUrl)); + result = concatenatePages(type, pages, totalSize); + return setResponseHeaders(result); + } - buildRequest(); + tailApiUrl = buildTailApiUrl(tailApiUrl); + setupConnection(root.getApiURL(tailApiUrl)); + buildRequest(); + while (true) {// loop while API rate limit is hit try { - T result = parse(type, instance); - if (type != null && type.isArray()) { // we might have to loop for pagination - done through recursion - final String links = uc.getHeaderField("link"); - if (links != null && links.contains("rel=\"next\"")) { - Pattern nextLinkPattern = Pattern.compile(".*<(.*)>; rel=\"next\""); - Matcher nextLinkMatcher = nextLinkPattern.matcher(links); - if (nextLinkMatcher.find()) { - final String link = nextLinkMatcher.group(1); - T nextResult = _to(link, type, instance); - setResponseHeaders(nextResult); - final int resultLength = Array.getLength(result); - final int nextResultLength = Array.getLength(nextResult); - T concatResult = (T) Array.newInstance(type.getComponentType(), - resultLength + nextResultLength); - System.arraycopy(result, 0, concatResult, 0, resultLength); - System.arraycopy(nextResult, 0, concatResult, resultLength, nextResultLength); - result = concatResult; - } - } - } + result = parse(type, instance); return setResponseHeaders(result); } catch (IOException e) { handleApiError(e); @@ -419,6 +401,43 @@ private T _to(String tailApiUrl, Class type, T instance) throws IOExcepti } } + private T concatenatePages(Class type, List pages, int totalLength) { + + T result = (T) Array.newInstance(type.getComponentType(), totalLength); + + int position = 0; + for (T page : pages) { + final int pageLength = Array.getLength(page); + System.arraycopy(page, 0, result, position, pageLength); + position += pageLength; + } + return result; + } + + private String buildTailApiUrl(String tailApiUrl) { + if (!isMethodWithBody() && !args.isEmpty()) { + try { + boolean questionMarkFound = tailApiUrl.indexOf('?') != -1; + StringBuilder argString = new StringBuilder(); + argString.append(questionMarkFound ? '&' : '?'); + + for (Iterator it = args.listIterator(); it.hasNext();) { + Entry arg = it.next(); + argString.append(URLEncoder.encode(arg.key, "UTF-8")); + argString.append('='); + argString.append(URLEncoder.encode(arg.value.toString(), "UTF-8")); + if (it.hasNext()) { + argString.append('&'); + } + } + tailApiUrl += argString; + } catch (UnsupportedEncodingException e) { + throw new AssertionError(e); // UTF-8 is mandatory + } + } + return tailApiUrl; + } + /** * Makes a request and just obtains the HTTP status code. * @@ -471,10 +490,14 @@ public InputStream asStream(String tailApiUrl) throws IOException { } private void noteRateLimit(String tailApiUrl) { + if (uc == null) { + return; + } if (tailApiUrl.startsWith("/search")) { // the search API uses a different rate limit return; } + String limitString = uc.getHeaderField("X-RateLimit-Limit"); if (StringUtils.isBlank(limitString)) { // if we are missing a header, return fast @@ -613,24 +636,10 @@ Iterator asIterator(String tailApiUrl, Class type, int pageSize) { if (pageSize != 0) args.add(new Entry("per_page", pageSize)); - StringBuilder s = new StringBuilder(tailApiUrl); - if (!args.isEmpty()) { - boolean first = true; - try { - for (Entry a : args) { - s.append(first ? '?' : '&'); - first = false; - s.append(URLEncoder.encode(a.key, "UTF-8")); - s.append('='); - s.append(URLEncoder.encode(a.value.toString(), "UTF-8")); - } - } catch (UnsupportedEncodingException e) { - throw new AssertionError(e); // UTF-8 is mandatory - } - } + tailApiUrl = buildTailApiUrl(tailApiUrl); try { - return new PagingIterator(type, tailApiUrl, root.getApiURL(s.toString())); + return new PagingIterator<>(type, tailApiUrl, root.getApiURL(tailApiUrl)); } catch (IOException e) { throw new GHException("Unable to build github Api URL", e); } diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-10-a97934.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-10-a97934.json index ea6a5672a7..75b848873c 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-10-a97934.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-10-a97934.json @@ -2,7 +2,7 @@ "id": "a979348d-c6be-4cb7-8877-7c42a6f013ae", "name": "notifications", "request": { - "url": "/notifications?all=true&page=9&all=true", + "url": "/notifications?all=true&page=9", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-11-89714e.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-11-89714e.json index 340b8a92eb..82ef74131a 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-11-89714e.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-11-89714e.json @@ -2,7 +2,7 @@ "id": "89714ed3-235b-4914-86a8-44ad66d59f30", "name": "notifications", "request": { - "url": "/notifications?all=true&page=10&all=true", + "url": "/notifications?all=true&page=10", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-12-2b7183.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-12-2b7183.json index 6e0cdb447b..21ea9c9f9b 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-12-2b7183.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-12-2b7183.json @@ -2,7 +2,7 @@ "id": "2b718339-36d3-4c6b-9484-79cdd79a79e4", "name": "notifications", "request": { - "url": "/notifications?all=true&page=11&all=true", + "url": "/notifications?all=true&page=11", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-13-989db4.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-13-989db4.json index 334b2d2725..d9630607d7 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-13-989db4.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-13-989db4.json @@ -2,7 +2,7 @@ "id": "989db4b3-8dde-4065-b4ef-6a2d90a2753a", "name": "notifications", "request": { - "url": "/notifications?all=true&page=12&all=true", + "url": "/notifications?all=true&page=12", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-14-50b907.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-14-50b907.json index 59c90bd0b6..5d3c4281a4 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-14-50b907.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-14-50b907.json @@ -2,7 +2,7 @@ "id": "50b907ef-a983-4cc9-bfd2-e2ba76eae729", "name": "notifications", "request": { - "url": "/notifications?all=true&page=13&all=true", + "url": "/notifications?all=true&page=13", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-15-f2648b.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-15-f2648b.json index 6b25c7de98..66534ef7cd 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-15-f2648b.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-15-f2648b.json @@ -2,7 +2,7 @@ "id": "f2648b73-4af1-4be3-a2a4-9edc712c5d59", "name": "notifications", "request": { - "url": "/notifications?all=true&page=14&all=true", + "url": "/notifications?all=true&page=14", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-16-ee5a6c.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-16-ee5a6c.json index 9da8b89150..063c092f13 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-16-ee5a6c.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-16-ee5a6c.json @@ -2,7 +2,7 @@ "id": "ee5a6c9f-da3a-47e7-a393-b403e82ae5d9", "name": "notifications", "request": { - "url": "/notifications?all=true&page=15&all=true", + "url": "/notifications?all=true&page=15", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-17-a41aee.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-17-a41aee.json index 3f36730721..6b8abb3763 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-17-a41aee.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-17-a41aee.json @@ -2,7 +2,7 @@ "id": "a41aeecf-7097-4ac6-b857-ab14797afe0a", "name": "notifications", "request": { - "url": "/notifications?all=true&page=16&all=true", + "url": "/notifications?all=true&page=16", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-18-e1d519.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-18-e1d519.json index bc4bbe5240..0a94a0c84f 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-18-e1d519.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-18-e1d519.json @@ -2,7 +2,7 @@ "id": "e1d519f7-9bd2-4fcd-a288-2391944ec7ca", "name": "notifications", "request": { - "url": "/notifications?all=true&page=17&all=true", + "url": "/notifications?all=true&page=17", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-19-1b6948.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-19-1b6948.json index 667c9f768a..33fbc0cbdc 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-19-1b6948.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-19-1b6948.json @@ -2,7 +2,7 @@ "id": "1b694852-8043-418c-a76e-39370f22db96", "name": "notifications", "request": { - "url": "/notifications?all=true&page=18&all=true", + "url": "/notifications?all=true&page=18", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-20-489082.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-20-489082.json index 46c3189aa4..55ed37649c 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-20-489082.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-20-489082.json @@ -2,7 +2,7 @@ "id": "48908278-ce2f-4cec-8662-6f4ca3d81226", "name": "notifications", "request": { - "url": "/notifications?all=true&page=19&all=true", + "url": "/notifications?all=true&page=19", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-21-42be65.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-21-42be65.json index 8238b8ca6a..d1d6ce1e5d 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-21-42be65.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-21-42be65.json @@ -2,7 +2,7 @@ "id": "42be6527-0570-4353-b42f-d0cae80258e3", "name": "notifications", "request": { - "url": "/notifications?all=true&page=20&all=true", + "url": "/notifications?all=true&page=20", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-22-5720c4.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-22-5720c4.json index 2a3aafe0f7..e57e5703da 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-22-5720c4.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-22-5720c4.json @@ -2,7 +2,7 @@ "id": "5720c49c-c69b-495b-b7e6-b885d88c10b1", "name": "notifications", "request": { - "url": "/notifications?all=true&page=21&all=true", + "url": "/notifications?all=true&page=21", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-23-045c36.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-23-045c36.json index 7c46c5d61e..e8dda461b9 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-23-045c36.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-23-045c36.json @@ -2,7 +2,7 @@ "id": "045c369a-0818-455a-afe1-3ae9ec919af2", "name": "notifications", "request": { - "url": "/notifications?all=true&page=22&all=true", + "url": "/notifications?all=true&page=22", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-24-bfc773.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-24-bfc773.json index 71a870674e..d128ed1bf1 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-24-bfc773.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-24-bfc773.json @@ -2,7 +2,7 @@ "id": "bfc7733f-6dff-4675-81e9-926103c40b83", "name": "notifications", "request": { - "url": "/notifications?all=true&page=23&all=true", + "url": "/notifications?all=true&page=23", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-3-d96172.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-3-d96172.json index e90a40a00c..8a177e2a2a 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-3-d96172.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-3-d96172.json @@ -2,7 +2,7 @@ "id": "d9617266-1ca6-44b2-b495-52c1f3be4b91", "name": "notifications", "request": { - "url": "/notifications?all=true&page=2&all=true", + "url": "/notifications?all=true&page=2", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-4-6dea52.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-4-6dea52.json index 2c5994ca0a..0e65dfad11 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-4-6dea52.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-4-6dea52.json @@ -2,7 +2,7 @@ "id": "6dea5253-3aa2-4484-b97a-effcad5c6ebd", "name": "notifications", "request": { - "url": "/notifications?all=true&page=3&all=true", + "url": "/notifications?all=true&page=3", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-5-a8e944.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-5-a8e944.json index 8763e59513..1a893896d2 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-5-a8e944.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-5-a8e944.json @@ -2,7 +2,7 @@ "id": "a8e9449d-b78c-4e46-801e-59fc459920d3", "name": "notifications", "request": { - "url": "/notifications?all=true&page=4&all=true", + "url": "/notifications?all=true&page=4", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-6-2658e9.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-6-2658e9.json index 7fe53ad5fc..8602bc43d0 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-6-2658e9.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-6-2658e9.json @@ -2,7 +2,7 @@ "id": "2658e99a-6619-4b0b-b70f-814a0841839e", "name": "notifications", "request": { - "url": "/notifications?all=true&page=5&all=true", + "url": "/notifications?all=true&page=5", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-7-f25246.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-7-f25246.json index e40f801aa1..330b27af4f 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-7-f25246.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-7-f25246.json @@ -2,7 +2,7 @@ "id": "f2524684-5156-4db6-97fa-10dedac5f779", "name": "notifications", "request": { - "url": "/notifications?all=true&page=6&all=true", + "url": "/notifications?all=true&page=6", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-8-943718.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-8-943718.json index 479c340c72..8dd6188c30 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-8-943718.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-8-943718.json @@ -2,7 +2,7 @@ "id": "9437189d-2f1b-47de-898d-66fde88ef05b", "name": "notifications", "request": { - "url": "/notifications?all=true&page=7&all=true", + "url": "/notifications?all=true&page=7", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-9-1de525.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-9-1de525.json index 079f9a0fa7..a783d53d33 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-9-1de525.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/notifications-9-1de525.json @@ -2,7 +2,7 @@ "id": "1de52522-e900-4b19-90cd-758573c2349a", "name": "notifications", "request": { - "url": "/notifications?all=true&page=8&all=true", + "url": "/notifications?all=true&page=8", "method": "GET" }, "response": { From 3296cef02d119bd65f3f7b458697a1da87db2a23 Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Mon, 25 Nov 2019 18:05:18 -0800 Subject: [PATCH 2/7] Change requester to GET by default --- .../github/GHAppCreateTokenBuilder.java | 2 +- src/main/java/org/kohsuke/github/GHAsset.java | 4 +- .../org/kohsuke/github/GHBlobBuilder.java | 2 +- .../java/org/kohsuke/github/GHBranch.java | 4 +- .../kohsuke/github/GHBranchProtection.java | 2 +- .../github/GHBranchProtectionBuilder.java | 2 +- .../java/org/kohsuke/github/GHCommit.java | 4 +- .../org/kohsuke/github/GHCommitBuilder.java | 2 +- .../org/kohsuke/github/GHCommitComment.java | 8 +- .../java/org/kohsuke/github/GHContent.java | 8 +- .../org/kohsuke/github/GHContentBuilder.java | 2 +- .../github/GHCreateRepositoryBuilder.java | 2 +- .../java/org/kohsuke/github/GHDeployKey.java | 3 +- .../kohsuke/github/GHDeploymentBuilder.java | 2 +- .../github/GHDeploymentStatusBuilder.java | 2 +- src/main/java/org/kohsuke/github/GHGist.java | 8 +- .../org/kohsuke/github/GHGistBuilder.java | 2 +- .../org/kohsuke/github/GHGistUpdater.java | 2 +- src/main/java/org/kohsuke/github/GHHook.java | 4 +- src/main/java/org/kohsuke/github/GHHooks.java | 4 +- src/main/java/org/kohsuke/github/GHIssue.java | 18 +-- .../org/kohsuke/github/GHIssueBuilder.java | 2 +- .../org/kohsuke/github/GHIssueComment.java | 8 +- .../java/org/kohsuke/github/GHMilestone.java | 2 +- .../java/org/kohsuke/github/GHMyself.java | 8 +- .../kohsuke/github/GHNotificationStream.java | 7 +- .../org/kohsuke/github/GHOrganization.java | 8 +- .../java/org/kohsuke/github/GHProject.java | 4 +- .../org/kohsuke/github/GHProjectCard.java | 4 +- .../org/kohsuke/github/GHProjectColumn.java | 4 +- .../org/kohsuke/github/GHPullRequest.java | 14 +-- .../kohsuke/github/GHPullRequestReview.java | 7 +- .../github/GHPullRequestReviewBuilder.java | 2 +- .../github/GHPullRequestReviewComment.java | 11 +- .../java/org/kohsuke/github/GHReaction.java | 2 +- src/main/java/org/kohsuke/github/GHRef.java | 10 +- .../java/org/kohsuke/github/GHRelease.java | 8 +- .../org/kohsuke/github/GHReleaseBuilder.java | 2 +- .../org/kohsuke/github/GHReleaseUpdater.java | 2 +- .../java/org/kohsuke/github/GHRepository.java | 70 +++++++----- .../org/kohsuke/github/GHSubscription.java | 2 +- src/main/java/org/kohsuke/github/GHTeam.java | 10 +- .../java/org/kohsuke/github/GHThread.java | 8 +- .../org/kohsuke/github/GHTreeBuilder.java | 2 +- src/main/java/org/kohsuke/github/GHUser.java | 9 +- src/main/java/org/kohsuke/github/GitHub.java | 32 ++++-- .../java/org/kohsuke/github/Requester.java | 107 +++++++++++------- 47 files changed, 252 insertions(+), 180 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java index 29830425ba..dcd25cea6c 100644 --- a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java +++ b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java @@ -23,7 +23,7 @@ public class GHAppCreateTokenBuilder { GHAppCreateTokenBuilder(GitHub root, String apiUrlTail, Map permissions) { this.root = root; this.apiUrlTail = apiUrlTail; - this.builder = new Requester(root); + this.builder = root.retrieve().method("POST"); withPermissions(builder, permissions); } diff --git a/src/main/java/org/kohsuke/github/GHAsset.java b/src/main/java/org/kohsuke/github/GHAsset.java index 0003c9703d..757abe3da2 100644 --- a/src/main/java/org/kohsuke/github/GHAsset.java +++ b/src/main/java/org/kohsuke/github/GHAsset.java @@ -135,7 +135,7 @@ public String getBrowserDownloadUrl() { } private void edit(String key, Object value) throws IOException { - new Requester(root).with(key, value).method("PATCH").to(getApiRoute()); + root.retrieve().method("POST").with(key, value).method("PATCH").to(getApiRoute()); } /** @@ -145,7 +145,7 @@ private void edit(String key, Object value) throws IOException { * the io exception */ public void delete() throws IOException { - new Requester(root).method("DELETE").to(getApiRoute()); + root.retrieve().method("DELETE").to(getApiRoute()); } private String getApiRoute() { diff --git a/src/main/java/org/kohsuke/github/GHBlobBuilder.java b/src/main/java/org/kohsuke/github/GHBlobBuilder.java index 6326525dc3..c59fae9436 100644 --- a/src/main/java/org/kohsuke/github/GHBlobBuilder.java +++ b/src/main/java/org/kohsuke/github/GHBlobBuilder.java @@ -13,7 +13,7 @@ public class GHBlobBuilder { GHBlobBuilder(GHRepository repo) { this.repo = repo; - req = new Requester(repo.root); + req = repo.root.retrieve().method("POST"); } /** diff --git a/src/main/java/org/kohsuke/github/GHBranch.java b/src/main/java/org/kohsuke/github/GHBranch.java index 7e1ff1a4f7..8146162071 100644 --- a/src/main/java/org/kohsuke/github/GHBranch.java +++ b/src/main/java/org/kohsuke/github/GHBranch.java @@ -9,8 +9,6 @@ import java.util.Collection; import java.util.Objects; -import static org.kohsuke.github.Previews.*; - /** * A branch in a repository. * @@ -122,7 +120,7 @@ public String getSHA1() { * if disabling protection fails */ public void disableProtection() throws IOException { - new Requester(root).method("DELETE").to(protection_url); + root.retrieve().method("DELETE").to(protection_url); } /** diff --git a/src/main/java/org/kohsuke/github/GHBranchProtection.java b/src/main/java/org/kohsuke/github/GHBranchProtection.java index 4c9246d9de..cbfcc1c4f6 100644 --- a/src/main/java/org/kohsuke/github/GHBranchProtection.java +++ b/src/main/java/org/kohsuke/github/GHBranchProtection.java @@ -123,7 +123,7 @@ GHBranchProtection wrap(GHBranch branch) { } private Requester requester() { - return new Requester(root).withPreview(ZZZAX); + return root.retrieve().method("POST").withPreview(ZZZAX); } /** diff --git a/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java b/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java index c94020b306..cfa06dc7c3 100644 --- a/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java +++ b/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java @@ -352,7 +352,7 @@ private StatusChecks getStatusChecks() { } private Requester requester() { - return new Requester(branch.getRoot()).withPreview(LUKE_CAGE); + return branch.getRoot().retrieve().method("POST").withPreview(LUKE_CAGE); } private static class Restrictions { diff --git a/src/main/java/org/kohsuke/github/GHCommit.java b/src/main/java/org/kohsuke/github/GHCommit.java index b1e7b7dc06..e36396c0a6 100644 --- a/src/main/java/org/kohsuke/github/GHCommit.java +++ b/src/main/java/org/kohsuke/github/GHCommit.java @@ -466,7 +466,9 @@ public PagedIterable listComments() { * if comment is not created */ public GHCommitComment createComment(String body, String path, Integer line, Integer position) throws IOException { - GHCommitComment r = new Requester(owner.root).with("body", body) + GHCommitComment r = owner.root.retrieve() + .method("POST") + .with("body", body) .with("path", path) .with("line", line) .with("position", position) diff --git a/src/main/java/org/kohsuke/github/GHCommitBuilder.java b/src/main/java/org/kohsuke/github/GHCommitBuilder.java index 71335ee02a..c25fe0403d 100644 --- a/src/main/java/org/kohsuke/github/GHCommitBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCommitBuilder.java @@ -34,7 +34,7 @@ private UserInfo(String name, String email, Date date) { GHCommitBuilder(GHRepository repo) { this.repo = repo; - req = new Requester(repo.root); + req = repo.root.retrieve().method("POST"); } /** diff --git a/src/main/java/org/kohsuke/github/GHCommitComment.java b/src/main/java/org/kohsuke/github/GHCommitComment.java index e53e8607f0..4e974a19a3 100644 --- a/src/main/java/org/kohsuke/github/GHCommitComment.java +++ b/src/main/java/org/kohsuke/github/GHCommitComment.java @@ -113,14 +113,16 @@ public GHCommit getCommit() throws IOException { * the io exception */ public void update(String body) throws IOException { - new Requester(owner.root).with("body", body).method("PATCH").to(getApiTail(), GHCommitComment.class); + owner.root.retrieve().method("POST").with("body", body).method("PATCH").to(getApiTail(), GHCommitComment.class); this.body = body; } @Preview @Deprecated public GHReaction createReaction(ReactionContent content) throws IOException { - return new Requester(owner.root).withPreview(SQUIRREL_GIRL) + return owner.root.retrieve() + .method("POST") + .withPreview(SQUIRREL_GIRL) .with("content", content.getContent()) .to(getApiTail() + "/reactions", GHReaction.class) .wrap(owner.root); @@ -141,7 +143,7 @@ public PagedIterable listReactions() { * the io exception */ public void delete() throws IOException { - new Requester(owner.root).method("DELETE").to(getApiTail()); + owner.root.retrieve().method("DELETE").to(getApiTail()); } private String getApiTail() { diff --git a/src/main/java/org/kohsuke/github/GHContent.java b/src/main/java/org/kohsuke/github/GHContent.java index 8683e6c2fb..b8e55f0ad1 100644 --- a/src/main/java/org/kohsuke/github/GHContent.java +++ b/src/main/java/org/kohsuke/github/GHContent.java @@ -306,7 +306,9 @@ public GHContentUpdateResponse update(byte[] newContentBytes, String commitMessa throws IOException { String encodedContent = Base64.encodeBase64String(newContentBytes); - Requester requester = new Requester(root).with("path", path) + Requester requester = root.retrieve() + .method("POST") + .with("path", path) .with("message", commitMessage) .with("sha", sha) .with("content", encodedContent) @@ -350,7 +352,9 @@ public GHContentUpdateResponse delete(String message) throws IOException { * the io exception */ public GHContentUpdateResponse delete(String commitMessage, String branch) throws IOException { - Requester requester = new Requester(root).with("path", path) + Requester requester = root.retrieve() + .method("POST") + .with("path", path) .with("message", commitMessage) .with("sha", sha) .method("DELETE"); diff --git a/src/main/java/org/kohsuke/github/GHContentBuilder.java b/src/main/java/org/kohsuke/github/GHContentBuilder.java index b50a7e257b..101289eb0f 100644 --- a/src/main/java/org/kohsuke/github/GHContentBuilder.java +++ b/src/main/java/org/kohsuke/github/GHContentBuilder.java @@ -21,7 +21,7 @@ public final class GHContentBuilder { GHContentBuilder(GHRepository repo) { this.repo = repo; - this.req = new Requester(repo.root).method("PUT"); + this.req = repo.root.retrieve().method("PUT"); } /** diff --git a/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java b/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java index 268bfa8ef3..c1d22ec2d9 100644 --- a/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java @@ -16,7 +16,7 @@ public class GHCreateRepositoryBuilder { GHCreateRepositoryBuilder(GitHub root, String apiUrlTail, String name) { this.root = root; this.apiUrlTail = apiUrlTail; - this.builder = new Requester(root); + this.builder = root.retrieve().method("POST"); this.builder.with("name", name); } diff --git a/src/main/java/org/kohsuke/github/GHDeployKey.java b/src/main/java/org/kohsuke/github/GHDeployKey.java index f9bd1acd52..0835ba3178 100644 --- a/src/main/java/org/kohsuke/github/GHDeployKey.java +++ b/src/main/java/org/kohsuke/github/GHDeployKey.java @@ -82,7 +82,8 @@ public String toString() { * the io exception */ public void delete() throws IOException { - new Requester(owner.root).method("DELETE") + owner.root.retrieve() + .method("DELETE") .to(String.format("/repos/%s/%s/keys/%d", owner.getOwnerName(), owner.getName(), id)); } } diff --git a/src/main/java/org/kohsuke/github/GHDeploymentBuilder.java b/src/main/java/org/kohsuke/github/GHDeploymentBuilder.java index c041538069..07031d7e6c 100644 --- a/src/main/java/org/kohsuke/github/GHDeploymentBuilder.java +++ b/src/main/java/org/kohsuke/github/GHDeploymentBuilder.java @@ -19,7 +19,7 @@ public class GHDeploymentBuilder { */ public GHDeploymentBuilder(GHRepository repo) { this.repo = repo; - this.builder = new Requester(repo.root); + this.builder = repo.root.retrieve().method("POST"); } /** diff --git a/src/main/java/org/kohsuke/github/GHDeploymentStatusBuilder.java b/src/main/java/org/kohsuke/github/GHDeploymentStatusBuilder.java index 31e54e64b1..d2f79c9609 100644 --- a/src/main/java/org/kohsuke/github/GHDeploymentStatusBuilder.java +++ b/src/main/java/org/kohsuke/github/GHDeploymentStatusBuilder.java @@ -30,7 +30,7 @@ public GHDeploymentStatusBuilder(GHRepository repo, int deploymentId, GHDeployme GHDeploymentStatusBuilder(GHRepository repo, long deploymentId, GHDeploymentState state) { this.repo = repo; this.deploymentId = deploymentId; - this.builder = new Requester(repo.root); + this.builder = repo.root.retrieve().method("POST"); this.builder.with("state", state); } diff --git a/src/main/java/org/kohsuke/github/GHGist.java b/src/main/java/org/kohsuke/github/GHGist.java index d772d3dd77..b1cfc1d076 100644 --- a/src/main/java/org/kohsuke/github/GHGist.java +++ b/src/main/java/org/kohsuke/github/GHGist.java @@ -182,7 +182,7 @@ String getApiTailUrl(String tail) { * the io exception */ public void star() throws IOException { - new Requester(root).method("PUT").to(getApiTailUrl("star")); + root.retrieve().method("PUT").to(getApiTailUrl("star")); } /** @@ -192,7 +192,7 @@ public void star() throws IOException { * the io exception */ public void unstar() throws IOException { - new Requester(root).method("DELETE").to(getApiTailUrl("star")); + root.retrieve().method("DELETE").to(getApiTailUrl("star")); } /** @@ -214,7 +214,7 @@ public boolean isStarred() throws IOException { * the io exception */ public GHGist fork() throws IOException { - return new Requester(root).to(getApiTailUrl("forks"), GHGist.class).wrapUp(root); + return root.retrieve().method("POST").to(getApiTailUrl("forks"), GHGist.class).wrapUp(root); } /** @@ -233,7 +233,7 @@ public PagedIterable listForks() { * the io exception */ public void delete() throws IOException { - new Requester(root).method("DELETE").to("/gists/" + id); + root.retrieve().method("DELETE").to("/gists/" + id); } /** diff --git a/src/main/java/org/kohsuke/github/GHGistBuilder.java b/src/main/java/org/kohsuke/github/GHGistBuilder.java index b0d572038e..5d7eaa6f39 100644 --- a/src/main/java/org/kohsuke/github/GHGistBuilder.java +++ b/src/main/java/org/kohsuke/github/GHGistBuilder.java @@ -23,7 +23,7 @@ public class GHGistBuilder { */ public GHGistBuilder(GitHub root) { this.root = root; - req = new Requester(root); + req = root.retrieve().method("POST"); } /** diff --git a/src/main/java/org/kohsuke/github/GHGistUpdater.java b/src/main/java/org/kohsuke/github/GHGistUpdater.java index af5a4876a1..3169da2607 100644 --- a/src/main/java/org/kohsuke/github/GHGistUpdater.java +++ b/src/main/java/org/kohsuke/github/GHGistUpdater.java @@ -16,7 +16,7 @@ public class GHGistUpdater { GHGistUpdater(GHGist base) { this.base = base; - this.builder = new Requester(base.root); + this.builder = base.root.retrieve().method("POST"); files = new LinkedHashMap<>(); } diff --git a/src/main/java/org/kohsuke/github/GHHook.java b/src/main/java/org/kohsuke/github/GHHook.java index a88c9a372c..5b93c238a3 100644 --- a/src/main/java/org/kohsuke/github/GHHook.java +++ b/src/main/java/org/kohsuke/github/GHHook.java @@ -74,7 +74,7 @@ public Map getConfig() { * @see Ping hook */ public void ping() throws IOException { - new Requester(getRoot()).method("POST").to(getApiRoute() + "/pings"); + getRoot().retrieve().method("POST").to(getApiRoute() + "/pings"); } /** @@ -84,7 +84,7 @@ public void ping() throws IOException { * the io exception */ public void delete() throws IOException { - new Requester(getRoot()).method("DELETE").to(getApiRoute()); + getRoot().retrieve().method("DELETE").to(getApiRoute()); } /** diff --git a/src/main/java/org/kohsuke/github/GHHooks.java b/src/main/java/org/kohsuke/github/GHHooks.java index 7f99de7a77..006774e45f 100644 --- a/src/main/java/org/kohsuke/github/GHHooks.java +++ b/src/main/java/org/kohsuke/github/GHHooks.java @@ -74,7 +74,9 @@ public GHHook createHook(String name, Map config, Collection listComments() throws IOException { @Preview @Deprecated public GHReaction createReaction(ReactionContent content) throws IOException { - return new Requester(owner.root).withPreview(SQUIRREL_GIRL) + return owner.root.retrieve() + .method("POST") + .withPreview(SQUIRREL_GIRL) .with("content", content.getContent()) .to(getApiRoute() + "/reactions", GHReaction.class) .wrap(root); @@ -513,7 +517,7 @@ public void setAssignees(GHUser... assignees) throws IOException { * the io exception */ public void setAssignees(Collection assignees) throws IOException { - new Requester(root).with(ASSIGNEES, getLogins(assignees)).method("PATCH").to(getIssuesApiRoute()); + root.retrieve().method("POST").with(ASSIGNEES, getLogins(assignees)).method("PATCH").to(getIssuesApiRoute()); } /** diff --git a/src/main/java/org/kohsuke/github/GHIssueBuilder.java b/src/main/java/org/kohsuke/github/GHIssueBuilder.java index 766449596e..cf65eee147 100644 --- a/src/main/java/org/kohsuke/github/GHIssueBuilder.java +++ b/src/main/java/org/kohsuke/github/GHIssueBuilder.java @@ -17,7 +17,7 @@ public class GHIssueBuilder { GHIssueBuilder(GHRepository repo, String title) { this.repo = repo; - this.builder = new Requester(repo.root); + this.builder = repo.root.retrieve().method("POST"); builder.with("title", title); } diff --git a/src/main/java/org/kohsuke/github/GHIssueComment.java b/src/main/java/org/kohsuke/github/GHIssueComment.java index 9c2f1ae587..dba4fd889a 100644 --- a/src/main/java/org/kohsuke/github/GHIssueComment.java +++ b/src/main/java/org/kohsuke/github/GHIssueComment.java @@ -108,7 +108,7 @@ public GHCommentAuthorAssociation getAuthorAssociation() { * the io exception */ public void update(String body) throws IOException { - new Requester(owner.root).with("body", body).method("PATCH").to(getApiRoute(), GHIssueComment.class); + owner.root.retrieve().method("POST").with("body", body).method("PATCH").to(getApiRoute(), GHIssueComment.class); this.body = body; } @@ -119,13 +119,15 @@ public void update(String body) throws IOException { * the io exception */ public void delete() throws IOException { - new Requester(owner.root).method("DELETE").to(getApiRoute()); + owner.root.retrieve().method("DELETE").to(getApiRoute()); } @Preview @Deprecated public GHReaction createReaction(ReactionContent content) throws IOException { - return new Requester(owner.root).withPreview(SQUIRREL_GIRL) + return owner.root.retrieve() + .method("POST") + .withPreview(SQUIRREL_GIRL) .with("content", content.getContent()) .to(getApiRoute() + "/reactions", GHReaction.class) .wrap(owner.root); diff --git a/src/main/java/org/kohsuke/github/GHMilestone.java b/src/main/java/org/kohsuke/github/GHMilestone.java index 2126869cbb..b52b1538af 100644 --- a/src/main/java/org/kohsuke/github/GHMilestone.java +++ b/src/main/java/org/kohsuke/github/GHMilestone.java @@ -159,7 +159,7 @@ public void delete() throws IOException { } private void edit(String key, Object value) throws IOException { - new Requester(root).with(key, value).method("PATCH").to(getApiRoute()); + root.retrieve().method("POST").with(key, value).method("PATCH").to(getApiRoute()); } /** diff --git a/src/main/java/org/kohsuke/github/GHMyself.java b/src/main/java/org/kohsuke/github/GHMyself.java index 0d16f77d4b..e80ba1c592 100644 --- a/src/main/java/org/kohsuke/github/GHMyself.java +++ b/src/main/java/org/kohsuke/github/GHMyself.java @@ -71,7 +71,7 @@ public List getEmails() throws IOException { * the io exception */ public List getEmails2() throws IOException { - GHEmail[] addresses = root.retrieve().to("/user/emails", GHEmail[].class); + GHEmail[] addresses = root.retrieve().toArray("/user/emails", GHEmail[].class); return Collections.unmodifiableList(Arrays.asList(addresses)); } @@ -86,7 +86,7 @@ public List getEmails2() throws IOException { * the io exception */ public List getPublicKeys() throws IOException { - return Collections.unmodifiableList(Arrays.asList(root.retrieve().to("/user/keys", GHKey[].class))); + return Collections.unmodifiableList(Arrays.asList(root.retrieve().toArray("/user/keys", GHKey[].class))); } /** @@ -101,7 +101,7 @@ public List getPublicKeys() throws IOException { */ public List getPublicVerifiedKeys() throws IOException { return Collections.unmodifiableList( - Arrays.asList(root.retrieve().to("/users/" + getLogin() + "/keys", GHVerifiedKey[].class))); + Arrays.asList(root.retrieve().toArray("/users/" + getLogin() + "/keys", GHVerifiedKey[].class))); } /** @@ -114,7 +114,7 @@ public List getPublicVerifiedKeys() throws IOException { public GHPersonSet getAllOrganizations() throws IOException { GHPersonSet orgs = new GHPersonSet(); Set names = new HashSet(); - for (GHOrganization o : root.retrieve().to("/user/orgs", GHOrganization[].class)) { + for (GHOrganization o : root.retrieve().toArray("/user/orgs", GHOrganization[].class)) { if (names.add(o.getLogin())) // in case of rumoured duplicates in the data orgs.add(root.getOrganization(o.getLogin())); } diff --git a/src/main/java/org/kohsuke/github/GHNotificationStream.java b/src/main/java/org/kohsuke/github/GHNotificationStream.java index 9d62480651..26d842aaa9 100644 --- a/src/main/java/org/kohsuke/github/GHNotificationStream.java +++ b/src/main/java/org/kohsuke/github/GHNotificationStream.java @@ -101,7 +101,8 @@ public GHNotificationStream nonBlocking(boolean v) { */ public Iterator iterator() { // capture the configuration setting here - final Requester req = new Requester(root).method("GET") + final Requester req = root.retrieve() + .method("GET") .with("all", all) .with("participating", participating) .with("since", since); @@ -180,7 +181,7 @@ GHThread fetch() { req.setHeader("If-Modified-Since", lastModified); - threads = req.to(apiUrl, GHThread[].class); + threads = req.toArray(apiUrl, GHThread[].class); if (threads == null) { threads = EMPTY_ARRAY; // if unmodified, we get empty array } else { @@ -232,7 +233,7 @@ public void markAsRead() throws IOException { * the io exception */ public void markAsRead(long timestamp) throws IOException { - final Requester req = new Requester(root).method("PUT"); + final Requester req = root.retrieve().method("PUT"); if (timestamp >= 0) req.with("last_read_at", GitHub.printDate(new Date(timestamp))); req.asHttpStatusCode(apiUrl); diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java index 62b38dbe35..a0ae6a3573 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -243,7 +243,7 @@ public boolean hasPublicMember(GHUser user) { * the io exception */ public void publicize(GHUser u) throws IOException { - root.retrieve().method("PUT").to("/orgs/" + login + "/public_members/" + u.getLogin(), null); + root.retrieve().method("PUT").to("/orgs/" + login + "/public_members/" + u.getLogin()); } /** @@ -314,7 +314,7 @@ private PagedIterable listMembers(final String suffix, final String filt * the io exception */ public void conceal(GHUser u) throws IOException { - root.retrieve().method("DELETE").to("/orgs/" + login + "/public_members/" + u.getLogin(), null); + root.retrieve().method("DELETE").to("/orgs/" + login + "/public_members/" + u.getLogin()); } /** @@ -389,7 +389,7 @@ public enum Permission { */ @Deprecated public GHTeam createTeam(String name, Permission p, Collection repositories) throws IOException { - Requester post = new Requester(root).with("name", name).with("permission", p); + Requester post = root.retrieve().method("POST").with("name", name).with("permission", p); List repo_names = new ArrayList(); for (GHRepository r : repositories) { repo_names.add(login + "/" + r.getName()); @@ -430,7 +430,7 @@ public GHTeam createTeam(String name, Permission p, GHRepository... repositories * the io exception */ public GHTeam createTeam(String name, Collection repositories) throws IOException { - Requester post = new Requester(root).with("name", name); + Requester post = root.retrieve().method("POST").with("name", name); List repo_names = new ArrayList(); for (GHRepository r : repositories) { repo_names.add(login + "/" + r.getName()); diff --git a/src/main/java/org/kohsuke/github/GHProject.java b/src/main/java/org/kohsuke/github/GHProject.java index 03807b795c..baa5acd2f6 100644 --- a/src/main/java/org/kohsuke/github/GHProject.java +++ b/src/main/java/org/kohsuke/github/GHProject.java @@ -176,7 +176,7 @@ public GHProject wrap(GitHub root) { } private void edit(String key, Object value) throws IOException { - new Requester(root).withPreview(INERTIA).with(key, value).method("PATCH").to(getApiRoute()); + root.retrieve().method("POST").withPreview(INERTIA).with(key, value).method("PATCH").to(getApiRoute()); } /** @@ -270,7 +270,7 @@ public void setPublic(boolean isPublic) throws IOException { * the io exception */ public void delete() throws IOException { - new Requester(root).withPreview(INERTIA).method("DELETE").to(getApiRoute()); + root.retrieve().method("POST").withPreview(INERTIA).method("DELETE").to(getApiRoute()); } /** diff --git a/src/main/java/org/kohsuke/github/GHProjectCard.java b/src/main/java/org/kohsuke/github/GHProjectCard.java index 2ed518fcce..8aa7405cfa 100644 --- a/src/main/java/org/kohsuke/github/GHProjectCard.java +++ b/src/main/java/org/kohsuke/github/GHProjectCard.java @@ -198,7 +198,7 @@ public void setArchived(boolean archived) throws IOException { } private void edit(String key, Object value) throws IOException { - new Requester(root).withPreview(INERTIA).with(key, value).method("PATCH").to(getApiRoute()); + root.retrieve().method("POST").withPreview(INERTIA).with(key, value).method("PATCH").to(getApiRoute()); } /** @@ -217,6 +217,6 @@ protected String getApiRoute() { * the io exception */ public void delete() throws IOException { - new Requester(root).withPreview(INERTIA).method("DELETE").to(getApiRoute()); + root.retrieve().method("POST").withPreview(INERTIA).method("DELETE").to(getApiRoute()); } } diff --git a/src/main/java/org/kohsuke/github/GHProjectColumn.java b/src/main/java/org/kohsuke/github/GHProjectColumn.java index b93f709c36..0bbca4cd96 100644 --- a/src/main/java/org/kohsuke/github/GHProjectColumn.java +++ b/src/main/java/org/kohsuke/github/GHProjectColumn.java @@ -106,7 +106,7 @@ public void setName(String name) throws IOException { } private void edit(String key, Object value) throws IOException { - new Requester(root).withPreview(INERTIA).with(key, value).method("PATCH").to(getApiRoute()); + root.retrieve().method("POST").withPreview(INERTIA).with(key, value).method("PATCH").to(getApiRoute()); } /** @@ -125,7 +125,7 @@ protected String getApiRoute() { * the io exception */ public void delete() throws IOException { - new Requester(root).withPreview(INERTIA).method("DELETE").to(getApiRoute()); + root.retrieve().method("POST").withPreview(INERTIA).method("DELETE").to(getApiRoute()); } /** diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index f8a9bb4bc7..c2763695ec 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -505,7 +505,8 @@ public GHPullRequestReviewBuilder createReview() { */ public GHPullRequestReviewComment createReviewComment(String body, String sha, String path, int position) throws IOException { - return new Requester(root).method("POST") + return root.retrieve() + .method("POST") .with("body", body) .with("commit_id", sha) .with("path", path) @@ -523,9 +524,7 @@ public GHPullRequestReviewComment createReviewComment(String body, String sha, S * the io exception */ public void requestReviewers(List reviewers) throws IOException { - new Requester(root).method("POST") - .with("reviewers", getLogins(reviewers)) - .to(getApiRoute() + REQUEST_REVIEWERS); + root.retrieve().method("POST").with("reviewers", getLogins(reviewers)).to(getApiRoute() + REQUEST_REVIEWERS); } /** @@ -541,7 +540,7 @@ public void requestTeamReviewers(List teams) throws IOException { for (GHTeam team : teams) { teamReviewers.add(team.getSlug()); } - new Requester(root).method("POST").with("team_reviewers", teamReviewers).to(getApiRoute() + REQUEST_REVIEWERS); + root.retrieve().method("POST").with("team_reviewers", teamReviewers).to(getApiRoute() + REQUEST_REVIEWERS); } /** @@ -589,7 +588,8 @@ public void merge(String msg, String sha) throws IOException { * the io exception */ public void merge(String msg, String sha, MergeMethod method) throws IOException { - new Requester(root).method("PUT") + root.retrieve() + .method("PUT") .with("commit_message", msg) .with("sha", sha) .with("merge_method", method) @@ -605,7 +605,7 @@ public enum MergeMethod { private void fetchIssue() throws IOException { if (!fetchedIssueDetails) { - new Requester(root).method("GET").to(getIssuesApiRoute(), this); + root.retrieve().method("GET").to(getIssuesApiRoute(), this); fetchedIssueDetails = true; } } diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReview.java b/src/main/java/org/kohsuke/github/GHPullRequestReview.java index 65a29d33a7..75b257cf6c 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReview.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReview.java @@ -160,7 +160,8 @@ public void submit(String body, GHPullRequestReviewState state) throws IOExcepti * the io exception */ public void submit(String body, GHPullRequestReviewEvent event) throws IOException { - new Requester(owner.root).method("POST") + owner.root.retrieve() + .method("POST") .with("body", body) .with("event", event.action()) .to(getApiRoute() + "/events", this); @@ -175,7 +176,7 @@ public void submit(String body, GHPullRequestReviewEvent event) throws IOExcepti * the io exception */ public void delete() throws IOException { - new Requester(owner.root).method("DELETE").to(getApiRoute()); + owner.root.retrieve().method("DELETE").to(getApiRoute()); } /** @@ -187,7 +188,7 @@ public void delete() throws IOException { * the io exception */ public void dismiss(String message) throws IOException { - new Requester(owner.root).method("PUT").with("message", message).to(getApiRoute() + "/dismissals"); + owner.root.retrieve().method("PUT").with("message", message).to(getApiRoute() + "/dismissals"); state = GHPullRequestReviewState.DISMISSED; } diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java index cf0bf2171d..be22a98620 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java @@ -17,7 +17,7 @@ public class GHPullRequestReviewBuilder { GHPullRequestReviewBuilder(GHPullRequest pr) { this.pr = pr; - this.builder = new Requester(pr.root); + this.builder = pr.root.retrieve().method("POST"); } // public GHPullRequestReview createReview(@Nullable String commitId, String body, GHPullRequestReviewEvent event, diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java index 74f9dd8d02..779c1952fc 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java @@ -163,7 +163,7 @@ protected String getApiRoute() { * the io exception */ public void update(String body) throws IOException { - new Requester(owner.root).method("PATCH").with("body", body).to(getApiRoute(), this); + owner.root.retrieve().method("PATCH").with("body", body).to(getApiRoute(), this); this.body = body; } @@ -174,7 +174,7 @@ public void update(String body) throws IOException { * the io exception */ public void delete() throws IOException { - new Requester(owner.root).method("DELETE").to(getApiRoute()); + owner.root.retrieve().method("DELETE").to(getApiRoute()); } /** @@ -187,7 +187,8 @@ public void delete() throws IOException { * the io exception */ public GHPullRequestReviewComment reply(String body) throws IOException { - return new Requester(owner.root).method("POST") + return owner.root.retrieve() + .method("POST") .with("body", body) .with("in_reply_to", getId()) .to(getApiRoute() + "/comments", GHPullRequestReviewComment.class) @@ -197,7 +198,9 @@ public GHPullRequestReviewComment reply(String body) throws IOException { @Preview @Deprecated public GHReaction createReaction(ReactionContent content) throws IOException { - return new Requester(owner.root).withPreview(SQUIRREL_GIRL) + return owner.root.retrieve() + .method("POST") + .withPreview(SQUIRREL_GIRL) .with("content", content.getContent()) .to(getApiRoute() + "/reactions", GHReaction.class) .wrap(owner.root); diff --git a/src/main/java/org/kohsuke/github/GHReaction.java b/src/main/java/org/kohsuke/github/GHReaction.java index ced6792b41..8400cd7b32 100644 --- a/src/main/java/org/kohsuke/github/GHReaction.java +++ b/src/main/java/org/kohsuke/github/GHReaction.java @@ -58,6 +58,6 @@ public URL getHtmlUrl() { * the io exception */ public void delete() throws IOException { - new Requester(root).method("DELETE").withPreview(SQUIRREL_GIRL).to("/reactions/" + id); + root.retrieve().method("DELETE").withPreview(SQUIRREL_GIRL).to("/reactions/" + id); } } diff --git a/src/main/java/org/kohsuke/github/GHRef.java b/src/main/java/org/kohsuke/github/GHRef.java index c450aae080..3a086a162a 100644 --- a/src/main/java/org/kohsuke/github/GHRef.java +++ b/src/main/java/org/kohsuke/github/GHRef.java @@ -66,7 +66,13 @@ public void updateTo(String sha) throws IOException { * the io exception */ public void updateTo(String sha, Boolean force) throws IOException { - new Requester(root).with("sha", sha).with("force", force).method("PATCH").to(url, GHRef.class).wrap(root); + root.retrieve() + .method("POST") + .with("sha", sha) + .with("force", force) + .method("PATCH") + .to(url, GHRef.class) + .wrap(root); } /** @@ -76,7 +82,7 @@ public void updateTo(String sha, Boolean force) throws IOException { * the io exception */ public void delete() throws IOException { - new Requester(root).method("DELETE").to(url); + root.retrieve().method("DELETE").to(url); } GHRef wrap(GitHub root) { diff --git a/src/main/java/org/kohsuke/github/GHRelease.java b/src/main/java/org/kohsuke/github/GHRelease.java index 3955693071..fbe2851a70 100644 --- a/src/main/java/org/kohsuke/github/GHRelease.java +++ b/src/main/java/org/kohsuke/github/GHRelease.java @@ -240,7 +240,7 @@ public GHAsset uploadAsset(File file, String contentType) throws IOException { * the io exception */ public GHAsset uploadAsset(String filename, InputStream stream, String contentType) throws IOException { - Requester builder = new Requester(owner.root); + Requester builder = owner.root.retrieve().method("POST"); String url = getUploadUrl(); // strip the helpful garbage from the url url = url.substring(0, url.indexOf('{')); @@ -256,9 +256,9 @@ public GHAsset uploadAsset(String filename, InputStream stream, String contentTy * the io exception */ public List getAssets() throws IOException { - Requester builder = new Requester(owner.root); + Requester builder = owner.root.retrieve().method("POST"); - GHAsset[] assets = builder.method("GET").to(getApiTailUrl("assets"), GHAsset[].class); + GHAsset[] assets = builder.method("GET").toArray(getApiTailUrl("assets"), GHAsset[].class); return Arrays.asList(GHAsset.wrap(assets, this)); } @@ -269,7 +269,7 @@ public List getAssets() throws IOException { * the io exception */ public void delete() throws IOException { - new Requester(root).method("DELETE").to(owner.getApiTailUrl("releases/" + id)); + root.retrieve().method("DELETE").to(owner.getApiTailUrl("releases/" + id)); } /** diff --git a/src/main/java/org/kohsuke/github/GHReleaseBuilder.java b/src/main/java/org/kohsuke/github/GHReleaseBuilder.java index 19dbafd6bf..2c23ecb879 100644 --- a/src/main/java/org/kohsuke/github/GHReleaseBuilder.java +++ b/src/main/java/org/kohsuke/github/GHReleaseBuilder.java @@ -21,7 +21,7 @@ public class GHReleaseBuilder { */ public GHReleaseBuilder(GHRepository ghRepository, String tag) { this.repo = ghRepository; - this.builder = new Requester(repo.root); + this.builder = repo.root.retrieve().method("POST"); builder.with("tag_name", tag); } diff --git a/src/main/java/org/kohsuke/github/GHReleaseUpdater.java b/src/main/java/org/kohsuke/github/GHReleaseUpdater.java index 3c52eb0864..fc436bdd6e 100644 --- a/src/main/java/org/kohsuke/github/GHReleaseUpdater.java +++ b/src/main/java/org/kohsuke/github/GHReleaseUpdater.java @@ -14,7 +14,7 @@ public class GHReleaseUpdater { GHReleaseUpdater(GHRelease base) { this.base = base; - this.builder = new Requester(base.root); + this.builder = base.root.retrieve().method("POST"); } /** diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 932e769ad6..d5f1e7cdcc 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -387,7 +387,7 @@ public List getIssues(GHIssueState state, GHMilestone milestone) throws return Arrays.asList(GHIssue.wrap(root.retrieve() .with("state", state) .with("milestone", milestone == null ? "none" : "" + milestone.getNumber()) - .to(getApiTailUrl("issues"), GHIssue[].class), this)); + .toArray(getApiTailUrl("issues"), GHIssue[].class), this)); } /** @@ -427,7 +427,9 @@ public GHReleaseBuilder createRelease(String tag) { * the io exception */ public GHRef createRef(String name, String sha) throws IOException { - return new Requester(root).with("ref", name) + return root.retrieve() + .method("POST") + .with("ref", name) .with("sha", sha) .method("POST") .to(getApiTailUrl("git/refs"), GHRef.class) @@ -786,7 +788,7 @@ public boolean hasAssignee(GHUser u) throws IOException { */ public Set getCollaboratorNames() throws IOException { Set r = new HashSet(); - for (GHUser u : GHUser.wrap(root.retrieve().to(getApiTailUrl("collaborators"), GHUser[].class), root)) + for (GHUser u : GHUser.wrap(root.retrieve().toArray(getApiTailUrl("collaborators"), GHUser[].class), root)) r.add(u.login); return r; } @@ -829,7 +831,7 @@ public GHPermissionType getPermission(GHUser u) throws IOException { */ public Set getTeams() throws IOException { return Collections.unmodifiableSet(new HashSet( - Arrays.asList(GHTeam.wrapUp(root.retrieve().to(getApiTailUrl("teams"), GHTeam[].class), + Arrays.asList(GHTeam.wrapUp(root.retrieve().toArray(getApiTailUrl("teams"), GHTeam[].class), root.getOrganization(getOwnerName()))))); } @@ -883,7 +885,7 @@ public void removeCollaborators(Collection users) throws IOException { private void modifyCollaborators(Collection users, String method) throws IOException { for (GHUser user : users) { - new Requester(root).method(method).to(getApiTailUrl("collaborators/" + user.getLogin())); + root.retrieve().method(method).to(getApiTailUrl("collaborators/" + user.getLogin())); } } @@ -898,7 +900,8 @@ private void modifyCollaborators(Collection users, String method) throws public void setEmailServiceHook(String address) throws IOException { Map config = new HashMap(); config.put("address", address); - new Requester(root).method("POST") + root.retrieve() + .method("POST") .with("name", "email") .with("config", config) .with("active", true) @@ -906,7 +909,7 @@ public void setEmailServiceHook(String address) throws IOException { } private void edit(String key, String value) throws IOException { - Requester requester = new Requester(root); + Requester requester = root.retrieve().method("POST"); if (!key.equals("name")) requester.with("name", name); // even when we don't change the name, we need to send it in requester.with(key, value).method("PATCH").to(getApiTailUrl("")); @@ -1052,7 +1055,7 @@ public void allowRebaseMerge(boolean value) throws IOException { */ public void delete() throws IOException { try { - new Requester(root).method("DELETE").to(getApiTailUrl("")); + root.retrieve().method("DELETE").to(getApiTailUrl("")); } catch (FileNotFoundException x) { throw (FileNotFoundException) new FileNotFoundException("Failed to delete " + getOwnerName() + "/" + name + "; might not exist, or you might need the delete_repo scope in your token: http://stackoverflow.com/a/19327004/12916") @@ -1123,7 +1126,7 @@ public PagedIterable listForks(final ForkSort sort) { * the io exception */ public GHRepository fork() throws IOException { - new Requester(root).method("POST").to(getApiTailUrl("forks"), null); + root.retrieve().method("POST").to(getApiTailUrl("forks")); // this API is asynchronous. we need to wait for a bit for (int i = 0; i < 10; i++) { @@ -1149,7 +1152,7 @@ public GHRepository fork() throws IOException { * the io exception */ public GHRepository forkTo(GHOrganization org) throws IOException { - new Requester(root).to(getApiTailUrl("forks?org=" + org.getLogin())); + root.retrieve().method("POST").to(getApiTailUrl("forks?org=" + org.getLogin())); // this API is asynchronous. we need to wait for a bit for (int i = 0; i < 10; i++) { @@ -1291,7 +1294,9 @@ public GHPullRequest createPullRequest(String title, String body, boolean maintainerCanModify, boolean draft) throws IOException { - return new Requester(root).withPreview(SHADOW_CAT) + return root.retrieve() + .method("POST") + .withPreview(SHADOW_CAT) .with("title", title) .with("head", head) .with("base", base) @@ -1400,7 +1405,7 @@ public GHCompare getCompare(GHBranch id1, GHBranch id2) throws IOException { */ public GHRef[] getRefs() throws IOException { return GHRef.wrap( - root.retrieve().to(String.format("/repos/%s/%s/git/refs", getOwnerName(), name), GHRef[].class), + root.retrieve().toArray(String.format("/repos/%s/%s/git/refs", getOwnerName(), name), GHRef[].class), root); } @@ -1426,9 +1431,8 @@ public PagedIterable listRefs() throws IOException { * on failure communicating with GitHub, potentially due to an invalid ref type being requested */ public GHRef[] getRefs(String refType) throws IOException { - return GHRef.wrap( - root.retrieve() - .to(String.format("/repos/%s/%s/git/refs/%s", getOwnerName(), name, refType), GHRef[].class), + return GHRef.wrap(root.retrieve() + .toArray(String.format("/repos/%s/%s/git/refs/%s", getOwnerName(), name, refType), GHRef[].class), root); } @@ -1704,7 +1708,9 @@ public GHCommitStatus createCommitStatus(String sha1, String targetUrl, String description, String context) throws IOException { - return new Requester(root).with("state", state) + return root.retrieve() + .method("POST") + .with("state", state) .with("target_url", targetUrl) .with("description", description) .with("context", context) @@ -2013,7 +2019,7 @@ GHRepository wrap(GitHub root) { */ public Map getBranches() throws IOException { Map r = new TreeMap(); - for (GHBranch p : root.retrieve().to(getApiTailUrl("branches"), GHBranch[].class)) { + for (GHBranch p : root.retrieve().toArray(getApiTailUrl("branches"), GHBranch[].class)) { p.wrap(this); r.put(p.getName(), p); } @@ -2146,7 +2152,7 @@ public List getDirectoryContent(String path, String ref) throws IOExc } String target = getApiTailUrl("contents/" + path); - GHContent[] files = requester.with("ref", ref).to(target, GHContent[].class); + GHContent[] files = requester.with("ref", ref).toArray(target, GHContent[].class); GHContent.wrap(files, this); @@ -2265,7 +2271,9 @@ public GHContentUpdateResponse createContent(byte[] contentBytes, String commitM * the io exception */ public GHMilestone createMilestone(String title, String description) throws IOException { - return new Requester(root).with("title", title) + return root.retrieve() + .method("POST") + .with("title", title) .with("description", description) .method("POST") .to(getApiTailUrl("milestones"), GHMilestone.class) @@ -2284,7 +2292,9 @@ public GHMilestone createMilestone(String title, String description) throws IOEx * the io exception */ public GHDeployKey addDeployKey(String title, String key) throws IOException { - return new Requester(root).with("title", title) + return root.retrieve() + .method("POST") + .with("title", title) .with("key", key) .method("POST") .to(getApiTailUrl("keys"), GHDeployKey.class) @@ -2301,7 +2311,7 @@ public GHDeployKey addDeployKey(String title, String key) throws IOException { */ public List getDeployKeys() throws IOException { List list = new ArrayList( - Arrays.asList(root.retrieve().to(getApiTailUrl("keys"), GHDeployKey[].class))); + Arrays.asList(root.retrieve().toArray(getApiTailUrl("keys"), GHDeployKey[].class))); for (GHDeployKey h : list) h.wrap(this); return list; @@ -2354,7 +2364,9 @@ public GHRepository getParent() throws IOException { * the io exception */ public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOException { - return new Requester(root).with("subscribed", subscribed) + return root.retrieve() + .method("POST") + .with("subscribed", subscribed) .with("ignored", ignored) .method("PUT") .to(getApiTailUrl("subscription"), GHSubscription.class) @@ -2490,10 +2502,14 @@ public PagedIterable listProjects() throws IOException { * @see GitHub#renderMarkdown(String) GitHub#renderMarkdown(String) */ public Reader renderMarkdown(String text, MarkdownMode mode) throws IOException { - return new InputStreamReader(new Requester(root).with("text", text) - .with("mode", mode == null ? null : mode.toString()) - .with("context", getFullName()) - .asStream("/markdown"), "UTF-8"); + return new InputStreamReader( + root.retrieve() + .method("POST") + .with("text", text) + .with("mode", mode == null ? null : mode.toString()) + .with("context", getFullName()) + .asStream("/markdown"), + "UTF-8"); } /** @@ -2603,7 +2619,7 @@ public List listTopics() throws IOException { * the io exception */ public void setTopics(List topics) throws IOException { - Requester requester = new Requester(root); + Requester requester = root.retrieve().method("POST"); requester.with("names", topics); requester.method("PUT").withPreview(MERCY).to(getApiTailUrl("topics")); } diff --git a/src/main/java/org/kohsuke/github/GHSubscription.java b/src/main/java/org/kohsuke/github/GHSubscription.java index a8ddc81dd9..f71081fd1e 100644 --- a/src/main/java/org/kohsuke/github/GHSubscription.java +++ b/src/main/java/org/kohsuke/github/GHSubscription.java @@ -87,7 +87,7 @@ public GHRepository getRepository() { * the io exception */ public void delete() throws IOException { - new Requester(root).method("DELETE").to(repo.getApiTailUrl("subscription")); + root.retrieve().method("DELETE").to(repo.getApiTailUrl("subscription")); } GHSubscription wrapUp(GHRepository repo) { diff --git a/src/main/java/org/kohsuke/github/GHTeam.java b/src/main/java/org/kohsuke/github/GHTeam.java index 9254817b91..cf7a629fcd 100644 --- a/src/main/java/org/kohsuke/github/GHTeam.java +++ b/src/main/java/org/kohsuke/github/GHTeam.java @@ -189,7 +189,7 @@ public PagedIterable listRepositories() { * @since 1.59 */ public void add(GHUser u) throws IOException { - root.retrieve().method("PUT").to(api("/memberships/" + u.getLogin()), null); + root.retrieve().method("PUT").to(api("/memberships/" + u.getLogin())); } /** @@ -205,7 +205,7 @@ public void add(GHUser u) throws IOException { * the io exception */ public void add(GHUser user, Role role) throws IOException { - root.retrieve().method("PUT").with("role", role).to(api("/memberships/" + user.getLogin()), null); + root.retrieve().method("PUT").with("role", role).to(api("/memberships/" + user.getLogin())); } /** @@ -217,7 +217,7 @@ public void add(GHUser user, Role role) throws IOException { * the io exception */ public void remove(GHUser u) throws IOException { - root.retrieve().method("DELETE").to(api("/members/" + u.getLogin()), null); + root.retrieve().method("DELETE").to(api("/members/" + u.getLogin())); } /** @@ -246,7 +246,7 @@ public void add(GHRepository r, GHOrganization.Permission permission) throws IOE root.retrieve() .method("PUT") .with("permission", permission) - .to(api("/repos/" + r.getOwnerName() + '/' + r.getName()), null); + .to(api("/repos/" + r.getOwnerName() + '/' + r.getName())); } /** @@ -258,7 +258,7 @@ public void add(GHRepository r, GHOrganization.Permission permission) throws IOE * the io exception */ public void remove(GHRepository r) throws IOException { - root.retrieve().method("DELETE").to(api("/repos/" + r.getOwnerName() + '/' + r.getName()), null); + root.retrieve().method("DELETE").to(api("/repos/" + r.getOwnerName() + '/' + r.getName())); } /** diff --git a/src/main/java/org/kohsuke/github/GHThread.java b/src/main/java/org/kohsuke/github/GHThread.java index 52b942512b..5bc35a227e 100644 --- a/src/main/java/org/kohsuke/github/GHThread.java +++ b/src/main/java/org/kohsuke/github/GHThread.java @@ -161,7 +161,7 @@ GHThread wrap(GitHub root) { * the io exception */ public void markAsRead() throws IOException { - new Requester(root).method("PATCH").to(url); + root.retrieve().method("PATCH").to(url); } /** @@ -176,7 +176,9 @@ public void markAsRead() throws IOException { * the io exception */ public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOException { - return new Requester(root).with("subscribed", subscribed) + return root.retrieve() + .method("POST") + .with("subscribed", subscribed) .with("ignored", ignored) .method("PUT") .to(subscription_url, GHSubscription.class) @@ -192,7 +194,7 @@ public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOEx */ public GHSubscription getSubscription() throws IOException { try { - return new Requester(root).to(subscription_url, GHSubscription.class).wrapUp(root); + return root.retrieve().method("POST").to(subscription_url, GHSubscription.class).wrapUp(root); } catch (FileNotFoundException e) { return null; } diff --git a/src/main/java/org/kohsuke/github/GHTreeBuilder.java b/src/main/java/org/kohsuke/github/GHTreeBuilder.java index ed27854b13..32f7267446 100644 --- a/src/main/java/org/kohsuke/github/GHTreeBuilder.java +++ b/src/main/java/org/kohsuke/github/GHTreeBuilder.java @@ -33,7 +33,7 @@ private TreeEntry(String path, String mode, String type) { GHTreeBuilder(GHRepository repo) { this.repo = repo; - req = new Requester(repo.root); + req = repo.root.retrieve().method("POST"); } /** diff --git a/src/main/java/org/kohsuke/github/GHUser.java b/src/main/java/org/kohsuke/github/GHUser.java index 73cdfea9bd..4158d367c3 100644 --- a/src/main/java/org/kohsuke/github/GHUser.java +++ b/src/main/java/org/kohsuke/github/GHUser.java @@ -43,7 +43,8 @@ public class GHUser extends GHPerson { * the io exception */ public List getKeys() throws IOException { - return Collections.unmodifiableList(Arrays.asList(root.retrieve().to(getApiTailUrl("keys"), GHKey[].class))); + return Collections + .unmodifiableList(Arrays.asList(root.retrieve().toArray(getApiTailUrl("keys"), GHKey[].class))); } /** @@ -53,7 +54,7 @@ public List getKeys() throws IOException { * the io exception */ public void follow() throws IOException { - new Requester(root).method("PUT").to("/user/following/" + login); + root.retrieve().method("PUT").to("/user/following/" + login); } /** @@ -63,7 +64,7 @@ public void follow() throws IOException { * the io exception */ public void unfollow() throws IOException { - new Requester(root).method("DELETE").to("/user/following/" + login); + root.retrieve().method("DELETE").to("/user/following/" + login); } /** @@ -186,7 +187,7 @@ static GHUser[] wrap(GHUser[] users, GitHub root) { public GHPersonSet getOrganizations() throws IOException { GHPersonSet orgs = new GHPersonSet(); Set names = new HashSet(); - for (GHOrganization o : root.retrieve().to("/users/" + login + "/orgs", GHOrganization[].class)) { + for (GHOrganization o : root.retrieve().toArray("/users/" + login + "/orgs", GHOrganization[].class)) { if (names.add(o.getLogin())) // I've seen some duplicates in the data orgs.add(root.getOrganization(o.getLogin())); } diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 27b29540e4..4da6395714 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -425,7 +425,7 @@ URL getApiURL(String tailApiUrl) throws IOException { } Requester retrieve() { - return new Requester(this).method("GET"); + return new Requester(this); } /** @@ -709,7 +709,7 @@ public GHLicense getLicense(String key) throws IOException { * the io exception */ public List getMyInvitations() throws IOException { - GHInvitation[] invitations = retrieve().to("/user/repository_invitations", GHInvitation[].class); + GHInvitation[] invitations = retrieve().toArray("/user/repository_invitations", GHInvitation[].class); for (GHInvitation i : invitations) { i.wrapUp(this); } @@ -727,7 +727,7 @@ public List getMyInvitations() throws IOException { * the io exception */ public Map getMyOrganizations() throws IOException { - GHOrganization[] orgs = retrieve().to("/user/orgs", GHOrganization[].class); + GHOrganization[] orgs = retrieve().toArray("/user/orgs", GHOrganization[].class); Map r = new HashMap(); for (GHOrganization o : orgs) { // don't put 'o' into orgs because they are shallow @@ -761,7 +761,7 @@ public Map getUserPublicOrganizations(GHUser user) throw * the io exception */ public Map getUserPublicOrganizations(String login) throws IOException { - GHOrganization[] orgs = retrieve().to("/users/" + login + "/orgs", GHOrganization[].class); + GHOrganization[] orgs = retrieve().toArray("/users/" + login + "/orgs", GHOrganization[].class); Map r = new HashMap(); for (GHOrganization o : orgs) { // don't put 'o' into orgs because they are shallow @@ -782,7 +782,7 @@ public Map getUserPublicOrganizations(String login) thro */ public Map> getMyTeams() throws IOException { Map> allMyTeams = new HashMap>(); - for (GHTeam team : retrieve().to("/user/teams", GHTeam[].class)) { + for (GHTeam team : retrieve().toArray("/user/teams", GHTeam[].class)) { team.wrapUp(this); String orgLogin = team.getOrganization().getLogin(); Set teamsPerOrg = allMyTeams.get(orgLogin); @@ -816,7 +816,7 @@ public GHTeam getTeam(int id) throws IOException { * the io exception */ public List getEvents() throws IOException { - GHEventInfo[] events = retrieve().to("/events", GHEventInfo[].class); + GHEventInfo[] events = retrieve().toArray("/events", GHEventInfo[].class); for (GHEventInfo e : events) e.wrapUp(this); return Arrays.asList(events); @@ -924,7 +924,10 @@ public GHCreateRepositoryBuilder createRepository(String name) { * @see Documentation */ public GHAuthorization createToken(Collection scope, String note, String noteUrl) throws IOException { - Requester requester = new Requester(this).with("scopes", scope).with("note", note).with("note_url", noteUrl); + Requester requester = retrieve().method("POST") + .with("scopes", scope) + .with("note", note) + .with("note_url", noteUrl); return requester.method("POST").to("/authorizations", GHAuthorization.class).wrap(this); } @@ -957,7 +960,8 @@ public GHAuthorization createToken(Collection scope, String note, String return createToken(scope, note, noteUrl); } catch (GHOTPRequiredException ex) { String OTPstring = OTP.get(); - Requester requester = new Requester(this).with("scopes", scope) + Requester requester = retrieve().method("POST") + .with("scopes", scope) .with("note", note) .with("note_url", noteUrl); // Add the OTP from the user @@ -990,7 +994,8 @@ public GHAuthorization createOrGetAuth(String clientId, List scopes, String note, String note_url) throws IOException { - Requester requester = new Requester(this).with("client_secret", clientSecret) + Requester requester = retrieve().method("POST") + .with("client_secret", clientSecret) .with("scopes", scopes) .with("note", note) .with("note_url", note_url); @@ -1339,9 +1344,12 @@ public PagedIterable listAllPublicRepositories(final String since) * @see GHRepository#renderMarkdown(String, MarkdownMode) GHRepository#renderMarkdown(String, MarkdownMode) */ public Reader renderMarkdown(String text) throws IOException { - return new InputStreamReader(new Requester(this).with(new ByteArrayInputStream(text.getBytes("UTF-8"))) - .contentType("text/plain;charset=UTF-8") - .asStream("/markdown/raw"), "UTF-8"); + return new InputStreamReader( + retrieve().method("POST") + .with(new ByteArrayInputStream(text.getBytes("UTF-8"))) + .contentType("text/plain;charset=UTF-8") + .asStream("/markdown/raw"), + "UTF-8"); } static URL parseURL(String s) { diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index c2ecf983d0..d7b14255b8 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -57,6 +57,7 @@ import java.util.zip.GZIPInputStream; import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; import javax.annotation.WillClose; import static java.util.Arrays.asList; @@ -77,7 +78,7 @@ class Requester { /** * Request method. */ - private String method = "POST"; + private String method = "GET"; private String contentType = null; private InputStream body; @@ -88,8 +89,8 @@ class Requester { private boolean forceBody; private static class Entry { - String key; - Object value; + final String key; + final Object value; private Entry(String key, Object value) { this.key = key; @@ -278,9 +279,9 @@ public Requester with(String key, Object value) { * @return the requester */ public Requester set(String key, Object value) { - for (Entry e : args) { - if (e.key.equals(key)) { - e.value = value; + for (int index = 0; index < args.size(); index++) { + if (args.get(index).key.equals(key)) { + args.set(index, new Entry(key, value)); return this; } } @@ -329,7 +330,7 @@ public Requester inBody() { * @throws IOException * the io exception */ - public void to(String tailApiUrl) throws IOException { + public void to(@Nonnull String tailApiUrl) throws IOException { _to(tailApiUrl, null, null); } @@ -346,10 +347,40 @@ public void to(String tailApiUrl) throws IOException { * @throws IOException * if the server returns 4xx/5xx responses. */ - public T to(String tailApiUrl, Class type) throws IOException { + public T to(@Nonnull String tailApiUrl, @Nonnull Class type) throws IOException { return _to(tailApiUrl, type, null); } + /** + * Sends a request to the specified URL, and parses the response into the given type via databinding. + * + * @param + * the type parameter + * @param tailApiUrl + * the tail api url + * @param type + * the type + * @return {@link Reader} that reads the response. + * @throws IOException + * if the server returns 4xx/5xx responses. + */ + public T[] toArray(@Nonnull String tailApiUrl, @Nonnull Class type) throws IOException { + T[] result; + + // for arrays we might have to loop for pagination + // use the iterator to handle it + List pages = new ArrayList<>(); + int totalSize = 0; + for (Iterator iterator = asIterator(tailApiUrl, type, 0); iterator.hasNext();) { + T[] nextResult = iterator.next(); + totalSize += Array.getLength(nextResult); + pages.add(nextResult); + } + + result = concatenatePages(type, pages, totalSize); + return setResponseHeaders(result); + } + /** * Like {@link #to(String, Class)} but updates an existing object instead of creating a new instance. * @@ -363,31 +394,15 @@ public T to(String tailApiUrl, Class type) throws IOException { * @throws IOException * the io exception */ - public T to(String tailApiUrl, T existingInstance) throws IOException { + public T to(@Nonnull String tailApiUrl, @Nonnull T existingInstance) throws IOException { return _to(tailApiUrl, null, existingInstance); } private T _to(String tailApiUrl, Class type, T instance) throws IOException { T result; - if (type != null && type.isArray()) { - // for arrays we might have to loop for pagination - // use the iterator to handle it - List pages = new ArrayList<>(); - int totalSize = 0; - for (Iterator iterator = asIterator(tailApiUrl, type, 0); iterator.hasNext();) { - T nextResult = iterator.next(); - totalSize += Array.getLength(nextResult); - pages.add(nextResult); - } - - result = concatenatePages(type, pages, totalSize); - return setResponseHeaders(result); - } - tailApiUrl = buildTailApiUrl(tailApiUrl); setupConnection(root.getApiURL(tailApiUrl)); - buildRequest(); while (true) {// loop while API rate limit is hit try { @@ -401,12 +416,12 @@ private T _to(String tailApiUrl, Class type, T instance) throws IOExcepti } } - private T concatenatePages(Class type, List pages, int totalLength) { + private T[] concatenatePages(Class type, List pages, int totalLength) { - T result = (T) Array.newInstance(type.getComponentType(), totalLength); + T[] result = type.cast(Array.newInstance(type.getComponentType(), totalLength)); int position = 0; - for (T page : pages) { + for (T[] page : pages) { final int pageLength = Array.getLength(page); System.arraycopy(page, 0, result, position, pageLength); position += pageLength; @@ -452,8 +467,6 @@ public int asHttpStatusCode(String tailApiUrl) throws IOException { method("GET"); setupConnection(root.getApiURL(tailApiUrl)); - buildRequest(); - try { return uc.getResponseCode(); } catch (IOException e) { @@ -477,8 +490,6 @@ public InputStream asStream(String tailApiUrl) throws IOException { while (true) {// loop while API rate limit is hit setupConnection(root.getApiURL(tailApiUrl)); - buildRequest(); - try { return wrapStream(uc.getInputStream()); } catch (IOException e) { @@ -592,31 +603,29 @@ private boolean isMethodWithBody() { } PagedIterable asPagedIterable(String tailApiUrl, Class type, Consumer consumer) { - return new PagedIterableWithConsumer<>(type, this, tailApiUrl, consumer); + return new PagedIterableWithConsumer<>(type, tailApiUrl, consumer); } - static class PagedIterableWithConsumer extends PagedIterable { + class PagedIterableWithConsumer extends PagedIterable { - private final Class clazz; - private final Requester requester; + private final Class clazz; private final String tailApiUrl; - private final Consumer consumer; + private final Consumer consumer; - PagedIterableWithConsumer(Class clazz, Requester requester, String tailApiUrl, Consumer consumer) { + PagedIterableWithConsumer(Class clazz, String tailApiUrl, Consumer consumer) { this.clazz = clazz; this.tailApiUrl = tailApiUrl; - this.requester = requester; this.consumer = consumer; } @Override - public PagedIterator _iterator(int pageSize) { - final Iterator iterator = requester.asIterator(tailApiUrl, clazz, pageSize); - return new PagedIterator(iterator) { + public PagedIterator _iterator(int pageSize) { + final Iterator iterator = asIterator(tailApiUrl, clazz, pageSize); + return new PagedIterator(iterator) { @Override - protected void wrapUp(S[] page) { + protected void wrapUp(T[] page) { if (consumer != null) { - for (S item : page) { + for (T item : page) { consumer.accept(item); } } @@ -645,6 +654,15 @@ Iterator asIterator(String tailApiUrl, Class type, int pageSize) { } } + /** + * May be used for any item that has pagination information. + * + * Works for array responses, also works for search results which are single instances with an array of items + * inside. + * + * @param + * type of each page (not the items in the page). + */ class PagingIterator implements Iterator { private final Class type; @@ -753,6 +771,7 @@ private void setupConnection(URL url) throws IOException { setRequestMethod(uc); uc.setRequestProperty("Accept-Encoding", "gzip"); + buildRequest(); } private void setRequestMethod(HttpURLConnection uc) throws IOException { From 60700d59feac3ac95529f635d1f4a46783e0b6ea Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Tue, 26 Nov 2019 15:14:29 -0800 Subject: [PATCH 3/7] Force URI encoding for api paths starting with slash --- .../java/org/kohsuke/github/GHContent.java | 4 +- .../org/kohsuke/github/GHContentBuilder.java | 2 +- src/main/java/org/kohsuke/github/GHLabel.java | 8 +- .../java/org/kohsuke/github/GHPerson.java | 3 +- .../java/org/kohsuke/github/GHRepository.java | 35 +- .../org/kohsuke/github/GHSearchBuilder.java | 2 +- .../java/org/kohsuke/github/Requester.java | 144 +++++++- src/test/java/org/kohsuke/github/AppTest.java | 4 +- .../kohsuke/github/RepositoryMockTest.java | 4 +- ..._github-api-test_deployments-4-b4bcda.json | 2 +- ...-1839874d-c184-4f20-942f-cc6d36806868.json | 41 +++ ...-5b2f012d-aa23-4e59-849c-22b53a469c95.json | 312 ++++++++++++++++++ ...-7f6b9ed5-222f-4c89-95a7-e45ef24d78a7.json | 101 ++++++ ...-044af303-143e-4469-be96-0a6e72032e5c.json | 309 +++++++++++++++++ ...-07a0042d-8162-4e85-9ed4-0ed31ebc9d63.json | 45 +++ .../orgs_github-api-test-org-3-183987.json | 43 +++ ...s_github-api-test-org_rubywm-5-5b2f01.json | 43 +++ .../repos_kohsuke_rubywm-2-7f6b9e.json | 43 +++ .../repos_kohsuke_rubywm_forks-4-044af3.json | 43 +++ .../testOrgFork/mappings/user-1-07a004.json | 43 +++ 20 files changed, 1178 insertions(+), 53 deletions(-) create mode 100644 src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/orgs_github-api-test-org-1839874d-c184-4f20-942f-cc6d36806868.json create mode 100644 src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/repos_github-api-test-org_rubywm-5b2f012d-aa23-4e59-849c-22b53a469c95.json create mode 100644 src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/repos_kohsuke_rubywm-7f6b9ed5-222f-4c89-95a7-e45ef24d78a7.json create mode 100644 src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/repos_kohsuke_rubywm_forks-044af303-143e-4469-be96-0a6e72032e5c.json create mode 100644 src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/user-07a0042d-8162-4e85-9ed4-0ed31ebc9d63.json create mode 100644 src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/orgs_github-api-test-org-3-183987.json create mode 100644 src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/repos_github-api-test-org_rubywm-5-5b2f01.json create mode 100644 src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/repos_kohsuke_rubywm-2-7f6b9e.json create mode 100644 src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/repos_kohsuke_rubywm_forks-4-044af3.json create mode 100644 src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/user-1-07a004.json diff --git a/src/main/java/org/kohsuke/github/GHContent.java b/src/main/java/org/kohsuke/github/GHContent.java index b8e55f0ad1..983988077e 100644 --- a/src/main/java/org/kohsuke/github/GHContent.java +++ b/src/main/java/org/kohsuke/github/GHContent.java @@ -237,7 +237,7 @@ public PagedIterable listDirectoryContent() throws IOException { if (!isDirectory()) throw new IllegalStateException(path + " is not a directory"); - return root.retrieve().asPagedIterable(url, GHContent[].class, item -> item.wrap(repository)); + return root.retrieve().setRawUrlPath(url).asPagedIterable(GHContent[].class, item -> item.wrap(repository)); } /** @@ -409,6 +409,6 @@ public static GHContent[] wrap(GHContent[] contents, GHRepository repository) { */ @Override public synchronized void refresh() throws IOException { - root.retrieve().to(url, this); + root.retrieve().setRawUrlPath(url).to(this); } } diff --git a/src/main/java/org/kohsuke/github/GHContentBuilder.java b/src/main/java/org/kohsuke/github/GHContentBuilder.java index 101289eb0f..9e0cf05950 100644 --- a/src/main/java/org/kohsuke/github/GHContentBuilder.java +++ b/src/main/java/org/kohsuke/github/GHContentBuilder.java @@ -50,7 +50,7 @@ public GHContentBuilder branch(String branch) { } /** - * Used when updating (but not creating a new content) to specify Thetblob SHA of the file being replaced. + * Used when updating (but not creating a new content) to specify the blob SHA of the file being replaced. * * @param sha * the sha diff --git a/src/main/java/org/kohsuke/github/GHLabel.java b/src/main/java/org/kohsuke/github/GHLabel.java index 7c6bc38a81..9a947524d4 100644 --- a/src/main/java/org/kohsuke/github/GHLabel.java +++ b/src/main/java/org/kohsuke/github/GHLabel.java @@ -69,7 +69,7 @@ GHLabel wrapUp(GHRepository repo) { * the io exception */ public void delete() throws IOException { - repo.root.retrieve().method("DELETE").to(url); + repo.root.retrieve().method("DELETE").setRawUrlPath(url).to(); } /** @@ -87,7 +87,8 @@ public void setColor(String newColor) throws IOException { .with("name", name) .with("color", newColor) .with("description", description) - .to(url); + .setRawUrlPath(url) + .to(); } /** @@ -107,7 +108,8 @@ public void setDescription(String newDescription) throws IOException { .with("name", name) .with("color", color) .with("description", newDescription) - .to(url); + .setRawUrlPath(url) + .to(); } static Collection toNames(Collection labels) { diff --git a/src/main/java/org/kohsuke/github/GHPerson.java b/src/main/java/org/kohsuke/github/GHPerson.java index 286e97e6f3..9a99571f69 100644 --- a/src/main/java/org/kohsuke/github/GHPerson.java +++ b/src/main/java/org/kohsuke/github/GHPerson.java @@ -113,7 +113,8 @@ public synchronized Iterable> iterateRepositories(final int p return new Iterable>() { public Iterator> iterator() { final Iterator pager = root.retrieve() - .asIterator("/users/" + login + "/repos", GHRepository[].class, pageSize); + .withUrlPath("users", login, "repos") + .asIterator(GHRepository[].class, pageSize); return new Iterator>() { public boolean hasNext() { diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index d5f1e7cdcc..eab1b3c18f 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -134,13 +134,14 @@ public PagedIterable getDeploymentStatuses(final int id) thr * @return the paged iterable */ public PagedIterable listDeployments(String sha, String ref, String task, String environment) { - List params = Arrays.asList(getParam("sha", sha), - getParam("ref", ref), - getParam("task", task), - getParam("environment", environment)); - final String deploymentsUrl = getApiTailUrl("deployments") + "?" + join(params, "&"); return root.retrieve() - .asPagedIterable(deploymentsUrl, GHDeployment[].class, item -> item.wrap(GHRepository.this)); + .with("sha", sha) + .with("ref", ref) + .with("task", task) + .with("environment", environment) + .asPagedIterable(getApiTailUrl("deployments"), + GHDeployment[].class, + item -> item.wrap(GHRepository.this)); } /** @@ -156,20 +157,6 @@ public GHDeployment getDeployment(long id) throws IOException { return root.retrieve().to(getApiTailUrl("deployments/" + id), GHDeployment.class).wrap(this); } - private String join(List params, String joinStr) { - StringBuilder output = new StringBuilder(); - for (String param : params) { - if (param != null) { - output.append(param + joinStr); - } - } - return output.toString(); - } - - private String getParam(String name, String value) { - return StringUtils.trimToNull(value) == null ? null : name + "=" + value; - } - /** * Gets deploy status. * @@ -1152,7 +1139,7 @@ public GHRepository fork() throws IOException { * the io exception */ public GHRepository forkTo(GHOrganization org) throws IOException { - root.retrieve().method("POST").to(getApiTailUrl("forks?org=" + org.getLogin())); + root.retrieve().method("POST").with("organization", org.getLogin()).to(getApiTailUrl("forks")); // this API is asynchronous. we need to wait for a bit for (int i = 0; i < 10; i++) { @@ -1513,8 +1500,8 @@ public GHTreeBuilder createTree() { * on failure communicating with GitHub, potentially due to an invalid tree type being requested */ public GHTree getTreeRecursive(String sha, int recursive) throws IOException { - String url = String.format("/repos/%s/%s/git/trees/%s?recursive=%d", getOwnerName(), name, sha, recursive); - return root.retrieve().to(url, GHTree.class).wrap(this); + String url = String.format("/repos/%s/%s/git/trees/%s", getOwnerName(), name, sha); + return root.retrieve().with("recursive", recursive).to(url, GHTree.class).wrap(this); } /** @@ -2562,7 +2549,7 @@ public boolean equals(Object obj) { String getApiTailUrl(String tail) { if (tail.length() > 0 && !tail.startsWith("/")) tail = '/' + tail; - return Requester.urlPathEncode("/repos/" + getOwnerName() + "/" + name + tail); + return "/repos/" + getOwnerName() + "/" + name + tail; } /** diff --git a/src/main/java/org/kohsuke/github/GHSearchBuilder.java b/src/main/java/org/kohsuke/github/GHSearchBuilder.java index a1c9e7c89d..d17f41cb98 100644 --- a/src/main/java/org/kohsuke/github/GHSearchBuilder.java +++ b/src/main/java/org/kohsuke/github/GHSearchBuilder.java @@ -45,7 +45,7 @@ public PagedSearchIterable list() { return new PagedSearchIterable(root) { public PagedIterator _iterator(int pageSize) { req.set("q", StringUtils.join(terms, " ")); - return new PagedIterator(adapt(req.asIterator(getApiUrl(), receiverType, pageSize))) { + return new PagedIterator(adapt(req.withUrlPath(getApiUrl()).asIterator(receiverType, pageSize))) { protected void wrapUp(T[] page) { // SearchResult.getItems() should do it } diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index d7b14255b8..e74824886d 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -52,6 +52,7 @@ import java.util.Locale; import java.util.Map; import java.util.NoSuchElementException; +import java.util.Objects; import java.util.function.Consumer; import java.util.logging.Logger; import java.util.zip.GZIPInputStream; @@ -75,6 +76,9 @@ class Requester { private final List args = new ArrayList(); private final Map headers = new LinkedHashMap(); + @Nonnull + private String urlPath = "/"; + /** * Request method. */ @@ -312,6 +316,56 @@ public Requester contentType(String contentType) { return this; } + /** + * NOT FOR PUBLIC USE. Do not make this method public. + *

+ * Sets the path component of api URL without URI encoding. + *

+ * Should only be used when passing a literal URL field from a GHObject, such as {@link GHContent#refresh()} or when + * needing to set query parameters on requests methods that don't usually have them, such as + * {@link GHRelease#uploadAsset(String, InputStream, String)}. + * + * @param urlOrPath + * the content type + * @return the requester + */ + Requester setRawUrlPath(String urlOrPath) { + Objects.requireNonNull(urlOrPath); + this.urlPath = urlOrPath; + return this; + } + + /** + * Path component of api URL. Appended to api url. + *

+ * If urlPath starts with a slash, it will be URI encoded as a path. If it starts with anything else, it will be + * used as is. + * + * @param urlPathItems + * the content type + * @return the requester + */ + public Requester withUrlPath(String... urlPathItems) { + if (!this.urlPath.startsWith("/")) { + throw new GHException("Cannot append to url path after setting a raw path"); + } + + if (urlPathItems.length == 1 && !urlPathItems[0].startsWith("/")) { + return setRawUrlPath(urlPathItems[0]); + } + + String tailUrlPath = String.join("/", urlPathItems); + + if (this.urlPath.endsWith("/")) { + tailUrlPath = StringUtils.stripStart(tailUrlPath, "/"); + } else { + tailUrlPath = StringUtils.prependIfMissing(tailUrlPath, "/"); + } + + this.urlPath += urlPathEncode(tailUrlPath); + return this; + } + /** * Small number of GitHub APIs use HTTP methods somewhat inconsistently, and use a body where it's not expected. * Normally whether parameters go as query parameters or a body depends on the HTTP verb in use, but this method @@ -331,7 +385,7 @@ public Requester inBody() { * the io exception */ public void to(@Nonnull String tailApiUrl) throws IOException { - _to(tailApiUrl, null, null); + withUrlPath(tailApiUrl).to(); } /** @@ -348,7 +402,7 @@ public void to(@Nonnull String tailApiUrl) throws IOException { * if the server returns 4xx/5xx responses. */ public T to(@Nonnull String tailApiUrl, @Nonnull Class type) throws IOException { - return _to(tailApiUrl, type, null); + return withUrlPath(tailApiUrl).to(type); } /** @@ -365,13 +419,70 @@ public T to(@Nonnull String tailApiUrl, @Nonnull Class type) throws IOExc * if the server returns 4xx/5xx responses. */ public T[] toArray(@Nonnull String tailApiUrl, @Nonnull Class type) throws IOException { + return withUrlPath(tailApiUrl).toArray(type); + } + + /** + * Like {@link #to(String, Class)} but updates an existing object instead of creating a new instance. + * + * @param + * the type parameter + * @param tailApiUrl + * the tail api url + * @param existingInstance + * the existing instance + * @return the t + * @throws IOException + * the io exception + */ + public T to(@Nonnull String tailApiUrl, @Nonnull T existingInstance) throws IOException { + return withUrlPath(tailApiUrl).to(existingInstance); + } + + /** + * To. + * + * @throws IOException + * the io exception + */ + public void to() throws IOException { + _to(null, null); + } + + /** + * Sends a request to the specified URL, and parses the response into the given type via databinding. + * + * @param + * the type parameter + * @param type + * the type + * @return {@link Reader} that reads the response. + * @throws IOException + * if the server returns 4xx/5xx responses. + */ + public T to(@Nonnull Class type) throws IOException { + return _to(type, null); + } + + /** + * Sends a request to the specified URL, and parses the response into the given type via databinding. + * + * @param + * the type parameter + * @param type + * the type + * @return {@link Reader} that reads the response. + * @throws IOException + * if the server returns 4xx/5xx responses. + */ + public T[] toArray(@Nonnull Class type) throws IOException { T[] result; // for arrays we might have to loop for pagination // use the iterator to handle it List pages = new ArrayList<>(); int totalSize = 0; - for (Iterator iterator = asIterator(tailApiUrl, type, 0); iterator.hasNext();) { + for (Iterator iterator = asIterator(type, 0); iterator.hasNext();) { T[] nextResult = iterator.next(); totalSize += Array.getLength(nextResult); pages.add(nextResult); @@ -386,22 +497,20 @@ public T[] toArray(@Nonnull String tailApiUrl, @Nonnull Class type) thr * * @param * the type parameter - * @param tailApiUrl - * the tail api url * @param existingInstance * the existing instance * @return the t * @throws IOException * the io exception */ - public T to(@Nonnull String tailApiUrl, @Nonnull T existingInstance) throws IOException { - return _to(tailApiUrl, null, existingInstance); + public T to(@Nonnull T existingInstance) throws IOException { + return _to(null, existingInstance); } - private T _to(String tailApiUrl, Class type, T instance) throws IOException { + private T _to(Class type, T instance) throws IOException { T result; - tailApiUrl = buildTailApiUrl(tailApiUrl); + String tailApiUrl = buildTailApiUrl(urlPath); setupConnection(root.getApiURL(tailApiUrl)); while (true) {// loop while API rate limit is hit @@ -464,6 +573,7 @@ private String buildTailApiUrl(String tailApiUrl) { */ public int asHttpStatusCode(String tailApiUrl) throws IOException { while (true) {// loop while API rate limit is hit + method("GET"); setupConnection(root.getApiURL(tailApiUrl)); @@ -603,24 +713,26 @@ private boolean isMethodWithBody() { } PagedIterable asPagedIterable(String tailApiUrl, Class type, Consumer consumer) { - return new PagedIterableWithConsumer<>(type, tailApiUrl, consumer); + return withUrlPath(tailApiUrl).asPagedIterable(type, consumer); + } + + PagedIterable asPagedIterable(Class type, Consumer consumer) { + return new PagedIterableWithConsumer<>(type, consumer); } class PagedIterableWithConsumer extends PagedIterable { private final Class clazz; - private final String tailApiUrl; private final Consumer consumer; - PagedIterableWithConsumer(Class clazz, String tailApiUrl, Consumer consumer) { + PagedIterableWithConsumer(Class clazz, Consumer consumer) { this.clazz = clazz; - this.tailApiUrl = tailApiUrl; this.consumer = consumer; } @Override public PagedIterator _iterator(int pageSize) { - final Iterator iterator = asIterator(tailApiUrl, clazz, pageSize); + final Iterator iterator = asIterator(clazz, pageSize); return new PagedIterator(iterator) { @Override protected void wrapUp(T[] page) { @@ -639,13 +751,13 @@ protected void wrapUp(T[] page) { * * Every iterator call reports a new batch. */ - Iterator asIterator(String tailApiUrl, Class type, int pageSize) { + Iterator asIterator(Class type, int pageSize) { method("GET"); if (pageSize != 0) args.add(new Entry("per_page", pageSize)); - tailApiUrl = buildTailApiUrl(tailApiUrl); + String tailApiUrl = buildTailApiUrl(urlPath); try { return new PagingIterator<>(type, tailApiUrl, root.getApiURL(tailApiUrl)); diff --git a/src/test/java/org/kohsuke/github/AppTest.java b/src/test/java/org/kohsuke/github/AppTest.java index fd223bb287..bd68e6c4b7 100755 --- a/src/test/java/org/kohsuke/github/AppTest.java +++ b/src/test/java/org/kohsuke/github/AppTest.java @@ -312,11 +312,9 @@ public void testPublicKeys() throws Exception { assertFalse(keys.isEmpty()); } - @Ignore("Needs mocking check") @Test public void testOrgFork() throws Exception { - kohsuke(); - + cleanupRepository(GITHUB_API_TEST_ORG + "/rubywm"); gitHub.getRepository("kohsuke/rubywm").forkTo(gitHub.getOrganization(GITHUB_API_TEST_ORG)); } diff --git a/src/test/java/org/kohsuke/github/RepositoryMockTest.java b/src/test/java/org/kohsuke/github/RepositoryMockTest.java index 6e8969adae..d43d06930f 100644 --- a/src/test/java/org/kohsuke/github/RepositoryMockTest.java +++ b/src/test/java/org/kohsuke/github/RepositoryMockTest.java @@ -44,7 +44,9 @@ public void listCollaborators() throws Exception { Requester requester = Mockito.mock(Requester.class); when(mockGitHub.retrieve()).thenReturn(requester); - when(requester.asIterator("/repos/*/*/collaborators", GHUser[].class, 0)).thenReturn(iterator, iterator); + when(requester.withUrlPath("/repos/*/*/collaborators")).thenReturn(requester); + + when(requester.asIterator(GHUser[].class, 0)).thenReturn(iterator, iterator); PagedIterable pagedIterable = Mockito.mock(PagedIterable.class); when(mockRepository.listCollaborators()).thenReturn(pagedIterable); diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testCreateAndListDeployments/mappings/repos_github-api-test-org_github-api-test_deployments-4-b4bcda.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testCreateAndListDeployments/mappings/repos_github-api-test-org_github-api-test_deployments-4-b4bcda.json index b5fe8f595e..0cd1ce7827 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testCreateAndListDeployments/mappings/repos_github-api-test-org_github-api-test_deployments-4-b4bcda.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testCreateAndListDeployments/mappings/repos_github-api-test-org_github-api-test_deployments-4-b4bcda.json @@ -2,7 +2,7 @@ "id": "b4bcdadb-a708-4509-9382-479f300eb172", "name": "repos_github-api-test-org_github-api-test_deployments", "request": { - "url": "/repos/github-api-test-org/github-api-test/deployments?ref=master&environment=unittest&", + "url": "/repos/github-api-test-org/github-api-test/deployments?ref=master&environment=unittest", "method": "GET" }, "response": { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/orgs_github-api-test-org-1839874d-c184-4f20-942f-cc6d36806868.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/orgs_github-api-test-org-1839874d-c184-4f20-942f-cc6d36806868.json new file mode 100644 index 0000000000..8a639e51da --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/orgs_github-api-test-org-1839874d-c184-4f20-942f-cc6d36806868.json @@ -0,0 +1,41 @@ +{ + "login": "github-api-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/github-api-test-org", + "repos_url": "https://api.github.com/orgs/github-api-test-org/repos", + "events_url": "https://api.github.com/orgs/github-api-test-org/events", + "hooks_url": "https://api.github.com/orgs/github-api-test-org/hooks", + "issues_url": "https://api.github.com/orgs/github-api-test-org/issues", + "members_url": "https://api.github.com/orgs/github-api-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/github-api-test-org/public_members{/member}", + "avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4", + "description": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 9, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/github-api-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2015-04-20T00:42:30Z", + "type": "Organization", + "total_private_repos": 0, + "owned_private_repos": 0, + "private_gists": 0, + "disk_usage": 132, + "collaborators": 0, + "billing_email": "kk@kohsuke.org", + "default_repository_permission": "none", + "members_can_create_repositories": false, + "two_factor_requirement_enabled": false, + "plan": { + "name": "free", + "space": 976562499, + "private_repos": 0, + "filled_seats": 10, + "seats": 0 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/repos_github-api-test-org_rubywm-5b2f012d-aa23-4e59-849c-22b53a469c95.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/repos_github-api-test-org_rubywm-5b2f012d-aa23-4e59-849c-22b53a469c95.json new file mode 100644 index 0000000000..81e8e7d2d0 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/repos_github-api-test-org_rubywm-5b2f012d-aa23-4e59-849c-22b53a469c95.json @@ -0,0 +1,312 @@ +{ + "id": 224294379, + "node_id": "MDEwOlJlcG9zaXRvcnkyMjQyOTQzNzk=", + "name": "rubywm", + "full_name": "github-api-test-org/rubywm", + "private": false, + "owner": { + "login": "github-api-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-api-test-org", + "html_url": "https://github.com/github-api-test-org", + "followers_url": "https://api.github.com/users/github-api-test-org/followers", + "following_url": "https://api.github.com/users/github-api-test-org/following{/other_user}", + "gists_url": "https://api.github.com/users/github-api-test-org/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-api-test-org/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-api-test-org/subscriptions", + "organizations_url": "https://api.github.com/users/github-api-test-org/orgs", + "repos_url": "https://api.github.com/users/github-api-test-org/repos", + "events_url": "https://api.github.com/users/github-api-test-org/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-api-test-org/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/github-api-test-org/rubywm", + "description": "My modifcation to ruby window management library (https://cixar.com/svn/arcanum/ruby/wm)", + "fork": true, + "url": "https://api.github.com/repos/github-api-test-org/rubywm", + "forks_url": "https://api.github.com/repos/github-api-test-org/rubywm/forks", + "keys_url": "https://api.github.com/repos/github-api-test-org/rubywm/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/github-api-test-org/rubywm/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/github-api-test-org/rubywm/teams", + "hooks_url": "https://api.github.com/repos/github-api-test-org/rubywm/hooks", + "issue_events_url": "https://api.github.com/repos/github-api-test-org/rubywm/issues/events{/number}", + "events_url": "https://api.github.com/repos/github-api-test-org/rubywm/events", + "assignees_url": "https://api.github.com/repos/github-api-test-org/rubywm/assignees{/user}", + "branches_url": "https://api.github.com/repos/github-api-test-org/rubywm/branches{/branch}", + "tags_url": "https://api.github.com/repos/github-api-test-org/rubywm/tags", + "blobs_url": "https://api.github.com/repos/github-api-test-org/rubywm/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/github-api-test-org/rubywm/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/github-api-test-org/rubywm/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/github-api-test-org/rubywm/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/github-api-test-org/rubywm/statuses/{sha}", + "languages_url": "https://api.github.com/repos/github-api-test-org/rubywm/languages", + "stargazers_url": "https://api.github.com/repos/github-api-test-org/rubywm/stargazers", + "contributors_url": "https://api.github.com/repos/github-api-test-org/rubywm/contributors", + "subscribers_url": "https://api.github.com/repos/github-api-test-org/rubywm/subscribers", + "subscription_url": "https://api.github.com/repos/github-api-test-org/rubywm/subscription", + "commits_url": "https://api.github.com/repos/github-api-test-org/rubywm/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/github-api-test-org/rubywm/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/github-api-test-org/rubywm/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/github-api-test-org/rubywm/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/github-api-test-org/rubywm/contents/{+path}", + "compare_url": "https://api.github.com/repos/github-api-test-org/rubywm/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/github-api-test-org/rubywm/merges", + "archive_url": "https://api.github.com/repos/github-api-test-org/rubywm/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/github-api-test-org/rubywm/downloads", + "issues_url": "https://api.github.com/repos/github-api-test-org/rubywm/issues{/number}", + "pulls_url": "https://api.github.com/repos/github-api-test-org/rubywm/pulls{/number}", + "milestones_url": "https://api.github.com/repos/github-api-test-org/rubywm/milestones{/number}", + "notifications_url": "https://api.github.com/repos/github-api-test-org/rubywm/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/github-api-test-org/rubywm/labels{/name}", + "releases_url": "https://api.github.com/repos/github-api-test-org/rubywm/releases{/id}", + "deployments_url": "https://api.github.com/repos/github-api-test-org/rubywm/deployments", + "created_at": "2019-11-26T22:05:41Z", + "updated_at": "2019-08-13T14:29:25Z", + "pushed_at": "2017-04-03T23:48:23Z", + "git_url": "git://github.com/github-api-test-org/rubywm.git", + "ssh_url": "git@github.com:github-api-test-org/rubywm.git", + "clone_url": "https://github.com/github-api-test-org/rubywm.git", + "svn_url": "https://github.com/github-api-test-org/rubywm", + "homepage": "", + "size": 15, + "stargazers_count": 0, + "watchers_count": 0, + "language": null, + "has_issues": false, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": null, + "forks": 0, + "open_issues": 0, + "watchers": 0, + "default_branch": "master", + "permissions": { + "admin": true, + "push": true, + "pull": true + }, + "allow_squash_merge": true, + "allow_merge_commit": true, + "allow_rebase_merge": true, + "organization": { + "login": "github-api-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-api-test-org", + "html_url": "https://github.com/github-api-test-org", + "followers_url": "https://api.github.com/users/github-api-test-org/followers", + "following_url": "https://api.github.com/users/github-api-test-org/following{/other_user}", + "gists_url": "https://api.github.com/users/github-api-test-org/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-api-test-org/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-api-test-org/subscriptions", + "organizations_url": "https://api.github.com/users/github-api-test-org/orgs", + "repos_url": "https://api.github.com/users/github-api-test-org/repos", + "events_url": "https://api.github.com/users/github-api-test-org/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-api-test-org/received_events", + "type": "Organization", + "site_admin": false + }, + "parent": { + "id": 383524, + "node_id": "MDEwOlJlcG9zaXRvcnkzODM1MjQ=", + "name": "rubywm", + "full_name": "kohsuke/rubywm", + "private": false, + "owner": { + "login": "kohsuke", + "id": 50003, + "node_id": "MDQ6VXNlcjUwMDAz", + "avatar_url": "https://avatars1.githubusercontent.com/u/50003?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/kohsuke", + "html_url": "https://github.com/kohsuke", + "followers_url": "https://api.github.com/users/kohsuke/followers", + "following_url": "https://api.github.com/users/kohsuke/following{/other_user}", + "gists_url": "https://api.github.com/users/kohsuke/gists{/gist_id}", + "starred_url": "https://api.github.com/users/kohsuke/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/kohsuke/subscriptions", + "organizations_url": "https://api.github.com/users/kohsuke/orgs", + "repos_url": "https://api.github.com/users/kohsuke/repos", + "events_url": "https://api.github.com/users/kohsuke/events{/privacy}", + "received_events_url": "https://api.github.com/users/kohsuke/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/kohsuke/rubywm", + "description": "My modifcation to ruby window management library (https://cixar.com/svn/arcanum/ruby/wm)", + "fork": false, + "url": "https://api.github.com/repos/kohsuke/rubywm", + "forks_url": "https://api.github.com/repos/kohsuke/rubywm/forks", + "keys_url": "https://api.github.com/repos/kohsuke/rubywm/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/kohsuke/rubywm/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/kohsuke/rubywm/teams", + "hooks_url": "https://api.github.com/repos/kohsuke/rubywm/hooks", + "issue_events_url": "https://api.github.com/repos/kohsuke/rubywm/issues/events{/number}", + "events_url": "https://api.github.com/repos/kohsuke/rubywm/events", + "assignees_url": "https://api.github.com/repos/kohsuke/rubywm/assignees{/user}", + "branches_url": "https://api.github.com/repos/kohsuke/rubywm/branches{/branch}", + "tags_url": "https://api.github.com/repos/kohsuke/rubywm/tags", + "blobs_url": "https://api.github.com/repos/kohsuke/rubywm/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/kohsuke/rubywm/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/kohsuke/rubywm/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/kohsuke/rubywm/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/kohsuke/rubywm/statuses/{sha}", + "languages_url": "https://api.github.com/repos/kohsuke/rubywm/languages", + "stargazers_url": "https://api.github.com/repos/kohsuke/rubywm/stargazers", + "contributors_url": "https://api.github.com/repos/kohsuke/rubywm/contributors", + "subscribers_url": "https://api.github.com/repos/kohsuke/rubywm/subscribers", + "subscription_url": "https://api.github.com/repos/kohsuke/rubywm/subscription", + "commits_url": "https://api.github.com/repos/kohsuke/rubywm/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/kohsuke/rubywm/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/kohsuke/rubywm/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/kohsuke/rubywm/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/kohsuke/rubywm/contents/{+path}", + "compare_url": "https://api.github.com/repos/kohsuke/rubywm/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/kohsuke/rubywm/merges", + "archive_url": "https://api.github.com/repos/kohsuke/rubywm/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/kohsuke/rubywm/downloads", + "issues_url": "https://api.github.com/repos/kohsuke/rubywm/issues{/number}", + "pulls_url": "https://api.github.com/repos/kohsuke/rubywm/pulls{/number}", + "milestones_url": "https://api.github.com/repos/kohsuke/rubywm/milestones{/number}", + "notifications_url": "https://api.github.com/repos/kohsuke/rubywm/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/kohsuke/rubywm/labels{/name}", + "releases_url": "https://api.github.com/repos/kohsuke/rubywm/releases{/id}", + "deployments_url": "https://api.github.com/repos/kohsuke/rubywm/deployments", + "created_at": "2009-11-24T05:38:50Z", + "updated_at": "2019-08-13T14:29:25Z", + "pushed_at": "2017-04-03T23:48:23Z", + "git_url": "git://github.com/kohsuke/rubywm.git", + "ssh_url": "git@github.com:kohsuke/rubywm.git", + "clone_url": "https://github.com/kohsuke/rubywm.git", + "svn_url": "https://github.com/kohsuke/rubywm", + "homepage": "", + "size": 15, + "stargazers_count": 7, + "watchers_count": 7, + "language": "C", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 6, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": null, + "forks": 6, + "open_issues": 0, + "watchers": 7, + "default_branch": "master" + }, + "source": { + "id": 383524, + "node_id": "MDEwOlJlcG9zaXRvcnkzODM1MjQ=", + "name": "rubywm", + "full_name": "kohsuke/rubywm", + "private": false, + "owner": { + "login": "kohsuke", + "id": 50003, + "node_id": "MDQ6VXNlcjUwMDAz", + "avatar_url": "https://avatars1.githubusercontent.com/u/50003?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/kohsuke", + "html_url": "https://github.com/kohsuke", + "followers_url": "https://api.github.com/users/kohsuke/followers", + "following_url": "https://api.github.com/users/kohsuke/following{/other_user}", + "gists_url": "https://api.github.com/users/kohsuke/gists{/gist_id}", + "starred_url": "https://api.github.com/users/kohsuke/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/kohsuke/subscriptions", + "organizations_url": "https://api.github.com/users/kohsuke/orgs", + "repos_url": "https://api.github.com/users/kohsuke/repos", + "events_url": "https://api.github.com/users/kohsuke/events{/privacy}", + "received_events_url": "https://api.github.com/users/kohsuke/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/kohsuke/rubywm", + "description": "My modifcation to ruby window management library (https://cixar.com/svn/arcanum/ruby/wm)", + "fork": false, + "url": "https://api.github.com/repos/kohsuke/rubywm", + "forks_url": "https://api.github.com/repos/kohsuke/rubywm/forks", + "keys_url": "https://api.github.com/repos/kohsuke/rubywm/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/kohsuke/rubywm/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/kohsuke/rubywm/teams", + "hooks_url": "https://api.github.com/repos/kohsuke/rubywm/hooks", + "issue_events_url": "https://api.github.com/repos/kohsuke/rubywm/issues/events{/number}", + "events_url": "https://api.github.com/repos/kohsuke/rubywm/events", + "assignees_url": "https://api.github.com/repos/kohsuke/rubywm/assignees{/user}", + "branches_url": "https://api.github.com/repos/kohsuke/rubywm/branches{/branch}", + "tags_url": "https://api.github.com/repos/kohsuke/rubywm/tags", + "blobs_url": "https://api.github.com/repos/kohsuke/rubywm/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/kohsuke/rubywm/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/kohsuke/rubywm/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/kohsuke/rubywm/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/kohsuke/rubywm/statuses/{sha}", + "languages_url": "https://api.github.com/repos/kohsuke/rubywm/languages", + "stargazers_url": "https://api.github.com/repos/kohsuke/rubywm/stargazers", + "contributors_url": "https://api.github.com/repos/kohsuke/rubywm/contributors", + "subscribers_url": "https://api.github.com/repos/kohsuke/rubywm/subscribers", + "subscription_url": "https://api.github.com/repos/kohsuke/rubywm/subscription", + "commits_url": "https://api.github.com/repos/kohsuke/rubywm/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/kohsuke/rubywm/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/kohsuke/rubywm/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/kohsuke/rubywm/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/kohsuke/rubywm/contents/{+path}", + "compare_url": "https://api.github.com/repos/kohsuke/rubywm/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/kohsuke/rubywm/merges", + "archive_url": "https://api.github.com/repos/kohsuke/rubywm/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/kohsuke/rubywm/downloads", + "issues_url": "https://api.github.com/repos/kohsuke/rubywm/issues{/number}", + "pulls_url": "https://api.github.com/repos/kohsuke/rubywm/pulls{/number}", + "milestones_url": "https://api.github.com/repos/kohsuke/rubywm/milestones{/number}", + "notifications_url": "https://api.github.com/repos/kohsuke/rubywm/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/kohsuke/rubywm/labels{/name}", + "releases_url": "https://api.github.com/repos/kohsuke/rubywm/releases{/id}", + "deployments_url": "https://api.github.com/repos/kohsuke/rubywm/deployments", + "created_at": "2009-11-24T05:38:50Z", + "updated_at": "2019-08-13T14:29:25Z", + "pushed_at": "2017-04-03T23:48:23Z", + "git_url": "git://github.com/kohsuke/rubywm.git", + "ssh_url": "git@github.com:kohsuke/rubywm.git", + "clone_url": "https://github.com/kohsuke/rubywm.git", + "svn_url": "https://github.com/kohsuke/rubywm", + "homepage": "", + "size": 15, + "stargazers_count": 7, + "watchers_count": 7, + "language": "C", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 6, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": null, + "forks": 6, + "open_issues": 0, + "watchers": 7, + "default_branch": "master" + }, + "network_count": 6, + "subscribers_count": 0 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/repos_kohsuke_rubywm-7f6b9ed5-222f-4c89-95a7-e45ef24d78a7.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/repos_kohsuke_rubywm-7f6b9ed5-222f-4c89-95a7-e45ef24d78a7.json new file mode 100644 index 0000000000..48ea41c76d --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/repos_kohsuke_rubywm-7f6b9ed5-222f-4c89-95a7-e45ef24d78a7.json @@ -0,0 +1,101 @@ +{ + "id": 383524, + "node_id": "MDEwOlJlcG9zaXRvcnkzODM1MjQ=", + "name": "rubywm", + "full_name": "kohsuke/rubywm", + "private": false, + "owner": { + "login": "kohsuke", + "id": 50003, + "node_id": "MDQ6VXNlcjUwMDAz", + "avatar_url": "https://avatars1.githubusercontent.com/u/50003?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/kohsuke", + "html_url": "https://github.com/kohsuke", + "followers_url": "https://api.github.com/users/kohsuke/followers", + "following_url": "https://api.github.com/users/kohsuke/following{/other_user}", + "gists_url": "https://api.github.com/users/kohsuke/gists{/gist_id}", + "starred_url": "https://api.github.com/users/kohsuke/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/kohsuke/subscriptions", + "organizations_url": "https://api.github.com/users/kohsuke/orgs", + "repos_url": "https://api.github.com/users/kohsuke/repos", + "events_url": "https://api.github.com/users/kohsuke/events{/privacy}", + "received_events_url": "https://api.github.com/users/kohsuke/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/kohsuke/rubywm", + "description": "My modifcation to ruby window management library (https://cixar.com/svn/arcanum/ruby/wm)", + "fork": false, + "url": "https://api.github.com/repos/kohsuke/rubywm", + "forks_url": "https://api.github.com/repos/kohsuke/rubywm/forks", + "keys_url": "https://api.github.com/repos/kohsuke/rubywm/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/kohsuke/rubywm/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/kohsuke/rubywm/teams", + "hooks_url": "https://api.github.com/repos/kohsuke/rubywm/hooks", + "issue_events_url": "https://api.github.com/repos/kohsuke/rubywm/issues/events{/number}", + "events_url": "https://api.github.com/repos/kohsuke/rubywm/events", + "assignees_url": "https://api.github.com/repos/kohsuke/rubywm/assignees{/user}", + "branches_url": "https://api.github.com/repos/kohsuke/rubywm/branches{/branch}", + "tags_url": "https://api.github.com/repos/kohsuke/rubywm/tags", + "blobs_url": "https://api.github.com/repos/kohsuke/rubywm/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/kohsuke/rubywm/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/kohsuke/rubywm/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/kohsuke/rubywm/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/kohsuke/rubywm/statuses/{sha}", + "languages_url": "https://api.github.com/repos/kohsuke/rubywm/languages", + "stargazers_url": "https://api.github.com/repos/kohsuke/rubywm/stargazers", + "contributors_url": "https://api.github.com/repos/kohsuke/rubywm/contributors", + "subscribers_url": "https://api.github.com/repos/kohsuke/rubywm/subscribers", + "subscription_url": "https://api.github.com/repos/kohsuke/rubywm/subscription", + "commits_url": "https://api.github.com/repos/kohsuke/rubywm/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/kohsuke/rubywm/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/kohsuke/rubywm/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/kohsuke/rubywm/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/kohsuke/rubywm/contents/{+path}", + "compare_url": "https://api.github.com/repos/kohsuke/rubywm/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/kohsuke/rubywm/merges", + "archive_url": "https://api.github.com/repos/kohsuke/rubywm/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/kohsuke/rubywm/downloads", + "issues_url": "https://api.github.com/repos/kohsuke/rubywm/issues{/number}", + "pulls_url": "https://api.github.com/repos/kohsuke/rubywm/pulls{/number}", + "milestones_url": "https://api.github.com/repos/kohsuke/rubywm/milestones{/number}", + "notifications_url": "https://api.github.com/repos/kohsuke/rubywm/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/kohsuke/rubywm/labels{/name}", + "releases_url": "https://api.github.com/repos/kohsuke/rubywm/releases{/id}", + "deployments_url": "https://api.github.com/repos/kohsuke/rubywm/deployments", + "created_at": "2009-11-24T05:38:50Z", + "updated_at": "2019-08-13T14:29:25Z", + "pushed_at": "2017-04-03T23:48:23Z", + "git_url": "git://github.com/kohsuke/rubywm.git", + "ssh_url": "git@github.com:kohsuke/rubywm.git", + "clone_url": "https://github.com/kohsuke/rubywm.git", + "svn_url": "https://github.com/kohsuke/rubywm", + "homepage": "", + "size": 15, + "stargazers_count": 7, + "watchers_count": 7, + "language": "C", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 5, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": null, + "forks": 5, + "open_issues": 0, + "watchers": 7, + "default_branch": "master", + "permissions": { + "admin": false, + "push": false, + "pull": true + }, + "network_count": 5, + "subscribers_count": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/repos_kohsuke_rubywm_forks-044af303-143e-4469-be96-0a6e72032e5c.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/repos_kohsuke_rubywm_forks-044af303-143e-4469-be96-0a6e72032e5c.json new file mode 100644 index 0000000000..f734edeabe --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/repos_kohsuke_rubywm_forks-044af303-143e-4469-be96-0a6e72032e5c.json @@ -0,0 +1,309 @@ +{ + "id": 224294379, + "node_id": "MDEwOlJlcG9zaXRvcnkyMjQyOTQzNzk=", + "name": "rubywm", + "full_name": "github-api-test-org/rubywm", + "private": false, + "owner": { + "login": "github-api-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-api-test-org", + "html_url": "https://github.com/github-api-test-org", + "followers_url": "https://api.github.com/users/github-api-test-org/followers", + "following_url": "https://api.github.com/users/github-api-test-org/following{/other_user}", + "gists_url": "https://api.github.com/users/github-api-test-org/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-api-test-org/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-api-test-org/subscriptions", + "organizations_url": "https://api.github.com/users/github-api-test-org/orgs", + "repos_url": "https://api.github.com/users/github-api-test-org/repos", + "events_url": "https://api.github.com/users/github-api-test-org/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-api-test-org/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/github-api-test-org/rubywm", + "description": "My modifcation to ruby window management library (https://cixar.com/svn/arcanum/ruby/wm)", + "fork": true, + "url": "https://api.github.com/repos/github-api-test-org/rubywm", + "forks_url": "https://api.github.com/repos/github-api-test-org/rubywm/forks", + "keys_url": "https://api.github.com/repos/github-api-test-org/rubywm/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/github-api-test-org/rubywm/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/github-api-test-org/rubywm/teams", + "hooks_url": "https://api.github.com/repos/github-api-test-org/rubywm/hooks", + "issue_events_url": "https://api.github.com/repos/github-api-test-org/rubywm/issues/events{/number}", + "events_url": "https://api.github.com/repos/github-api-test-org/rubywm/events", + "assignees_url": "https://api.github.com/repos/github-api-test-org/rubywm/assignees{/user}", + "branches_url": "https://api.github.com/repos/github-api-test-org/rubywm/branches{/branch}", + "tags_url": "https://api.github.com/repos/github-api-test-org/rubywm/tags", + "blobs_url": "https://api.github.com/repos/github-api-test-org/rubywm/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/github-api-test-org/rubywm/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/github-api-test-org/rubywm/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/github-api-test-org/rubywm/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/github-api-test-org/rubywm/statuses/{sha}", + "languages_url": "https://api.github.com/repos/github-api-test-org/rubywm/languages", + "stargazers_url": "https://api.github.com/repos/github-api-test-org/rubywm/stargazers", + "contributors_url": "https://api.github.com/repos/github-api-test-org/rubywm/contributors", + "subscribers_url": "https://api.github.com/repos/github-api-test-org/rubywm/subscribers", + "subscription_url": "https://api.github.com/repos/github-api-test-org/rubywm/subscription", + "commits_url": "https://api.github.com/repos/github-api-test-org/rubywm/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/github-api-test-org/rubywm/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/github-api-test-org/rubywm/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/github-api-test-org/rubywm/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/github-api-test-org/rubywm/contents/{+path}", + "compare_url": "https://api.github.com/repos/github-api-test-org/rubywm/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/github-api-test-org/rubywm/merges", + "archive_url": "https://api.github.com/repos/github-api-test-org/rubywm/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/github-api-test-org/rubywm/downloads", + "issues_url": "https://api.github.com/repos/github-api-test-org/rubywm/issues{/number}", + "pulls_url": "https://api.github.com/repos/github-api-test-org/rubywm/pulls{/number}", + "milestones_url": "https://api.github.com/repos/github-api-test-org/rubywm/milestones{/number}", + "notifications_url": "https://api.github.com/repos/github-api-test-org/rubywm/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/github-api-test-org/rubywm/labels{/name}", + "releases_url": "https://api.github.com/repos/github-api-test-org/rubywm/releases{/id}", + "deployments_url": "https://api.github.com/repos/github-api-test-org/rubywm/deployments", + "created_at": "2019-11-26T22:05:41Z", + "updated_at": "2019-08-13T14:29:25Z", + "pushed_at": "2017-04-03T23:48:23Z", + "git_url": "git://github.com/github-api-test-org/rubywm.git", + "ssh_url": "git@github.com:github-api-test-org/rubywm.git", + "clone_url": "https://github.com/github-api-test-org/rubywm.git", + "svn_url": "https://github.com/github-api-test-org/rubywm", + "homepage": "", + "size": 15, + "stargazers_count": 0, + "watchers_count": 0, + "language": null, + "has_issues": false, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": null, + "forks": 0, + "open_issues": 0, + "watchers": 0, + "default_branch": "master", + "permissions": { + "admin": true, + "push": true, + "pull": true + }, + "organization": { + "login": "github-api-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-api-test-org", + "html_url": "https://github.com/github-api-test-org", + "followers_url": "https://api.github.com/users/github-api-test-org/followers", + "following_url": "https://api.github.com/users/github-api-test-org/following{/other_user}", + "gists_url": "https://api.github.com/users/github-api-test-org/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-api-test-org/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-api-test-org/subscriptions", + "organizations_url": "https://api.github.com/users/github-api-test-org/orgs", + "repos_url": "https://api.github.com/users/github-api-test-org/repos", + "events_url": "https://api.github.com/users/github-api-test-org/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-api-test-org/received_events", + "type": "Organization", + "site_admin": false + }, + "parent": { + "id": 383524, + "node_id": "MDEwOlJlcG9zaXRvcnkzODM1MjQ=", + "name": "rubywm", + "full_name": "kohsuke/rubywm", + "private": false, + "owner": { + "login": "kohsuke", + "id": 50003, + "node_id": "MDQ6VXNlcjUwMDAz", + "avatar_url": "https://avatars1.githubusercontent.com/u/50003?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/kohsuke", + "html_url": "https://github.com/kohsuke", + "followers_url": "https://api.github.com/users/kohsuke/followers", + "following_url": "https://api.github.com/users/kohsuke/following{/other_user}", + "gists_url": "https://api.github.com/users/kohsuke/gists{/gist_id}", + "starred_url": "https://api.github.com/users/kohsuke/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/kohsuke/subscriptions", + "organizations_url": "https://api.github.com/users/kohsuke/orgs", + "repos_url": "https://api.github.com/users/kohsuke/repos", + "events_url": "https://api.github.com/users/kohsuke/events{/privacy}", + "received_events_url": "https://api.github.com/users/kohsuke/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/kohsuke/rubywm", + "description": "My modifcation to ruby window management library (https://cixar.com/svn/arcanum/ruby/wm)", + "fork": false, + "url": "https://api.github.com/repos/kohsuke/rubywm", + "forks_url": "https://api.github.com/repos/kohsuke/rubywm/forks", + "keys_url": "https://api.github.com/repos/kohsuke/rubywm/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/kohsuke/rubywm/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/kohsuke/rubywm/teams", + "hooks_url": "https://api.github.com/repos/kohsuke/rubywm/hooks", + "issue_events_url": "https://api.github.com/repos/kohsuke/rubywm/issues/events{/number}", + "events_url": "https://api.github.com/repos/kohsuke/rubywm/events", + "assignees_url": "https://api.github.com/repos/kohsuke/rubywm/assignees{/user}", + "branches_url": "https://api.github.com/repos/kohsuke/rubywm/branches{/branch}", + "tags_url": "https://api.github.com/repos/kohsuke/rubywm/tags", + "blobs_url": "https://api.github.com/repos/kohsuke/rubywm/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/kohsuke/rubywm/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/kohsuke/rubywm/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/kohsuke/rubywm/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/kohsuke/rubywm/statuses/{sha}", + "languages_url": "https://api.github.com/repos/kohsuke/rubywm/languages", + "stargazers_url": "https://api.github.com/repos/kohsuke/rubywm/stargazers", + "contributors_url": "https://api.github.com/repos/kohsuke/rubywm/contributors", + "subscribers_url": "https://api.github.com/repos/kohsuke/rubywm/subscribers", + "subscription_url": "https://api.github.com/repos/kohsuke/rubywm/subscription", + "commits_url": "https://api.github.com/repos/kohsuke/rubywm/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/kohsuke/rubywm/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/kohsuke/rubywm/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/kohsuke/rubywm/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/kohsuke/rubywm/contents/{+path}", + "compare_url": "https://api.github.com/repos/kohsuke/rubywm/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/kohsuke/rubywm/merges", + "archive_url": "https://api.github.com/repos/kohsuke/rubywm/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/kohsuke/rubywm/downloads", + "issues_url": "https://api.github.com/repos/kohsuke/rubywm/issues{/number}", + "pulls_url": "https://api.github.com/repos/kohsuke/rubywm/pulls{/number}", + "milestones_url": "https://api.github.com/repos/kohsuke/rubywm/milestones{/number}", + "notifications_url": "https://api.github.com/repos/kohsuke/rubywm/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/kohsuke/rubywm/labels{/name}", + "releases_url": "https://api.github.com/repos/kohsuke/rubywm/releases{/id}", + "deployments_url": "https://api.github.com/repos/kohsuke/rubywm/deployments", + "created_at": "2009-11-24T05:38:50Z", + "updated_at": "2019-08-13T14:29:25Z", + "pushed_at": "2017-04-03T23:48:23Z", + "git_url": "git://github.com/kohsuke/rubywm.git", + "ssh_url": "git@github.com:kohsuke/rubywm.git", + "clone_url": "https://github.com/kohsuke/rubywm.git", + "svn_url": "https://github.com/kohsuke/rubywm", + "homepage": "", + "size": 15, + "stargazers_count": 7, + "watchers_count": 7, + "language": "C", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 6, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": null, + "forks": 6, + "open_issues": 0, + "watchers": 7, + "default_branch": "master" + }, + "source": { + "id": 383524, + "node_id": "MDEwOlJlcG9zaXRvcnkzODM1MjQ=", + "name": "rubywm", + "full_name": "kohsuke/rubywm", + "private": false, + "owner": { + "login": "kohsuke", + "id": 50003, + "node_id": "MDQ6VXNlcjUwMDAz", + "avatar_url": "https://avatars1.githubusercontent.com/u/50003?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/kohsuke", + "html_url": "https://github.com/kohsuke", + "followers_url": "https://api.github.com/users/kohsuke/followers", + "following_url": "https://api.github.com/users/kohsuke/following{/other_user}", + "gists_url": "https://api.github.com/users/kohsuke/gists{/gist_id}", + "starred_url": "https://api.github.com/users/kohsuke/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/kohsuke/subscriptions", + "organizations_url": "https://api.github.com/users/kohsuke/orgs", + "repos_url": "https://api.github.com/users/kohsuke/repos", + "events_url": "https://api.github.com/users/kohsuke/events{/privacy}", + "received_events_url": "https://api.github.com/users/kohsuke/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/kohsuke/rubywm", + "description": "My modifcation to ruby window management library (https://cixar.com/svn/arcanum/ruby/wm)", + "fork": false, + "url": "https://api.github.com/repos/kohsuke/rubywm", + "forks_url": "https://api.github.com/repos/kohsuke/rubywm/forks", + "keys_url": "https://api.github.com/repos/kohsuke/rubywm/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/kohsuke/rubywm/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/kohsuke/rubywm/teams", + "hooks_url": "https://api.github.com/repos/kohsuke/rubywm/hooks", + "issue_events_url": "https://api.github.com/repos/kohsuke/rubywm/issues/events{/number}", + "events_url": "https://api.github.com/repos/kohsuke/rubywm/events", + "assignees_url": "https://api.github.com/repos/kohsuke/rubywm/assignees{/user}", + "branches_url": "https://api.github.com/repos/kohsuke/rubywm/branches{/branch}", + "tags_url": "https://api.github.com/repos/kohsuke/rubywm/tags", + "blobs_url": "https://api.github.com/repos/kohsuke/rubywm/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/kohsuke/rubywm/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/kohsuke/rubywm/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/kohsuke/rubywm/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/kohsuke/rubywm/statuses/{sha}", + "languages_url": "https://api.github.com/repos/kohsuke/rubywm/languages", + "stargazers_url": "https://api.github.com/repos/kohsuke/rubywm/stargazers", + "contributors_url": "https://api.github.com/repos/kohsuke/rubywm/contributors", + "subscribers_url": "https://api.github.com/repos/kohsuke/rubywm/subscribers", + "subscription_url": "https://api.github.com/repos/kohsuke/rubywm/subscription", + "commits_url": "https://api.github.com/repos/kohsuke/rubywm/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/kohsuke/rubywm/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/kohsuke/rubywm/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/kohsuke/rubywm/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/kohsuke/rubywm/contents/{+path}", + "compare_url": "https://api.github.com/repos/kohsuke/rubywm/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/kohsuke/rubywm/merges", + "archive_url": "https://api.github.com/repos/kohsuke/rubywm/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/kohsuke/rubywm/downloads", + "issues_url": "https://api.github.com/repos/kohsuke/rubywm/issues{/number}", + "pulls_url": "https://api.github.com/repos/kohsuke/rubywm/pulls{/number}", + "milestones_url": "https://api.github.com/repos/kohsuke/rubywm/milestones{/number}", + "notifications_url": "https://api.github.com/repos/kohsuke/rubywm/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/kohsuke/rubywm/labels{/name}", + "releases_url": "https://api.github.com/repos/kohsuke/rubywm/releases{/id}", + "deployments_url": "https://api.github.com/repos/kohsuke/rubywm/deployments", + "created_at": "2009-11-24T05:38:50Z", + "updated_at": "2019-08-13T14:29:25Z", + "pushed_at": "2017-04-03T23:48:23Z", + "git_url": "git://github.com/kohsuke/rubywm.git", + "ssh_url": "git@github.com:kohsuke/rubywm.git", + "clone_url": "https://github.com/kohsuke/rubywm.git", + "svn_url": "https://github.com/kohsuke/rubywm", + "homepage": "", + "size": 15, + "stargazers_count": 7, + "watchers_count": 7, + "language": "C", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 6, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": null, + "forks": 6, + "open_issues": 0, + "watchers": 7, + "default_branch": "master" + }, + "network_count": 6, + "subscribers_count": 0 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/user-07a0042d-8162-4e85-9ed4-0ed31ebc9d63.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/user-07a0042d-8162-4e85-9ed4-0ed31ebc9d63.json new file mode 100644 index 0000000000..a45e820c9e --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/__files/user-07a0042d-8162-4e85-9ed4-0ed31ebc9d63.json @@ -0,0 +1,45 @@ +{ + "login": "bitwiseman", + "id": 1958953, + "node_id": "MDQ6VXNlcjE5NTg5NTM=", + "avatar_url": "https://avatars3.githubusercontent.com/u/1958953?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/bitwiseman", + "html_url": "https://github.com/bitwiseman", + "followers_url": "https://api.github.com/users/bitwiseman/followers", + "following_url": "https://api.github.com/users/bitwiseman/following{/other_user}", + "gists_url": "https://api.github.com/users/bitwiseman/gists{/gist_id}", + "starred_url": "https://api.github.com/users/bitwiseman/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bitwiseman/subscriptions", + "organizations_url": "https://api.github.com/users/bitwiseman/orgs", + "repos_url": "https://api.github.com/users/bitwiseman/repos", + "events_url": "https://api.github.com/users/bitwiseman/events{/privacy}", + "received_events_url": "https://api.github.com/users/bitwiseman/received_events", + "type": "User", + "site_admin": false, + "name": "Liam Newman", + "company": "Cloudbees, Inc.", + "blog": "", + "location": "Seattle, WA, USA", + "email": "bitwiseman@gmail.com", + "hireable": null, + "bio": "https://twitter.com/bitwiseman", + "public_repos": 176, + "public_gists": 7, + "followers": 141, + "following": 9, + "created_at": "2012-07-11T20:38:33Z", + "updated_at": "2019-11-26T22:02:50Z", + "private_gists": 7, + "total_private_repos": 10, + "owned_private_repos": 0, + "disk_usage": 33697, + "collaborators": 0, + "two_factor_authentication": true, + "plan": { + "name": "free", + "space": 976562499, + "collaborators": 0, + "private_repos": 10000 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/orgs_github-api-test-org-3-183987.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/orgs_github-api-test-org-3-183987.json new file mode 100644 index 0000000000..43e0fedadb --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/orgs_github-api-test-org-3-183987.json @@ -0,0 +1,43 @@ +{ + "id": "1839874d-c184-4f20-942f-cc6d36806868", + "name": "orgs_github-api-test-org", + "request": { + "url": "/orgs/github-api-test-org", + "method": "GET" + }, + "response": { + "status": 200, + "bodyFileName": "orgs_github-api-test-org-1839874d-c184-4f20-942f-cc6d36806868.json", + "headers": { + "Date": "Tue, 26 Nov 2019 22:05:41 GMT", + "Content-Type": "application/json; charset=utf-8", + "Server": "GitHub.com", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4913", + "X-RateLimit-Reset": "1574809159", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding" + ], + "ETag": "W/\"21e3e165e412ba27b4bd9260ce4bcf70\"", + "Last-Modified": "Mon, 20 Apr 2015 00:42:30 GMT", + "X-OAuth-Scopes": "admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, write:discussion", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "F26C:3C0B:7D58F8:93D8C8:5DDDA1B4" + } + }, + "uuid": "1839874d-c184-4f20-942f-cc6d36806868", + "persistent": true, + "insertionIndex": 3 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/repos_github-api-test-org_rubywm-5-5b2f01.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/repos_github-api-test-org_rubywm-5-5b2f01.json new file mode 100644 index 0000000000..a975a853d0 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/repos_github-api-test-org_rubywm-5-5b2f01.json @@ -0,0 +1,43 @@ +{ + "id": "5b2f012d-aa23-4e59-849c-22b53a469c95", + "name": "repos_github-api-test-org_rubywm", + "request": { + "url": "/repos/github-api-test-org/rubywm", + "method": "GET" + }, + "response": { + "status": 200, + "bodyFileName": "repos_github-api-test-org_rubywm-5b2f012d-aa23-4e59-849c-22b53a469c95.json", + "headers": { + "Date": "Tue, 26 Nov 2019 22:05:42 GMT", + "Content-Type": "application/json; charset=utf-8", + "Server": "GitHub.com", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4911", + "X-RateLimit-Reset": "1574809159", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding" + ], + "ETag": "W/\"4b00cafaee1fc02361314a36cba325da\"", + "Last-Modified": "Tue, 13 Aug 2019 14:29:25 GMT", + "X-OAuth-Scopes": "admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, write:discussion", + "X-Accepted-OAuth-Scopes": "repo", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "F26C:3C0B:7D598F:93D986:5DDDA1B6" + } + }, + "uuid": "5b2f012d-aa23-4e59-849c-22b53a469c95", + "persistent": true, + "insertionIndex": 5 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/repos_kohsuke_rubywm-2-7f6b9e.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/repos_kohsuke_rubywm-2-7f6b9e.json new file mode 100644 index 0000000000..7cfe8f5677 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/repos_kohsuke_rubywm-2-7f6b9e.json @@ -0,0 +1,43 @@ +{ + "id": "7f6b9ed5-222f-4c89-95a7-e45ef24d78a7", + "name": "repos_kohsuke_rubywm", + "request": { + "url": "/repos/kohsuke/rubywm", + "method": "GET" + }, + "response": { + "status": 200, + "bodyFileName": "repos_kohsuke_rubywm-7f6b9ed5-222f-4c89-95a7-e45ef24d78a7.json", + "headers": { + "Date": "Tue, 26 Nov 2019 22:05:40 GMT", + "Content-Type": "application/json; charset=utf-8", + "Server": "GitHub.com", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4914", + "X-RateLimit-Reset": "1574809159", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding" + ], + "ETag": "W/\"956ce297c162ac69efaf4ba1328b1cdb\"", + "Last-Modified": "Tue, 13 Aug 2019 14:29:25 GMT", + "X-OAuth-Scopes": "admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, write:discussion", + "X-Accepted-OAuth-Scopes": "repo", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "F26C:3C0B:7D58DD:93D7F2:5DDDA1B3" + } + }, + "uuid": "7f6b9ed5-222f-4c89-95a7-e45ef24d78a7", + "persistent": true, + "insertionIndex": 2 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/repos_kohsuke_rubywm_forks-4-044af3.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/repos_kohsuke_rubywm_forks-4-044af3.json new file mode 100644 index 0000000000..242c23878c --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/repos_kohsuke_rubywm_forks-4-044af3.json @@ -0,0 +1,43 @@ +{ + "id": "044af303-143e-4469-be96-0a6e72032e5c", + "name": "repos_kohsuke_rubywm_forks", + "request": { + "url": "/repos/kohsuke/rubywm/forks", + "method": "POST", + "bodyPatterns": [ + { + "equalToJson": "{\"organization\":\"github-api-test-org\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ] + }, + "response": { + "status": 202, + "bodyFileName": "repos_kohsuke_rubywm_forks-044af303-143e-4469-be96-0a6e72032e5c.json", + "headers": { + "Date": "Tue, 26 Nov 2019 22:05:42 GMT", + "Content-Type": "application/json; charset=utf-8", + "Server": "GitHub.com", + "Status": "202 Accepted", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4912", + "X-RateLimit-Reset": "1574809159", + "X-OAuth-Scopes": "admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, write:discussion", + "X-Accepted-OAuth-Scopes": "", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "F26C:3C0B:7D5915:93D8F7:5DDDA1B5" + } + }, + "uuid": "044af303-143e-4469-be96-0a6e72032e5c", + "persistent": true, + "insertionIndex": 4 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/user-1-07a004.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/user-1-07a004.json new file mode 100644 index 0000000000..fd2c70467d --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testOrgFork/mappings/user-1-07a004.json @@ -0,0 +1,43 @@ +{ + "id": "07a0042d-8162-4e85-9ed4-0ed31ebc9d63", + "name": "user", + "request": { + "url": "/user", + "method": "GET" + }, + "response": { + "status": 200, + "bodyFileName": "user-07a0042d-8162-4e85-9ed4-0ed31ebc9d63.json", + "headers": { + "Date": "Tue, 26 Nov 2019 22:05:39 GMT", + "Content-Type": "application/json; charset=utf-8", + "Server": "GitHub.com", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4917", + "X-RateLimit-Reset": "1574809159", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding" + ], + "ETag": "W/\"072b29f799172fd1523e04ec9f30fc24\"", + "Last-Modified": "Tue, 26 Nov 2019 22:02:50 GMT", + "X-OAuth-Scopes": "admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, write:discussion", + "X-Accepted-OAuth-Scopes": "", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "F26C:3C0B:7D5829:93D7D9:5DDDA1B3" + } + }, + "uuid": "07a0042d-8162-4e85-9ed4-0ed31ebc9d63", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file From 0f9482864c56cdfc0abac8c4aa0c77895ff37b7a Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Tue, 26 Nov 2019 15:26:46 -0800 Subject: [PATCH 4/7] Move url to separate method --- src/main/java/org/kohsuke/github/GHApp.java | 12 +- .../github/GHAppCreateTokenBuilder.java | 3 +- .../org/kohsuke/github/GHAppInstallation.java | 6 +- src/main/java/org/kohsuke/github/GHAsset.java | 4 +- .../org/kohsuke/github/GHBlobBuilder.java | 2 +- .../java/org/kohsuke/github/GHBranch.java | 4 +- .../kohsuke/github/GHBranchProtection.java | 6 +- .../github/GHBranchProtectionBuilder.java | 3 +- .../java/org/kohsuke/github/GHCommit.java | 7 +- .../org/kohsuke/github/GHCommitBuilder.java | 2 +- .../org/kohsuke/github/GHCommitComment.java | 12 +- .../java/org/kohsuke/github/GHContent.java | 8 +- .../org/kohsuke/github/GHContentBuilder.java | 3 +- .../github/GHCreateRepositoryBuilder.java | 2 +- .../java/org/kohsuke/github/GHDeployKey.java | 3 +- .../kohsuke/github/GHDeploymentBuilder.java | 2 +- .../github/GHDeploymentStatusBuilder.java | 3 +- src/main/java/org/kohsuke/github/GHGist.java | 8 +- .../org/kohsuke/github/GHGistBuilder.java | 2 +- .../org/kohsuke/github/GHGistUpdater.java | 2 +- src/main/java/org/kohsuke/github/GHHook.java | 4 +- src/main/java/org/kohsuke/github/GHHooks.java | 10 +- .../java/org/kohsuke/github/GHInvitation.java | 4 +- src/main/java/org/kohsuke/github/GHIssue.java | 27 ++-- .../org/kohsuke/github/GHIssueBuilder.java | 3 +- .../org/kohsuke/github/GHIssueComment.java | 12 +- .../java/org/kohsuke/github/GHLicense.java | 2 +- .../java/org/kohsuke/github/GHMembership.java | 2 +- .../java/org/kohsuke/github/GHMilestone.java | 4 +- .../java/org/kohsuke/github/GHMyself.java | 13 +- .../kohsuke/github/GHNotificationStream.java | 2 +- .../org/kohsuke/github/GHOrganization.java | 20 +-- .../java/org/kohsuke/github/GHPerson.java | 4 +- .../java/org/kohsuke/github/GHProject.java | 19 ++- .../org/kohsuke/github/GHProjectCard.java | 18 ++- .../org/kohsuke/github/GHProjectColumn.java | 18 ++- .../org/kohsuke/github/GHPullRequest.java | 22 ++- .../kohsuke/github/GHPullRequestReview.java | 7 +- .../github/GHPullRequestReviewBuilder.java | 3 +- .../github/GHPullRequestReviewComment.java | 10 +- .../java/org/kohsuke/github/GHReaction.java | 2 +- src/main/java/org/kohsuke/github/GHRef.java | 5 +- .../java/org/kohsuke/github/GHRelease.java | 6 +- .../org/kohsuke/github/GHReleaseBuilder.java | 2 +- .../org/kohsuke/github/GHReleaseUpdater.java | 3 +- .../java/org/kohsuke/github/GHRepository.java | 130 ++++++++++-------- .../github/GHRepositoryStatistics.java | 2 +- .../org/kohsuke/github/GHSubscription.java | 2 +- src/main/java/org/kohsuke/github/GHTeam.java | 19 +-- .../java/org/kohsuke/github/GHThread.java | 7 +- .../org/kohsuke/github/GHTreeBuilder.java | 2 +- src/main/java/org/kohsuke/github/GHUser.java | 12 +- src/main/java/org/kohsuke/github/GitHub.java | 62 +++++---- .../java/org/kohsuke/github/Requester.java | 65 +-------- .../java/org/kohsuke/github/GitHubTest.java | 3 +- 55 files changed, 336 insertions(+), 284 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHApp.java b/src/main/java/org/kohsuke/github/GHApp.java index affdf9eca1..464263f32a 100644 --- a/src/main/java/org/kohsuke/github/GHApp.java +++ b/src/main/java/org/kohsuke/github/GHApp.java @@ -200,7 +200,8 @@ public PagedIterable listInstallations() { public GHAppInstallation getInstallationById(long id) throws IOException { return root.retrieve() .withPreview(MACHINE_MAN) - .to(String.format("/app/installations/%d", id), GHAppInstallation.class) + .withUrlPath(String.format("/app/installations/%d", id)) + .to(GHAppInstallation.class) .wrapUp(root); } @@ -222,7 +223,8 @@ public GHAppInstallation getInstallationById(long id) throws IOException { public GHAppInstallation getInstallationByOrganization(String name) throws IOException { return root.retrieve() .withPreview(MACHINE_MAN) - .to(String.format("/orgs/%s/installation", name), GHAppInstallation.class) + .withUrlPath(String.format("/orgs/%s/installation", name)) + .to(GHAppInstallation.class) .wrapUp(root); } @@ -246,7 +248,8 @@ public GHAppInstallation getInstallationByOrganization(String name) throws IOExc public GHAppInstallation getInstallationByRepository(String ownerName, String repositoryName) throws IOException { return root.retrieve() .withPreview(MACHINE_MAN) - .to(String.format("/repos/%s/%s/installation", ownerName, repositoryName), GHAppInstallation.class) + .withUrlPath(String.format("/repos/%s/%s/installation", ownerName, repositoryName)) + .to(GHAppInstallation.class) .wrapUp(root); } @@ -267,7 +270,8 @@ public GHAppInstallation getInstallationByRepository(String ownerName, String re public GHAppInstallation getInstallationByUser(String name) throws IOException { return root.retrieve() .withPreview(MACHINE_MAN) - .to(String.format("/users/%s/installation", name), GHAppInstallation.class) + .withUrlPath(String.format("/users/%s/installation", name)) + .to(GHAppInstallation.class) .wrapUp(root); } diff --git a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java index dcd25cea6c..f2b70088e3 100644 --- a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java +++ b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java @@ -57,7 +57,8 @@ public GHAppCreateTokenBuilder repositoryIds(List repositoryIds) { public GHAppInstallationToken create() throws IOException { return builder.method("POST") .withPreview(MACHINE_MAN) - .to(apiUrlTail, GHAppInstallationToken.class) + .withUrlPath(apiUrlTail) + .to(GHAppInstallationToken.class) .wrapUp(root); } diff --git a/src/main/java/org/kohsuke/github/GHAppInstallation.java b/src/main/java/org/kohsuke/github/GHAppInstallation.java index a9f2043c31..1869bbef57 100644 --- a/src/main/java/org/kohsuke/github/GHAppInstallation.java +++ b/src/main/java/org/kohsuke/github/GHAppInstallation.java @@ -271,7 +271,11 @@ GHAppInstallation wrapUp(GitHub root) { @Preview @Deprecated public void deleteInstallation() throws IOException { - root.retrieve().method("DELETE").withPreview(GAMBIT).to(String.format("/app/installations/%d", id)); + root.retrieve() + .method("DELETE") + .withPreview(GAMBIT) + .withUrlPath(String.format("/app/installations/%d", id)) + .to(); } /** diff --git a/src/main/java/org/kohsuke/github/GHAsset.java b/src/main/java/org/kohsuke/github/GHAsset.java index 757abe3da2..121dde349d 100644 --- a/src/main/java/org/kohsuke/github/GHAsset.java +++ b/src/main/java/org/kohsuke/github/GHAsset.java @@ -135,7 +135,7 @@ public String getBrowserDownloadUrl() { } private void edit(String key, Object value) throws IOException { - root.retrieve().method("POST").with(key, value).method("PATCH").to(getApiRoute()); + root.retrieve().method("POST").with(key, value).method("PATCH").withUrlPath(getApiRoute()).to(); } /** @@ -145,7 +145,7 @@ private void edit(String key, Object value) throws IOException { * the io exception */ public void delete() throws IOException { - root.retrieve().method("DELETE").to(getApiRoute()); + root.retrieve().method("DELETE").withUrlPath(getApiRoute()).to(); } private String getApiRoute() { diff --git a/src/main/java/org/kohsuke/github/GHBlobBuilder.java b/src/main/java/org/kohsuke/github/GHBlobBuilder.java index c59fae9436..5fb1708663 100644 --- a/src/main/java/org/kohsuke/github/GHBlobBuilder.java +++ b/src/main/java/org/kohsuke/github/GHBlobBuilder.java @@ -55,6 +55,6 @@ private String getApiTail() { * if the blob cannot be created. */ public GHBlob create() throws IOException { - return req.method("POST").to(getApiTail(), GHBlob.class); + return req.method("POST").withUrlPath(getApiTail()).to(GHBlob.class); } } diff --git a/src/main/java/org/kohsuke/github/GHBranch.java b/src/main/java/org/kohsuke/github/GHBranch.java index 8146162071..3622849302 100644 --- a/src/main/java/org/kohsuke/github/GHBranch.java +++ b/src/main/java/org/kohsuke/github/GHBranch.java @@ -101,7 +101,7 @@ public URL getProtectionUrl() { * the io exception */ public GHBranchProtection getProtection() throws IOException { - return root.retrieve().to(protection_url, GHBranchProtection.class).wrap(this); + return root.retrieve().withUrlPath(protection_url).to(GHBranchProtection.class).wrap(this); } /** @@ -120,7 +120,7 @@ public String getSHA1() { * if disabling protection fails */ public void disableProtection() throws IOException { - root.retrieve().method("DELETE").to(protection_url); + root.retrieve().method("DELETE").withUrlPath(protection_url).to(); } /** diff --git a/src/main/java/org/kohsuke/github/GHBranchProtection.java b/src/main/java/org/kohsuke/github/GHBranchProtection.java index cbfcc1c4f6..c0c4676bf9 100644 --- a/src/main/java/org/kohsuke/github/GHBranchProtection.java +++ b/src/main/java/org/kohsuke/github/GHBranchProtection.java @@ -44,7 +44,7 @@ public class GHBranchProtection { @Preview @Deprecated public void enabledSignedCommits() throws IOException { - requester().method("POST").to(url + REQUIRE_SIGNATURES_URI, RequiredSignatures.class); + requester().method("POST").withUrlPath(url + REQUIRE_SIGNATURES_URI).to(RequiredSignatures.class); } /** @@ -56,7 +56,7 @@ public void enabledSignedCommits() throws IOException { @Preview @Deprecated public void disableSignedCommits() throws IOException { - requester().method("DELETE").to(url + REQUIRE_SIGNATURES_URI); + requester().method("DELETE").withUrlPath(url + REQUIRE_SIGNATURES_URI).to(); } /** @@ -87,7 +87,7 @@ public RequiredReviews getRequiredReviews() { @Preview @Deprecated public boolean getRequiredSignatures() throws IOException { - return requester().method("GET").to(url + REQUIRE_SIGNATURES_URI, RequiredSignatures.class).enabled; + return requester().method("GET").withUrlPath(url + REQUIRE_SIGNATURES_URI).to(RequiredSignatures.class).enabled; } /** diff --git a/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java b/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java index cfa06dc7c3..13d4fb1a20 100644 --- a/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java +++ b/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java @@ -93,7 +93,8 @@ public GHBranchProtection enable() throws IOException { .withNullable("required_pull_request_reviews", prReviews) .withNullable("restrictions", restrictions) .withNullable("enforce_admins", enforceAdmins) - .to(branch.getProtectionUrl().toString(), GHBranchProtection.class) + .withUrlPath(branch.getProtectionUrl().toString()) + .to(GHBranchProtection.class) .wrap(branch); } diff --git a/src/main/java/org/kohsuke/github/GHCommit.java b/src/main/java/org/kohsuke/github/GHCommit.java index e36396c0a6..e5c9629ea8 100644 --- a/src/main/java/org/kohsuke/github/GHCommit.java +++ b/src/main/java/org/kohsuke/github/GHCommit.java @@ -472,8 +472,9 @@ public GHCommitComment createComment(String body, String path, Integer line, Int .with("path", path) .with("line", line) .with("position", position) - .to(String.format("/repos/%s/%s/commits/%s/comments", owner.getOwnerName(), owner.getName(), sha), - GHCommitComment.class); + .withUrlPath( + String.format("/repos/%s/%s/commits/%s/comments", owner.getOwnerName(), owner.getName(), sha)) + .to(GHCommitComment.class); return r.wrap(owner); } @@ -520,7 +521,7 @@ public GHCommitStatus getLastStatus() throws IOException { */ void populate() throws IOException { if (files == null && stats == null) - owner.root.retrieve().to(owner.getApiTailUrl("commits/" + sha), this); + owner.root.retrieve().withUrlPath(owner.getApiTailUrl("commits/" + sha)).to(this); } GHCommit wrapUp(GHRepository owner) { diff --git a/src/main/java/org/kohsuke/github/GHCommitBuilder.java b/src/main/java/org/kohsuke/github/GHCommitBuilder.java index c25fe0403d..0b51f0045f 100644 --- a/src/main/java/org/kohsuke/github/GHCommitBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCommitBuilder.java @@ -118,6 +118,6 @@ private String getApiTail() { */ public GHCommit create() throws IOException { req.with("parents", parents); - return req.method("POST").to(getApiTail(), GHCommit.class).wrapUp(repo); + return req.method("POST").withUrlPath(getApiTail()).to(GHCommit.class).wrapUp(repo); } } diff --git a/src/main/java/org/kohsuke/github/GHCommitComment.java b/src/main/java/org/kohsuke/github/GHCommitComment.java index 4e974a19a3..c7c5963277 100644 --- a/src/main/java/org/kohsuke/github/GHCommitComment.java +++ b/src/main/java/org/kohsuke/github/GHCommitComment.java @@ -113,7 +113,12 @@ public GHCommit getCommit() throws IOException { * the io exception */ public void update(String body) throws IOException { - owner.root.retrieve().method("POST").with("body", body).method("PATCH").to(getApiTail(), GHCommitComment.class); + owner.root.retrieve() + .method("POST") + .with("body", body) + .method("PATCH") + .withUrlPath(getApiTail()) + .to(GHCommitComment.class); this.body = body; } @@ -124,7 +129,8 @@ public GHReaction createReaction(ReactionContent content) throws IOException { .method("POST") .withPreview(SQUIRREL_GIRL) .with("content", content.getContent()) - .to(getApiTail() + "/reactions", GHReaction.class) + .withUrlPath(getApiTail() + "/reactions") + .to(GHReaction.class) .wrap(owner.root); } @@ -143,7 +149,7 @@ public PagedIterable listReactions() { * the io exception */ public void delete() throws IOException { - owner.root.retrieve().method("DELETE").to(getApiTail()); + owner.root.retrieve().method("DELETE").withUrlPath(getApiTail()).to(); } private String getApiTail() { diff --git a/src/main/java/org/kohsuke/github/GHContent.java b/src/main/java/org/kohsuke/github/GHContent.java index 983988077e..79d09a65ef 100644 --- a/src/main/java/org/kohsuke/github/GHContent.java +++ b/src/main/java/org/kohsuke/github/GHContent.java @@ -223,7 +223,7 @@ public boolean isDirectory() { * the io exception */ protected synchronized void populate() throws IOException { - root.retrieve().to(url, this); + root.retrieve().withUrlPath(url).to(this); } /** @@ -318,7 +318,8 @@ public GHContentUpdateResponse update(byte[] newContentBytes, String commitMessa requester.with("branch", branch); } - GHContentUpdateResponse response = requester.to(getApiRoute(repository, path), GHContentUpdateResponse.class); + GHContentUpdateResponse response = requester.withUrlPath(getApiRoute(repository, path)) + .to(GHContentUpdateResponse.class); response.getContent().wrap(repository); response.getCommit().wrapUp(repository); @@ -363,7 +364,8 @@ public GHContentUpdateResponse delete(String commitMessage, String branch) throw requester.with("branch", branch); } - GHContentUpdateResponse response = requester.to(getApiRoute(repository, path), GHContentUpdateResponse.class); + GHContentUpdateResponse response = requester.withUrlPath(getApiRoute(repository, path)) + .to(GHContentUpdateResponse.class); response.getCommit().wrapUp(repository); return response; diff --git a/src/main/java/org/kohsuke/github/GHContentBuilder.java b/src/main/java/org/kohsuke/github/GHContentBuilder.java index 9e0cf05950..39d95d9e96 100644 --- a/src/main/java/org/kohsuke/github/GHContentBuilder.java +++ b/src/main/java/org/kohsuke/github/GHContentBuilder.java @@ -108,7 +108,8 @@ public GHContentBuilder message(String commitMessage) { * the io exception */ public GHContentUpdateResponse commit() throws IOException { - GHContentUpdateResponse response = req.to(GHContent.getApiRoute(repo, path), GHContentUpdateResponse.class); + GHContentUpdateResponse response = req.withUrlPath(GHContent.getApiRoute(repo, path)) + .to(GHContentUpdateResponse.class); response.getContent().wrap(repo); response.getCommit().wrapUp(repo); diff --git a/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java b/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java index c1d22ec2d9..0c833d3a34 100644 --- a/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java @@ -196,7 +196,7 @@ public GHCreateRepositoryBuilder team(GHTeam team) { * if repsitory cannot be created */ public GHRepository create() throws IOException { - return builder.method("POST").to(apiUrlTail, GHRepository.class).wrap(root); + return builder.method("POST").withUrlPath(apiUrlTail).to(GHRepository.class).wrap(root); } } diff --git a/src/main/java/org/kohsuke/github/GHDeployKey.java b/src/main/java/org/kohsuke/github/GHDeployKey.java index 0835ba3178..30c425ac8f 100644 --- a/src/main/java/org/kohsuke/github/GHDeployKey.java +++ b/src/main/java/org/kohsuke/github/GHDeployKey.java @@ -84,6 +84,7 @@ public String toString() { public void delete() throws IOException { owner.root.retrieve() .method("DELETE") - .to(String.format("/repos/%s/%s/keys/%d", owner.getOwnerName(), owner.getName(), id)); + .withUrlPath(String.format("/repos/%s/%s/keys/%d", owner.getOwnerName(), owner.getName(), id)) + .to(); } } diff --git a/src/main/java/org/kohsuke/github/GHDeploymentBuilder.java b/src/main/java/org/kohsuke/github/GHDeploymentBuilder.java index 07031d7e6c..b1b411a441 100644 --- a/src/main/java/org/kohsuke/github/GHDeploymentBuilder.java +++ b/src/main/java/org/kohsuke/github/GHDeploymentBuilder.java @@ -127,6 +127,6 @@ public GHDeploymentBuilder description(String description) { * the io exception */ public GHDeployment create() throws IOException { - return builder.to(repo.getApiTailUrl("deployments"), GHDeployment.class).wrap(repo); + return builder.withUrlPath(repo.getApiTailUrl("deployments")).to(GHDeployment.class).wrap(repo); } } diff --git a/src/main/java/org/kohsuke/github/GHDeploymentStatusBuilder.java b/src/main/java/org/kohsuke/github/GHDeploymentStatusBuilder.java index d2f79c9609..e01ca41285 100644 --- a/src/main/java/org/kohsuke/github/GHDeploymentStatusBuilder.java +++ b/src/main/java/org/kohsuke/github/GHDeploymentStatusBuilder.java @@ -66,7 +66,8 @@ public GHDeploymentStatusBuilder targetUrl(String targetUrl) { * the io exception */ public GHDeploymentStatus create() throws IOException { - return builder.to(repo.getApiTailUrl("deployments/" + deploymentId + "/statuses"), GHDeploymentStatus.class) + return builder.withUrlPath(repo.getApiTailUrl("deployments/" + deploymentId + "/statuses")) + .to(GHDeploymentStatus.class) .wrap(repo); } } diff --git a/src/main/java/org/kohsuke/github/GHGist.java b/src/main/java/org/kohsuke/github/GHGist.java index b1cfc1d076..f0c59d3f56 100644 --- a/src/main/java/org/kohsuke/github/GHGist.java +++ b/src/main/java/org/kohsuke/github/GHGist.java @@ -182,7 +182,7 @@ String getApiTailUrl(String tail) { * the io exception */ public void star() throws IOException { - root.retrieve().method("PUT").to(getApiTailUrl("star")); + root.retrieve().method("PUT").withUrlPath(getApiTailUrl("star")).to(); } /** @@ -192,7 +192,7 @@ public void star() throws IOException { * the io exception */ public void unstar() throws IOException { - root.retrieve().method("DELETE").to(getApiTailUrl("star")); + root.retrieve().method("DELETE").withUrlPath(getApiTailUrl("star")).to(); } /** @@ -214,7 +214,7 @@ public boolean isStarred() throws IOException { * the io exception */ public GHGist fork() throws IOException { - return root.retrieve().method("POST").to(getApiTailUrl("forks"), GHGist.class).wrapUp(root); + return root.retrieve().method("POST").withUrlPath(getApiTailUrl("forks")).to(GHGist.class).wrapUp(root); } /** @@ -233,7 +233,7 @@ public PagedIterable listForks() { * the io exception */ public void delete() throws IOException { - root.retrieve().method("DELETE").to("/gists/" + id); + root.retrieve().method("DELETE").withUrlPath("/gists/" + id).to(); } /** diff --git a/src/main/java/org/kohsuke/github/GHGistBuilder.java b/src/main/java/org/kohsuke/github/GHGistBuilder.java index 5d7eaa6f39..c51cbf4b7d 100644 --- a/src/main/java/org/kohsuke/github/GHGistBuilder.java +++ b/src/main/java/org/kohsuke/github/GHGistBuilder.java @@ -73,6 +73,6 @@ public GHGistBuilder file(String fileName, String content) { */ public GHGist create() throws IOException { req.with("files", files); - return req.to("/gists", GHGist.class).wrapUp(root); + return req.withUrlPath("/gists").to(GHGist.class).wrapUp(root); } } diff --git a/src/main/java/org/kohsuke/github/GHGistUpdater.java b/src/main/java/org/kohsuke/github/GHGistUpdater.java index 3169da2607..94064b6a01 100644 --- a/src/main/java/org/kohsuke/github/GHGistUpdater.java +++ b/src/main/java/org/kohsuke/github/GHGistUpdater.java @@ -96,6 +96,6 @@ public GHGistUpdater description(String desc) { */ public GHGist update() throws IOException { builder.with("files", files); - return builder.method("PATCH").to(base.getApiTailUrl(""), GHGist.class).wrap(base.owner); + return builder.method("PATCH").withUrlPath(base.getApiTailUrl("")).to(GHGist.class).wrap(base.owner); } } diff --git a/src/main/java/org/kohsuke/github/GHHook.java b/src/main/java/org/kohsuke/github/GHHook.java index 5b93c238a3..c1cca7150f 100644 --- a/src/main/java/org/kohsuke/github/GHHook.java +++ b/src/main/java/org/kohsuke/github/GHHook.java @@ -74,7 +74,7 @@ public Map getConfig() { * @see Ping hook */ public void ping() throws IOException { - getRoot().retrieve().method("POST").to(getApiRoute() + "/pings"); + getRoot().retrieve().method("POST").withUrlPath(getApiRoute() + "/pings").to(); } /** @@ -84,7 +84,7 @@ public void ping() throws IOException { * the io exception */ public void delete() throws IOException { - getRoot().retrieve().method("DELETE").to(getApiRoute()); + getRoot().retrieve().method("DELETE").withUrlPath(getApiRoute()).to(); } /** diff --git a/src/main/java/org/kohsuke/github/GHHooks.java b/src/main/java/org/kohsuke/github/GHHooks.java index 006774e45f..f020b9c6b1 100644 --- a/src/main/java/org/kohsuke/github/GHHooks.java +++ b/src/main/java/org/kohsuke/github/GHHooks.java @@ -28,8 +28,9 @@ private Context(GitHub root) { */ public List getHooks() throws IOException { - GHHook[] hookArray = root.retrieve().to(collection(), collectionClass()); // jdk/eclipse bug requires this - // to be on separate line + GHHook[] hookArray = root.retrieve().withUrlPath(collection()).to(collectionClass()); // jdk/eclipse bug + // requires this + // to be on separate line List list = new ArrayList(Arrays.asList(hookArray)); for (GHHook h : list) wrap(h); @@ -46,7 +47,7 @@ public List getHooks() throws IOException { * the io exception */ public GHHook getHook(int id) throws IOException { - GHHook hook = root.retrieve().to(collection() + "/" + id, clazz()); + GHHook hook = root.retrieve().withUrlPath(collection() + "/" + id).to(clazz()); return wrap(hook); } @@ -80,7 +81,8 @@ public GHHook createHook(String name, Map config, Collection assignees) throws IOException { root.retrieve() .method("POST") .with(ASSIGNEES, getLogins(assignees)) - .to(getIssuesApiRoute() + "/assignees", this); + .withUrlPath(getIssuesApiRoute() + "/assignees") + .to(this); } /** @@ -517,7 +520,12 @@ public void setAssignees(GHUser... assignees) throws IOException { * the io exception */ public void setAssignees(Collection assignees) throws IOException { - root.retrieve().method("POST").with(ASSIGNEES, getLogins(assignees)).method("PATCH").to(getIssuesApiRoute()); + root.retrieve() + .method("POST") + .with(ASSIGNEES, getLogins(assignees)) + .method("PATCH") + .withUrlPath(getIssuesApiRoute()) + .to(); } /** @@ -545,7 +553,8 @@ public void removeAssignees(Collection assignees) throws IOException { .method("DELETE") .with(ASSIGNEES, getLogins(assignees)) .inBody() - .to(getIssuesApiRoute() + "/assignees", this); + .withUrlPath(getIssuesApiRoute() + "/assignees") + .to(this); } /** diff --git a/src/main/java/org/kohsuke/github/GHIssueBuilder.java b/src/main/java/org/kohsuke/github/GHIssueBuilder.java index cf65eee147..55be4d1703 100644 --- a/src/main/java/org/kohsuke/github/GHIssueBuilder.java +++ b/src/main/java/org/kohsuke/github/GHIssueBuilder.java @@ -95,7 +95,8 @@ public GHIssueBuilder label(String label) { public GHIssue create() throws IOException { return builder.with("labels", labels) .with("assignees", assignees) - .to(repo.getApiTailUrl("issues"), GHIssue.class) + .withUrlPath(repo.getApiTailUrl("issues")) + .to(GHIssue.class) .wrap(repo); } } diff --git a/src/main/java/org/kohsuke/github/GHIssueComment.java b/src/main/java/org/kohsuke/github/GHIssueComment.java index dba4fd889a..2328897f2d 100644 --- a/src/main/java/org/kohsuke/github/GHIssueComment.java +++ b/src/main/java/org/kohsuke/github/GHIssueComment.java @@ -108,7 +108,12 @@ public GHCommentAuthorAssociation getAuthorAssociation() { * the io exception */ public void update(String body) throws IOException { - owner.root.retrieve().method("POST").with("body", body).method("PATCH").to(getApiRoute(), GHIssueComment.class); + owner.root.retrieve() + .method("POST") + .with("body", body) + .method("PATCH") + .withUrlPath(getApiRoute()) + .to(GHIssueComment.class); this.body = body; } @@ -119,7 +124,7 @@ public void update(String body) throws IOException { * the io exception */ public void delete() throws IOException { - owner.root.retrieve().method("DELETE").to(getApiRoute()); + owner.root.retrieve().method("DELETE").withUrlPath(getApiRoute()).to(); } @Preview @@ -129,7 +134,8 @@ public GHReaction createReaction(ReactionContent content) throws IOException { .method("POST") .withPreview(SQUIRREL_GIRL) .with("content", content.getContent()) - .to(getApiRoute() + "/reactions", GHReaction.class) + .withUrlPath(getApiRoute() + "/reactions") + .to(GHReaction.class) .wrap(owner.root); } diff --git a/src/main/java/org/kohsuke/github/GHLicense.java b/src/main/java/org/kohsuke/github/GHLicense.java index e7c4cff56d..630a27546e 100644 --- a/src/main/java/org/kohsuke/github/GHLicense.java +++ b/src/main/java/org/kohsuke/github/GHLicense.java @@ -199,7 +199,7 @@ protected synchronized void populate() throws IOException { if (description != null) return; // already populated - root.retrieve().to(url, this); + root.retrieve().withUrlPath(url).to(this); } @Override diff --git a/src/main/java/org/kohsuke/github/GHMembership.java b/src/main/java/org/kohsuke/github/GHMembership.java index 666e229fa3..d69b94af09 100644 --- a/src/main/java/org/kohsuke/github/GHMembership.java +++ b/src/main/java/org/kohsuke/github/GHMembership.java @@ -72,7 +72,7 @@ public GHOrganization getOrganization() { * @see GHMyself#getMembership(GHOrganization) GHMyself#getMembership(GHOrganization) */ public void activate() throws IOException { - root.retrieve().method("PATCH").with("state", State.ACTIVE).to(url, this); + root.retrieve().method("PATCH").with("state", State.ACTIVE).withUrlPath(url).to(this); } GHMembership wrap(GitHub root) { diff --git a/src/main/java/org/kohsuke/github/GHMilestone.java b/src/main/java/org/kohsuke/github/GHMilestone.java index b52b1538af..222b73fe31 100644 --- a/src/main/java/org/kohsuke/github/GHMilestone.java +++ b/src/main/java/org/kohsuke/github/GHMilestone.java @@ -155,11 +155,11 @@ public void reopen() throws IOException { * the io exception */ public void delete() throws IOException { - root.retrieve().method("DELETE").to(getApiRoute()); + root.retrieve().method("DELETE").withUrlPath(getApiRoute()).to(); } private void edit(String key, Object value) throws IOException { - root.retrieve().method("POST").with(key, value).method("PATCH").to(getApiRoute()); + root.retrieve().method("POST").with(key, value).method("PATCH").withUrlPath(getApiRoute()).to(); } /** diff --git a/src/main/java/org/kohsuke/github/GHMyself.java b/src/main/java/org/kohsuke/github/GHMyself.java index e80ba1c592..5045cdf6b5 100644 --- a/src/main/java/org/kohsuke/github/GHMyself.java +++ b/src/main/java/org/kohsuke/github/GHMyself.java @@ -71,7 +71,7 @@ public List getEmails() throws IOException { * the io exception */ public List getEmails2() throws IOException { - GHEmail[] addresses = root.retrieve().toArray("/user/emails", GHEmail[].class); + GHEmail[] addresses = root.retrieve().withUrlPath("/user/emails").toArray(GHEmail[].class); return Collections.unmodifiableList(Arrays.asList(addresses)); } @@ -86,7 +86,8 @@ public List getEmails2() throws IOException { * the io exception */ public List getPublicKeys() throws IOException { - return Collections.unmodifiableList(Arrays.asList(root.retrieve().toArray("/user/keys", GHKey[].class))); + return Collections + .unmodifiableList(Arrays.asList(root.retrieve().withUrlPath("/user/keys").toArray(GHKey[].class))); } /** @@ -100,8 +101,8 @@ public List getPublicKeys() throws IOException { * the io exception */ public List getPublicVerifiedKeys() throws IOException { - return Collections.unmodifiableList( - Arrays.asList(root.retrieve().toArray("/users/" + getLogin() + "/keys", GHVerifiedKey[].class))); + return Collections.unmodifiableList(Arrays + .asList(root.retrieve().withUrlPath("/users/" + getLogin() + "/keys").toArray(GHVerifiedKey[].class))); } /** @@ -114,7 +115,7 @@ public List getPublicVerifiedKeys() throws IOException { public GHPersonSet getAllOrganizations() throws IOException { GHPersonSet orgs = new GHPersonSet(); Set names = new HashSet(); - for (GHOrganization o : root.retrieve().toArray("/user/orgs", GHOrganization[].class)) { + for (GHOrganization o : root.retrieve().withUrlPath("/user/orgs").toArray(GHOrganization[].class)) { if (names.add(o.getLogin())) // in case of rumoured duplicates in the data orgs.add(root.getOrganization(o.getLogin())); } @@ -223,7 +224,7 @@ public PagedIterable listOrgMemberships(final GHMembership.State s * the io exception */ public GHMembership getMembership(GHOrganization o) throws IOException { - return root.retrieve().to("/user/memberships/orgs/" + o.getLogin(), GHMembership.class).wrap(root); + return root.retrieve().withUrlPath("/user/memberships/orgs/" + o.getLogin()).to(GHMembership.class).wrap(root); } // public void addEmails(Collection emails) throws IOException { diff --git a/src/main/java/org/kohsuke/github/GHNotificationStream.java b/src/main/java/org/kohsuke/github/GHNotificationStream.java index 26d842aaa9..9209cdc52f 100644 --- a/src/main/java/org/kohsuke/github/GHNotificationStream.java +++ b/src/main/java/org/kohsuke/github/GHNotificationStream.java @@ -181,7 +181,7 @@ GHThread fetch() { req.setHeader("If-Modified-Since", lastModified); - threads = req.toArray(apiUrl, GHThread[].class); + threads = req.withUrlPath(apiUrl).toArray(GHThread[].class); if (threads == null) { threads = EMPTY_ARRAY; // if unmodified, we get empty array } else { diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java index a0ae6a3573..867cb6e942 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -186,7 +186,8 @@ public void add(GHUser user, Role role) throws IOException { root.retrieve() .method("PUT") .with("role", role.name().toLowerCase()) - .to("/orgs/" + login + "/memberships/" + user.getLogin()); + .withUrlPath("/orgs/" + login + "/memberships/" + user.getLogin()) + .to(); } /** @@ -198,7 +199,7 @@ public void add(GHUser user, Role role) throws IOException { */ public boolean hasMember(GHUser user) { try { - root.retrieve().to("/orgs/" + login + "/members/" + user.getLogin()); + root.retrieve().withUrlPath("/orgs/" + login + "/members/" + user.getLogin()).to(); return true; } catch (IOException ignore) { return false; @@ -215,7 +216,7 @@ public boolean hasMember(GHUser user) { * the io exception */ public void remove(GHUser user) throws IOException { - root.retrieve().method("DELETE").to("/orgs/" + login + "/members/" + user.getLogin()); + root.retrieve().method("DELETE").withUrlPath("/orgs/" + login + "/members/" + user.getLogin()).to(); } /** @@ -227,7 +228,7 @@ public void remove(GHUser user) throws IOException { */ public boolean hasPublicMember(GHUser user) { try { - root.retrieve().to("/orgs/" + login + "/public_members/" + user.getLogin()); + root.retrieve().withUrlPath("/orgs/" + login + "/public_members/" + user.getLogin()).to(); return true; } catch (IOException ignore) { return false; @@ -243,7 +244,7 @@ public boolean hasPublicMember(GHUser user) { * the io exception */ public void publicize(GHUser u) throws IOException { - root.retrieve().method("PUT").to("/orgs/" + login + "/public_members/" + u.getLogin()); + root.retrieve().method("PUT").withUrlPath("/orgs/" + login + "/public_members/" + u.getLogin()).to(); } /** @@ -314,7 +315,7 @@ private PagedIterable listMembers(final String suffix, final String filt * the io exception */ public void conceal(GHUser u) throws IOException { - root.retrieve().method("DELETE").to("/orgs/" + login + "/public_members/" + u.getLogin()); + root.retrieve().method("DELETE").withUrlPath("/orgs/" + login + "/public_members/" + u.getLogin()).to(); } /** @@ -361,7 +362,8 @@ public GHProject createProject(String name, String body) throws IOException { .withPreview(INERTIA) .with("name", name) .with("body", body) - .to(String.format("/orgs/%s/projects", login), GHProject.class) + .withUrlPath(String.format("/orgs/%s/projects", login)) + .to(GHProject.class) .wrap(root); } @@ -395,7 +397,7 @@ public GHTeam createTeam(String name, Permission p, Collection rep repo_names.add(login + "/" + r.getName()); } post.with("repo_names", repo_names); - return post.method("POST").to("/orgs/" + login + "/teams", GHTeam.class).wrapUp(this); + return post.method("POST").withUrlPath("/orgs/" + login + "/teams").to(GHTeam.class).wrapUp(this); } /** @@ -436,7 +438,7 @@ public GHTeam createTeam(String name, Collection repositories) thr repo_names.add(login + "/" + r.getName()); } post.with("repo_names", repo_names); - return post.method("POST").to("/orgs/" + login + "/teams", GHTeam.class).wrapUp(this); + return post.method("POST").withUrlPath("/orgs/" + login + "/teams").to(GHTeam.class).wrapUp(this); } /** diff --git a/src/main/java/org/kohsuke/github/GHPerson.java b/src/main/java/org/kohsuke/github/GHPerson.java index 9a99571f69..06e86c5ad5 100644 --- a/src/main/java/org/kohsuke/github/GHPerson.java +++ b/src/main/java/org/kohsuke/github/GHPerson.java @@ -47,7 +47,7 @@ protected synchronized void populate() throws IOException { if (root == null || root.isOffline()) { return; // cannot populate, will have to live with what we have } - root.retrieve().to(url, this); + root.retrieve().withUrlPath(url).to(this); } /** @@ -147,7 +147,7 @@ public void remove() { */ public GHRepository getRepository(String name) throws IOException { try { - return root.retrieve().to("/repos/" + login + '/' + name, GHRepository.class).wrap(root); + return root.retrieve().withUrlPath("/repos/" + login + '/' + name).to(GHRepository.class).wrap(root); } catch (FileNotFoundException e) { return null; } diff --git a/src/main/java/org/kohsuke/github/GHProject.java b/src/main/java/org/kohsuke/github/GHProject.java index baa5acd2f6..f10102f593 100644 --- a/src/main/java/org/kohsuke/github/GHProject.java +++ b/src/main/java/org/kohsuke/github/GHProject.java @@ -74,11 +74,11 @@ public GHObject getOwner() throws IOException { if (owner == null) { try { if (owner_url.contains("/orgs/")) { - owner = root.retrieve().to(getOwnerUrl().getPath(), GHOrganization.class).wrapUp(root); + owner = root.retrieve().withUrlPath(getOwnerUrl().getPath()).to(GHOrganization.class).wrapUp(root); } else if (owner_url.contains("/users/")) { - owner = root.retrieve().to(getOwnerUrl().getPath(), GHUser.class).wrapUp(root); + owner = root.retrieve().withUrlPath(getOwnerUrl().getPath()).to(GHUser.class).wrapUp(root); } else if (owner_url.contains("/repos/")) { - owner = root.retrieve().to(getOwnerUrl().getPath(), GHRepository.class).wrap(root); + owner = root.retrieve().withUrlPath(getOwnerUrl().getPath()).to(GHRepository.class).wrap(root); } } catch (FileNotFoundException e) { return null; @@ -176,7 +176,13 @@ public GHProject wrap(GitHub root) { } private void edit(String key, Object value) throws IOException { - root.retrieve().method("POST").withPreview(INERTIA).with(key, value).method("PATCH").to(getApiRoute()); + root.retrieve() + .method("POST") + .withPreview(INERTIA) + .with(key, value) + .method("PATCH") + .withUrlPath(getApiRoute()) + .to(); } /** @@ -270,7 +276,7 @@ public void setPublic(boolean isPublic) throws IOException { * the io exception */ public void delete() throws IOException { - root.retrieve().method("POST").withPreview(INERTIA).method("DELETE").to(getApiRoute()); + root.retrieve().method("POST").withPreview(INERTIA).method("DELETE").withUrlPath(getApiRoute()).to(); } /** @@ -303,7 +309,8 @@ public GHProjectColumn createColumn(String name) throws IOException { .method("POST") .withPreview(INERTIA) .with("name", name) - .to(String.format("/projects/%d/columns", id), GHProjectColumn.class) + .withUrlPath(String.format("/projects/%d/columns", id)) + .to(GHProjectColumn.class) .wrap(this); } } \ No newline at end of file diff --git a/src/main/java/org/kohsuke/github/GHProjectCard.java b/src/main/java/org/kohsuke/github/GHProjectCard.java index 8aa7405cfa..80746c43cb 100644 --- a/src/main/java/org/kohsuke/github/GHProjectCard.java +++ b/src/main/java/org/kohsuke/github/GHProjectCard.java @@ -72,7 +72,7 @@ public GitHub getRoot() { public GHProject getProject() throws IOException { if (project == null) { try { - project = root.retrieve().to(getProjectUrl().getPath(), GHProject.class).wrap(root); + project = root.retrieve().withUrlPath(getProjectUrl().getPath()).to(GHProject.class).wrap(root); } catch (FileNotFoundException e) { return null; } @@ -90,7 +90,7 @@ public GHProject getProject() throws IOException { public GHProjectColumn getColumn() throws IOException { if (column == null) { try { - column = root.retrieve().to(getColumnUrl().getPath(), GHProjectColumn.class).wrap(root); + column = root.retrieve().withUrlPath(getColumnUrl().getPath()).to(GHProjectColumn.class).wrap(root); } catch (FileNotFoundException e) { return null; } @@ -110,9 +110,9 @@ public GHIssue getContent() throws IOException { return null; try { if (content_url.contains("/pulls")) { - return root.retrieve().to(getContentUrl().getPath(), GHPullRequest.class).wrap(root); + return root.retrieve().withUrlPath(getContentUrl().getPath()).to(GHPullRequest.class).wrap(root); } else { - return root.retrieve().to(getContentUrl().getPath(), GHIssue.class).wrap(root); + return root.retrieve().withUrlPath(getContentUrl().getPath()).to(GHIssue.class).wrap(root); } } catch (FileNotFoundException e) { return null; @@ -198,7 +198,13 @@ public void setArchived(boolean archived) throws IOException { } private void edit(String key, Object value) throws IOException { - root.retrieve().method("POST").withPreview(INERTIA).with(key, value).method("PATCH").to(getApiRoute()); + root.retrieve() + .method("POST") + .withPreview(INERTIA) + .with(key, value) + .method("PATCH") + .withUrlPath(getApiRoute()) + .to(); } /** @@ -217,6 +223,6 @@ protected String getApiRoute() { * the io exception */ public void delete() throws IOException { - root.retrieve().method("POST").withPreview(INERTIA).method("DELETE").to(getApiRoute()); + root.retrieve().method("POST").withPreview(INERTIA).method("DELETE").withUrlPath(getApiRoute()).to(); } } diff --git a/src/main/java/org/kohsuke/github/GHProjectColumn.java b/src/main/java/org/kohsuke/github/GHProjectColumn.java index 0bbca4cd96..660b135760 100644 --- a/src/main/java/org/kohsuke/github/GHProjectColumn.java +++ b/src/main/java/org/kohsuke/github/GHProjectColumn.java @@ -67,7 +67,7 @@ public GitHub getRoot() { public GHProject getProject() throws IOException { if (project == null) { try { - project = root.retrieve().to(getProjectUrl().getPath(), GHProject.class).wrap(root); + project = root.retrieve().withUrlPath(getProjectUrl().getPath()).to(GHProject.class).wrap(root); } catch (FileNotFoundException e) { return null; } @@ -106,7 +106,13 @@ public void setName(String name) throws IOException { } private void edit(String key, Object value) throws IOException { - root.retrieve().method("POST").withPreview(INERTIA).with(key, value).method("PATCH").to(getApiRoute()); + root.retrieve() + .method("POST") + .withPreview(INERTIA) + .with(key, value) + .method("PATCH") + .withUrlPath(getApiRoute()) + .to(); } /** @@ -125,7 +131,7 @@ protected String getApiRoute() { * the io exception */ public void delete() throws IOException { - root.retrieve().method("POST").withPreview(INERTIA).method("DELETE").to(getApiRoute()); + root.retrieve().method("POST").withPreview(INERTIA).method("DELETE").withUrlPath(getApiRoute()).to(); } /** @@ -158,7 +164,8 @@ public GHProjectCard createCard(String note) throws IOException { .method("POST") .withPreview(INERTIA) .with("note", note) - .to(String.format("/projects/columns/%d/cards", id), GHProjectCard.class) + .withUrlPath(String.format("/projects/columns/%d/cards", id)) + .to(GHProjectCard.class) .wrap(this); } @@ -177,7 +184,8 @@ public GHProjectCard createCard(GHIssue issue) throws IOException { .withPreview(INERTIA) .with("content_type", issue instanceof GHPullRequest ? "PullRequest" : "Issue") .with("content_id", issue.getId()) - .to(String.format("/projects/columns/%d/cards", id), GHProjectCard.class) + .withUrlPath(String.format("/projects/columns/%d/cards", id)) + .to(GHProjectCard.class) .wrap(this); } } diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index c2763695ec..744a29921f 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -384,7 +384,7 @@ public void refresh() throws IOException { if (root.isOffline()) { return; // cannot populate, will have to live with what we have } - root.retrieve().withPreview(SHADOW_CAT).to(url, this).wrapUp(owner); + root.retrieve().withPreview(SHADOW_CAT).withUrlPath(url).to(this).wrapUp(owner); } /** @@ -511,7 +511,8 @@ public GHPullRequestReviewComment createReviewComment(String body, String sha, S .with("commit_id", sha) .with("path", path) .with("position", position) - .to(getApiRoute() + COMMENTS_ACTION, GHPullRequestReviewComment.class) + .withUrlPath(getApiRoute() + COMMENTS_ACTION) + .to(GHPullRequestReviewComment.class) .wrapUp(this); } @@ -524,7 +525,11 @@ public GHPullRequestReviewComment createReviewComment(String body, String sha, S * the io exception */ public void requestReviewers(List reviewers) throws IOException { - root.retrieve().method("POST").with("reviewers", getLogins(reviewers)).to(getApiRoute() + REQUEST_REVIEWERS); + root.retrieve() + .method("POST") + .with("reviewers", getLogins(reviewers)) + .withUrlPath(getApiRoute() + REQUEST_REVIEWERS) + .to(); } /** @@ -540,7 +545,11 @@ public void requestTeamReviewers(List teams) throws IOException { for (GHTeam team : teams) { teamReviewers.add(team.getSlug()); } - root.retrieve().method("POST").with("team_reviewers", teamReviewers).to(getApiRoute() + REQUEST_REVIEWERS); + root.retrieve() + .method("POST") + .with("team_reviewers", teamReviewers) + .withUrlPath(getApiRoute() + REQUEST_REVIEWERS) + .to(); } /** @@ -593,7 +602,8 @@ public void merge(String msg, String sha, MergeMethod method) throws IOException .with("commit_message", msg) .with("sha", sha) .with("merge_method", method) - .to(getApiRoute() + "/merge"); + .withUrlPath(getApiRoute() + "/merge") + .to(); } /** @@ -605,7 +615,7 @@ public enum MergeMethod { private void fetchIssue() throws IOException { if (!fetchedIssueDetails) { - root.retrieve().method("GET").to(getIssuesApiRoute(), this); + root.retrieve().method("GET").withUrlPath(getIssuesApiRoute()).to(this); fetchedIssueDetails = true; } } diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReview.java b/src/main/java/org/kohsuke/github/GHPullRequestReview.java index 75b257cf6c..4754b45336 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReview.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReview.java @@ -164,7 +164,8 @@ public void submit(String body, GHPullRequestReviewEvent event) throws IOExcepti .method("POST") .with("body", body) .with("event", event.action()) - .to(getApiRoute() + "/events", this); + .withUrlPath(getApiRoute() + "/events") + .to(this); this.body = body; this.state = event.toState(); } @@ -176,7 +177,7 @@ public void submit(String body, GHPullRequestReviewEvent event) throws IOExcepti * the io exception */ public void delete() throws IOException { - owner.root.retrieve().method("DELETE").to(getApiRoute()); + owner.root.retrieve().method("DELETE").withUrlPath(getApiRoute()).to(); } /** @@ -188,7 +189,7 @@ public void delete() throws IOException { * the io exception */ public void dismiss(String message) throws IOException { - owner.root.retrieve().method("PUT").with("message", message).to(getApiRoute() + "/dismissals"); + owner.root.retrieve().method("PUT").with("message", message).withUrlPath(getApiRoute() + "/dismissals").to(); state = GHPullRequestReviewState.DISMISSED; } diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java index be22a98620..df08aed0f9 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java @@ -91,7 +91,8 @@ public GHPullRequestReviewBuilder comment(String body, String path, int position public GHPullRequestReview create() throws IOException { return builder.method("POST") .with("comments", comments) - .to(pr.getApiRoute() + "/reviews", GHPullRequestReview.class) + .withUrlPath(pr.getApiRoute() + "/reviews") + .to(GHPullRequestReview.class) .wrapUp(pr); } diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java index 779c1952fc..5b2e2b1dcc 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java @@ -163,7 +163,7 @@ protected String getApiRoute() { * the io exception */ public void update(String body) throws IOException { - owner.root.retrieve().method("PATCH").with("body", body).to(getApiRoute(), this); + owner.root.retrieve().method("PATCH").with("body", body).withUrlPath(getApiRoute()).to(this); this.body = body; } @@ -174,7 +174,7 @@ public void update(String body) throws IOException { * the io exception */ public void delete() throws IOException { - owner.root.retrieve().method("DELETE").to(getApiRoute()); + owner.root.retrieve().method("DELETE").withUrlPath(getApiRoute()).to(); } /** @@ -191,7 +191,8 @@ public GHPullRequestReviewComment reply(String body) throws IOException { .method("POST") .with("body", body) .with("in_reply_to", getId()) - .to(getApiRoute() + "/comments", GHPullRequestReviewComment.class) + .withUrlPath(getApiRoute() + "/comments") + .to(GHPullRequestReviewComment.class) .wrapUp(owner); } @@ -202,7 +203,8 @@ public GHReaction createReaction(ReactionContent content) throws IOException { .method("POST") .withPreview(SQUIRREL_GIRL) .with("content", content.getContent()) - .to(getApiRoute() + "/reactions", GHReaction.class) + .withUrlPath(getApiRoute() + "/reactions") + .to(GHReaction.class) .wrap(owner.root); } diff --git a/src/main/java/org/kohsuke/github/GHReaction.java b/src/main/java/org/kohsuke/github/GHReaction.java index 8400cd7b32..158a289b41 100644 --- a/src/main/java/org/kohsuke/github/GHReaction.java +++ b/src/main/java/org/kohsuke/github/GHReaction.java @@ -58,6 +58,6 @@ public URL getHtmlUrl() { * the io exception */ public void delete() throws IOException { - root.retrieve().method("DELETE").withPreview(SQUIRREL_GIRL).to("/reactions/" + id); + root.retrieve().method("DELETE").withPreview(SQUIRREL_GIRL).withUrlPath("/reactions/" + id).to(); } } diff --git a/src/main/java/org/kohsuke/github/GHRef.java b/src/main/java/org/kohsuke/github/GHRef.java index 3a086a162a..1022d86714 100644 --- a/src/main/java/org/kohsuke/github/GHRef.java +++ b/src/main/java/org/kohsuke/github/GHRef.java @@ -71,7 +71,8 @@ public void updateTo(String sha, Boolean force) throws IOException { .with("sha", sha) .with("force", force) .method("PATCH") - .to(url, GHRef.class) + .withUrlPath(url) + .to(GHRef.class) .wrap(root); } @@ -82,7 +83,7 @@ public void updateTo(String sha, Boolean force) throws IOException { * the io exception */ public void delete() throws IOException { - root.retrieve().method("DELETE").to(url); + root.retrieve().method("DELETE").withUrlPath(url).to(); } GHRef wrap(GitHub root) { diff --git a/src/main/java/org/kohsuke/github/GHRelease.java b/src/main/java/org/kohsuke/github/GHRelease.java index fbe2851a70..b742d6bf58 100644 --- a/src/main/java/org/kohsuke/github/GHRelease.java +++ b/src/main/java/org/kohsuke/github/GHRelease.java @@ -245,7 +245,7 @@ public GHAsset uploadAsset(String filename, InputStream stream, String contentTy // strip the helpful garbage from the url url = url.substring(0, url.indexOf('{')); url += "?name=" + URLEncoder.encode(filename, "UTF-8"); - return builder.contentType(contentType).with(stream).to(url, GHAsset.class).wrap(this); + return builder.contentType(contentType).with(stream).withUrlPath(url).to(GHAsset.class).wrap(this); } /** @@ -258,7 +258,7 @@ public GHAsset uploadAsset(String filename, InputStream stream, String contentTy public List getAssets() throws IOException { Requester builder = owner.root.retrieve().method("POST"); - GHAsset[] assets = builder.method("GET").toArray(getApiTailUrl("assets"), GHAsset[].class); + GHAsset[] assets = builder.method("GET").withUrlPath(getApiTailUrl("assets")).toArray(GHAsset[].class); return Arrays.asList(GHAsset.wrap(assets, this)); } @@ -269,7 +269,7 @@ public List getAssets() throws IOException { * the io exception */ public void delete() throws IOException { - root.retrieve().method("DELETE").to(owner.getApiTailUrl("releases/" + id)); + root.retrieve().method("DELETE").withUrlPath(owner.getApiTailUrl("releases/" + id)).to(); } /** diff --git a/src/main/java/org/kohsuke/github/GHReleaseBuilder.java b/src/main/java/org/kohsuke/github/GHReleaseBuilder.java index 2c23ecb879..1333cccd37 100644 --- a/src/main/java/org/kohsuke/github/GHReleaseBuilder.java +++ b/src/main/java/org/kohsuke/github/GHReleaseBuilder.java @@ -95,6 +95,6 @@ public GHReleaseBuilder prerelease(boolean prerelease) { * the io exception */ public GHRelease create() throws IOException { - return builder.to(repo.getApiTailUrl("releases"), GHRelease.class).wrap(repo); + return builder.withUrlPath(repo.getApiTailUrl("releases")).to(GHRelease.class).wrap(repo); } } diff --git a/src/main/java/org/kohsuke/github/GHReleaseUpdater.java b/src/main/java/org/kohsuke/github/GHReleaseUpdater.java index fc436bdd6e..e659b80a25 100644 --- a/src/main/java/org/kohsuke/github/GHReleaseUpdater.java +++ b/src/main/java/org/kohsuke/github/GHReleaseUpdater.java @@ -100,7 +100,8 @@ public GHReleaseUpdater prerelease(boolean prerelease) { */ public GHRelease update() throws IOException { return builder.method("PATCH") - .to(base.owner.getApiTailUrl("releases/" + base.id), GHRelease.class) + .withUrlPath(base.owner.getApiTailUrl("releases/" + base.id)) + .to(GHRelease.class) .wrap(base.owner); } diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index eab1b3c18f..d50ce194e1 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -154,7 +154,7 @@ public PagedIterable listDeployments(String sha, String ref, Strin * the io exception */ public GHDeployment getDeployment(long id) throws IOException { - return root.retrieve().to(getApiTailUrl("deployments/" + id), GHDeployment.class).wrap(this); + return root.retrieve().withUrlPath(getApiTailUrl("deployments/" + id)).to(GHDeployment.class).wrap(this); } /** @@ -332,7 +332,7 @@ public GHUser getOwner() throws IOException { * the io exception */ public GHIssue getIssue(int id) throws IOException { - return root.retrieve().to(getApiTailUrl("issues/" + id), GHIssue.class).wrap(this); + return root.retrieve().withUrlPath(getApiTailUrl("issues/" + id)).to(GHIssue.class).wrap(this); } /** @@ -371,10 +371,11 @@ public List getIssues(GHIssueState state) throws IOException { * the io exception */ public List getIssues(GHIssueState state, GHMilestone milestone) throws IOException { - return Arrays.asList(GHIssue.wrap(root.retrieve() + Requester requester = root.retrieve() .with("state", state) - .with("milestone", milestone == null ? "none" : "" + milestone.getNumber()) - .toArray(getApiTailUrl("issues"), GHIssue[].class), this)); + .with("milestone", milestone == null ? "none" : "" + milestone.getNumber()); + return Arrays + .asList(GHIssue.wrap(requester.withUrlPath(getApiTailUrl("issues")).toArray(GHIssue[].class), this)); } /** @@ -419,7 +420,8 @@ public GHRef createRef(String name, String sha) throws IOException { .with("ref", name) .with("sha", sha) .method("POST") - .to(getApiTailUrl("git/refs"), GHRef.class) + .withUrlPath(getApiTailUrl("git/refs")) + .to(GHRef.class) .wrap(root); } @@ -446,7 +448,7 @@ public List getReleases() throws IOException { */ public GHRelease getRelease(long id) throws IOException { try { - return root.retrieve().to(getApiTailUrl("releases/" + id), GHRelease.class).wrap(this); + return root.retrieve().withUrlPath(getApiTailUrl("releases/" + id)).to(GHRelease.class).wrap(this); } catch (FileNotFoundException e) { return null; // no release for this id } @@ -463,7 +465,7 @@ public GHRelease getRelease(long id) throws IOException { */ public GHRelease getReleaseByTagName(String tag) throws IOException { try { - return root.retrieve().to(getApiTailUrl("releases/tags/" + tag), GHRelease.class).wrap(this); + return root.retrieve().withUrlPath(getApiTailUrl("releases/tags/" + tag)).to(GHRelease.class).wrap(this); } catch (FileNotFoundException e) { return null; // no release for this tag } @@ -478,7 +480,7 @@ public GHRelease getReleaseByTagName(String tag) throws IOException { */ public GHRelease getLatestRelease() throws IOException { try { - return root.retrieve().to(getApiTailUrl("releases/latest"), GHRelease.class).wrap(this); + return root.retrieve().withUrlPath(getApiTailUrl("releases/latest")).to(GHRelease.class).wrap(this); } catch (FileNotFoundException e) { return null; // no latest release } @@ -517,7 +519,7 @@ public PagedIterable listTags() throws IOException { * the io exception */ public Map listLanguages() throws IOException { - return root.retrieve().to(getApiTailUrl("languages"), HashMap.class); + return root.retrieve().withUrlPath(getApiTailUrl("languages")).to(HashMap.class); } /** @@ -775,7 +777,8 @@ public boolean hasAssignee(GHUser u) throws IOException { */ public Set getCollaboratorNames() throws IOException { Set r = new HashSet(); - for (GHUser u : GHUser.wrap(root.retrieve().toArray(getApiTailUrl("collaborators"), GHUser[].class), root)) + for (GHUser u : GHUser.wrap(root.retrieve().withUrlPath(getApiTailUrl("collaborators")).toArray(GHUser[].class), + root)) r.add(u.login); return r; } @@ -791,7 +794,8 @@ public Set getCollaboratorNames() throws IOException { */ public GHPermissionType getPermission(String user) throws IOException { GHPermission perm = root.retrieve() - .to(getApiTailUrl("collaborators/" + user + "/permission"), GHPermission.class); + .withUrlPath(getApiTailUrl("collaborators/" + user + "/permission")) + .to(GHPermission.class); perm.wrapUp(root); return perm.getPermissionType(); } @@ -818,7 +822,7 @@ public GHPermissionType getPermission(GHUser u) throws IOException { */ public Set getTeams() throws IOException { return Collections.unmodifiableSet(new HashSet( - Arrays.asList(GHTeam.wrapUp(root.retrieve().toArray(getApiTailUrl("teams"), GHTeam[].class), + Arrays.asList(GHTeam.wrapUp(root.retrieve().withUrlPath(getApiTailUrl("teams")).toArray(GHTeam[].class), root.getOrganization(getOwnerName()))))); } @@ -872,7 +876,7 @@ public void removeCollaborators(Collection users) throws IOException { private void modifyCollaborators(Collection users, String method) throws IOException { for (GHUser user : users) { - root.retrieve().method(method).to(getApiTailUrl("collaborators/" + user.getLogin())); + root.retrieve().method(method).withUrlPath(getApiTailUrl("collaborators/" + user.getLogin())).to(); } } @@ -892,14 +896,15 @@ public void setEmailServiceHook(String address) throws IOException { .with("name", "email") .with("config", config) .with("active", true) - .to(getApiTailUrl("hooks")); + .withUrlPath(getApiTailUrl("hooks")) + .to(); } private void edit(String key, String value) throws IOException { Requester requester = root.retrieve().method("POST"); if (!key.equals("name")) requester.with("name", name); // even when we don't change the name, we need to send it in - requester.with(key, value).method("PATCH").to(getApiTailUrl("")); + requester.with(key, value).method("PATCH").withUrlPath(getApiTailUrl("")).to(); } /** @@ -1042,7 +1047,7 @@ public void allowRebaseMerge(boolean value) throws IOException { */ public void delete() throws IOException { try { - root.retrieve().method("DELETE").to(getApiTailUrl("")); + root.retrieve().method("DELETE").withUrlPath(getApiTailUrl("")).to(); } catch (FileNotFoundException x) { throw (FileNotFoundException) new FileNotFoundException("Failed to delete " + getOwnerName() + "/" + name + "; might not exist, or you might need the delete_repo scope in your token: http://stackoverflow.com/a/19327004/12916") @@ -1113,7 +1118,7 @@ public PagedIterable listForks(final ForkSort sort) { * the io exception */ public GHRepository fork() throws IOException { - root.retrieve().method("POST").to(getApiTailUrl("forks")); + root.retrieve().method("POST").withUrlPath(getApiTailUrl("forks")).to(); // this API is asynchronous. we need to wait for a bit for (int i = 0; i < 10; i++) { @@ -1139,7 +1144,7 @@ public GHRepository fork() throws IOException { * the io exception */ public GHRepository forkTo(GHOrganization org) throws IOException { - root.retrieve().method("POST").with("organization", org.getLogin()).to(getApiTailUrl("forks")); + root.retrieve().method("POST").with("organization", org.getLogin()).withUrlPath(getApiTailUrl("forks")).to(); // this API is asynchronous. we need to wait for a bit for (int i = 0; i < 10; i++) { @@ -1167,7 +1172,8 @@ public GHRepository forkTo(GHOrganization org) throws IOException { public GHPullRequest getPullRequest(int i) throws IOException { return root.retrieve() .withPreview(SHADOW_CAT) - .to(getApiTailUrl("pulls/" + i), GHPullRequest.class) + .withUrlPath(getApiTailUrl("pulls/" + i)) + .to(GHPullRequest.class) .wrapUp(this); } @@ -1290,7 +1296,8 @@ public GHPullRequest createPullRequest(String title, .with("body", body) .with("maintainer_can_modify", maintainerCanModify) .with("draft", draft) - .to(getApiTailUrl("pulls"), GHPullRequest.class) + .withUrlPath(getApiTailUrl("pulls")) + .to(GHPullRequest.class) .wrapUp(this); } @@ -1333,7 +1340,8 @@ public GHHook getHook(int id) throws IOException { */ public GHCompare getCompare(String id1, String id2) throws IOException { GHCompare compare = root.retrieve() - .to(getApiTailUrl(String.format("compare/%s...%s", id1, id2)), GHCompare.class); + .withUrlPath(getApiTailUrl(String.format("compare/%s...%s", id1, id2))) + .to(GHCompare.class); return compare.wrap(this); } @@ -1391,9 +1399,9 @@ public GHCompare getCompare(GHBranch id1, GHBranch id2) throws IOException { * on failure communicating with GitHub */ public GHRef[] getRefs() throws IOException { - return GHRef.wrap( - root.retrieve().toArray(String.format("/repos/%s/%s/git/refs", getOwnerName(), name), GHRef[].class), - root); + return GHRef.wrap(root.retrieve() + .withUrlPath(String.format("/repos/%s/%s/git/refs", getOwnerName(), name)) + .toArray(GHRef[].class), root); } /** @@ -1419,8 +1427,8 @@ public PagedIterable listRefs() throws IOException { */ public GHRef[] getRefs(String refType) throws IOException { return GHRef.wrap(root.retrieve() - .toArray(String.format("/repos/%s/%s/git/refs/%s", getOwnerName(), name, refType), GHRef[].class), - root); + .withUrlPath(String.format("/repos/%s/%s/git/refs/%s", getOwnerName(), name, refType)) + .toArray(GHRef[].class), root); } /** @@ -1447,7 +1455,10 @@ public PagedIterable listRefs(String refType) throws IOException { * on failure communicating with GitHub, potentially due to an invalid ref type being requested */ public GHRef getRef(String refName) throws IOException { - return root.retrieve().to(getApiTailUrl(String.format("git/refs/%s", refName)), GHRef.class).wrap(root); + return root.retrieve() + .withUrlPath(getApiTailUrl(String.format("git/refs/%s", refName))) + .to(GHRef.class) + .wrap(root); } /** @@ -1461,7 +1472,7 @@ public GHRef getRef(String refName) throws IOException { * the io exception */ public GHTagObject getTagObject(String sha) throws IOException { - return root.retrieve().to(getApiTailUrl("git/tags/" + sha), GHTagObject.class).wrap(this); + return root.retrieve().withUrlPath(getApiTailUrl("git/tags/" + sha)).to(GHTagObject.class).wrap(this); } /** @@ -1475,7 +1486,7 @@ public GHTagObject getTagObject(String sha) throws IOException { */ public GHTree getTree(String sha) throws IOException { String url = String.format("/repos/%s/%s/git/trees/%s", getOwnerName(), name, sha); - return root.retrieve().to(url, GHTree.class).wrap(this); + return root.retrieve().withUrlPath(url).to(GHTree.class).wrap(this); } /** @@ -1501,7 +1512,7 @@ public GHTreeBuilder createTree() { */ public GHTree getTreeRecursive(String sha, int recursive) throws IOException { String url = String.format("/repos/%s/%s/git/trees/%s", getOwnerName(), name, sha); - return root.retrieve().with("recursive", recursive).to(url, GHTree.class).wrap(this); + return root.retrieve().with("recursive", recursive).withUrlPath(url).to(GHTree.class).wrap(this); } /** @@ -1520,7 +1531,7 @@ public GHTree getTreeRecursive(String sha, int recursive) throws IOException { */ public GHBlob getBlob(String blobSha) throws IOException { String target = getApiTailUrl("git/blobs/" + blobSha); - return root.retrieve().to(target, GHBlob.class); + return root.retrieve().withUrlPath(target).to(GHBlob.class); } /** @@ -1561,7 +1572,8 @@ public GHCommit getCommit(String sha1) throws IOException { GHCommit c = commits.get(sha1); if (c == null) { c = root.retrieve() - .to(String.format("/repos/%s/%s/commits/%s", getOwnerName(), name, sha1), GHCommit.class) + .withUrlPath(String.format("/repos/%s/%s/commits/%s", getOwnerName(), name, sha1)) + .to(GHCommit.class) .wrapUp(this); commits.put(sha1, c); } @@ -1637,7 +1649,7 @@ public GHContent getLicenseContent() throws IOException { private GHContentWithLicense getLicenseContent_() throws IOException { try { - return root.retrieve().to(getApiTailUrl("license"), GHContentWithLicense.class).wrap(this); + return root.retrieve().withUrlPath(getApiTailUrl("license")).to(GHContentWithLicense.class).wrap(this); } catch (FileNotFoundException e) { return null; } @@ -1701,7 +1713,8 @@ public GHCommitStatus createCommitStatus(String sha1, .with("target_url", targetUrl) .with("description", description) .with("context", context) - .to(String.format("/repos/%s/%s/statuses/%s", getOwnerName(), this.name, sha1), GHCommitStatus.class) + .withUrlPath(String.format("/repos/%s/%s/statuses/%s", getOwnerName(), this.name, sha1)) + .to(GHCommitStatus.class) .wrapUp(root); } @@ -1766,7 +1779,11 @@ public PagedIterable listLabels() throws IOException { * the io exception */ public GHLabel getLabel(String name) throws IOException { - return root.retrieve().withPreview(SYMMETRA).to(getApiTailUrl("labels/" + name), GHLabel.class).wrapUp(this); + return root.retrieve() + .withPreview(SYMMETRA) + .withUrlPath(getApiTailUrl("labels/" + name)) + .to(GHLabel.class) + .wrapUp(this); } /** @@ -1806,7 +1823,8 @@ public GHLabel createLabel(String name, String color, String description) throws .with("name", name) .with("color", color) .with("description", description) - .to(getApiTailUrl("labels"), GHLabel.class) + .withUrlPath(getApiTailUrl("labels")) + .to(GHLabel.class) .wrapUp(this); } @@ -2006,7 +2024,7 @@ GHRepository wrap(GitHub root) { */ public Map getBranches() throws IOException { Map r = new TreeMap(); - for (GHBranch p : root.retrieve().toArray(getApiTailUrl("branches"), GHBranch[].class)) { + for (GHBranch p : root.retrieve().withUrlPath(getApiTailUrl("branches")).toArray(GHBranch[].class)) { p.wrap(this); r.put(p.getName(), p); } @@ -2023,7 +2041,7 @@ public Map getBranches() throws IOException { * the io exception */ public GHBranch getBranch(String name) throws IOException { - return root.retrieve().to(getApiTailUrl("branches/" + name), GHBranch.class).wrap(this); + return root.retrieve().withUrlPath(getApiTailUrl("branches/" + name)).to(GHBranch.class).wrap(this); } /** @@ -2069,7 +2087,7 @@ public PagedIterable listMilestones(final GHIssueState state) { public GHMilestone getMilestone(int number) throws IOException { GHMilestone m = milestones.get(number); if (m == null) { - m = root.retrieve().to(getApiTailUrl("milestones/" + number), GHMilestone.class); + m = root.retrieve().withUrlPath(getApiTailUrl("milestones/" + number)).to(GHMilestone.class); m.owner = this; m.root = root; milestones.put(m.getNumber(), m); @@ -2105,7 +2123,7 @@ public GHContent getFileContent(String path, String ref) throws IOException { Requester requester = root.retrieve(); String target = getApiTailUrl("contents/" + path); - return requester.with("ref", ref).to(target, GHContent.class).wrap(this); + return requester.with("ref", ref).withUrlPath(target).to(GHContent.class).wrap(this); } /** @@ -2139,7 +2157,7 @@ public List getDirectoryContent(String path, String ref) throws IOExc } String target = getApiTailUrl("contents/" + path); - GHContent[] files = requester.with("ref", ref).toArray(target, GHContent[].class); + GHContent[] files = requester.with("ref", ref).withUrlPath(target).toArray(GHContent[].class); GHContent.wrap(files, this); @@ -2155,7 +2173,7 @@ public List getDirectoryContent(String path, String ref) throws IOExc */ public GHContent getReadme() throws IOException { Requester requester = root.retrieve(); - return requester.to(getApiTailUrl("readme"), GHContent.class).wrap(this); + return requester.withUrlPath(getApiTailUrl("readme")).to(GHContent.class).wrap(this); } /** @@ -2263,7 +2281,8 @@ public GHMilestone createMilestone(String title, String description) throws IOEx .with("title", title) .with("description", description) .method("POST") - .to(getApiTailUrl("milestones"), GHMilestone.class) + .withUrlPath(getApiTailUrl("milestones")) + .to(GHMilestone.class) .wrap(this); } @@ -2284,7 +2303,8 @@ public GHDeployKey addDeployKey(String title, String key) throws IOException { .with("title", title) .with("key", key) .method("POST") - .to(getApiTailUrl("keys"), GHDeployKey.class) + .withUrlPath(getApiTailUrl("keys")) + .to(GHDeployKey.class) .wrap(this); } @@ -2298,7 +2318,7 @@ public GHDeployKey addDeployKey(String title, String key) throws IOException { */ public List getDeployKeys() throws IOException { List list = new ArrayList( - Arrays.asList(root.retrieve().toArray(getApiTailUrl("keys"), GHDeployKey[].class))); + Arrays.asList(root.retrieve().withUrlPath(getApiTailUrl("keys")).toArray(GHDeployKey[].class))); for (GHDeployKey h : list) h.wrap(this); return list; @@ -2356,7 +2376,8 @@ public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOEx .with("subscribed", subscribed) .with("ignored", ignored) .method("PUT") - .to(getApiTailUrl("subscription"), GHSubscription.class) + .withUrlPath(getApiTailUrl("subscription")) + .to(GHSubscription.class) .wrapUp(this); } @@ -2369,7 +2390,7 @@ public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOEx */ public GHSubscription getSubscription() throws IOException { try { - return root.retrieve().to(getApiTailUrl("subscription"), GHSubscription.class).wrapUp(this); + return root.retrieve().withUrlPath(getApiTailUrl("subscription")).to(GHSubscription.class).wrapUp(this); } catch (FileNotFoundException e) { return null; } @@ -2443,7 +2464,8 @@ public GHProject createProject(String name, String body) throws IOException { .withPreview(INERTIA) .with("name", name) .with("body", body) - .to(getApiTailUrl("projects"), GHProject.class) + .withUrlPath(getApiTailUrl("projects")) + .to(GHProject.class) .wrap(this); } @@ -2517,7 +2539,7 @@ public GHNotificationStream listNotifications() { * the io exception */ public GHRepositoryViewTraffic getViewTraffic() throws IOException { - return root.retrieve().to(getApiTailUrl("/traffic/views"), GHRepositoryViewTraffic.class); + return root.retrieve().withUrlPath(getApiTailUrl("/traffic/views")).to(GHRepositoryViewTraffic.class); } /** @@ -2529,7 +2551,7 @@ public GHRepositoryViewTraffic getViewTraffic() throws IOException { * the io exception */ public GHRepositoryCloneTraffic getCloneTraffic() throws IOException { - return root.retrieve().to(getApiTailUrl("/traffic/clones"), GHRepositoryCloneTraffic.class); + return root.retrieve().withUrlPath(getApiTailUrl("/traffic/clones")).to(GHRepositoryCloneTraffic.class); } @Override @@ -2575,7 +2597,7 @@ public PagedIterable listIssueEvents() throws IOException { * the io exception */ public GHIssueEvent getIssueEvent(long id) throws IOException { - return root.retrieve().to(getApiTailUrl("issues/events/" + id), GHIssueEvent.class).wrapUp(root); + return root.retrieve().withUrlPath(getApiTailUrl("issues/events/" + id)).to(GHIssueEvent.class).wrapUp(root); } // Only used within listTopics(). @@ -2592,7 +2614,7 @@ private static class Topics { * the io exception */ public List listTopics() throws IOException { - Topics topics = root.retrieve().withPreview(MERCY).to(getApiTailUrl("topics"), Topics.class); + Topics topics = root.retrieve().withPreview(MERCY).withUrlPath(getApiTailUrl("topics")).to(Topics.class); return topics.names; } @@ -2608,6 +2630,6 @@ public List listTopics() throws IOException { public void setTopics(List topics) throws IOException { Requester requester = root.retrieve().method("POST"); requester.with("names", topics); - requester.method("PUT").withPreview(MERCY).to(getApiTailUrl("topics")); + requester.method("PUT").withPreview(MERCY).withUrlPath(getApiTailUrl("topics")).to(); } } diff --git a/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java b/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java index 043a585f15..19b8bf8128 100644 --- a/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java +++ b/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java @@ -400,7 +400,7 @@ public String toString() { * the io exception */ public Participation getParticipation() throws IOException { - return root.retrieve().to(getApiTailUrl("participation"), Participation.class); + return root.retrieve().withUrlPath(getApiTailUrl("participation")).to(Participation.class); } /** diff --git a/src/main/java/org/kohsuke/github/GHSubscription.java b/src/main/java/org/kohsuke/github/GHSubscription.java index f71081fd1e..6fabc87490 100644 --- a/src/main/java/org/kohsuke/github/GHSubscription.java +++ b/src/main/java/org/kohsuke/github/GHSubscription.java @@ -87,7 +87,7 @@ public GHRepository getRepository() { * the io exception */ public void delete() throws IOException { - root.retrieve().method("DELETE").to(repo.getApiTailUrl("subscription")); + root.retrieve().method("DELETE").withUrlPath(repo.getApiTailUrl("subscription")).to(); } GHSubscription wrapUp(GHRepository repo) { diff --git a/src/main/java/org/kohsuke/github/GHTeam.java b/src/main/java/org/kohsuke/github/GHTeam.java index cf7a629fcd..f2f8d35992 100644 --- a/src/main/java/org/kohsuke/github/GHTeam.java +++ b/src/main/java/org/kohsuke/github/GHTeam.java @@ -103,7 +103,7 @@ public String getDescription() { * the io exception */ public void setDescription(String description) throws IOException { - root.retrieve().method("PATCH").with("description", description).to(api("")); + root.retrieve().method("PATCH").with("description", description).withUrlPath(api("")).to(); } /** @@ -146,7 +146,7 @@ public Set getMembers() throws IOException { */ public boolean hasMember(GHUser user) { try { - root.retrieve().to("/teams/" + id + "/members/" + user.getLogin()); + root.retrieve().withUrlPath("/teams/" + id + "/members/" + user.getLogin()).to(); return true; } catch (IOException ignore) { return false; @@ -189,7 +189,7 @@ public PagedIterable listRepositories() { * @since 1.59 */ public void add(GHUser u) throws IOException { - root.retrieve().method("PUT").to(api("/memberships/" + u.getLogin())); + root.retrieve().method("PUT").withUrlPath(api("/memberships/" + u.getLogin())).to(); } /** @@ -205,7 +205,7 @@ public void add(GHUser u) throws IOException { * the io exception */ public void add(GHUser user, Role role) throws IOException { - root.retrieve().method("PUT").with("role", role).to(api("/memberships/" + user.getLogin())); + root.retrieve().method("PUT").with("role", role).withUrlPath(api("/memberships/" + user.getLogin())).to(); } /** @@ -217,7 +217,7 @@ public void add(GHUser user, Role role) throws IOException { * the io exception */ public void remove(GHUser u) throws IOException { - root.retrieve().method("DELETE").to(api("/members/" + u.getLogin())); + root.retrieve().method("DELETE").withUrlPath(api("/members/" + u.getLogin())).to(); } /** @@ -246,7 +246,8 @@ public void add(GHRepository r, GHOrganization.Permission permission) throws IOE root.retrieve() .method("PUT") .with("permission", permission) - .to(api("/repos/" + r.getOwnerName() + '/' + r.getName())); + .withUrlPath(api("/repos/" + r.getOwnerName() + '/' + r.getName())) + .to(); } /** @@ -258,7 +259,7 @@ public void add(GHRepository r, GHOrganization.Permission permission) throws IOE * the io exception */ public void remove(GHRepository r) throws IOException { - root.retrieve().method("DELETE").to(api("/repos/" + r.getOwnerName() + '/' + r.getName())); + root.retrieve().method("DELETE").withUrlPath(api("/repos/" + r.getOwnerName() + '/' + r.getName())).to(); } /** @@ -268,7 +269,7 @@ public void remove(GHRepository r) throws IOException { * the io exception */ public void delete() throws IOException { - root.retrieve().method("DELETE").to(api("")); + root.retrieve().method("DELETE").withUrlPath(api("")).to(); } private String api(String tail) { @@ -289,6 +290,6 @@ public GHOrganization getOrganization() throws IOException { @Override public void refresh() throws IOException { - root.retrieve().to(api(""), this).wrapUp(root); + root.retrieve().withUrlPath(api("")).to(this).wrapUp(root); } } diff --git a/src/main/java/org/kohsuke/github/GHThread.java b/src/main/java/org/kohsuke/github/GHThread.java index 5bc35a227e..40974660a8 100644 --- a/src/main/java/org/kohsuke/github/GHThread.java +++ b/src/main/java/org/kohsuke/github/GHThread.java @@ -161,7 +161,7 @@ GHThread wrap(GitHub root) { * the io exception */ public void markAsRead() throws IOException { - root.retrieve().method("PATCH").to(url); + root.retrieve().method("PATCH").withUrlPath(url).to(); } /** @@ -181,7 +181,8 @@ public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOEx .with("subscribed", subscribed) .with("ignored", ignored) .method("PUT") - .to(subscription_url, GHSubscription.class) + .withUrlPath(subscription_url) + .to(GHSubscription.class) .wrapUp(root); } @@ -194,7 +195,7 @@ public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOEx */ public GHSubscription getSubscription() throws IOException { try { - return root.retrieve().method("POST").to(subscription_url, GHSubscription.class).wrapUp(root); + return root.retrieve().method("POST").withUrlPath(subscription_url).to(GHSubscription.class).wrapUp(root); } catch (FileNotFoundException e) { return null; } diff --git a/src/main/java/org/kohsuke/github/GHTreeBuilder.java b/src/main/java/org/kohsuke/github/GHTreeBuilder.java index 32f7267446..c712a2359c 100644 --- a/src/main/java/org/kohsuke/github/GHTreeBuilder.java +++ b/src/main/java/org/kohsuke/github/GHTreeBuilder.java @@ -163,6 +163,6 @@ private String getApiTail() { */ public GHTree create() throws IOException { req.with("tree", treeEntries); - return req.method("POST").to(getApiTail(), GHTree.class).wrap(repo); + return req.method("POST").withUrlPath(getApiTail()).to(GHTree.class).wrap(repo); } } diff --git a/src/main/java/org/kohsuke/github/GHUser.java b/src/main/java/org/kohsuke/github/GHUser.java index 4158d367c3..0e3b86e36d 100644 --- a/src/main/java/org/kohsuke/github/GHUser.java +++ b/src/main/java/org/kohsuke/github/GHUser.java @@ -43,8 +43,8 @@ public class GHUser extends GHPerson { * the io exception */ public List getKeys() throws IOException { - return Collections - .unmodifiableList(Arrays.asList(root.retrieve().toArray(getApiTailUrl("keys"), GHKey[].class))); + return Collections.unmodifiableList( + Arrays.asList(root.retrieve().withUrlPath(getApiTailUrl("keys")).toArray(GHKey[].class))); } /** @@ -54,7 +54,7 @@ public List getKeys() throws IOException { * the io exception */ public void follow() throws IOException { - root.retrieve().method("PUT").to("/user/following/" + login); + root.retrieve().method("PUT").withUrlPath("/user/following/" + login).to(); } /** @@ -64,7 +64,7 @@ public void follow() throws IOException { * the io exception */ public void unfollow() throws IOException { - root.retrieve().method("DELETE").to("/user/following/" + login); + root.retrieve().method("DELETE").withUrlPath("/user/following/" + login).to(); } /** @@ -187,7 +187,9 @@ static GHUser[] wrap(GHUser[] users, GitHub root) { public GHPersonSet getOrganizations() throws IOException { GHPersonSet orgs = new GHPersonSet(); Set names = new HashSet(); - for (GHOrganization o : root.retrieve().toArray("/users/" + login + "/orgs", GHOrganization[].class)) { + for (GHOrganization o : root.retrieve() + .withUrlPath("/users/" + login + "/orgs") + .toArray(GHOrganization[].class)) { if (names.add(o.getLogin())) // I've seen some duplicates in the data orgs.add(root.getOrganization(o.getLogin())); } diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 4da6395714..24c36be6db 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -438,7 +438,7 @@ Requester retrieve() { public GHRateLimit getRateLimit() throws IOException { GHRateLimit rateLimit; try { - rateLimit = retrieve().to("/rate_limit", JsonRateLimit.class).resources; + rateLimit = retrieve().withUrlPath("/rate_limit").to(JsonRateLimit.class).resources; } catch (FileNotFoundException e) { // GitHub Enterprise doesn't have the rate limit // return a default rate limit that @@ -544,7 +544,7 @@ public GHMyself getMyself() throws IOException { if (this.myself != null) return myself; - GHMyself u = retrieve().to("/user", GHMyself.class); + GHMyself u = retrieve().withUrlPath("/user").to(GHMyself.class); u.root = this; this.myself = u; @@ -564,7 +564,7 @@ public GHMyself getMyself() throws IOException { public GHUser getUser(String login) throws IOException { GHUser u = users.get(login); if (u == null) { - u = retrieve().to("/users/" + login, GHUser.class); + u = retrieve().withUrlPath("/users/" + login).to(GHUser.class); u.root = this; users.put(u.getLogin(), u); } @@ -608,7 +608,7 @@ protected GHUser getUser(GHUser orig) { public GHOrganization getOrganization(String name) throws IOException { GHOrganization o = orgs.get(name); if (o == null) { - o = retrieve().to("/orgs/" + name, GHOrganization.class).wrapUp(this); + o = retrieve().withUrlPath("/orgs/" + name).to(GHOrganization.class).wrapUp(this); orgs.put(name, o); } return o; @@ -648,7 +648,7 @@ public PagedIterable listOrganizations(final String since) { */ public GHRepository getRepository(String name) throws IOException { String[] tokens = name.split("/"); - return retrieve().to("/repos/" + tokens[0] + '/' + tokens[1], GHRepository.class).wrap(this); + return retrieve().withUrlPath("/repos/" + tokens[0] + '/' + tokens[1]).to(GHRepository.class).wrap(this); } /** @@ -661,7 +661,7 @@ public GHRepository getRepository(String name) throws IOException { * the io exception */ public GHRepository getRepositoryById(String id) throws IOException { - return retrieve().to("/repositories/" + id, GHRepository.class).wrap(this); + return retrieve().withUrlPath("/repositories/" + id).to(GHRepository.class).wrap(this); } /** @@ -698,7 +698,7 @@ public PagedIterable listUsers() throws IOException { * @see GHLicense#getKey() GHLicense#getKey() */ public GHLicense getLicense(String key) throws IOException { - return retrieve().to("/licenses/" + key, GHLicense.class); + return retrieve().withUrlPath("/licenses/" + key).to(GHLicense.class); } /** @@ -709,7 +709,8 @@ public GHLicense getLicense(String key) throws IOException { * the io exception */ public List getMyInvitations() throws IOException { - GHInvitation[] invitations = retrieve().toArray("/user/repository_invitations", GHInvitation[].class); + GHInvitation[] invitations = retrieve().withUrlPath("/user/repository_invitations") + .toArray(GHInvitation[].class); for (GHInvitation i : invitations) { i.wrapUp(this); } @@ -727,7 +728,7 @@ public List getMyInvitations() throws IOException { * the io exception */ public Map getMyOrganizations() throws IOException { - GHOrganization[] orgs = retrieve().toArray("/user/orgs", GHOrganization[].class); + GHOrganization[] orgs = retrieve().withUrlPath("/user/orgs").toArray(GHOrganization[].class); Map r = new HashMap(); for (GHOrganization o : orgs) { // don't put 'o' into orgs because they are shallow @@ -761,7 +762,7 @@ public Map getUserPublicOrganizations(GHUser user) throw * the io exception */ public Map getUserPublicOrganizations(String login) throws IOException { - GHOrganization[] orgs = retrieve().toArray("/users/" + login + "/orgs", GHOrganization[].class); + GHOrganization[] orgs = retrieve().withUrlPath("/users/" + login + "/orgs").toArray(GHOrganization[].class); Map r = new HashMap(); for (GHOrganization o : orgs) { // don't put 'o' into orgs because they are shallow @@ -782,7 +783,7 @@ public Map getUserPublicOrganizations(String login) thro */ public Map> getMyTeams() throws IOException { Map> allMyTeams = new HashMap>(); - for (GHTeam team : retrieve().toArray("/user/teams", GHTeam[].class)) { + for (GHTeam team : retrieve().withUrlPath("/user/teams").toArray(GHTeam[].class)) { team.wrapUp(this); String orgLogin = team.getOrganization().getLogin(); Set teamsPerOrg = allMyTeams.get(orgLogin); @@ -805,7 +806,7 @@ public Map> getMyTeams() throws IOException { * the io exception */ public GHTeam getTeam(int id) throws IOException { - return retrieve().to("/teams/" + id, GHTeam.class).wrapUp(this); + return retrieve().withUrlPath("/teams/" + id).to(GHTeam.class).wrapUp(this); } /** @@ -816,7 +817,7 @@ public GHTeam getTeam(int id) throws IOException { * the io exception */ public List getEvents() throws IOException { - GHEventInfo[] events = retrieve().toArray("/events", GHEventInfo[].class); + GHEventInfo[] events = retrieve().withUrlPath("/events").toArray(GHEventInfo[].class); for (GHEventInfo e : events) e.wrapUp(this); return Arrays.asList(events); @@ -832,7 +833,7 @@ public List getEvents() throws IOException { * the io exception */ public GHGist getGist(String id) throws IOException { - return retrieve().to("/gists/" + id, GHGist.class).wrapUp(this); + return retrieve().withUrlPath("/gists/" + id).to(GHGist.class).wrapUp(this); } /** @@ -929,7 +930,7 @@ public GHAuthorization createToken(Collection scope, String note, String .with("note", note) .with("note_url", noteUrl); - return requester.method("POST").to("/authorizations", GHAuthorization.class).wrap(this); + return requester.method("POST").withUrlPath("/authorizations").to(GHAuthorization.class).wrap(this); } /** @@ -966,7 +967,7 @@ public GHAuthorization createToken(Collection scope, String note, String .with("note_url", noteUrl); // Add the OTP from the user requester.setHeader("x-github-otp", OTPstring); - return requester.method("POST").to("/authorizations", GHAuthorization.class).wrap(this); + return requester.method("POST").withUrlPath("/authorizations").to(GHAuthorization.class).wrap(this); } } @@ -1000,7 +1001,7 @@ public GHAuthorization createOrGetAuth(String clientId, .with("note", note) .with("note_url", note_url); - return requester.method("PUT").to("/authorizations/clients/" + clientId, GHAuthorization.class); + return requester.method("PUT").withUrlPath("/authorizations/clients/" + clientId).to(GHAuthorization.class); } /** @@ -1014,7 +1015,7 @@ public GHAuthorization createOrGetAuth(String clientId, * authorization */ public void deleteAuth(long id) throws IOException { - retrieve().method("DELETE").to("/authorizations/" + id); + retrieve().method("DELETE").withUrlPath("/authorizations/" + id).to(); } /** @@ -1031,7 +1032,7 @@ public void deleteAuth(long id) throws IOException { * authorization */ public GHAuthorization checkAuth(@Nonnull String clientId, @Nonnull String accessToken) throws IOException { - return retrieve().to("/applications/" + clientId + "/tokens/" + accessToken, GHAuthorization.class); + return retrieve().withUrlPath("/applications/" + clientId + "/tokens/" + accessToken).to(GHAuthorization.class); } /** @@ -1049,7 +1050,8 @@ public GHAuthorization checkAuth(@Nonnull String clientId, @Nonnull String acces */ public GHAuthorization resetAuth(@Nonnull String clientId, @Nonnull String accessToken) throws IOException { return retrieve().method("POST") - .to("/applications/" + clientId + "/tokens/" + accessToken, GHAuthorization.class); + .withUrlPath("/applications/" + clientId + "/tokens/" + accessToken) + .to(GHAuthorization.class); } /** @@ -1079,7 +1081,7 @@ public PagedIterable listMyAuthorizations() throws IOException @Preview @Deprecated public GHApp getApp() throws IOException { - return retrieve().withPreview(MACHINE_MAN).to("/app", GHApp.class).wrapUp(this); + return retrieve().withPreview(MACHINE_MAN).withUrlPath("/app").to(GHApp.class).wrapUp(this); } /** @@ -1089,7 +1091,7 @@ public GHApp getApp() throws IOException { */ public boolean isCredentialValid() { try { - retrieve().to("/user", GHUser.class); + retrieve().withUrlPath("/user").to(GHUser.class); return true; } catch (IOException e) { if (LOGGER.isLoggable(FINE)) @@ -1110,7 +1112,7 @@ public boolean isCredentialValid() { * @see Get Meta */ public GHMeta getMeta() throws IOException { - return retrieve().to("/meta", GHMeta.class); + return retrieve().withUrlPath("/meta").to(GHMeta.class); } GHUser intern(GHUser user) throws IOException { @@ -1137,7 +1139,7 @@ GHUser intern(GHUser user) throws IOException { * the io exception */ public GHProject getProject(long id) throws IOException { - return retrieve().withPreview(INERTIA).to("/projects/" + id, GHProject.class).wrap(this); + return retrieve().withPreview(INERTIA).withUrlPath("/projects/" + id).to(GHProject.class).wrap(this); } /** @@ -1150,7 +1152,10 @@ public GHProject getProject(long id) throws IOException { * the io exception */ public GHProjectColumn getProjectColumn(long id) throws IOException { - return retrieve().withPreview(INERTIA).to("/projects/columns/" + id, GHProjectColumn.class).wrap(this); + return retrieve().withPreview(INERTIA) + .withUrlPath("/projects/columns/" + id) + .to(GHProjectColumn.class) + .wrap(this); } /** @@ -1163,7 +1168,10 @@ public GHProjectColumn getProjectColumn(long id) throws IOException { * the io exception */ public GHProjectCard getProjectCard(long id) throws IOException { - return retrieve().withPreview(INERTIA).to("/projects/columns/cards/" + id, GHProjectCard.class).wrap(this); + return retrieve().withPreview(INERTIA) + .withUrlPath("/projects/columns/cards/" + id) + .to(GHProjectCard.class) + .wrap(this); } private static class GHApiInfo { @@ -1193,7 +1201,7 @@ void check(String apiUrl) throws IOException { */ public void checkApiUrlValidity() throws IOException { try { - retrieve().to("/", GHApiInfo.class).check(apiUrl); + retrieve().withUrlPath("/").to(GHApiInfo.class).check(apiUrl); } catch (IOException e) { if (isPrivateModeEnabled()) { throw (IOException) new IOException( diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index e74824886d..3a6581865d 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -376,69 +376,6 @@ public Requester inBody() { return this; } - /** - * To. - * - * @param tailApiUrl - * the tail api url - * @throws IOException - * the io exception - */ - public void to(@Nonnull String tailApiUrl) throws IOException { - withUrlPath(tailApiUrl).to(); - } - - /** - * Sends a request to the specified URL, and parses the response into the given type via databinding. - * - * @param - * the type parameter - * @param tailApiUrl - * the tail api url - * @param type - * the type - * @return {@link Reader} that reads the response. - * @throws IOException - * if the server returns 4xx/5xx responses. - */ - public T to(@Nonnull String tailApiUrl, @Nonnull Class type) throws IOException { - return withUrlPath(tailApiUrl).to(type); - } - - /** - * Sends a request to the specified URL, and parses the response into the given type via databinding. - * - * @param - * the type parameter - * @param tailApiUrl - * the tail api url - * @param type - * the type - * @return {@link Reader} that reads the response. - * @throws IOException - * if the server returns 4xx/5xx responses. - */ - public T[] toArray(@Nonnull String tailApiUrl, @Nonnull Class type) throws IOException { - return withUrlPath(tailApiUrl).toArray(type); - } - - /** - * Like {@link #to(String, Class)} but updates an existing object instead of creating a new instance. - * - * @param - * the type parameter - * @param tailApiUrl - * the tail api url - * @param existingInstance - * the existing instance - * @return the t - * @throws IOException - * the io exception - */ - public T to(@Nonnull String tailApiUrl, @Nonnull T existingInstance) throws IOException { - return withUrlPath(tailApiUrl).to(existingInstance); - } - /** * To. * @@ -493,7 +430,7 @@ public T[] toArray(@Nonnull Class type) throws IOException { } /** - * Like {@link #to(String, Class)} but updates an existing object instead of creating a new instance. + * Like {@link #to(Class)} but updates an existing object instead of creating a new instance. * * @param * the type parameter diff --git a/src/test/java/org/kohsuke/github/GitHubTest.java b/src/test/java/org/kohsuke/github/GitHubTest.java index 6b4d3b7a02..c3a3449dc9 100644 --- a/src/test/java/org/kohsuke/github/GitHubTest.java +++ b/src/test/java/org/kohsuke/github/GitHubTest.java @@ -97,7 +97,8 @@ public void getMeta() throws IOException { for (Class metaClass : examples) { ReadOnlyObjects.GHMetaExample metaExample = gitHub.retrieve() - .to("/meta", (Class) metaClass); + .withUrlPath("/meta") + .to((Class) metaClass); assertTrue(metaExample.isVerifiablePasswordAuthentication()); assertEquals(19, metaExample.getApi().size()); assertEquals(19, metaExample.getGit().size()); From 40f05e4dbb551e94c6879022e087c8be7dbc3ecf Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Mon, 16 Dec 2019 11:18:56 -0800 Subject: [PATCH 5/7] Clean up request method calls --- .../github/GHAppCreateTokenBuilder.java | 2 +- src/main/java/org/kohsuke/github/GHAsset.java | 2 +- .../org/kohsuke/github/GHBlobBuilder.java | 2 +- .../kohsuke/github/GHBranchProtection.java | 4 +-- .../github/GHBranchProtectionBuilder.java | 2 +- .../org/kohsuke/github/GHCommitComment.java | 7 +---- .../github/GHCreateRepositoryBuilder.java | 2 +- src/main/java/org/kohsuke/github/GHGist.java | 2 +- .../org/kohsuke/github/GHGistUpdater.java | 2 +- src/main/java/org/kohsuke/github/GHIssue.java | 11 +++----- .../org/kohsuke/github/GHIssueComment.java | 7 +---- .../java/org/kohsuke/github/GHMilestone.java | 2 +- .../kohsuke/github/GHNotificationStream.java | 5 ++-- .../org/kohsuke/github/GHOrganization.java | 4 +-- .../java/org/kohsuke/github/GHProject.java | 10 ++----- .../org/kohsuke/github/GHProjectCard.java | 10 ++----- .../org/kohsuke/github/GHProjectColumn.java | 10 ++----- .../org/kohsuke/github/GHPullRequest.java | 2 +- .../github/GHPullRequestReviewBuilder.java | 2 +- src/main/java/org/kohsuke/github/GHRef.java | 3 +-- .../java/org/kohsuke/github/GHRelease.java | 4 +-- .../org/kohsuke/github/GHReleaseUpdater.java | 2 +- .../java/org/kohsuke/github/GHRepository.java | 27 ++++++++++--------- .../github/GHRepositoryStatistics.java | 4 +-- .../java/org/kohsuke/github/GHThread.java | 3 +-- .../org/kohsuke/github/GHTreeBuilder.java | 2 +- src/main/java/org/kohsuke/github/GitHub.java | 16 ++++------- .../java/org/kohsuke/github/Requester.java | 24 ++++++++--------- 28 files changed, 66 insertions(+), 107 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java index f2b70088e3..c504b2ee74 100644 --- a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java +++ b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java @@ -23,7 +23,7 @@ public class GHAppCreateTokenBuilder { GHAppCreateTokenBuilder(GitHub root, String apiUrlTail, Map permissions) { this.root = root; this.apiUrlTail = apiUrlTail; - this.builder = root.retrieve().method("POST"); + this.builder = root.retrieve(); withPermissions(builder, permissions); } diff --git a/src/main/java/org/kohsuke/github/GHAsset.java b/src/main/java/org/kohsuke/github/GHAsset.java index 121dde349d..1bd739c786 100644 --- a/src/main/java/org/kohsuke/github/GHAsset.java +++ b/src/main/java/org/kohsuke/github/GHAsset.java @@ -135,7 +135,7 @@ public String getBrowserDownloadUrl() { } private void edit(String key, Object value) throws IOException { - root.retrieve().method("POST").with(key, value).method("PATCH").withUrlPath(getApiRoute()).to(); + root.retrieve().with(key, value).method("PATCH").withUrlPath(getApiRoute()).to(); } /** diff --git a/src/main/java/org/kohsuke/github/GHBlobBuilder.java b/src/main/java/org/kohsuke/github/GHBlobBuilder.java index 5fb1708663..c26ce8a825 100644 --- a/src/main/java/org/kohsuke/github/GHBlobBuilder.java +++ b/src/main/java/org/kohsuke/github/GHBlobBuilder.java @@ -13,7 +13,7 @@ public class GHBlobBuilder { GHBlobBuilder(GHRepository repo) { this.repo = repo; - req = repo.root.retrieve().method("POST"); + req = repo.root.retrieve(); } /** diff --git a/src/main/java/org/kohsuke/github/GHBranchProtection.java b/src/main/java/org/kohsuke/github/GHBranchProtection.java index c0c4676bf9..5db307ca69 100644 --- a/src/main/java/org/kohsuke/github/GHBranchProtection.java +++ b/src/main/java/org/kohsuke/github/GHBranchProtection.java @@ -87,7 +87,7 @@ public RequiredReviews getRequiredReviews() { @Preview @Deprecated public boolean getRequiredSignatures() throws IOException { - return requester().method("GET").withUrlPath(url + REQUIRE_SIGNATURES_URI).to(RequiredSignatures.class).enabled; + return requester().withUrlPath(url + REQUIRE_SIGNATURES_URI).to(RequiredSignatures.class).enabled; } /** @@ -123,7 +123,7 @@ GHBranchProtection wrap(GHBranch branch) { } private Requester requester() { - return root.retrieve().method("POST").withPreview(ZZZAX); + return root.retrieve().withPreview(ZZZAX); } /** diff --git a/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java b/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java index 13d4fb1a20..ad57d372d0 100644 --- a/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java +++ b/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java @@ -353,7 +353,7 @@ private StatusChecks getStatusChecks() { } private Requester requester() { - return branch.getRoot().retrieve().method("POST").withPreview(LUKE_CAGE); + return branch.getRoot().retrieve().withPreview(LUKE_CAGE); } private static class Restrictions { diff --git a/src/main/java/org/kohsuke/github/GHCommitComment.java b/src/main/java/org/kohsuke/github/GHCommitComment.java index c7c5963277..e658cf5a0c 100644 --- a/src/main/java/org/kohsuke/github/GHCommitComment.java +++ b/src/main/java/org/kohsuke/github/GHCommitComment.java @@ -113,12 +113,7 @@ public GHCommit getCommit() throws IOException { * the io exception */ public void update(String body) throws IOException { - owner.root.retrieve() - .method("POST") - .with("body", body) - .method("PATCH") - .withUrlPath(getApiTail()) - .to(GHCommitComment.class); + owner.root.retrieve().method("PATCH").with("body", body).withUrlPath(getApiTail()).to(GHCommitComment.class); this.body = body; } diff --git a/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java b/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java index 0c833d3a34..2f1854d0ed 100644 --- a/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java @@ -16,7 +16,7 @@ public class GHCreateRepositoryBuilder { GHCreateRepositoryBuilder(GitHub root, String apiUrlTail, String name) { this.root = root; this.apiUrlTail = apiUrlTail; - this.builder = root.retrieve().method("POST"); + this.builder = root.retrieve(); this.builder.with("name", name); } diff --git a/src/main/java/org/kohsuke/github/GHGist.java b/src/main/java/org/kohsuke/github/GHGist.java index f0c59d3f56..df9de4603c 100644 --- a/src/main/java/org/kohsuke/github/GHGist.java +++ b/src/main/java/org/kohsuke/github/GHGist.java @@ -203,7 +203,7 @@ public void unstar() throws IOException { * the io exception */ public boolean isStarred() throws IOException { - return root.retrieve().asHttpStatusCode(getApiTailUrl("star")) / 100 == 2; + return root.retrieve().withUrlPath(getApiTailUrl("star")).asHttpStatusCode() / 100 == 2; } /** diff --git a/src/main/java/org/kohsuke/github/GHGistUpdater.java b/src/main/java/org/kohsuke/github/GHGistUpdater.java index 94064b6a01..fc8ef11503 100644 --- a/src/main/java/org/kohsuke/github/GHGistUpdater.java +++ b/src/main/java/org/kohsuke/github/GHGistUpdater.java @@ -16,7 +16,7 @@ public class GHGistUpdater { GHGistUpdater(GHGist base) { this.base = base; - this.builder = base.root.retrieve().method("POST"); + this.builder = base.root.retrieve(); files = new LinkedHashMap<>(); } diff --git a/src/main/java/org/kohsuke/github/GHIssue.java b/src/main/java/org/kohsuke/github/GHIssue.java index 4700a6d534..22aeafb4d5 100644 --- a/src/main/java/org/kohsuke/github/GHIssue.java +++ b/src/main/java/org/kohsuke/github/GHIssue.java @@ -239,11 +239,11 @@ public GHIssueComment comment(String message) throws IOException { } private void edit(String key, Object value) throws IOException { - root.retrieve().method("POST").with(key, value).method("PATCH").withUrlPath(getApiRoute()).to(); + root.retrieve().with(key, value).method("PATCH").withUrlPath(getApiRoute()).to(); } private void editIssue(String key, Object value) throws IOException { - root.retrieve().method("POST").with(key, value).method("PATCH").withUrlPath(getIssuesApiRoute()).to(); + root.retrieve().with(key, value).method("PATCH").withUrlPath(getIssuesApiRoute()).to(); } /** @@ -520,12 +520,7 @@ public void setAssignees(GHUser... assignees) throws IOException { * the io exception */ public void setAssignees(Collection assignees) throws IOException { - root.retrieve() - .method("POST") - .with(ASSIGNEES, getLogins(assignees)) - .method("PATCH") - .withUrlPath(getIssuesApiRoute()) - .to(); + root.retrieve().method("PATCH").with(ASSIGNEES, getLogins(assignees)).withUrlPath(getIssuesApiRoute()).to(); } /** diff --git a/src/main/java/org/kohsuke/github/GHIssueComment.java b/src/main/java/org/kohsuke/github/GHIssueComment.java index 2328897f2d..68415b073e 100644 --- a/src/main/java/org/kohsuke/github/GHIssueComment.java +++ b/src/main/java/org/kohsuke/github/GHIssueComment.java @@ -108,12 +108,7 @@ public GHCommentAuthorAssociation getAuthorAssociation() { * the io exception */ public void update(String body) throws IOException { - owner.root.retrieve() - .method("POST") - .with("body", body) - .method("PATCH") - .withUrlPath(getApiRoute()) - .to(GHIssueComment.class); + owner.root.retrieve().method("PATCH").with("body", body).withUrlPath(getApiRoute()).to(GHIssueComment.class); this.body = body; } diff --git a/src/main/java/org/kohsuke/github/GHMilestone.java b/src/main/java/org/kohsuke/github/GHMilestone.java index 222b73fe31..4b0ef40319 100644 --- a/src/main/java/org/kohsuke/github/GHMilestone.java +++ b/src/main/java/org/kohsuke/github/GHMilestone.java @@ -159,7 +159,7 @@ public void delete() throws IOException { } private void edit(String key, Object value) throws IOException { - root.retrieve().method("POST").with(key, value).method("PATCH").withUrlPath(getApiRoute()).to(); + root.retrieve().with(key, value).method("PATCH").withUrlPath(getApiRoute()).to(); } /** diff --git a/src/main/java/org/kohsuke/github/GHNotificationStream.java b/src/main/java/org/kohsuke/github/GHNotificationStream.java index 9209cdc52f..b29ed55663 100644 --- a/src/main/java/org/kohsuke/github/GHNotificationStream.java +++ b/src/main/java/org/kohsuke/github/GHNotificationStream.java @@ -102,7 +102,6 @@ public GHNotificationStream nonBlocking(boolean v) { public Iterator iterator() { // capture the configuration setting here final Requester req = root.retrieve() - .method("GET") .with("all", all) .with("participating", participating) .with("since", since); @@ -233,10 +232,10 @@ public void markAsRead() throws IOException { * the io exception */ public void markAsRead(long timestamp) throws IOException { - final Requester req = root.retrieve().method("PUT"); + final Requester req = root.retrieve(); if (timestamp >= 0) req.with("last_read_at", GitHub.printDate(new Date(timestamp))); - req.asHttpStatusCode(apiUrl); + req.withUrlPath(apiUrl).asHttpStatusCode(); } private static final GHThread[] EMPTY_ARRAY = new GHThread[0]; diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java index 867cb6e942..25eddfbb70 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -397,7 +397,7 @@ public GHTeam createTeam(String name, Permission p, Collection rep repo_names.add(login + "/" + r.getName()); } post.with("repo_names", repo_names); - return post.method("POST").withUrlPath("/orgs/" + login + "/teams").to(GHTeam.class).wrapUp(this); + return post.withUrlPath("/orgs/" + login + "/teams").to(GHTeam.class).wrapUp(this); } /** @@ -438,7 +438,7 @@ public GHTeam createTeam(String name, Collection repositories) thr repo_names.add(login + "/" + r.getName()); } post.with("repo_names", repo_names); - return post.method("POST").withUrlPath("/orgs/" + login + "/teams").to(GHTeam.class).wrapUp(this); + return post.withUrlPath("/orgs/" + login + "/teams").to(GHTeam.class).wrapUp(this); } /** diff --git a/src/main/java/org/kohsuke/github/GHProject.java b/src/main/java/org/kohsuke/github/GHProject.java index f10102f593..c7afcb5db6 100644 --- a/src/main/java/org/kohsuke/github/GHProject.java +++ b/src/main/java/org/kohsuke/github/GHProject.java @@ -176,13 +176,7 @@ public GHProject wrap(GitHub root) { } private void edit(String key, Object value) throws IOException { - root.retrieve() - .method("POST") - .withPreview(INERTIA) - .with(key, value) - .method("PATCH") - .withUrlPath(getApiRoute()) - .to(); + root.retrieve().method("PATCH").withPreview(INERTIA).with(key, value).withUrlPath(getApiRoute()).to(); } /** @@ -276,7 +270,7 @@ public void setPublic(boolean isPublic) throws IOException { * the io exception */ public void delete() throws IOException { - root.retrieve().method("POST").withPreview(INERTIA).method("DELETE").withUrlPath(getApiRoute()).to(); + root.retrieve().withPreview(INERTIA).method("DELETE").withUrlPath(getApiRoute()).to(); } /** diff --git a/src/main/java/org/kohsuke/github/GHProjectCard.java b/src/main/java/org/kohsuke/github/GHProjectCard.java index 80746c43cb..7a9af18d91 100644 --- a/src/main/java/org/kohsuke/github/GHProjectCard.java +++ b/src/main/java/org/kohsuke/github/GHProjectCard.java @@ -198,13 +198,7 @@ public void setArchived(boolean archived) throws IOException { } private void edit(String key, Object value) throws IOException { - root.retrieve() - .method("POST") - .withPreview(INERTIA) - .with(key, value) - .method("PATCH") - .withUrlPath(getApiRoute()) - .to(); + root.retrieve().method("PATCH").withPreview(INERTIA).with(key, value).withUrlPath(getApiRoute()).to(); } /** @@ -223,6 +217,6 @@ protected String getApiRoute() { * the io exception */ public void delete() throws IOException { - root.retrieve().method("POST").withPreview(INERTIA).method("DELETE").withUrlPath(getApiRoute()).to(); + root.retrieve().withPreview(INERTIA).method("DELETE").withUrlPath(getApiRoute()).to(); } } diff --git a/src/main/java/org/kohsuke/github/GHProjectColumn.java b/src/main/java/org/kohsuke/github/GHProjectColumn.java index 660b135760..fcf43c813a 100644 --- a/src/main/java/org/kohsuke/github/GHProjectColumn.java +++ b/src/main/java/org/kohsuke/github/GHProjectColumn.java @@ -106,13 +106,7 @@ public void setName(String name) throws IOException { } private void edit(String key, Object value) throws IOException { - root.retrieve() - .method("POST") - .withPreview(INERTIA) - .with(key, value) - .method("PATCH") - .withUrlPath(getApiRoute()) - .to(); + root.retrieve().method("PATCH").withPreview(INERTIA).with(key, value).withUrlPath(getApiRoute()).to(); } /** @@ -131,7 +125,7 @@ protected String getApiRoute() { * the io exception */ public void delete() throws IOException { - root.retrieve().method("POST").withPreview(INERTIA).method("DELETE").withUrlPath(getApiRoute()).to(); + root.retrieve().withPreview(INERTIA).method("DELETE").withUrlPath(getApiRoute()).to(); } /** diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index 744a29921f..af368ae258 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -615,7 +615,7 @@ public enum MergeMethod { private void fetchIssue() throws IOException { if (!fetchedIssueDetails) { - root.retrieve().method("GET").withUrlPath(getIssuesApiRoute()).to(this); + root.retrieve().withUrlPath(getIssuesApiRoute()).to(this); fetchedIssueDetails = true; } } diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java index df08aed0f9..27a5550159 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java @@ -17,7 +17,7 @@ public class GHPullRequestReviewBuilder { GHPullRequestReviewBuilder(GHPullRequest pr) { this.pr = pr; - this.builder = pr.root.retrieve().method("POST"); + this.builder = pr.root.retrieve(); } // public GHPullRequestReview createReview(@Nullable String commitId, String body, GHPullRequestReviewEvent event, diff --git a/src/main/java/org/kohsuke/github/GHRef.java b/src/main/java/org/kohsuke/github/GHRef.java index 1022d86714..c6370e1da0 100644 --- a/src/main/java/org/kohsuke/github/GHRef.java +++ b/src/main/java/org/kohsuke/github/GHRef.java @@ -67,10 +67,9 @@ public void updateTo(String sha) throws IOException { */ public void updateTo(String sha, Boolean force) throws IOException { root.retrieve() - .method("POST") + .method("PATCH") .with("sha", sha) .with("force", force) - .method("PATCH") .withUrlPath(url) .to(GHRef.class) .wrap(root); diff --git a/src/main/java/org/kohsuke/github/GHRelease.java b/src/main/java/org/kohsuke/github/GHRelease.java index b742d6bf58..c3eff0594c 100644 --- a/src/main/java/org/kohsuke/github/GHRelease.java +++ b/src/main/java/org/kohsuke/github/GHRelease.java @@ -256,9 +256,9 @@ public GHAsset uploadAsset(String filename, InputStream stream, String contentTy * the io exception */ public List getAssets() throws IOException { - Requester builder = owner.root.retrieve().method("POST"); + Requester builder = owner.root.retrieve(); - GHAsset[] assets = builder.method("GET").withUrlPath(getApiTailUrl("assets")).toArray(GHAsset[].class); + GHAsset[] assets = builder.withUrlPath(getApiTailUrl("assets")).toArray(GHAsset[].class); return Arrays.asList(GHAsset.wrap(assets, this)); } diff --git a/src/main/java/org/kohsuke/github/GHReleaseUpdater.java b/src/main/java/org/kohsuke/github/GHReleaseUpdater.java index e659b80a25..b9a3106ef5 100644 --- a/src/main/java/org/kohsuke/github/GHReleaseUpdater.java +++ b/src/main/java/org/kohsuke/github/GHReleaseUpdater.java @@ -14,7 +14,7 @@ public class GHReleaseUpdater { GHReleaseUpdater(GHRelease base) { this.base = base; - this.builder = base.root.retrieve().method("POST"); + this.builder = base.root.retrieve(); } /** diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index d50ce194e1..02dcfda100 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -419,7 +419,6 @@ public GHRef createRef(String name, String sha) throws IOException { .method("POST") .with("ref", name) .with("sha", sha) - .method("POST") .withUrlPath(getApiTailUrl("git/refs")) .to(GHRef.class) .wrap(root); @@ -764,7 +763,7 @@ public PagedIterable listAssignees() throws IOException { * the io exception */ public boolean hasAssignee(GHUser u) throws IOException { - return root.retrieve().asHttpStatusCode(getApiTailUrl("assignees/" + u.getLogin())) / 100 == 2; + return root.retrieve().withUrlPath(getApiTailUrl("assignees/" + u.getLogin())).asHttpStatusCode() / 100 == 2; } /** @@ -901,7 +900,7 @@ public void setEmailServiceHook(String address) throws IOException { } private void edit(String key, String value) throws IOException { - Requester requester = root.retrieve().method("POST"); + Requester requester = root.retrieve(); if (!key.equals("name")) requester.with("name", name); // even when we don't change the name, we need to send it in requester.with(key, value).method("PATCH").withUrlPath(getApiTailUrl("")).to(); @@ -1556,7 +1555,10 @@ public GHBlobBuilder createBlob() { */ public InputStream readBlob(String blobSha) throws IOException { String target = getApiTailUrl("git/blobs/" + blobSha); - return root.retrieve().withHeader("Accept", "application/vnd.github.VERSION.raw").asStream(target); + return root.retrieve() + .withHeader("Accept", "application/vnd.github.VERSION.raw") + .withUrlPath(target) + .toStream(); } /** @@ -2280,7 +2282,6 @@ public GHMilestone createMilestone(String title, String description) throws IOEx .method("POST") .with("title", title) .with("description", description) - .method("POST") .withUrlPath(getApiTailUrl("milestones")) .to(GHMilestone.class) .wrap(this); @@ -2302,7 +2303,6 @@ public GHDeployKey addDeployKey(String title, String key) throws IOException { .method("POST") .with("title", title) .with("key", key) - .method("POST") .withUrlPath(getApiTailUrl("keys")) .to(GHDeployKey.class) .wrap(this); @@ -2372,10 +2372,9 @@ public GHRepository getParent() throws IOException { */ public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOException { return root.retrieve() - .method("POST") + .method("PUT") .with("subscribed", subscribed) .with("ignored", ignored) - .method("PUT") .withUrlPath(getApiTailUrl("subscription")) .to(GHSubscription.class) .wrapUp(this); @@ -2517,7 +2516,8 @@ public Reader renderMarkdown(String text, MarkdownMode mode) throws IOException .with("text", text) .with("mode", mode == null ? null : mode.toString()) .with("context", getFullName()) - .asStream("/markdown"), + .withUrlPath("/markdown") + .toStream(), "UTF-8"); } @@ -2628,8 +2628,11 @@ public List listTopics() throws IOException { * the io exception */ public void setTopics(List topics) throws IOException { - Requester requester = root.retrieve().method("POST"); - requester.with("names", topics); - requester.method("PUT").withPreview(MERCY).withUrlPath(getApiTailUrl("topics")).to(); + root.retrieve() + .method("PUT") + .with("names", topics) + .withPreview(MERCY) + .withUrlPath(getApiTailUrl("topics")) + .to(); } } diff --git a/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java b/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java index 19b8bf8128..9d6ea70654 100644 --- a/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java +++ b/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java @@ -318,7 +318,7 @@ public List getCodeFrequency() throws IOException { // Map to ArrayLists first, since there are no field names in the // returned JSON. try { - InputStream stream = root.retrieve().asStream(getApiTailUrl("code_frequency")); + InputStream stream = root.retrieve().withUrlPath(getApiTailUrl("code_frequency")).toStream(); ObjectMapper mapper = new ObjectMapper(); TypeReference>> typeRef = new TypeReference>>() { @@ -460,7 +460,7 @@ Participation wrapUp(GitHub root) { public List getPunchCard() throws IOException { // Map to ArrayLists first, since there are no field names in the // returned JSON. - InputStream stream = root.retrieve().asStream(getApiTailUrl("punch_card")); + InputStream stream = root.retrieve().withUrlPath(getApiTailUrl("punch_card")).toStream(); ObjectMapper mapper = new ObjectMapper(); TypeReference>> typeRef = new TypeReference>>() { diff --git a/src/main/java/org/kohsuke/github/GHThread.java b/src/main/java/org/kohsuke/github/GHThread.java index 40974660a8..98ffb90580 100644 --- a/src/main/java/org/kohsuke/github/GHThread.java +++ b/src/main/java/org/kohsuke/github/GHThread.java @@ -177,10 +177,9 @@ public void markAsRead() throws IOException { */ public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOException { return root.retrieve() - .method("POST") + .method("PUT") .with("subscribed", subscribed) .with("ignored", ignored) - .method("PUT") .withUrlPath(subscription_url) .to(GHSubscription.class) .wrapUp(root); diff --git a/src/main/java/org/kohsuke/github/GHTreeBuilder.java b/src/main/java/org/kohsuke/github/GHTreeBuilder.java index c712a2359c..65b6369c12 100644 --- a/src/main/java/org/kohsuke/github/GHTreeBuilder.java +++ b/src/main/java/org/kohsuke/github/GHTreeBuilder.java @@ -33,7 +33,7 @@ private TreeEntry(String path, String mode, String type) { GHTreeBuilder(GHRepository repo) { this.repo = repo; - req = repo.root.retrieve().method("POST"); + req = repo.root.retrieve(); } /** diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 24c36be6db..60b2ae5d41 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -925,10 +925,7 @@ public GHCreateRepositoryBuilder createRepository(String name) { * @see Documentation */ public GHAuthorization createToken(Collection scope, String note, String noteUrl) throws IOException { - Requester requester = retrieve().method("POST") - .with("scopes", scope) - .with("note", note) - .with("note_url", noteUrl); + Requester requester = retrieve().with("scopes", scope).with("note", note).with("note_url", noteUrl); return requester.method("POST").withUrlPath("/authorizations").to(GHAuthorization.class).wrap(this); } @@ -961,10 +958,7 @@ public GHAuthorization createToken(Collection scope, String note, String return createToken(scope, note, noteUrl); } catch (GHOTPRequiredException ex) { String OTPstring = OTP.get(); - Requester requester = retrieve().method("POST") - .with("scopes", scope) - .with("note", note) - .with("note_url", noteUrl); + Requester requester = retrieve().with("scopes", scope).with("note", note).with("note_url", noteUrl); // Add the OTP from the user requester.setHeader("x-github-otp", OTPstring); return requester.method("POST").withUrlPath("/authorizations").to(GHAuthorization.class).wrap(this); @@ -995,8 +989,7 @@ public GHAuthorization createOrGetAuth(String clientId, List scopes, String note, String note_url) throws IOException { - Requester requester = retrieve().method("POST") - .with("client_secret", clientSecret) + Requester requester = retrieve().with("client_secret", clientSecret) .with("scopes", scopes) .with("note", note) .with("note_url", note_url); @@ -1356,7 +1349,8 @@ public Reader renderMarkdown(String text) throws IOException { retrieve().method("POST") .with(new ByteArrayInputStream(text.getBytes("UTF-8"))) .contentType("text/plain;charset=UTF-8") - .asStream("/markdown/raw"), + .withUrlPath("/markdown/raw") + .toStream(), "UTF-8"); } diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index 3a6581865d..f3fdb04ccf 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -500,26 +500,24 @@ private String buildTailApiUrl(String tailApiUrl) { } /** - * Makes a request and just obtains the HTTP status code. + * Makes a request and just obtains the HTTP status code. Method does not throw exceptions for many status codes + * that would otherwise throw. * - * @param tailApiUrl - * the tail api url * @return the int * @throws IOException * the io exception */ - public int asHttpStatusCode(String tailApiUrl) throws IOException { + public int asHttpStatusCode() throws IOException { while (true) {// loop while API rate limit is hit - method("GET"); - setupConnection(root.getApiURL(tailApiUrl)); + setupConnection(root.getApiURL(urlPath)); try { return uc.getResponseCode(); } catch (IOException e) { handleApiError(e); } finally { - noteRateLimit(tailApiUrl); + noteRateLimit(urlPath); } } } @@ -527,22 +525,20 @@ public int asHttpStatusCode(String tailApiUrl) throws IOException { /** * As stream input stream. * - * @param tailApiUrl - * the tail api url * @return the input stream * @throws IOException * the io exception */ - public InputStream asStream(String tailApiUrl) throws IOException { + public InputStream toStream() throws IOException { while (true) {// loop while API rate limit is hit - setupConnection(root.getApiURL(tailApiUrl)); + setupConnection(root.getApiURL(urlPath)); try { return wrapStream(uc.getInputStream()); } catch (IOException e) { handleApiError(e); } finally { - noteRateLimit(tailApiUrl); + noteRateLimit(urlPath); } } } @@ -689,7 +685,9 @@ protected void wrapUp(T[] page) { * Every iterator call reports a new batch. */ Iterator asIterator(Class type, int pageSize) { - method("GET"); + if (method != "GET") { + throw new IllegalStateException("Request method \"GET\" is required for iterator."); + } if (pageSize != 0) args.add(new Entry("per_page", pageSize)); From 305267d07ff73bed9289ed81c50ad5e55fce0a46 Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Tue, 17 Dec 2019 12:41:23 -0800 Subject: [PATCH 6/7] Rename methods for better clarity --- src/main/java/org/kohsuke/github/GHApp.java | 18 +- .../github/GHAppCreateTokenBuilder.java | 4 +- .../org/kohsuke/github/GHAppInstallation.java | 4 +- src/main/java/org/kohsuke/github/GHAsset.java | 4 +- .../org/kohsuke/github/GHBlobBuilder.java | 4 +- .../java/org/kohsuke/github/GHBranch.java | 4 +- .../kohsuke/github/GHBranchProtection.java | 8 +- .../github/GHBranchProtectionBuilder.java | 4 +- .../java/org/kohsuke/github/GHCommit.java | 8 +- .../org/kohsuke/github/GHCommitBuilder.java | 4 +- .../org/kohsuke/github/GHCommitComment.java | 14 +- .../kohsuke/github/GHCommitQueryBuilder.java | 2 +- .../java/org/kohsuke/github/GHContent.java | 16 +- .../org/kohsuke/github/GHContentBuilder.java | 4 +- .../github/GHCreateRepositoryBuilder.java | 4 +- .../java/org/kohsuke/github/GHDeployKey.java | 4 +- .../java/org/kohsuke/github/GHDeployment.java | 2 +- .../kohsuke/github/GHDeploymentBuilder.java | 4 +- .../github/GHDeploymentStatusBuilder.java | 4 +- src/main/java/org/kohsuke/github/GHGist.java | 12 +- .../org/kohsuke/github/GHGistBuilder.java | 4 +- .../org/kohsuke/github/GHGistUpdater.java | 4 +- src/main/java/org/kohsuke/github/GHHook.java | 4 +- src/main/java/org/kohsuke/github/GHHooks.java | 11 +- .../java/org/kohsuke/github/GHInvitation.java | 4 +- src/main/java/org/kohsuke/github/GHIssue.java | 36 +-- .../org/kohsuke/github/GHIssueBuilder.java | 4 +- .../org/kohsuke/github/GHIssueComment.java | 14 +- src/main/java/org/kohsuke/github/GHLabel.java | 10 +- .../java/org/kohsuke/github/GHLicense.java | 2 +- .../java/org/kohsuke/github/GHMembership.java | 2 +- .../java/org/kohsuke/github/GHMilestone.java | 4 +- .../java/org/kohsuke/github/GHMyself.java | 21 +- .../kohsuke/github/GHNotificationStream.java | 8 +- .../org/kohsuke/github/GHOrganization.java | 36 +-- .../java/org/kohsuke/github/GHPerson.java | 11 +- .../java/org/kohsuke/github/GHProject.java | 22 +- .../org/kohsuke/github/GHProjectCard.java | 18 +- .../org/kohsuke/github/GHProjectColumn.java | 16 +- .../org/kohsuke/github/GHPullRequest.java | 28 +-- .../kohsuke/github/GHPullRequestReview.java | 14 +- .../github/GHPullRequestReviewBuilder.java | 4 +- .../github/GHPullRequestReviewComment.java | 14 +- .../org/kohsuke/github/GHQueryBuilder.java | 2 +- .../java/org/kohsuke/github/GHReaction.java | 2 +- src/main/java/org/kohsuke/github/GHRef.java | 6 +- .../java/org/kohsuke/github/GHRelease.java | 10 +- .../org/kohsuke/github/GHReleaseBuilder.java | 4 +- .../org/kohsuke/github/GHReleaseUpdater.java | 4 +- .../java/org/kohsuke/github/GHRepository.java | 218 ++++++++++-------- .../github/GHRepositoryStatistics.java | 10 +- .../org/kohsuke/github/GHSubscription.java | 2 +- src/main/java/org/kohsuke/github/GHTeam.java | 28 ++- .../java/org/kohsuke/github/GHThread.java | 12 +- .../org/kohsuke/github/GHTreeBuilder.java | 4 +- src/main/java/org/kohsuke/github/GHUser.java | 19 +- src/main/java/org/kohsuke/github/GitHub.java | 89 +++---- .../java/org/kohsuke/github/Requester.java | 31 +-- .../java/org/kohsuke/github/GitHubTest.java | 4 +- .../kohsuke/github/RepositoryMockTest.java | 2 +- 60 files changed, 471 insertions(+), 395 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHApp.java b/src/main/java/org/kohsuke/github/GHApp.java index 464263f32a..311dfccc1b 100644 --- a/src/main/java/org/kohsuke/github/GHApp.java +++ b/src/main/java/org/kohsuke/github/GHApp.java @@ -178,7 +178,7 @@ GHApp wrapUp(GitHub root) { @Preview @Deprecated public PagedIterable listInstallations() { - return root.retrieve() + return root.createRequest() .withPreview(MACHINE_MAN) .asPagedIterable("/app/installations", GHAppInstallation[].class, item -> item.wrapUp(root)); } @@ -198,10 +198,10 @@ public PagedIterable listInstallations() { @Preview @Deprecated public GHAppInstallation getInstallationById(long id) throws IOException { - return root.retrieve() + return root.createRequest() .withPreview(MACHINE_MAN) .withUrlPath(String.format("/app/installations/%d", id)) - .to(GHAppInstallation.class) + .fetch(GHAppInstallation.class) .wrapUp(root); } @@ -221,10 +221,10 @@ public GHAppInstallation getInstallationById(long id) throws IOException { @Preview @Deprecated public GHAppInstallation getInstallationByOrganization(String name) throws IOException { - return root.retrieve() + return root.createRequest() .withPreview(MACHINE_MAN) .withUrlPath(String.format("/orgs/%s/installation", name)) - .to(GHAppInstallation.class) + .fetch(GHAppInstallation.class) .wrapUp(root); } @@ -246,10 +246,10 @@ public GHAppInstallation getInstallationByOrganization(String name) throws IOExc @Preview @Deprecated public GHAppInstallation getInstallationByRepository(String ownerName, String repositoryName) throws IOException { - return root.retrieve() + return root.createRequest() .withPreview(MACHINE_MAN) .withUrlPath(String.format("/repos/%s/%s/installation", ownerName, repositoryName)) - .to(GHAppInstallation.class) + .fetch(GHAppInstallation.class) .wrapUp(root); } @@ -268,10 +268,10 @@ public GHAppInstallation getInstallationByRepository(String ownerName, String re @Preview @Deprecated public GHAppInstallation getInstallationByUser(String name) throws IOException { - return root.retrieve() + return root.createRequest() .withPreview(MACHINE_MAN) .withUrlPath(String.format("/users/%s/installation", name)) - .to(GHAppInstallation.class) + .fetch(GHAppInstallation.class) .wrapUp(root); } diff --git a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java index c504b2ee74..7631204f45 100644 --- a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java +++ b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java @@ -23,7 +23,7 @@ public class GHAppCreateTokenBuilder { GHAppCreateTokenBuilder(GitHub root, String apiUrlTail, Map permissions) { this.root = root; this.apiUrlTail = apiUrlTail; - this.builder = root.retrieve(); + this.builder = root.createRequest(); withPermissions(builder, permissions); } @@ -58,7 +58,7 @@ public GHAppInstallationToken create() throws IOException { return builder.method("POST") .withPreview(MACHINE_MAN) .withUrlPath(apiUrlTail) - .to(GHAppInstallationToken.class) + .fetch(GHAppInstallationToken.class) .wrapUp(root); } diff --git a/src/main/java/org/kohsuke/github/GHAppInstallation.java b/src/main/java/org/kohsuke/github/GHAppInstallation.java index 1869bbef57..68ca25c90b 100644 --- a/src/main/java/org/kohsuke/github/GHAppInstallation.java +++ b/src/main/java/org/kohsuke/github/GHAppInstallation.java @@ -271,11 +271,11 @@ GHAppInstallation wrapUp(GitHub root) { @Preview @Deprecated public void deleteInstallation() throws IOException { - root.retrieve() + root.createRequest() .method("DELETE") .withPreview(GAMBIT) .withUrlPath(String.format("/app/installations/%d", id)) - .to(); + .send(); } /** diff --git a/src/main/java/org/kohsuke/github/GHAsset.java b/src/main/java/org/kohsuke/github/GHAsset.java index 1bd739c786..694ff91b2d 100644 --- a/src/main/java/org/kohsuke/github/GHAsset.java +++ b/src/main/java/org/kohsuke/github/GHAsset.java @@ -135,7 +135,7 @@ public String getBrowserDownloadUrl() { } private void edit(String key, Object value) throws IOException { - root.retrieve().with(key, value).method("PATCH").withUrlPath(getApiRoute()).to(); + root.createRequest().with(key, value).method("PATCH").withUrlPath(getApiRoute()).send(); } /** @@ -145,7 +145,7 @@ private void edit(String key, Object value) throws IOException { * the io exception */ public void delete() throws IOException { - root.retrieve().method("DELETE").withUrlPath(getApiRoute()).to(); + root.createRequest().method("DELETE").withUrlPath(getApiRoute()).send(); } private String getApiRoute() { diff --git a/src/main/java/org/kohsuke/github/GHBlobBuilder.java b/src/main/java/org/kohsuke/github/GHBlobBuilder.java index c26ce8a825..43cf196f13 100644 --- a/src/main/java/org/kohsuke/github/GHBlobBuilder.java +++ b/src/main/java/org/kohsuke/github/GHBlobBuilder.java @@ -13,7 +13,7 @@ public class GHBlobBuilder { GHBlobBuilder(GHRepository repo) { this.repo = repo; - req = repo.root.retrieve(); + req = repo.root.createRequest(); } /** @@ -55,6 +55,6 @@ private String getApiTail() { * if the blob cannot be created. */ public GHBlob create() throws IOException { - return req.method("POST").withUrlPath(getApiTail()).to(GHBlob.class); + return req.method("POST").withUrlPath(getApiTail()).fetch(GHBlob.class); } } diff --git a/src/main/java/org/kohsuke/github/GHBranch.java b/src/main/java/org/kohsuke/github/GHBranch.java index 3622849302..7b945107c0 100644 --- a/src/main/java/org/kohsuke/github/GHBranch.java +++ b/src/main/java/org/kohsuke/github/GHBranch.java @@ -101,7 +101,7 @@ public URL getProtectionUrl() { * the io exception */ public GHBranchProtection getProtection() throws IOException { - return root.retrieve().withUrlPath(protection_url).to(GHBranchProtection.class).wrap(this); + return root.createRequest().withUrlPath(protection_url).fetch(GHBranchProtection.class).wrap(this); } /** @@ -120,7 +120,7 @@ public String getSHA1() { * if disabling protection fails */ public void disableProtection() throws IOException { - root.retrieve().method("DELETE").withUrlPath(protection_url).to(); + root.createRequest().method("DELETE").withUrlPath(protection_url).send(); } /** diff --git a/src/main/java/org/kohsuke/github/GHBranchProtection.java b/src/main/java/org/kohsuke/github/GHBranchProtection.java index 5db307ca69..8782a74ec9 100644 --- a/src/main/java/org/kohsuke/github/GHBranchProtection.java +++ b/src/main/java/org/kohsuke/github/GHBranchProtection.java @@ -44,7 +44,7 @@ public class GHBranchProtection { @Preview @Deprecated public void enabledSignedCommits() throws IOException { - requester().method("POST").withUrlPath(url + REQUIRE_SIGNATURES_URI).to(RequiredSignatures.class); + requester().method("POST").withUrlPath(url + REQUIRE_SIGNATURES_URI).fetch(RequiredSignatures.class); } /** @@ -56,7 +56,7 @@ public void enabledSignedCommits() throws IOException { @Preview @Deprecated public void disableSignedCommits() throws IOException { - requester().method("DELETE").withUrlPath(url + REQUIRE_SIGNATURES_URI).to(); + requester().method("DELETE").withUrlPath(url + REQUIRE_SIGNATURES_URI).send(); } /** @@ -87,7 +87,7 @@ public RequiredReviews getRequiredReviews() { @Preview @Deprecated public boolean getRequiredSignatures() throws IOException { - return requester().withUrlPath(url + REQUIRE_SIGNATURES_URI).to(RequiredSignatures.class).enabled; + return requester().withUrlPath(url + REQUIRE_SIGNATURES_URI).fetch(RequiredSignatures.class).enabled; } /** @@ -123,7 +123,7 @@ GHBranchProtection wrap(GHBranch branch) { } private Requester requester() { - return root.retrieve().withPreview(ZZZAX); + return root.createRequest().withPreview(ZZZAX); } /** diff --git a/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java b/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java index ad57d372d0..9f60aec13b 100644 --- a/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java +++ b/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java @@ -94,7 +94,7 @@ public GHBranchProtection enable() throws IOException { .withNullable("restrictions", restrictions) .withNullable("enforce_admins", enforceAdmins) .withUrlPath(branch.getProtectionUrl().toString()) - .to(GHBranchProtection.class) + .fetch(GHBranchProtection.class) .wrap(branch); } @@ -353,7 +353,7 @@ private StatusChecks getStatusChecks() { } private Requester requester() { - return branch.getRoot().retrieve().withPreview(LUKE_CAGE); + return branch.getRoot().createRequest().withPreview(LUKE_CAGE); } private static class Restrictions { diff --git a/src/main/java/org/kohsuke/github/GHCommit.java b/src/main/java/org/kohsuke/github/GHCommit.java index e5c9629ea8..515410a37d 100644 --- a/src/main/java/org/kohsuke/github/GHCommit.java +++ b/src/main/java/org/kohsuke/github/GHCommit.java @@ -441,7 +441,7 @@ private GHUser resolveUser(User author) throws IOException { * @return {@link PagedIterable} with all the commit comments in this repository. */ public PagedIterable listComments() { - return owner.root.retrieve() + return owner.root.createRequest() .asPagedIterable( String.format("/repos/%s/%s/commits/%s/comments", owner.getOwnerName(), owner.getName(), sha), GHCommitComment[].class, @@ -466,7 +466,7 @@ public PagedIterable listComments() { * if comment is not created */ public GHCommitComment createComment(String body, String path, Integer line, Integer position) throws IOException { - GHCommitComment r = owner.root.retrieve() + GHCommitComment r = owner.root.createRequest() .method("POST") .with("body", body) .with("path", path) @@ -474,7 +474,7 @@ public GHCommitComment createComment(String body, String path, Integer line, Int .with("position", position) .withUrlPath( String.format("/repos/%s/%s/commits/%s/comments", owner.getOwnerName(), owner.getName(), sha)) - .to(GHCommitComment.class); + .fetch(GHCommitComment.class); return r.wrap(owner); } @@ -521,7 +521,7 @@ public GHCommitStatus getLastStatus() throws IOException { */ void populate() throws IOException { if (files == null && stats == null) - owner.root.retrieve().withUrlPath(owner.getApiTailUrl("commits/" + sha)).to(this); + owner.root.createRequest().withUrlPath(owner.getApiTailUrl("commits/" + sha)).fetchInto(this); } GHCommit wrapUp(GHRepository owner) { diff --git a/src/main/java/org/kohsuke/github/GHCommitBuilder.java b/src/main/java/org/kohsuke/github/GHCommitBuilder.java index 0b51f0045f..c7b459a22d 100644 --- a/src/main/java/org/kohsuke/github/GHCommitBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCommitBuilder.java @@ -34,7 +34,7 @@ private UserInfo(String name, String email, Date date) { GHCommitBuilder(GHRepository repo) { this.repo = repo; - req = repo.root.retrieve().method("POST"); + req = repo.root.createRequest().method("POST"); } /** @@ -118,6 +118,6 @@ private String getApiTail() { */ public GHCommit create() throws IOException { req.with("parents", parents); - return req.method("POST").withUrlPath(getApiTail()).to(GHCommit.class).wrapUp(repo); + return req.method("POST").withUrlPath(getApiTail()).fetch(GHCommit.class).wrapUp(repo); } } diff --git a/src/main/java/org/kohsuke/github/GHCommitComment.java b/src/main/java/org/kohsuke/github/GHCommitComment.java index e658cf5a0c..b3da925c8f 100644 --- a/src/main/java/org/kohsuke/github/GHCommitComment.java +++ b/src/main/java/org/kohsuke/github/GHCommitComment.java @@ -113,26 +113,30 @@ public GHCommit getCommit() throws IOException { * the io exception */ public void update(String body) throws IOException { - owner.root.retrieve().method("PATCH").with("body", body).withUrlPath(getApiTail()).to(GHCommitComment.class); + owner.root.createRequest() + .method("PATCH") + .with("body", body) + .withUrlPath(getApiTail()) + .fetch(GHCommitComment.class); this.body = body; } @Preview @Deprecated public GHReaction createReaction(ReactionContent content) throws IOException { - return owner.root.retrieve() + return owner.root.createRequest() .method("POST") .withPreview(SQUIRREL_GIRL) .with("content", content.getContent()) .withUrlPath(getApiTail() + "/reactions") - .to(GHReaction.class) + .fetch(GHReaction.class) .wrap(owner.root); } @Preview @Deprecated public PagedIterable listReactions() { - return owner.root.retrieve() + return owner.root.createRequest() .withPreview(SQUIRREL_GIRL) .asPagedIterable(getApiTail() + "/reactions", GHReaction[].class, item -> item.wrap(owner.root)); } @@ -144,7 +148,7 @@ public PagedIterable listReactions() { * the io exception */ public void delete() throws IOException { - owner.root.retrieve().method("DELETE").withUrlPath(getApiTail()).to(); + owner.root.createRequest().method("DELETE").withUrlPath(getApiTail()).send(); } private String getApiTail() { diff --git a/src/main/java/org/kohsuke/github/GHCommitQueryBuilder.java b/src/main/java/org/kohsuke/github/GHCommitQueryBuilder.java index dc544b390e..0350ec4a3b 100644 --- a/src/main/java/org/kohsuke/github/GHCommitQueryBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCommitQueryBuilder.java @@ -24,7 +24,7 @@ public class GHCommitQueryBuilder { GHCommitQueryBuilder(GHRepository repo) { this.repo = repo; - this.req = repo.root.retrieve(); // requester to build up + this.req = repo.root.createRequest(); // requester to build up } /** diff --git a/src/main/java/org/kohsuke/github/GHContent.java b/src/main/java/org/kohsuke/github/GHContent.java index 79d09a65ef..bca79eb53d 100644 --- a/src/main/java/org/kohsuke/github/GHContent.java +++ b/src/main/java/org/kohsuke/github/GHContent.java @@ -223,7 +223,7 @@ public boolean isDirectory() { * the io exception */ protected synchronized void populate() throws IOException { - root.retrieve().withUrlPath(url).to(this); + root.createRequest().withUrlPath(url).fetchInto(this); } /** @@ -237,7 +237,9 @@ public PagedIterable listDirectoryContent() throws IOException { if (!isDirectory()) throw new IllegalStateException(path + " is not a directory"); - return root.retrieve().setRawUrlPath(url).asPagedIterable(GHContent[].class, item -> item.wrap(repository)); + return root.createRequest() + .setRawUrlPath(url) + .asPagedIterable(GHContent[].class, item -> item.wrap(repository)); } /** @@ -306,7 +308,7 @@ public GHContentUpdateResponse update(byte[] newContentBytes, String commitMessa throws IOException { String encodedContent = Base64.encodeBase64String(newContentBytes); - Requester requester = root.retrieve() + Requester requester = root.createRequest() .method("POST") .with("path", path) .with("message", commitMessage) @@ -319,7 +321,7 @@ public GHContentUpdateResponse update(byte[] newContentBytes, String commitMessa } GHContentUpdateResponse response = requester.withUrlPath(getApiRoute(repository, path)) - .to(GHContentUpdateResponse.class); + .fetch(GHContentUpdateResponse.class); response.getContent().wrap(repository); response.getCommit().wrapUp(repository); @@ -353,7 +355,7 @@ public GHContentUpdateResponse delete(String message) throws IOException { * the io exception */ public GHContentUpdateResponse delete(String commitMessage, String branch) throws IOException { - Requester requester = root.retrieve() + Requester requester = root.createRequest() .method("POST") .with("path", path) .with("message", commitMessage) @@ -365,7 +367,7 @@ public GHContentUpdateResponse delete(String commitMessage, String branch) throw } GHContentUpdateResponse response = requester.withUrlPath(getApiRoute(repository, path)) - .to(GHContentUpdateResponse.class); + .fetch(GHContentUpdateResponse.class); response.getCommit().wrapUp(repository); return response; @@ -411,6 +413,6 @@ public static GHContent[] wrap(GHContent[] contents, GHRepository repository) { */ @Override public synchronized void refresh() throws IOException { - root.retrieve().setRawUrlPath(url).to(this); + root.createRequest().setRawUrlPath(url).fetchInto(this); } } diff --git a/src/main/java/org/kohsuke/github/GHContentBuilder.java b/src/main/java/org/kohsuke/github/GHContentBuilder.java index 39d95d9e96..6687baf975 100644 --- a/src/main/java/org/kohsuke/github/GHContentBuilder.java +++ b/src/main/java/org/kohsuke/github/GHContentBuilder.java @@ -21,7 +21,7 @@ public final class GHContentBuilder { GHContentBuilder(GHRepository repo) { this.repo = repo; - this.req = repo.root.retrieve().method("PUT"); + this.req = repo.root.createRequest().method("PUT"); } /** @@ -109,7 +109,7 @@ public GHContentBuilder message(String commitMessage) { */ public GHContentUpdateResponse commit() throws IOException { GHContentUpdateResponse response = req.withUrlPath(GHContent.getApiRoute(repo, path)) - .to(GHContentUpdateResponse.class); + .fetch(GHContentUpdateResponse.class); response.getContent().wrap(repo); response.getCommit().wrapUp(repo); diff --git a/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java b/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java index 2f1854d0ed..d25e3b4446 100644 --- a/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java @@ -16,7 +16,7 @@ public class GHCreateRepositoryBuilder { GHCreateRepositoryBuilder(GitHub root, String apiUrlTail, String name) { this.root = root; this.apiUrlTail = apiUrlTail; - this.builder = root.retrieve(); + this.builder = root.createRequest(); this.builder.with("name", name); } @@ -196,7 +196,7 @@ public GHCreateRepositoryBuilder team(GHTeam team) { * if repsitory cannot be created */ public GHRepository create() throws IOException { - return builder.method("POST").withUrlPath(apiUrlTail).to(GHRepository.class).wrap(root); + return builder.method("POST").withUrlPath(apiUrlTail).fetch(GHRepository.class).wrap(root); } } diff --git a/src/main/java/org/kohsuke/github/GHDeployKey.java b/src/main/java/org/kohsuke/github/GHDeployKey.java index 30c425ac8f..ddcbff0450 100644 --- a/src/main/java/org/kohsuke/github/GHDeployKey.java +++ b/src/main/java/org/kohsuke/github/GHDeployKey.java @@ -82,9 +82,9 @@ public String toString() { * the io exception */ public void delete() throws IOException { - owner.root.retrieve() + owner.root.createRequest() .method("DELETE") .withUrlPath(String.format("/repos/%s/%s/keys/%d", owner.getOwnerName(), owner.getName(), id)) - .to(); + .send(); } } diff --git a/src/main/java/org/kohsuke/github/GHDeployment.java b/src/main/java/org/kohsuke/github/GHDeployment.java index 601bf258d6..01451cf9f5 100644 --- a/src/main/java/org/kohsuke/github/GHDeployment.java +++ b/src/main/java/org/kohsuke/github/GHDeployment.java @@ -131,7 +131,7 @@ public GHDeploymentStatusBuilder createStatus(GHDeploymentState state) { * @return the paged iterable */ public PagedIterable listStatuses() { - return root.retrieve().asPagedIterable(statuses_url, GHDeploymentStatus[].class, item -> item.wrap(owner)); + return root.createRequest().asPagedIterable(statuses_url, GHDeploymentStatus[].class, item -> item.wrap(owner)); } } diff --git a/src/main/java/org/kohsuke/github/GHDeploymentBuilder.java b/src/main/java/org/kohsuke/github/GHDeploymentBuilder.java index b1b411a441..9677f55b6e 100644 --- a/src/main/java/org/kohsuke/github/GHDeploymentBuilder.java +++ b/src/main/java/org/kohsuke/github/GHDeploymentBuilder.java @@ -19,7 +19,7 @@ public class GHDeploymentBuilder { */ public GHDeploymentBuilder(GHRepository repo) { this.repo = repo; - this.builder = repo.root.retrieve().method("POST"); + this.builder = repo.root.createRequest().method("POST"); } /** @@ -127,6 +127,6 @@ public GHDeploymentBuilder description(String description) { * the io exception */ public GHDeployment create() throws IOException { - return builder.withUrlPath(repo.getApiTailUrl("deployments")).to(GHDeployment.class).wrap(repo); + return builder.withUrlPath(repo.getApiTailUrl("deployments")).fetch(GHDeployment.class).wrap(repo); } } diff --git a/src/main/java/org/kohsuke/github/GHDeploymentStatusBuilder.java b/src/main/java/org/kohsuke/github/GHDeploymentStatusBuilder.java index e01ca41285..34ff201a33 100644 --- a/src/main/java/org/kohsuke/github/GHDeploymentStatusBuilder.java +++ b/src/main/java/org/kohsuke/github/GHDeploymentStatusBuilder.java @@ -30,7 +30,7 @@ public GHDeploymentStatusBuilder(GHRepository repo, int deploymentId, GHDeployme GHDeploymentStatusBuilder(GHRepository repo, long deploymentId, GHDeploymentState state) { this.repo = repo; this.deploymentId = deploymentId; - this.builder = repo.root.retrieve().method("POST"); + this.builder = repo.root.createRequest().method("POST"); this.builder.with("state", state); } @@ -67,7 +67,7 @@ public GHDeploymentStatusBuilder targetUrl(String targetUrl) { */ public GHDeploymentStatus create() throws IOException { return builder.withUrlPath(repo.getApiTailUrl("deployments/" + deploymentId + "/statuses")) - .to(GHDeploymentStatus.class) + .fetch(GHDeploymentStatus.class) .wrap(repo); } } diff --git a/src/main/java/org/kohsuke/github/GHGist.java b/src/main/java/org/kohsuke/github/GHGist.java index df9de4603c..86365b1c33 100644 --- a/src/main/java/org/kohsuke/github/GHGist.java +++ b/src/main/java/org/kohsuke/github/GHGist.java @@ -182,7 +182,7 @@ String getApiTailUrl(String tail) { * the io exception */ public void star() throws IOException { - root.retrieve().method("PUT").withUrlPath(getApiTailUrl("star")).to(); + root.createRequest().method("PUT").withUrlPath(getApiTailUrl("star")).send(); } /** @@ -192,7 +192,7 @@ public void star() throws IOException { * the io exception */ public void unstar() throws IOException { - root.retrieve().method("DELETE").withUrlPath(getApiTailUrl("star")).to(); + root.createRequest().method("DELETE").withUrlPath(getApiTailUrl("star")).send(); } /** @@ -203,7 +203,7 @@ public void unstar() throws IOException { * the io exception */ public boolean isStarred() throws IOException { - return root.retrieve().withUrlPath(getApiTailUrl("star")).asHttpStatusCode() / 100 == 2; + return root.createRequest().withUrlPath(getApiTailUrl("star")).fetchHttpStatusCode() / 100 == 2; } /** @@ -214,7 +214,7 @@ public boolean isStarred() throws IOException { * the io exception */ public GHGist fork() throws IOException { - return root.retrieve().method("POST").withUrlPath(getApiTailUrl("forks")).to(GHGist.class).wrapUp(root); + return root.createRequest().method("POST").withUrlPath(getApiTailUrl("forks")).fetch(GHGist.class).wrapUp(root); } /** @@ -223,7 +223,7 @@ public GHGist fork() throws IOException { * @return the paged iterable */ public PagedIterable listForks() { - return root.retrieve().asPagedIterable(getApiTailUrl("forks"), GHGist[].class, item -> item.wrapUp(root)); + return root.createRequest().asPagedIterable(getApiTailUrl("forks"), GHGist[].class, item -> item.wrapUp(root)); } /** @@ -233,7 +233,7 @@ public PagedIterable listForks() { * the io exception */ public void delete() throws IOException { - root.retrieve().method("DELETE").withUrlPath("/gists/" + id).to(); + root.createRequest().method("DELETE").withUrlPath("/gists/" + id).send(); } /** diff --git a/src/main/java/org/kohsuke/github/GHGistBuilder.java b/src/main/java/org/kohsuke/github/GHGistBuilder.java index c51cbf4b7d..1ea95b0b9c 100644 --- a/src/main/java/org/kohsuke/github/GHGistBuilder.java +++ b/src/main/java/org/kohsuke/github/GHGistBuilder.java @@ -23,7 +23,7 @@ public class GHGistBuilder { */ public GHGistBuilder(GitHub root) { this.root = root; - req = root.retrieve().method("POST"); + req = root.createRequest().method("POST"); } /** @@ -73,6 +73,6 @@ public GHGistBuilder file(String fileName, String content) { */ public GHGist create() throws IOException { req.with("files", files); - return req.withUrlPath("/gists").to(GHGist.class).wrapUp(root); + return req.withUrlPath("/gists").fetch(GHGist.class).wrapUp(root); } } diff --git a/src/main/java/org/kohsuke/github/GHGistUpdater.java b/src/main/java/org/kohsuke/github/GHGistUpdater.java index fc8ef11503..6a9726c7d3 100644 --- a/src/main/java/org/kohsuke/github/GHGistUpdater.java +++ b/src/main/java/org/kohsuke/github/GHGistUpdater.java @@ -16,7 +16,7 @@ public class GHGistUpdater { GHGistUpdater(GHGist base) { this.base = base; - this.builder = base.root.retrieve(); + this.builder = base.root.createRequest(); files = new LinkedHashMap<>(); } @@ -96,6 +96,6 @@ public GHGistUpdater description(String desc) { */ public GHGist update() throws IOException { builder.with("files", files); - return builder.method("PATCH").withUrlPath(base.getApiTailUrl("")).to(GHGist.class).wrap(base.owner); + return builder.method("PATCH").withUrlPath(base.getApiTailUrl("")).fetch(GHGist.class).wrap(base.owner); } } diff --git a/src/main/java/org/kohsuke/github/GHHook.java b/src/main/java/org/kohsuke/github/GHHook.java index c1cca7150f..35fa7bd1f9 100644 --- a/src/main/java/org/kohsuke/github/GHHook.java +++ b/src/main/java/org/kohsuke/github/GHHook.java @@ -74,7 +74,7 @@ public Map getConfig() { * @see Ping hook */ public void ping() throws IOException { - getRoot().retrieve().method("POST").withUrlPath(getApiRoute() + "/pings").to(); + getRoot().createRequest().method("POST").withUrlPath(getApiRoute() + "/pings").send(); } /** @@ -84,7 +84,7 @@ public void ping() throws IOException { * the io exception */ public void delete() throws IOException { - getRoot().retrieve().method("DELETE").withUrlPath(getApiRoute()).to(); + getRoot().createRequest().method("DELETE").withUrlPath(getApiRoute()).send(); } /** diff --git a/src/main/java/org/kohsuke/github/GHHooks.java b/src/main/java/org/kohsuke/github/GHHooks.java index f020b9c6b1..05ad6fc3b8 100644 --- a/src/main/java/org/kohsuke/github/GHHooks.java +++ b/src/main/java/org/kohsuke/github/GHHooks.java @@ -28,8 +28,9 @@ private Context(GitHub root) { */ public List getHooks() throws IOException { - GHHook[] hookArray = root.retrieve().withUrlPath(collection()).to(collectionClass()); // jdk/eclipse bug - // requires this + GHHook[] hookArray = root.createRequest().withUrlPath(collection()).fetch(collectionClass()); // jdk/eclipse + // bug + // requires this // to be on separate line List list = new ArrayList(Arrays.asList(hookArray)); for (GHHook h : list) @@ -47,7 +48,7 @@ public List getHooks() throws IOException { * the io exception */ public GHHook getHook(int id) throws IOException { - GHHook hook = root.retrieve().withUrlPath(collection() + "/" + id).to(clazz()); + GHHook hook = root.createRequest().withUrlPath(collection() + "/" + id).fetch(clazz()); return wrap(hook); } @@ -75,14 +76,14 @@ public GHHook createHook(String name, Map config, Collection getComments() throws IOException { * the io exception */ public PagedIterable listComments() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(getIssuesApiRoute() + "/comments", GHIssueComment[].class, item -> item.wrapUp(GHIssue.this)); @@ -454,19 +454,19 @@ public PagedIterable listComments() throws IOException { @Preview @Deprecated public GHReaction createReaction(ReactionContent content) throws IOException { - return owner.root.retrieve() + return owner.root.createRequest() .method("POST") .withPreview(SQUIRREL_GIRL) .with("content", content.getContent()) .withUrlPath(getApiRoute() + "/reactions") - .to(GHReaction.class) + .fetch(GHReaction.class) .wrap(root); } @Preview @Deprecated public PagedIterable listReactions() { - return owner.root.retrieve() + return owner.root.createRequest() .withPreview(SQUIRREL_GIRL) .asPagedIterable(getApiRoute() + "/reactions", GHReaction[].class, item -> item.wrap(owner.root)); } @@ -492,11 +492,11 @@ public void addAssignees(GHUser... assignees) throws IOException { * the io exception */ public void addAssignees(Collection assignees) throws IOException { - root.retrieve() + root.createRequest() .method("POST") .with(ASSIGNEES, getLogins(assignees)) .withUrlPath(getIssuesApiRoute() + "/assignees") - .to(this); + .fetchInto(this); } /** @@ -520,7 +520,11 @@ public void setAssignees(GHUser... assignees) throws IOException { * the io exception */ public void setAssignees(Collection assignees) throws IOException { - root.retrieve().method("PATCH").with(ASSIGNEES, getLogins(assignees)).withUrlPath(getIssuesApiRoute()).to(); + root.createRequest() + .method("PATCH") + .with(ASSIGNEES, getLogins(assignees)) + .withUrlPath(getIssuesApiRoute()) + .send(); } /** @@ -544,12 +548,12 @@ public void removeAssignees(GHUser... assignees) throws IOException { * the io exception */ public void removeAssignees(Collection assignees) throws IOException { - root.retrieve() + root.createRequest() .method("DELETE") .with(ASSIGNEES, getLogins(assignees)) .inBody() .withUrlPath(getIssuesApiRoute() + "/assignees") - .to(this); + .fetchInto(this); } /** @@ -711,7 +715,7 @@ protected static List getLogins(Collection users) { * the io exception */ public PagedIterable listEvents() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(owner.getApiTailUrl(String.format("/issues/%s/events", number)), GHIssueEvent[].class, item -> item.wrapUp(GHIssue.this)); diff --git a/src/main/java/org/kohsuke/github/GHIssueBuilder.java b/src/main/java/org/kohsuke/github/GHIssueBuilder.java index 55be4d1703..2d21d3fd03 100644 --- a/src/main/java/org/kohsuke/github/GHIssueBuilder.java +++ b/src/main/java/org/kohsuke/github/GHIssueBuilder.java @@ -17,7 +17,7 @@ public class GHIssueBuilder { GHIssueBuilder(GHRepository repo, String title) { this.repo = repo; - this.builder = repo.root.retrieve().method("POST"); + this.builder = repo.root.createRequest().method("POST"); builder.with("title", title); } @@ -96,7 +96,7 @@ public GHIssue create() throws IOException { return builder.with("labels", labels) .with("assignees", assignees) .withUrlPath(repo.getApiTailUrl("issues")) - .to(GHIssue.class) + .fetch(GHIssue.class) .wrap(repo); } } diff --git a/src/main/java/org/kohsuke/github/GHIssueComment.java b/src/main/java/org/kohsuke/github/GHIssueComment.java index 68415b073e..1a174f2c51 100644 --- a/src/main/java/org/kohsuke/github/GHIssueComment.java +++ b/src/main/java/org/kohsuke/github/GHIssueComment.java @@ -108,7 +108,11 @@ public GHCommentAuthorAssociation getAuthorAssociation() { * the io exception */ public void update(String body) throws IOException { - owner.root.retrieve().method("PATCH").with("body", body).withUrlPath(getApiRoute()).to(GHIssueComment.class); + owner.root.createRequest() + .method("PATCH") + .with("body", body) + .withUrlPath(getApiRoute()) + .fetch(GHIssueComment.class); this.body = body; } @@ -119,25 +123,25 @@ public void update(String body) throws IOException { * the io exception */ public void delete() throws IOException { - owner.root.retrieve().method("DELETE").withUrlPath(getApiRoute()).to(); + owner.root.createRequest().method("DELETE").withUrlPath(getApiRoute()).send(); } @Preview @Deprecated public GHReaction createReaction(ReactionContent content) throws IOException { - return owner.root.retrieve() + return owner.root.createRequest() .method("POST") .withPreview(SQUIRREL_GIRL) .with("content", content.getContent()) .withUrlPath(getApiRoute() + "/reactions") - .to(GHReaction.class) + .fetch(GHReaction.class) .wrap(owner.root); } @Preview @Deprecated public PagedIterable listReactions() { - return owner.root.retrieve() + return owner.root.createRequest() .withPreview(SQUIRREL_GIRL) .asPagedIterable(getApiRoute() + "/reactions", GHReaction[].class, item -> item.wrap(owner.root)); } diff --git a/src/main/java/org/kohsuke/github/GHLabel.java b/src/main/java/org/kohsuke/github/GHLabel.java index 9a947524d4..b47e1f2d99 100644 --- a/src/main/java/org/kohsuke/github/GHLabel.java +++ b/src/main/java/org/kohsuke/github/GHLabel.java @@ -69,7 +69,7 @@ GHLabel wrapUp(GHRepository repo) { * the io exception */ public void delete() throws IOException { - repo.root.retrieve().method("DELETE").setRawUrlPath(url).to(); + repo.root.createRequest().method("DELETE").setRawUrlPath(url).send(); } /** @@ -81,14 +81,14 @@ public void delete() throws IOException { * the io exception */ public void setColor(String newColor) throws IOException { - repo.root.retrieve() + repo.root.createRequest() .method("PATCH") .withPreview(SYMMETRA) .with("name", name) .with("color", newColor) .with("description", description) .setRawUrlPath(url) - .to(); + .send(); } /** @@ -102,14 +102,14 @@ public void setColor(String newColor) throws IOException { @Preview @Deprecated public void setDescription(String newDescription) throws IOException { - repo.root.retrieve() + repo.root.createRequest() .method("PATCH") .withPreview(SYMMETRA) .with("name", name) .with("color", color) .with("description", newDescription) .setRawUrlPath(url) - .to(); + .send(); } static Collection toNames(Collection labels) { diff --git a/src/main/java/org/kohsuke/github/GHLicense.java b/src/main/java/org/kohsuke/github/GHLicense.java index 630a27546e..0e7851e96a 100644 --- a/src/main/java/org/kohsuke/github/GHLicense.java +++ b/src/main/java/org/kohsuke/github/GHLicense.java @@ -199,7 +199,7 @@ protected synchronized void populate() throws IOException { if (description != null) return; // already populated - root.retrieve().withUrlPath(url).to(this); + root.createRequest().withUrlPath(url).fetchInto(this); } @Override diff --git a/src/main/java/org/kohsuke/github/GHMembership.java b/src/main/java/org/kohsuke/github/GHMembership.java index d69b94af09..b8099d5276 100644 --- a/src/main/java/org/kohsuke/github/GHMembership.java +++ b/src/main/java/org/kohsuke/github/GHMembership.java @@ -72,7 +72,7 @@ public GHOrganization getOrganization() { * @see GHMyself#getMembership(GHOrganization) GHMyself#getMembership(GHOrganization) */ public void activate() throws IOException { - root.retrieve().method("PATCH").with("state", State.ACTIVE).withUrlPath(url).to(this); + root.createRequest().method("PATCH").with("state", State.ACTIVE).withUrlPath(url).fetchInto(this); } GHMembership wrap(GitHub root) { diff --git a/src/main/java/org/kohsuke/github/GHMilestone.java b/src/main/java/org/kohsuke/github/GHMilestone.java index 4b0ef40319..bfe806f14c 100644 --- a/src/main/java/org/kohsuke/github/GHMilestone.java +++ b/src/main/java/org/kohsuke/github/GHMilestone.java @@ -155,11 +155,11 @@ public void reopen() throws IOException { * the io exception */ public void delete() throws IOException { - root.retrieve().method("DELETE").withUrlPath(getApiRoute()).to(); + root.createRequest().method("DELETE").withUrlPath(getApiRoute()).send(); } private void edit(String key, Object value) throws IOException { - root.retrieve().with(key, value).method("PATCH").withUrlPath(getApiRoute()).to(); + root.createRequest().with(key, value).method("PATCH").withUrlPath(getApiRoute()).send(); } /** diff --git a/src/main/java/org/kohsuke/github/GHMyself.java b/src/main/java/org/kohsuke/github/GHMyself.java index 5045cdf6b5..1a83ff0d2d 100644 --- a/src/main/java/org/kohsuke/github/GHMyself.java +++ b/src/main/java/org/kohsuke/github/GHMyself.java @@ -71,7 +71,7 @@ public List getEmails() throws IOException { * the io exception */ public List getEmails2() throws IOException { - GHEmail[] addresses = root.retrieve().withUrlPath("/user/emails").toArray(GHEmail[].class); + GHEmail[] addresses = root.createRequest().withUrlPath("/user/emails").fetchArray(GHEmail[].class); return Collections.unmodifiableList(Arrays.asList(addresses)); } @@ -86,8 +86,8 @@ public List getEmails2() throws IOException { * the io exception */ public List getPublicKeys() throws IOException { - return Collections - .unmodifiableList(Arrays.asList(root.retrieve().withUrlPath("/user/keys").toArray(GHKey[].class))); + return Collections.unmodifiableList( + Arrays.asList(root.createRequest().withUrlPath("/user/keys").fetchArray(GHKey[].class))); } /** @@ -101,8 +101,8 @@ public List getPublicKeys() throws IOException { * the io exception */ public List getPublicVerifiedKeys() throws IOException { - return Collections.unmodifiableList(Arrays - .asList(root.retrieve().withUrlPath("/users/" + getLogin() + "/keys").toArray(GHVerifiedKey[].class))); + return Collections.unmodifiableList(Arrays.asList( + root.createRequest().withUrlPath("/users/" + getLogin() + "/keys").fetchArray(GHVerifiedKey[].class))); } /** @@ -115,7 +115,7 @@ public List getPublicVerifiedKeys() throws IOException { public GHPersonSet getAllOrganizations() throws IOException { GHPersonSet orgs = new GHPersonSet(); Set names = new HashSet(); - for (GHOrganization o : root.retrieve().withUrlPath("/user/orgs").toArray(GHOrganization[].class)) { + for (GHOrganization o : root.createRequest().withUrlPath("/user/orgs").fetchArray(GHOrganization[].class)) { if (names.add(o.getLogin())) // in case of rumoured duplicates in the data orgs.add(root.getOrganization(o.getLogin())); } @@ -176,7 +176,7 @@ public PagedIterable listRepositories(final int pageSize) { * @return the paged iterable */ public PagedIterable listRepositories(final int pageSize, final RepositoryListFilter repoType) { - return root.retrieve() + return root.createRequest() .with("type", repoType) .asPagedIterable("/user/repos", GHRepository[].class, item -> item.wrap(root)) .withPageSize(pageSize); @@ -209,7 +209,7 @@ public PagedIterable listOrgMemberships() { * @return the paged iterable */ public PagedIterable listOrgMemberships(final GHMembership.State state) { - return root.retrieve() + return root.createRequest() .with("state", state) .asPagedIterable("/user/memberships/orgs", GHMembership[].class, item -> item.wrap(root)); } @@ -224,7 +224,10 @@ public PagedIterable listOrgMemberships(final GHMembership.State s * the io exception */ public GHMembership getMembership(GHOrganization o) throws IOException { - return root.retrieve().withUrlPath("/user/memberships/orgs/" + o.getLogin()).to(GHMembership.class).wrap(root); + return root.createRequest() + .withUrlPath("/user/memberships/orgs/" + o.getLogin()) + .fetch(GHMembership.class) + .wrap(root); } // public void addEmails(Collection emails) throws IOException { diff --git a/src/main/java/org/kohsuke/github/GHNotificationStream.java b/src/main/java/org/kohsuke/github/GHNotificationStream.java index b29ed55663..65bd604d8b 100644 --- a/src/main/java/org/kohsuke/github/GHNotificationStream.java +++ b/src/main/java/org/kohsuke/github/GHNotificationStream.java @@ -101,7 +101,7 @@ public GHNotificationStream nonBlocking(boolean v) { */ public Iterator iterator() { // capture the configuration setting here - final Requester req = root.retrieve() + final Requester req = root.createRequest() .with("all", all) .with("participating", participating) .with("since", since); @@ -180,7 +180,7 @@ GHThread fetch() { req.setHeader("If-Modified-Since", lastModified); - threads = req.withUrlPath(apiUrl).toArray(GHThread[].class); + threads = req.withUrlPath(apiUrl).fetchArray(GHThread[].class); if (threads == null) { threads = EMPTY_ARRAY; // if unmodified, we get empty array } else { @@ -232,10 +232,10 @@ public void markAsRead() throws IOException { * the io exception */ public void markAsRead(long timestamp) throws IOException { - final Requester req = root.retrieve(); + final Requester req = root.createRequest(); if (timestamp >= 0) req.with("last_read_at", GitHub.printDate(new Date(timestamp))); - req.withUrlPath(apiUrl).asHttpStatusCode(); + req.withUrlPath(apiUrl).fetchHttpStatusCode(); } private static final GHThread[] EMPTY_ARRAY = new GHThread[0]; diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java index 25eddfbb70..dac65cb530 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -121,7 +121,7 @@ public Map getTeams() throws IOException { * the io exception */ public PagedIterable listTeams() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(String.format("/orgs/%s/teams", login), GHTeam[].class, item -> item.wrapUp(GHOrganization.this)); @@ -183,11 +183,11 @@ public enum Role { * "https://developer.github.com/v3/orgs/members/#add-or-update-organization-membership">documentation */ public void add(GHUser user, Role role) throws IOException { - root.retrieve() + root.createRequest() .method("PUT") .with("role", role.name().toLowerCase()) .withUrlPath("/orgs/" + login + "/memberships/" + user.getLogin()) - .to(); + .send(); } /** @@ -199,7 +199,7 @@ public void add(GHUser user, Role role) throws IOException { */ public boolean hasMember(GHUser user) { try { - root.retrieve().withUrlPath("/orgs/" + login + "/members/" + user.getLogin()).to(); + root.createRequest().withUrlPath("/orgs/" + login + "/members/" + user.getLogin()).send(); return true; } catch (IOException ignore) { return false; @@ -216,7 +216,7 @@ public boolean hasMember(GHUser user) { * the io exception */ public void remove(GHUser user) throws IOException { - root.retrieve().method("DELETE").withUrlPath("/orgs/" + login + "/members/" + user.getLogin()).to(); + root.createRequest().method("DELETE").withUrlPath("/orgs/" + login + "/members/" + user.getLogin()).send(); } /** @@ -228,7 +228,7 @@ public void remove(GHUser user) throws IOException { */ public boolean hasPublicMember(GHUser user) { try { - root.retrieve().withUrlPath("/orgs/" + login + "/public_members/" + user.getLogin()).to(); + root.createRequest().withUrlPath("/orgs/" + login + "/public_members/" + user.getLogin()).send(); return true; } catch (IOException ignore) { return false; @@ -244,7 +244,7 @@ public boolean hasPublicMember(GHUser user) { * the io exception */ public void publicize(GHUser u) throws IOException { - root.retrieve().method("PUT").withUrlPath("/orgs/" + login + "/public_members/" + u.getLogin()).to(); + root.createRequest().method("PUT").withUrlPath("/orgs/" + login + "/public_members/" + u.getLogin()).send(); } /** @@ -300,7 +300,7 @@ public PagedIterable listMembersWithFilter(String filter) throws IOExcep private PagedIterable listMembers(final String suffix, final String filter) throws IOException { String filterParams = (filter == null) ? "" : ("?filter=" + filter); - return root.retrieve() + return root.createRequest() .asPagedIterable(String.format("/orgs/%s/%s%s", login, suffix, filterParams), GHUser[].class, item -> item.wrapUp(root)); @@ -315,7 +315,7 @@ private PagedIterable listMembers(final String suffix, final String filt * the io exception */ public void conceal(GHUser u) throws IOException { - root.retrieve().method("DELETE").withUrlPath("/orgs/" + login + "/public_members/" + u.getLogin()).to(); + root.createRequest().method("DELETE").withUrlPath("/orgs/" + login + "/public_members/" + u.getLogin()).send(); } /** @@ -328,7 +328,7 @@ public void conceal(GHUser u) throws IOException { * the io exception */ public PagedIterable listProjects(final GHProject.ProjectStateFilter status) throws IOException { - return root.retrieve() + return root.createRequest() .withPreview(INERTIA) .with("state", status) .asPagedIterable(String.format("/orgs/%s/projects", login), GHProject[].class, item -> item.wrap(root)); @@ -357,13 +357,13 @@ public PagedIterable listProjects() throws IOException { * the io exception */ public GHProject createProject(String name, String body) throws IOException { - return root.retrieve() + return root.createRequest() .method("POST") .withPreview(INERTIA) .with("name", name) .with("body", body) .withUrlPath(String.format("/orgs/%s/projects", login)) - .to(GHProject.class) + .fetch(GHProject.class) .wrap(root); } @@ -391,13 +391,13 @@ public enum Permission { */ @Deprecated public GHTeam createTeam(String name, Permission p, Collection repositories) throws IOException { - Requester post = root.retrieve().method("POST").with("name", name).with("permission", p); + Requester post = root.createRequest().method("POST").with("name", name).with("permission", p); List repo_names = new ArrayList(); for (GHRepository r : repositories) { repo_names.add(login + "/" + r.getName()); } post.with("repo_names", repo_names); - return post.withUrlPath("/orgs/" + login + "/teams").to(GHTeam.class).wrapUp(this); + return post.withUrlPath("/orgs/" + login + "/teams").fetch(GHTeam.class).wrapUp(this); } /** @@ -432,13 +432,13 @@ public GHTeam createTeam(String name, Permission p, GHRepository... repositories * the io exception */ public GHTeam createTeam(String name, Collection repositories) throws IOException { - Requester post = root.retrieve().method("POST").with("name", name); + Requester post = root.createRequest().method("POST").with("name", name); List repo_names = new ArrayList(); for (GHRepository r : repositories) { repo_names.add(login + "/" + r.getName()); } post.with("repo_names", repo_names); - return post.withUrlPath("/orgs/" + login + "/teams").to(GHTeam.class).wrapUp(this); + return post.withUrlPath("/orgs/" + login + "/teams").fetch(GHTeam.class).wrapUp(this); } /** @@ -497,7 +497,7 @@ public List getPullRequests() throws IOException { * Lists events performed by a user (this includes private events if the caller is authenticated. */ public PagedIterable listEvents() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(String.format("/orgs/%s/events", login), GHEventInfo[].class, item -> item.wrapUp(root)); @@ -513,7 +513,7 @@ public PagedIterable listEvents() throws IOException { */ @Override public PagedIterable listRepositories(final int pageSize) { - return root.retrieve() + return root.createRequest() .asPagedIterable("/orgs/" + login + "/repos", GHRepository[].class, item -> item.wrap(root)) .withPageSize(pageSize); } diff --git a/src/main/java/org/kohsuke/github/GHPerson.java b/src/main/java/org/kohsuke/github/GHPerson.java index 06e86c5ad5..2f47d3f9fd 100644 --- a/src/main/java/org/kohsuke/github/GHPerson.java +++ b/src/main/java/org/kohsuke/github/GHPerson.java @@ -47,7 +47,7 @@ protected synchronized void populate() throws IOException { if (root == null || root.isOffline()) { return; // cannot populate, will have to live with what we have } - root.retrieve().withUrlPath(url).to(this); + root.createRequest().withUrlPath(url).fetchInto(this); } /** @@ -88,7 +88,7 @@ public PagedIterable listRepositories() { * @return the paged iterable */ public PagedIterable listRepositories(final int pageSize) { - return root.retrieve() + return root.createRequest() .asPagedIterable("/users/" + login + "/repos", GHRepository[].class, item -> item.wrap(root)) .withPageSize(pageSize); } @@ -112,7 +112,7 @@ public PagedIterable listRepositories(final int pageSize) { public synchronized Iterable> iterateRepositories(final int pageSize) { return new Iterable>() { public Iterator> iterator() { - final Iterator pager = root.retrieve() + final Iterator pager = root.createRequest() .withUrlPath("users", login, "repos") .asIterator(GHRepository[].class, pageSize); @@ -147,7 +147,10 @@ public void remove() { */ public GHRepository getRepository(String name) throws IOException { try { - return root.retrieve().withUrlPath("/repos/" + login + '/' + name).to(GHRepository.class).wrap(root); + return root.createRequest() + .withUrlPath("/repos/" + login + '/' + name) + .fetch(GHRepository.class) + .wrap(root); } catch (FileNotFoundException e) { return null; } diff --git a/src/main/java/org/kohsuke/github/GHProject.java b/src/main/java/org/kohsuke/github/GHProject.java index c7afcb5db6..56714ffac5 100644 --- a/src/main/java/org/kohsuke/github/GHProject.java +++ b/src/main/java/org/kohsuke/github/GHProject.java @@ -74,11 +74,17 @@ public GHObject getOwner() throws IOException { if (owner == null) { try { if (owner_url.contains("/orgs/")) { - owner = root.retrieve().withUrlPath(getOwnerUrl().getPath()).to(GHOrganization.class).wrapUp(root); + owner = root.createRequest() + .withUrlPath(getOwnerUrl().getPath()) + .fetch(GHOrganization.class) + .wrapUp(root); } else if (owner_url.contains("/users/")) { - owner = root.retrieve().withUrlPath(getOwnerUrl().getPath()).to(GHUser.class).wrapUp(root); + owner = root.createRequest().withUrlPath(getOwnerUrl().getPath()).fetch(GHUser.class).wrapUp(root); } else if (owner_url.contains("/repos/")) { - owner = root.retrieve().withUrlPath(getOwnerUrl().getPath()).to(GHRepository.class).wrap(root); + owner = root.createRequest() + .withUrlPath(getOwnerUrl().getPath()) + .fetch(GHRepository.class) + .wrap(root); } } catch (FileNotFoundException e) { return null; @@ -176,7 +182,7 @@ public GHProject wrap(GitHub root) { } private void edit(String key, Object value) throws IOException { - root.retrieve().method("PATCH").withPreview(INERTIA).with(key, value).withUrlPath(getApiRoute()).to(); + root.createRequest().method("PATCH").withPreview(INERTIA).with(key, value).withUrlPath(getApiRoute()).send(); } /** @@ -270,7 +276,7 @@ public void setPublic(boolean isPublic) throws IOException { * the io exception */ public void delete() throws IOException { - root.retrieve().withPreview(INERTIA).method("DELETE").withUrlPath(getApiRoute()).to(); + root.createRequest().withPreview(INERTIA).method("DELETE").withUrlPath(getApiRoute()).send(); } /** @@ -282,7 +288,7 @@ public void delete() throws IOException { */ public PagedIterable listColumns() throws IOException { final GHProject project = this; - return root.retrieve() + return root.createRequest() .withPreview(INERTIA) .asPagedIterable(String.format("/projects/%d/columns", id), GHProjectColumn[].class, @@ -299,12 +305,12 @@ public PagedIterable listColumns() throws IOException { * the io exception */ public GHProjectColumn createColumn(String name) throws IOException { - return root.retrieve() + return root.createRequest() .method("POST") .withPreview(INERTIA) .with("name", name) .withUrlPath(String.format("/projects/%d/columns", id)) - .to(GHProjectColumn.class) + .fetch(GHProjectColumn.class) .wrap(this); } } \ No newline at end of file diff --git a/src/main/java/org/kohsuke/github/GHProjectCard.java b/src/main/java/org/kohsuke/github/GHProjectCard.java index 7a9af18d91..94b130c3aa 100644 --- a/src/main/java/org/kohsuke/github/GHProjectCard.java +++ b/src/main/java/org/kohsuke/github/GHProjectCard.java @@ -72,7 +72,7 @@ public GitHub getRoot() { public GHProject getProject() throws IOException { if (project == null) { try { - project = root.retrieve().withUrlPath(getProjectUrl().getPath()).to(GHProject.class).wrap(root); + project = root.createRequest().withUrlPath(getProjectUrl().getPath()).fetch(GHProject.class).wrap(root); } catch (FileNotFoundException e) { return null; } @@ -90,7 +90,10 @@ public GHProject getProject() throws IOException { public GHProjectColumn getColumn() throws IOException { if (column == null) { try { - column = root.retrieve().withUrlPath(getColumnUrl().getPath()).to(GHProjectColumn.class).wrap(root); + column = root.createRequest() + .withUrlPath(getColumnUrl().getPath()) + .fetch(GHProjectColumn.class) + .wrap(root); } catch (FileNotFoundException e) { return null; } @@ -110,9 +113,12 @@ public GHIssue getContent() throws IOException { return null; try { if (content_url.contains("/pulls")) { - return root.retrieve().withUrlPath(getContentUrl().getPath()).to(GHPullRequest.class).wrap(root); + return root.createRequest() + .withUrlPath(getContentUrl().getPath()) + .fetch(GHPullRequest.class) + .wrap(root); } else { - return root.retrieve().withUrlPath(getContentUrl().getPath()).to(GHIssue.class).wrap(root); + return root.createRequest().withUrlPath(getContentUrl().getPath()).fetch(GHIssue.class).wrap(root); } } catch (FileNotFoundException e) { return null; @@ -198,7 +204,7 @@ public void setArchived(boolean archived) throws IOException { } private void edit(String key, Object value) throws IOException { - root.retrieve().method("PATCH").withPreview(INERTIA).with(key, value).withUrlPath(getApiRoute()).to(); + root.createRequest().method("PATCH").withPreview(INERTIA).with(key, value).withUrlPath(getApiRoute()).send(); } /** @@ -217,6 +223,6 @@ protected String getApiRoute() { * the io exception */ public void delete() throws IOException { - root.retrieve().withPreview(INERTIA).method("DELETE").withUrlPath(getApiRoute()).to(); + root.createRequest().withPreview(INERTIA).method("DELETE").withUrlPath(getApiRoute()).send(); } } diff --git a/src/main/java/org/kohsuke/github/GHProjectColumn.java b/src/main/java/org/kohsuke/github/GHProjectColumn.java index fcf43c813a..b561f6f905 100644 --- a/src/main/java/org/kohsuke/github/GHProjectColumn.java +++ b/src/main/java/org/kohsuke/github/GHProjectColumn.java @@ -67,7 +67,7 @@ public GitHub getRoot() { public GHProject getProject() throws IOException { if (project == null) { try { - project = root.retrieve().withUrlPath(getProjectUrl().getPath()).to(GHProject.class).wrap(root); + project = root.createRequest().withUrlPath(getProjectUrl().getPath()).fetch(GHProject.class).wrap(root); } catch (FileNotFoundException e) { return null; } @@ -106,7 +106,7 @@ public void setName(String name) throws IOException { } private void edit(String key, Object value) throws IOException { - root.retrieve().method("PATCH").withPreview(INERTIA).with(key, value).withUrlPath(getApiRoute()).to(); + root.createRequest().method("PATCH").withPreview(INERTIA).with(key, value).withUrlPath(getApiRoute()).send(); } /** @@ -125,7 +125,7 @@ protected String getApiRoute() { * the io exception */ public void delete() throws IOException { - root.retrieve().withPreview(INERTIA).method("DELETE").withUrlPath(getApiRoute()).to(); + root.createRequest().withPreview(INERTIA).method("DELETE").withUrlPath(getApiRoute()).send(); } /** @@ -137,7 +137,7 @@ public void delete() throws IOException { */ public PagedIterable listCards() throws IOException { final GHProjectColumn column = this; - return root.retrieve() + return root.createRequest() .withPreview(INERTIA) .asPagedIterable(String.format("/projects/columns/%d/cards", id), GHProjectCard[].class, @@ -154,12 +154,12 @@ public PagedIterable listCards() throws IOException { * the io exception */ public GHProjectCard createCard(String note) throws IOException { - return root.retrieve() + return root.createRequest() .method("POST") .withPreview(INERTIA) .with("note", note) .withUrlPath(String.format("/projects/columns/%d/cards", id)) - .to(GHProjectCard.class) + .fetch(GHProjectCard.class) .wrap(this); } @@ -173,13 +173,13 @@ public GHProjectCard createCard(String note) throws IOException { * the io exception */ public GHProjectCard createCard(GHIssue issue) throws IOException { - return root.retrieve() + return root.createRequest() .method("POST") .withPreview(INERTIA) .with("content_type", issue instanceof GHPullRequest ? "PullRequest" : "Issue") .with("content_id", issue.getId()) .withUrlPath(String.format("/projects/columns/%d/cards", id)) - .to(GHProjectCard.class) + .fetch(GHProjectCard.class) .wrap(this); } } diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index af368ae258..fb891f7139 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -384,7 +384,7 @@ public void refresh() throws IOException { if (root.isOffline()) { return; // cannot populate, will have to live with what we have } - root.retrieve().withPreview(SHADOW_CAT).withUrlPath(url).to(this).wrapUp(owner); + root.createRequest().withPreview(SHADOW_CAT).withUrlPath(url).fetchInto(this).wrapUp(owner); } /** @@ -393,7 +393,7 @@ public void refresh() throws IOException { * @return the paged iterable */ public PagedIterable listFiles() { - return root.retrieve() + return root.createRequest() .asPagedIterable(String.format("%s/files", getApiRoute()), GHPullRequestFileDetail[].class, null); } @@ -403,7 +403,7 @@ public PagedIterable listFiles() { * @return the paged iterable */ public PagedIterable listReviews() { - return root.retrieve() + return root.createRequest() .asPagedIterable(String.format("%s/reviews", getApiRoute()), GHPullRequestReview[].class, item -> item.wrapUp(GHPullRequest.this)); @@ -417,7 +417,7 @@ public PagedIterable listReviews() { * the io exception */ public PagedIterable listReviewComments() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(getApiRoute() + COMMENTS_ACTION, GHPullRequestReviewComment[].class, item -> item.wrapUp(GHPullRequest.this)); @@ -429,7 +429,7 @@ public PagedIterable listReviewComments() throws IOE * @return the paged iterable */ public PagedIterable listCommits() { - return root.retrieve() + return root.createRequest() .asPagedIterable(String.format("%s/commits", getApiRoute()), GHPullRequestCommitDetail[].class, item -> item.wrapUp(GHPullRequest.this)); @@ -505,14 +505,14 @@ public GHPullRequestReviewBuilder createReview() { */ public GHPullRequestReviewComment createReviewComment(String body, String sha, String path, int position) throws IOException { - return root.retrieve() + return root.createRequest() .method("POST") .with("body", body) .with("commit_id", sha) .with("path", path) .with("position", position) .withUrlPath(getApiRoute() + COMMENTS_ACTION) - .to(GHPullRequestReviewComment.class) + .fetch(GHPullRequestReviewComment.class) .wrapUp(this); } @@ -525,11 +525,11 @@ public GHPullRequestReviewComment createReviewComment(String body, String sha, S * the io exception */ public void requestReviewers(List reviewers) throws IOException { - root.retrieve() + root.createRequest() .method("POST") .with("reviewers", getLogins(reviewers)) .withUrlPath(getApiRoute() + REQUEST_REVIEWERS) - .to(); + .send(); } /** @@ -545,11 +545,11 @@ public void requestTeamReviewers(List teams) throws IOException { for (GHTeam team : teams) { teamReviewers.add(team.getSlug()); } - root.retrieve() + root.createRequest() .method("POST") .with("team_reviewers", teamReviewers) .withUrlPath(getApiRoute() + REQUEST_REVIEWERS) - .to(); + .send(); } /** @@ -597,13 +597,13 @@ public void merge(String msg, String sha) throws IOException { * the io exception */ public void merge(String msg, String sha, MergeMethod method) throws IOException { - root.retrieve() + root.createRequest() .method("PUT") .with("commit_message", msg) .with("sha", sha) .with("merge_method", method) .withUrlPath(getApiRoute() + "/merge") - .to(); + .send(); } /** @@ -615,7 +615,7 @@ public enum MergeMethod { private void fetchIssue() throws IOException { if (!fetchedIssueDetails) { - root.retrieve().withUrlPath(getIssuesApiRoute()).to(this); + root.createRequest().withUrlPath(getIssuesApiRoute()).fetchInto(this); fetchedIssueDetails = true; } } diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReview.java b/src/main/java/org/kohsuke/github/GHPullRequestReview.java index 4754b45336..0498ce183f 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReview.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReview.java @@ -160,12 +160,12 @@ public void submit(String body, GHPullRequestReviewState state) throws IOExcepti * the io exception */ public void submit(String body, GHPullRequestReviewEvent event) throws IOException { - owner.root.retrieve() + owner.root.createRequest() .method("POST") .with("body", body) .with("event", event.action()) .withUrlPath(getApiRoute() + "/events") - .to(this); + .fetchInto(this); this.body = body; this.state = event.toState(); } @@ -177,7 +177,7 @@ public void submit(String body, GHPullRequestReviewEvent event) throws IOExcepti * the io exception */ public void delete() throws IOException { - owner.root.retrieve().method("DELETE").withUrlPath(getApiRoute()).to(); + owner.root.createRequest().method("DELETE").withUrlPath(getApiRoute()).send(); } /** @@ -189,7 +189,11 @@ public void delete() throws IOException { * the io exception */ public void dismiss(String message) throws IOException { - owner.root.retrieve().method("PUT").with("message", message).withUrlPath(getApiRoute() + "/dismissals").to(); + owner.root.createRequest() + .method("PUT") + .with("message", message) + .withUrlPath(getApiRoute() + "/dismissals") + .send(); state = GHPullRequestReviewState.DISMISSED; } @@ -201,7 +205,7 @@ public void dismiss(String message) throws IOException { * the io exception */ public PagedIterable listReviewComments() throws IOException { - return owner.root.retrieve() + return owner.root.createRequest() .asPagedIterable(getApiRoute() + "/comments", GHPullRequestReviewComment[].class, item -> item.wrapUp(owner)); diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java index 27a5550159..3a93777fd5 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReviewBuilder.java @@ -17,7 +17,7 @@ public class GHPullRequestReviewBuilder { GHPullRequestReviewBuilder(GHPullRequest pr) { this.pr = pr; - this.builder = pr.root.retrieve(); + this.builder = pr.root.createRequest(); } // public GHPullRequestReview createReview(@Nullable String commitId, String body, GHPullRequestReviewEvent event, @@ -92,7 +92,7 @@ public GHPullRequestReview create() throws IOException { return builder.method("POST") .with("comments", comments) .withUrlPath(pr.getApiRoute() + "/reviews") - .to(GHPullRequestReview.class) + .fetch(GHPullRequestReview.class) .wrapUp(pr); } diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java index 5b2e2b1dcc..4864b05b45 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java @@ -163,7 +163,7 @@ protected String getApiRoute() { * the io exception */ public void update(String body) throws IOException { - owner.root.retrieve().method("PATCH").with("body", body).withUrlPath(getApiRoute()).to(this); + owner.root.createRequest().method("PATCH").with("body", body).withUrlPath(getApiRoute()).fetchInto(this); this.body = body; } @@ -174,7 +174,7 @@ public void update(String body) throws IOException { * the io exception */ public void delete() throws IOException { - owner.root.retrieve().method("DELETE").withUrlPath(getApiRoute()).to(); + owner.root.createRequest().method("DELETE").withUrlPath(getApiRoute()).send(); } /** @@ -187,31 +187,31 @@ public void delete() throws IOException { * the io exception */ public GHPullRequestReviewComment reply(String body) throws IOException { - return owner.root.retrieve() + return owner.root.createRequest() .method("POST") .with("body", body) .with("in_reply_to", getId()) .withUrlPath(getApiRoute() + "/comments") - .to(GHPullRequestReviewComment.class) + .fetch(GHPullRequestReviewComment.class) .wrapUp(owner); } @Preview @Deprecated public GHReaction createReaction(ReactionContent content) throws IOException { - return owner.root.retrieve() + return owner.root.createRequest() .method("POST") .withPreview(SQUIRREL_GIRL) .with("content", content.getContent()) .withUrlPath(getApiRoute() + "/reactions") - .to(GHReaction.class) + .fetch(GHReaction.class) .wrap(owner.root); } @Preview @Deprecated public PagedIterable listReactions() { - return owner.root.retrieve() + return owner.root.createRequest() .withPreview(SQUIRREL_GIRL) .asPagedIterable(getApiRoute() + "/reactions", GHReaction[].class, item -> item.wrap(owner.root)); } diff --git a/src/main/java/org/kohsuke/github/GHQueryBuilder.java b/src/main/java/org/kohsuke/github/GHQueryBuilder.java index be63c7b324..b9ee5e061d 100644 --- a/src/main/java/org/kohsuke/github/GHQueryBuilder.java +++ b/src/main/java/org/kohsuke/github/GHQueryBuilder.java @@ -13,7 +13,7 @@ public abstract class GHQueryBuilder { GHQueryBuilder(GitHub root) { this.root = root; - this.req = root.retrieve(); + this.req = root.createRequest(); } /** diff --git a/src/main/java/org/kohsuke/github/GHReaction.java b/src/main/java/org/kohsuke/github/GHReaction.java index 158a289b41..2b0b80c391 100644 --- a/src/main/java/org/kohsuke/github/GHReaction.java +++ b/src/main/java/org/kohsuke/github/GHReaction.java @@ -58,6 +58,6 @@ public URL getHtmlUrl() { * the io exception */ public void delete() throws IOException { - root.retrieve().method("DELETE").withPreview(SQUIRREL_GIRL).withUrlPath("/reactions/" + id).to(); + root.createRequest().method("DELETE").withPreview(SQUIRREL_GIRL).withUrlPath("/reactions/" + id).send(); } } diff --git a/src/main/java/org/kohsuke/github/GHRef.java b/src/main/java/org/kohsuke/github/GHRef.java index c6370e1da0..75194a5357 100644 --- a/src/main/java/org/kohsuke/github/GHRef.java +++ b/src/main/java/org/kohsuke/github/GHRef.java @@ -66,12 +66,12 @@ public void updateTo(String sha) throws IOException { * the io exception */ public void updateTo(String sha, Boolean force) throws IOException { - root.retrieve() + root.createRequest() .method("PATCH") .with("sha", sha) .with("force", force) .withUrlPath(url) - .to(GHRef.class) + .fetch(GHRef.class) .wrap(root); } @@ -82,7 +82,7 @@ public void updateTo(String sha, Boolean force) throws IOException { * the io exception */ public void delete() throws IOException { - root.retrieve().method("DELETE").withUrlPath(url).to(); + root.createRequest().method("DELETE").withUrlPath(url).send(); } GHRef wrap(GitHub root) { diff --git a/src/main/java/org/kohsuke/github/GHRelease.java b/src/main/java/org/kohsuke/github/GHRelease.java index c3eff0594c..23e90916b3 100644 --- a/src/main/java/org/kohsuke/github/GHRelease.java +++ b/src/main/java/org/kohsuke/github/GHRelease.java @@ -240,12 +240,12 @@ public GHAsset uploadAsset(File file, String contentType) throws IOException { * the io exception */ public GHAsset uploadAsset(String filename, InputStream stream, String contentType) throws IOException { - Requester builder = owner.root.retrieve().method("POST"); + Requester builder = owner.root.createRequest().method("POST"); String url = getUploadUrl(); // strip the helpful garbage from the url url = url.substring(0, url.indexOf('{')); url += "?name=" + URLEncoder.encode(filename, "UTF-8"); - return builder.contentType(contentType).with(stream).withUrlPath(url).to(GHAsset.class).wrap(this); + return builder.contentType(contentType).with(stream).withUrlPath(url).fetch(GHAsset.class).wrap(this); } /** @@ -256,9 +256,9 @@ public GHAsset uploadAsset(String filename, InputStream stream, String contentTy * the io exception */ public List getAssets() throws IOException { - Requester builder = owner.root.retrieve(); + Requester builder = owner.root.createRequest(); - GHAsset[] assets = builder.withUrlPath(getApiTailUrl("assets")).toArray(GHAsset[].class); + GHAsset[] assets = builder.withUrlPath(getApiTailUrl("assets")).fetchArray(GHAsset[].class); return Arrays.asList(GHAsset.wrap(assets, this)); } @@ -269,7 +269,7 @@ public List getAssets() throws IOException { * the io exception */ public void delete() throws IOException { - root.retrieve().method("DELETE").withUrlPath(owner.getApiTailUrl("releases/" + id)).to(); + root.createRequest().method("DELETE").withUrlPath(owner.getApiTailUrl("releases/" + id)).send(); } /** diff --git a/src/main/java/org/kohsuke/github/GHReleaseBuilder.java b/src/main/java/org/kohsuke/github/GHReleaseBuilder.java index 1333cccd37..6c0914def1 100644 --- a/src/main/java/org/kohsuke/github/GHReleaseBuilder.java +++ b/src/main/java/org/kohsuke/github/GHReleaseBuilder.java @@ -21,7 +21,7 @@ public class GHReleaseBuilder { */ public GHReleaseBuilder(GHRepository ghRepository, String tag) { this.repo = ghRepository; - this.builder = repo.root.retrieve().method("POST"); + this.builder = repo.root.createRequest().method("POST"); builder.with("tag_name", tag); } @@ -95,6 +95,6 @@ public GHReleaseBuilder prerelease(boolean prerelease) { * the io exception */ public GHRelease create() throws IOException { - return builder.withUrlPath(repo.getApiTailUrl("releases")).to(GHRelease.class).wrap(repo); + return builder.withUrlPath(repo.getApiTailUrl("releases")).fetch(GHRelease.class).wrap(repo); } } diff --git a/src/main/java/org/kohsuke/github/GHReleaseUpdater.java b/src/main/java/org/kohsuke/github/GHReleaseUpdater.java index b9a3106ef5..4d1b69b89e 100644 --- a/src/main/java/org/kohsuke/github/GHReleaseUpdater.java +++ b/src/main/java/org/kohsuke/github/GHReleaseUpdater.java @@ -14,7 +14,7 @@ public class GHReleaseUpdater { GHReleaseUpdater(GHRelease base) { this.base = base; - this.builder = base.root.retrieve(); + this.builder = base.root.createRequest(); } /** @@ -101,7 +101,7 @@ public GHReleaseUpdater prerelease(boolean prerelease) { public GHRelease update() throws IOException { return builder.method("PATCH") .withUrlPath(base.owner.getApiTailUrl("releases/" + base.id)) - .to(GHRelease.class) + .fetch(GHRelease.class) .wrap(base.owner); } diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 02dcfda100..a76dd5b1e7 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -134,7 +134,7 @@ public PagedIterable getDeploymentStatuses(final int id) thr * @return the paged iterable */ public PagedIterable listDeployments(String sha, String ref, String task, String environment) { - return root.retrieve() + return root.createRequest() .with("sha", sha) .with("ref", ref) .with("task", task) @@ -154,7 +154,10 @@ public PagedIterable listDeployments(String sha, String ref, Strin * the io exception */ public GHDeployment getDeployment(long id) throws IOException { - return root.retrieve().withUrlPath(getApiTailUrl("deployments/" + id)).to(GHDeployment.class).wrap(this); + return root.createRequest() + .withUrlPath(getApiTailUrl("deployments/" + id)) + .fetch(GHDeployment.class) + .wrap(this); } /** @@ -332,7 +335,7 @@ public GHUser getOwner() throws IOException { * the io exception */ public GHIssue getIssue(int id) throws IOException { - return root.retrieve().withUrlPath(getApiTailUrl("issues/" + id)).to(GHIssue.class).wrap(this); + return root.createRequest().withUrlPath(getApiTailUrl("issues/" + id)).fetch(GHIssue.class).wrap(this); } /** @@ -371,11 +374,11 @@ public List getIssues(GHIssueState state) throws IOException { * the io exception */ public List getIssues(GHIssueState state, GHMilestone milestone) throws IOException { - Requester requester = root.retrieve() + Requester requester = root.createRequest() .with("state", state) .with("milestone", milestone == null ? "none" : "" + milestone.getNumber()); return Arrays - .asList(GHIssue.wrap(requester.withUrlPath(getApiTailUrl("issues")).toArray(GHIssue[].class), this)); + .asList(GHIssue.wrap(requester.withUrlPath(getApiTailUrl("issues")).fetchArray(GHIssue[].class), this)); } /** @@ -386,7 +389,7 @@ public List getIssues(GHIssueState state, GHMilestone milestone) throws * @return the paged iterable */ public PagedIterable listIssues(final GHIssueState state) { - return root.retrieve() + return root.createRequest() .with("state", state) .asPagedIterable(getApiTailUrl("issues"), GHIssue[].class, item -> item.wrap(GHRepository.this)); } @@ -415,12 +418,12 @@ public GHReleaseBuilder createRelease(String tag) { * the io exception */ public GHRef createRef(String name, String sha) throws IOException { - return root.retrieve() + return root.createRequest() .method("POST") .with("ref", name) .with("sha", sha) .withUrlPath(getApiTailUrl("git/refs")) - .to(GHRef.class) + .fetch(GHRef.class) .wrap(root); } @@ -447,7 +450,7 @@ public List getReleases() throws IOException { */ public GHRelease getRelease(long id) throws IOException { try { - return root.retrieve().withUrlPath(getApiTailUrl("releases/" + id)).to(GHRelease.class).wrap(this); + return root.createRequest().withUrlPath(getApiTailUrl("releases/" + id)).fetch(GHRelease.class).wrap(this); } catch (FileNotFoundException e) { return null; // no release for this id } @@ -464,7 +467,10 @@ public GHRelease getRelease(long id) throws IOException { */ public GHRelease getReleaseByTagName(String tag) throws IOException { try { - return root.retrieve().withUrlPath(getApiTailUrl("releases/tags/" + tag)).to(GHRelease.class).wrap(this); + return root.createRequest() + .withUrlPath(getApiTailUrl("releases/tags/" + tag)) + .fetch(GHRelease.class) + .wrap(this); } catch (FileNotFoundException e) { return null; // no release for this tag } @@ -479,7 +485,7 @@ public GHRelease getReleaseByTagName(String tag) throws IOException { */ public GHRelease getLatestRelease() throws IOException { try { - return root.retrieve().withUrlPath(getApiTailUrl("releases/latest")).to(GHRelease.class).wrap(this); + return root.createRequest().withUrlPath(getApiTailUrl("releases/latest")).fetch(GHRelease.class).wrap(this); } catch (FileNotFoundException e) { return null; // no latest release } @@ -493,7 +499,7 @@ public GHRelease getLatestRelease() throws IOException { * the io exception */ public PagedIterable listReleases() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(getApiTailUrl("releases"), GHRelease[].class, item -> item.wrap(GHRepository.this)); } @@ -505,7 +511,7 @@ public PagedIterable listReleases() throws IOException { * the io exception */ public PagedIterable listTags() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(getApiTailUrl("tags"), GHTag[].class, item -> item.wrap(GHRepository.this)); } @@ -518,7 +524,7 @@ public PagedIterable listTags() throws IOException { * the io exception */ public Map listLanguages() throws IOException { - return root.retrieve().withUrlPath(getApiTailUrl("languages")).to(HashMap.class); + return root.createRequest().withUrlPath(getApiTailUrl("languages")).fetch(HashMap.class); } /** @@ -763,7 +769,8 @@ public PagedIterable listAssignees() throws IOException { * the io exception */ public boolean hasAssignee(GHUser u) throws IOException { - return root.retrieve().withUrlPath(getApiTailUrl("assignees/" + u.getLogin())).asHttpStatusCode() / 100 == 2; + return root.createRequest().withUrlPath(getApiTailUrl("assignees/" + u.getLogin())).fetchHttpStatusCode() + / 100 == 2; } /** @@ -776,7 +783,8 @@ public boolean hasAssignee(GHUser u) throws IOException { */ public Set getCollaboratorNames() throws IOException { Set r = new HashSet(); - for (GHUser u : GHUser.wrap(root.retrieve().withUrlPath(getApiTailUrl("collaborators")).toArray(GHUser[].class), + for (GHUser u : GHUser.wrap( + root.createRequest().withUrlPath(getApiTailUrl("collaborators")).fetchArray(GHUser[].class), root)) r.add(u.login); return r; @@ -792,9 +800,9 @@ public Set getCollaboratorNames() throws IOException { * the io exception */ public GHPermissionType getPermission(String user) throws IOException { - GHPermission perm = root.retrieve() + GHPermission perm = root.createRequest() .withUrlPath(getApiTailUrl("collaborators/" + user + "/permission")) - .to(GHPermission.class); + .fetch(GHPermission.class); perm.wrapUp(root); return perm.getPermissionType(); } @@ -820,8 +828,8 @@ public GHPermissionType getPermission(GHUser u) throws IOException { * the io exception */ public Set getTeams() throws IOException { - return Collections.unmodifiableSet(new HashSet( - Arrays.asList(GHTeam.wrapUp(root.retrieve().withUrlPath(getApiTailUrl("teams")).toArray(GHTeam[].class), + return Collections.unmodifiableSet(new HashSet(Arrays.asList( + GHTeam.wrapUp(root.createRequest().withUrlPath(getApiTailUrl("teams")).fetchArray(GHTeam[].class), root.getOrganization(getOwnerName()))))); } @@ -875,7 +883,7 @@ public void removeCollaborators(Collection users) throws IOException { private void modifyCollaborators(Collection users, String method) throws IOException { for (GHUser user : users) { - root.retrieve().method(method).withUrlPath(getApiTailUrl("collaborators/" + user.getLogin())).to(); + root.createRequest().method(method).withUrlPath(getApiTailUrl("collaborators/" + user.getLogin())).send(); } } @@ -890,20 +898,20 @@ private void modifyCollaborators(Collection users, String method) throws public void setEmailServiceHook(String address) throws IOException { Map config = new HashMap(); config.put("address", address); - root.retrieve() + root.createRequest() .method("POST") .with("name", "email") .with("config", config) .with("active", true) .withUrlPath(getApiTailUrl("hooks")) - .to(); + .send(); } private void edit(String key, String value) throws IOException { - Requester requester = root.retrieve(); + Requester requester = root.createRequest(); if (!key.equals("name")) requester.with("name", name); // even when we don't change the name, we need to send it in - requester.with(key, value).method("PATCH").withUrlPath(getApiTailUrl("")).to(); + requester.with(key, value).method("PATCH").withUrlPath(getApiTailUrl("")).send(); } /** @@ -1046,7 +1054,7 @@ public void allowRebaseMerge(boolean value) throws IOException { */ public void delete() throws IOException { try { - root.retrieve().method("DELETE").withUrlPath(getApiTailUrl("")).to(); + root.createRequest().method("DELETE").withUrlPath(getApiTailUrl("")).send(); } catch (FileNotFoundException x) { throw (FileNotFoundException) new FileNotFoundException("Failed to delete " + getOwnerName() + "/" + name + "; might not exist, or you might need the delete_repo scope in your token: http://stackoverflow.com/a/19327004/12916") @@ -1104,7 +1112,7 @@ public PagedIterable listForks() { * @return the paged iterable */ public PagedIterable listForks(final ForkSort sort) { - return root.retrieve() + return root.createRequest() .with("sort", sort) .asPagedIterable(getApiTailUrl("forks"), GHRepository[].class, item -> item.wrap(root)); } @@ -1117,7 +1125,7 @@ public PagedIterable listForks(final ForkSort sort) { * the io exception */ public GHRepository fork() throws IOException { - root.retrieve().method("POST").withUrlPath(getApiTailUrl("forks")).to(); + root.createRequest().method("POST").withUrlPath(getApiTailUrl("forks")).send(); // this API is asynchronous. we need to wait for a bit for (int i = 0; i < 10; i++) { @@ -1143,7 +1151,11 @@ public GHRepository fork() throws IOException { * the io exception */ public GHRepository forkTo(GHOrganization org) throws IOException { - root.retrieve().method("POST").with("organization", org.getLogin()).withUrlPath(getApiTailUrl("forks")).to(); + root.createRequest() + .method("POST") + .with("organization", org.getLogin()) + .withUrlPath(getApiTailUrl("forks")) + .send(); // this API is asynchronous. we need to wait for a bit for (int i = 0; i < 10; i++) { @@ -1169,10 +1181,10 @@ public GHRepository forkTo(GHOrganization org) throws IOException { * the io exception */ public GHPullRequest getPullRequest(int i) throws IOException { - return root.retrieve() + return root.createRequest() .withPreview(SHADOW_CAT) .withUrlPath(getApiTailUrl("pulls/" + i)) - .to(GHPullRequest.class) + .fetch(GHPullRequest.class) .wrapUp(this); } @@ -1286,7 +1298,7 @@ public GHPullRequest createPullRequest(String title, String body, boolean maintainerCanModify, boolean draft) throws IOException { - return root.retrieve() + return root.createRequest() .method("POST") .withPreview(SHADOW_CAT) .with("title", title) @@ -1296,7 +1308,7 @@ public GHPullRequest createPullRequest(String title, .with("maintainer_can_modify", maintainerCanModify) .with("draft", draft) .withUrlPath(getApiTailUrl("pulls")) - .to(GHPullRequest.class) + .fetch(GHPullRequest.class) .wrapUp(this); } @@ -1338,9 +1350,9 @@ public GHHook getHook(int id) throws IOException { * on failure communicating with GitHub */ public GHCompare getCompare(String id1, String id2) throws IOException { - GHCompare compare = root.retrieve() + GHCompare compare = root.createRequest() .withUrlPath(getApiTailUrl(String.format("compare/%s...%s", id1, id2))) - .to(GHCompare.class); + .fetch(GHCompare.class); return compare.wrap(this); } @@ -1398,9 +1410,9 @@ public GHCompare getCompare(GHBranch id1, GHBranch id2) throws IOException { * on failure communicating with GitHub */ public GHRef[] getRefs() throws IOException { - return GHRef.wrap(root.retrieve() + return GHRef.wrap(root.createRequest() .withUrlPath(String.format("/repos/%s/%s/git/refs", getOwnerName(), name)) - .toArray(GHRef[].class), root); + .fetchArray(GHRef[].class), root); } /** @@ -1412,7 +1424,7 @@ public GHRef[] getRefs() throws IOException { */ public PagedIterable listRefs() throws IOException { final String url = String.format("/repos/%s/%s/git/refs", getOwnerName(), name); - return root.retrieve().asPagedIterable(url, GHRef[].class, item -> item.wrap(root)); + return root.createRequest().asPagedIterable(url, GHRef[].class, item -> item.wrap(root)); } /** @@ -1425,9 +1437,9 @@ public PagedIterable listRefs() throws IOException { * on failure communicating with GitHub, potentially due to an invalid ref type being requested */ public GHRef[] getRefs(String refType) throws IOException { - return GHRef.wrap(root.retrieve() + return GHRef.wrap(root.createRequest() .withUrlPath(String.format("/repos/%s/%s/git/refs/%s", getOwnerName(), name, refType)) - .toArray(GHRef[].class), root); + .fetchArray(GHRef[].class), root); } /** @@ -1441,7 +1453,7 @@ public GHRef[] getRefs(String refType) throws IOException { */ public PagedIterable listRefs(String refType) throws IOException { final String url = String.format("/repos/%s/%s/git/refs/%s", getOwnerName(), name, refType); - return root.retrieve().asPagedIterable(url, GHRef[].class, item -> item.wrap(root)); + return root.createRequest().asPagedIterable(url, GHRef[].class, item -> item.wrap(root)); } /** @@ -1454,9 +1466,9 @@ public PagedIterable listRefs(String refType) throws IOException { * on failure communicating with GitHub, potentially due to an invalid ref type being requested */ public GHRef getRef(String refName) throws IOException { - return root.retrieve() + return root.createRequest() .withUrlPath(getApiTailUrl(String.format("git/refs/%s", refName))) - .to(GHRef.class) + .fetch(GHRef.class) .wrap(root); } @@ -1471,7 +1483,7 @@ public GHRef getRef(String refName) throws IOException { * the io exception */ public GHTagObject getTagObject(String sha) throws IOException { - return root.retrieve().withUrlPath(getApiTailUrl("git/tags/" + sha)).to(GHTagObject.class).wrap(this); + return root.createRequest().withUrlPath(getApiTailUrl("git/tags/" + sha)).fetch(GHTagObject.class).wrap(this); } /** @@ -1485,7 +1497,7 @@ public GHTagObject getTagObject(String sha) throws IOException { */ public GHTree getTree(String sha) throws IOException { String url = String.format("/repos/%s/%s/git/trees/%s", getOwnerName(), name, sha); - return root.retrieve().withUrlPath(url).to(GHTree.class).wrap(this); + return root.createRequest().withUrlPath(url).fetch(GHTree.class).wrap(this); } /** @@ -1511,7 +1523,7 @@ public GHTreeBuilder createTree() { */ public GHTree getTreeRecursive(String sha, int recursive) throws IOException { String url = String.format("/repos/%s/%s/git/trees/%s", getOwnerName(), name, sha); - return root.retrieve().with("recursive", recursive).withUrlPath(url).to(GHTree.class).wrap(this); + return root.createRequest().with("recursive", recursive).withUrlPath(url).fetch(GHTree.class).wrap(this); } /** @@ -1530,7 +1542,7 @@ public GHTree getTreeRecursive(String sha, int recursive) throws IOException { */ public GHBlob getBlob(String blobSha) throws IOException { String target = getApiTailUrl("git/blobs/" + blobSha); - return root.retrieve().withUrlPath(target).to(GHBlob.class); + return root.createRequest().withUrlPath(target).fetch(GHBlob.class); } /** @@ -1555,10 +1567,10 @@ public GHBlobBuilder createBlob() { */ public InputStream readBlob(String blobSha) throws IOException { String target = getApiTailUrl("git/blobs/" + blobSha); - return root.retrieve() + return root.createRequest() .withHeader("Accept", "application/vnd.github.VERSION.raw") .withUrlPath(target) - .toStream(); + .fetchStream(); } /** @@ -1573,9 +1585,9 @@ public InputStream readBlob(String blobSha) throws IOException { public GHCommit getCommit(String sha1) throws IOException { GHCommit c = commits.get(sha1); if (c == null) { - c = root.retrieve() + c = root.createRequest() .withUrlPath(String.format("/repos/%s/%s/commits/%s", getOwnerName(), name, sha1)) - .to(GHCommit.class) + .fetch(GHCommit.class) .wrapUp(this); commits.put(sha1, c); } @@ -1597,7 +1609,7 @@ public GHCommitBuilder createCommit() { * @return the paged iterable */ public PagedIterable listCommits() { - return root.retrieve() + return root.createRequest() .asPagedIterable(String.format("/repos/%s/%s/commits", getOwnerName(), name), GHCommit[].class, item -> item.wrapUp(GHRepository.this)); @@ -1618,7 +1630,7 @@ public GHCommitQueryBuilder queryCommits() { * @return the paged iterable */ public PagedIterable listCommitComments() { - return root.retrieve() + return root.createRequest() .asPagedIterable(String.format("/repos/%s/%s/comments", getOwnerName(), name), GHCommitComment[].class, item -> item.wrap(GHRepository.this)); @@ -1651,7 +1663,10 @@ public GHContent getLicenseContent() throws IOException { private GHContentWithLicense getLicenseContent_() throws IOException { try { - return root.retrieve().withUrlPath(getApiTailUrl("license")).to(GHContentWithLicense.class).wrap(this); + return root.createRequest() + .withUrlPath(getApiTailUrl("license")) + .fetch(GHContentWithLicense.class) + .wrap(this); } catch (FileNotFoundException e) { return null; } @@ -1667,7 +1682,7 @@ private GHContentWithLicense getLicenseContent_() throws IOException { * the io exception */ public PagedIterable listCommitStatuses(final String sha1) throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(String.format("/repos/%s/%s/statuses/%s", getOwnerName(), name, sha1), GHCommitStatus[].class, item -> item.wrapUp(root)); @@ -1709,14 +1724,14 @@ public GHCommitStatus createCommitStatus(String sha1, String targetUrl, String description, String context) throws IOException { - return root.retrieve() + return root.createRequest() .method("POST") .with("state", state) .with("target_url", targetUrl) .with("description", description) .with("context", context) .withUrlPath(String.format("/repos/%s/%s/statuses/%s", getOwnerName(), this.name, sha1)) - .to(GHCommitStatus.class) + .fetch(GHCommitStatus.class) .wrapUp(root); } @@ -1750,7 +1765,7 @@ public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, Strin * the io exception */ public PagedIterable listEvents() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(String.format("/repos/%s/%s/events", getOwnerName(), name), GHEventInfo[].class, item -> item.wrapUp(root)); @@ -1766,7 +1781,7 @@ public PagedIterable listEvents() throws IOException { * the io exception */ public PagedIterable listLabels() throws IOException { - return root.retrieve() + return root.createRequest() .withPreview(SYMMETRA) .asPagedIterable(getApiTailUrl("labels"), GHLabel[].class, item -> item.wrapUp(GHRepository.this)); } @@ -1781,10 +1796,10 @@ public PagedIterable listLabels() throws IOException { * the io exception */ public GHLabel getLabel(String name) throws IOException { - return root.retrieve() + return root.createRequest() .withPreview(SYMMETRA) .withUrlPath(getApiTailUrl("labels/" + name)) - .to(GHLabel.class) + .fetch(GHLabel.class) .wrapUp(this); } @@ -1819,14 +1834,14 @@ public GHLabel createLabel(String name, String color) throws IOException { @Preview @Deprecated public GHLabel createLabel(String name, String color, String description) throws IOException { - return root.retrieve() + return root.createRequest() .method("POST") .withPreview(SYMMETRA) .with("name", name) .with("color", color) .with("description", description) .withUrlPath(getApiTailUrl("labels")) - .to(GHLabel.class) + .fetch(GHLabel.class) .wrapUp(this); } @@ -1836,7 +1851,7 @@ public GHLabel createLabel(String name, String color, String description) throws * @return the paged iterable */ public PagedIterable listInvitations() { - return root.retrieve() + return root.createRequest() .asPagedIterable(String.format("/repos/%s/%s/invitations", getOwnerName(), name), GHInvitation[].class, item -> item.wrapUp(root)); @@ -1870,7 +1885,7 @@ public PagedIterable listStargazers() { * @return the paged iterable */ public PagedIterable listStargazers2() { - return root.retrieve() + return root.createRequest() .withPreview("application/vnd.github.v3.star+json") .asPagedIterable(getApiTailUrl("stargazers"), GHStargazer[].class, @@ -1878,7 +1893,7 @@ public PagedIterable listStargazers2() { } private PagedIterable listUsers(final String suffix) { - return root.retrieve().asPagedIterable(getApiTailUrl(suffix), GHUser[].class, item -> item.wrapUp(root)); + return root.createRequest().asPagedIterable(getApiTailUrl(suffix), GHUser[].class, item -> item.wrapUp(root)); } /** @@ -2026,7 +2041,7 @@ GHRepository wrap(GitHub root) { */ public Map getBranches() throws IOException { Map r = new TreeMap(); - for (GHBranch p : root.retrieve().withUrlPath(getApiTailUrl("branches")).toArray(GHBranch[].class)) { + for (GHBranch p : root.createRequest().withUrlPath(getApiTailUrl("branches")).fetchArray(GHBranch[].class)) { p.wrap(this); r.put(p.getName(), p); } @@ -2043,7 +2058,7 @@ public Map getBranches() throws IOException { * the io exception */ public GHBranch getBranch(String name) throws IOException { - return root.retrieve().withUrlPath(getApiTailUrl("branches/" + name)).to(GHBranch.class).wrap(this); + return root.createRequest().withUrlPath(getApiTailUrl("branches/" + name)).fetch(GHBranch.class).wrap(this); } /** @@ -2070,7 +2085,7 @@ public Map getMilestones() throws IOException { * @return the paged iterable */ public PagedIterable listMilestones(final GHIssueState state) { - return root.retrieve() + return root.createRequest() .with("state", state) .asPagedIterable(getApiTailUrl("milestones"), GHMilestone[].class, @@ -2089,7 +2104,7 @@ public PagedIterable listMilestones(final GHIssueState state) { public GHMilestone getMilestone(int number) throws IOException { GHMilestone m = milestones.get(number); if (m == null) { - m = root.retrieve().withUrlPath(getApiTailUrl("milestones/" + number)).to(GHMilestone.class); + m = root.createRequest().withUrlPath(getApiTailUrl("milestones/" + number)).fetch(GHMilestone.class); m.owner = this; m.root = root; milestones.put(m.getNumber(), m); @@ -2122,10 +2137,10 @@ public GHContent getFileContent(String path) throws IOException { * the io exception */ public GHContent getFileContent(String path, String ref) throws IOException { - Requester requester = root.retrieve(); + Requester requester = root.createRequest(); String target = getApiTailUrl("contents/" + path); - return requester.with("ref", ref).withUrlPath(target).to(GHContent.class).wrap(this); + return requester.with("ref", ref).withUrlPath(target).fetch(GHContent.class).wrap(this); } /** @@ -2153,13 +2168,13 @@ public List getDirectoryContent(String path) throws IOException { * the io exception */ public List getDirectoryContent(String path, String ref) throws IOException { - Requester requester = root.retrieve(); + Requester requester = root.createRequest(); while (path.endsWith("/")) { path = path.substring(0, path.length() - 1); } String target = getApiTailUrl("contents/" + path); - GHContent[] files = requester.with("ref", ref).withUrlPath(target).toArray(GHContent[].class); + GHContent[] files = requester.with("ref", ref).withUrlPath(target).fetchArray(GHContent[].class); GHContent.wrap(files, this); @@ -2174,8 +2189,8 @@ public List getDirectoryContent(String path, String ref) throws IOExc * the io exception */ public GHContent getReadme() throws IOException { - Requester requester = root.retrieve(); - return requester.withUrlPath(getApiTailUrl("readme")).to(GHContent.class).wrap(this); + Requester requester = root.createRequest(); + return requester.withUrlPath(getApiTailUrl("readme")).fetch(GHContent.class).wrap(this); } /** @@ -2278,12 +2293,12 @@ public GHContentUpdateResponse createContent(byte[] contentBytes, String commitM * the io exception */ public GHMilestone createMilestone(String title, String description) throws IOException { - return root.retrieve() + return root.createRequest() .method("POST") .with("title", title) .with("description", description) .withUrlPath(getApiTailUrl("milestones")) - .to(GHMilestone.class) + .fetch(GHMilestone.class) .wrap(this); } @@ -2299,12 +2314,12 @@ public GHMilestone createMilestone(String title, String description) throws IOEx * the io exception */ public GHDeployKey addDeployKey(String title, String key) throws IOException { - return root.retrieve() + return root.createRequest() .method("POST") .with("title", title) .with("key", key) .withUrlPath(getApiTailUrl("keys")) - .to(GHDeployKey.class) + .fetch(GHDeployKey.class) .wrap(this); } @@ -2318,7 +2333,7 @@ public GHDeployKey addDeployKey(String title, String key) throws IOException { */ public List getDeployKeys() throws IOException { List list = new ArrayList( - Arrays.asList(root.retrieve().withUrlPath(getApiTailUrl("keys")).toArray(GHDeployKey[].class))); + Arrays.asList(root.createRequest().withUrlPath(getApiTailUrl("keys")).fetchArray(GHDeployKey[].class))); for (GHDeployKey h : list) h.wrap(this); return list; @@ -2371,12 +2386,12 @@ public GHRepository getParent() throws IOException { * the io exception */ public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOException { - return root.retrieve() + return root.createRequest() .method("PUT") .with("subscribed", subscribed) .with("ignored", ignored) .withUrlPath(getApiTailUrl("subscription")) - .to(GHSubscription.class) + .fetch(GHSubscription.class) .wrapUp(this); } @@ -2389,7 +2404,10 @@ public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOEx */ public GHSubscription getSubscription() throws IOException { try { - return root.retrieve().withUrlPath(getApiTailUrl("subscription")).to(GHSubscription.class).wrapUp(this); + return root.createRequest() + .withUrlPath(getApiTailUrl("subscription")) + .fetch(GHSubscription.class) + .wrapUp(this); } catch (FileNotFoundException e) { return null; } @@ -2403,7 +2421,7 @@ public GHSubscription getSubscription() throws IOException { * the io exception */ public PagedIterable listContributors() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(getApiTailUrl("contributors"), Contributor[].class, item -> item.wrapUp(root)); } @@ -2458,13 +2476,13 @@ public GHRepositoryStatistics getStatistics() { * the io exception */ public GHProject createProject(String name, String body) throws IOException { - return root.retrieve() + return root.createRequest() .method("POST") .withPreview(INERTIA) .with("name", name) .with("body", body) .withUrlPath(getApiTailUrl("projects")) - .to(GHProject.class) + .fetch(GHProject.class) .wrap(this); } @@ -2478,7 +2496,7 @@ public GHProject createProject(String name, String body) throws IOException { * the io exception */ public PagedIterable listProjects(final GHProject.ProjectStateFilter status) throws IOException { - return root.retrieve() + return root.createRequest() .withPreview(INERTIA) .with("state", status) .asPagedIterable(getApiTailUrl("projects"), GHProject[].class, item -> item.wrap(GHRepository.this)); @@ -2511,13 +2529,13 @@ public PagedIterable listProjects() throws IOException { */ public Reader renderMarkdown(String text, MarkdownMode mode) throws IOException { return new InputStreamReader( - root.retrieve() + root.createRequest() .method("POST") .with("text", text) .with("mode", mode == null ? null : mode.toString()) .with("context", getFullName()) .withUrlPath("/markdown") - .toStream(), + .fetchStream(), "UTF-8"); } @@ -2539,7 +2557,7 @@ public GHNotificationStream listNotifications() { * the io exception */ public GHRepositoryViewTraffic getViewTraffic() throws IOException { - return root.retrieve().withUrlPath(getApiTailUrl("/traffic/views")).to(GHRepositoryViewTraffic.class); + return root.createRequest().withUrlPath(getApiTailUrl("/traffic/views")).fetch(GHRepositoryViewTraffic.class); } /** @@ -2551,7 +2569,7 @@ public GHRepositoryViewTraffic getViewTraffic() throws IOException { * the io exception */ public GHRepositoryCloneTraffic getCloneTraffic() throws IOException { - return root.retrieve().withUrlPath(getApiTailUrl("/traffic/clones")).to(GHRepositoryCloneTraffic.class); + return root.createRequest().withUrlPath(getApiTailUrl("/traffic/clones")).fetch(GHRepositoryCloneTraffic.class); } @Override @@ -2583,7 +2601,7 @@ String getApiTailUrl(String tail) { * the io exception */ public PagedIterable listIssueEvents() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(getApiTailUrl("issues/events"), GHIssueEvent[].class, item -> item.wrapUp(root)); } @@ -2597,7 +2615,10 @@ public PagedIterable listIssueEvents() throws IOException { * the io exception */ public GHIssueEvent getIssueEvent(long id) throws IOException { - return root.retrieve().withUrlPath(getApiTailUrl("issues/events/" + id)).to(GHIssueEvent.class).wrapUp(root); + return root.createRequest() + .withUrlPath(getApiTailUrl("issues/events/" + id)) + .fetch(GHIssueEvent.class) + .wrapUp(root); } // Only used within listTopics(). @@ -2614,7 +2635,10 @@ private static class Topics { * the io exception */ public List listTopics() throws IOException { - Topics topics = root.retrieve().withPreview(MERCY).withUrlPath(getApiTailUrl("topics")).to(Topics.class); + Topics topics = root.createRequest() + .withPreview(MERCY) + .withUrlPath(getApiTailUrl("topics")) + .fetch(Topics.class); return topics.names; } @@ -2628,11 +2652,11 @@ public List listTopics() throws IOException { * the io exception */ public void setTopics(List topics) throws IOException { - root.retrieve() + root.createRequest() .method("PUT") .with("names", topics) .withPreview(MERCY) .withUrlPath(getApiTailUrl("topics")) - .to(); + .send(); } } diff --git a/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java b/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java index 9d6ea70654..49b30bae70 100644 --- a/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java +++ b/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java @@ -87,7 +87,7 @@ public PagedIterable getContributorStats(boolean waitTillReady * This gets the actual statistics from the server. Returns null if they are still being cached. */ private PagedIterable getContributorStatsImpl() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(getApiTailUrl("contributors"), ContributorStats[].class, item -> item.wrapUp(root)); } @@ -243,7 +243,7 @@ ContributorStats wrapUp(GitHub root) { * the io exception */ public PagedIterable getCommitActivity() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(getApiTailUrl("commit_activity"), CommitActivity[].class, item -> item.wrapUp(root)); } @@ -318,7 +318,7 @@ public List getCodeFrequency() throws IOException { // Map to ArrayLists first, since there are no field names in the // returned JSON. try { - InputStream stream = root.retrieve().withUrlPath(getApiTailUrl("code_frequency")).toStream(); + InputStream stream = root.createRequest().withUrlPath(getApiTailUrl("code_frequency")).fetchStream(); ObjectMapper mapper = new ObjectMapper(); TypeReference>> typeRef = new TypeReference>>() { @@ -400,7 +400,7 @@ public String toString() { * the io exception */ public Participation getParticipation() throws IOException { - return root.retrieve().withUrlPath(getApiTailUrl("participation")).to(Participation.class); + return root.createRequest().withUrlPath(getApiTailUrl("participation")).fetch(Participation.class); } /** @@ -460,7 +460,7 @@ Participation wrapUp(GitHub root) { public List getPunchCard() throws IOException { // Map to ArrayLists first, since there are no field names in the // returned JSON. - InputStream stream = root.retrieve().withUrlPath(getApiTailUrl("punch_card")).toStream(); + InputStream stream = root.createRequest().withUrlPath(getApiTailUrl("punch_card")).fetchStream(); ObjectMapper mapper = new ObjectMapper(); TypeReference>> typeRef = new TypeReference>>() { diff --git a/src/main/java/org/kohsuke/github/GHSubscription.java b/src/main/java/org/kohsuke/github/GHSubscription.java index 6fabc87490..b3e7da4fa8 100644 --- a/src/main/java/org/kohsuke/github/GHSubscription.java +++ b/src/main/java/org/kohsuke/github/GHSubscription.java @@ -87,7 +87,7 @@ public GHRepository getRepository() { * the io exception */ public void delete() throws IOException { - root.retrieve().method("DELETE").withUrlPath(repo.getApiTailUrl("subscription")).to(); + root.createRequest().method("DELETE").withUrlPath(repo.getApiTailUrl("subscription")).send(); } GHSubscription wrapUp(GHRepository repo) { diff --git a/src/main/java/org/kohsuke/github/GHTeam.java b/src/main/java/org/kohsuke/github/GHTeam.java index f2f8d35992..b0f6f3c862 100644 --- a/src/main/java/org/kohsuke/github/GHTeam.java +++ b/src/main/java/org/kohsuke/github/GHTeam.java @@ -103,7 +103,7 @@ public String getDescription() { * the io exception */ public void setDescription(String description) throws IOException { - root.retrieve().method("PATCH").with("description", description).withUrlPath(api("")).to(); + root.createRequest().method("PATCH").with("description", description).withUrlPath(api("")).send(); } /** @@ -123,7 +123,7 @@ public int getId() { * the io exception */ public PagedIterable listMembers() throws IOException { - return root.retrieve().asPagedIterable(api("/members"), GHUser[].class, item -> item.wrapUp(root)); + return root.createRequest().asPagedIterable(api("/members"), GHUser[].class, item -> item.wrapUp(root)); } /** @@ -146,7 +146,7 @@ public Set getMembers() throws IOException { */ public boolean hasMember(GHUser user) { try { - root.retrieve().withUrlPath("/teams/" + id + "/members/" + user.getLogin()).to(); + root.createRequest().withUrlPath("/teams/" + id + "/members/" + user.getLogin()).send(); return true; } catch (IOException ignore) { return false; @@ -174,7 +174,7 @@ public Map getRepositories() throws IOException { * @return the paged iterable */ public PagedIterable listRepositories() { - return root.retrieve().asPagedIterable(api("/repos"), GHRepository[].class, item -> item.wrap(root)); + return root.createRequest().asPagedIterable(api("/repos"), GHRepository[].class, item -> item.wrap(root)); } /** @@ -189,7 +189,7 @@ public PagedIterable listRepositories() { * @since 1.59 */ public void add(GHUser u) throws IOException { - root.retrieve().method("PUT").withUrlPath(api("/memberships/" + u.getLogin())).to(); + root.createRequest().method("PUT").withUrlPath(api("/memberships/" + u.getLogin())).send(); } /** @@ -205,7 +205,11 @@ public void add(GHUser u) throws IOException { * the io exception */ public void add(GHUser user, Role role) throws IOException { - root.retrieve().method("PUT").with("role", role).withUrlPath(api("/memberships/" + user.getLogin())).to(); + root.createRequest() + .method("PUT") + .with("role", role) + .withUrlPath(api("/memberships/" + user.getLogin())) + .send(); } /** @@ -217,7 +221,7 @@ public void add(GHUser user, Role role) throws IOException { * the io exception */ public void remove(GHUser u) throws IOException { - root.retrieve().method("DELETE").withUrlPath(api("/members/" + u.getLogin())).to(); + root.createRequest().method("DELETE").withUrlPath(api("/members/" + u.getLogin())).send(); } /** @@ -243,11 +247,11 @@ public void add(GHRepository r) throws IOException { * the io exception */ public void add(GHRepository r, GHOrganization.Permission permission) throws IOException { - root.retrieve() + root.createRequest() .method("PUT") .with("permission", permission) .withUrlPath(api("/repos/" + r.getOwnerName() + '/' + r.getName())) - .to(); + .send(); } /** @@ -259,7 +263,7 @@ public void add(GHRepository r, GHOrganization.Permission permission) throws IOE * the io exception */ public void remove(GHRepository r) throws IOException { - root.retrieve().method("DELETE").withUrlPath(api("/repos/" + r.getOwnerName() + '/' + r.getName())).to(); + root.createRequest().method("DELETE").withUrlPath(api("/repos/" + r.getOwnerName() + '/' + r.getName())).send(); } /** @@ -269,7 +273,7 @@ public void remove(GHRepository r) throws IOException { * the io exception */ public void delete() throws IOException { - root.retrieve().method("DELETE").withUrlPath(api("")).to(); + root.createRequest().method("DELETE").withUrlPath(api("")).send(); } private String api(String tail) { @@ -290,6 +294,6 @@ public GHOrganization getOrganization() throws IOException { @Override public void refresh() throws IOException { - root.retrieve().withUrlPath(api("")).to(this).wrapUp(root); + root.createRequest().withUrlPath(api("")).fetchInto(this).wrapUp(root); } } diff --git a/src/main/java/org/kohsuke/github/GHThread.java b/src/main/java/org/kohsuke/github/GHThread.java index 98ffb90580..cfd492d500 100644 --- a/src/main/java/org/kohsuke/github/GHThread.java +++ b/src/main/java/org/kohsuke/github/GHThread.java @@ -161,7 +161,7 @@ GHThread wrap(GitHub root) { * the io exception */ public void markAsRead() throws IOException { - root.retrieve().method("PATCH").withUrlPath(url).to(); + root.createRequest().method("PATCH").withUrlPath(url).send(); } /** @@ -176,12 +176,12 @@ public void markAsRead() throws IOException { * the io exception */ public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOException { - return root.retrieve() + return root.createRequest() .method("PUT") .with("subscribed", subscribed) .with("ignored", ignored) .withUrlPath(subscription_url) - .to(GHSubscription.class) + .fetch(GHSubscription.class) .wrapUp(root); } @@ -194,7 +194,11 @@ public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOEx */ public GHSubscription getSubscription() throws IOException { try { - return root.retrieve().method("POST").withUrlPath(subscription_url).to(GHSubscription.class).wrapUp(root); + return root.createRequest() + .method("POST") + .withUrlPath(subscription_url) + .fetch(GHSubscription.class) + .wrapUp(root); } catch (FileNotFoundException e) { return null; } diff --git a/src/main/java/org/kohsuke/github/GHTreeBuilder.java b/src/main/java/org/kohsuke/github/GHTreeBuilder.java index 65b6369c12..0439c808c3 100644 --- a/src/main/java/org/kohsuke/github/GHTreeBuilder.java +++ b/src/main/java/org/kohsuke/github/GHTreeBuilder.java @@ -33,7 +33,7 @@ private TreeEntry(String path, String mode, String type) { GHTreeBuilder(GHRepository repo) { this.repo = repo; - req = repo.root.retrieve(); + req = repo.root.createRequest(); } /** @@ -163,6 +163,6 @@ private String getApiTail() { */ public GHTree create() throws IOException { req.with("tree", treeEntries); - return req.method("POST").withUrlPath(getApiTail()).to(GHTree.class).wrap(repo); + return req.method("POST").withUrlPath(getApiTail()).fetch(GHTree.class).wrap(repo); } } diff --git a/src/main/java/org/kohsuke/github/GHUser.java b/src/main/java/org/kohsuke/github/GHUser.java index 0e3b86e36d..4624788023 100644 --- a/src/main/java/org/kohsuke/github/GHUser.java +++ b/src/main/java/org/kohsuke/github/GHUser.java @@ -44,7 +44,7 @@ public class GHUser extends GHPerson { */ public List getKeys() throws IOException { return Collections.unmodifiableList( - Arrays.asList(root.retrieve().withUrlPath(getApiTailUrl("keys")).toArray(GHKey[].class))); + Arrays.asList(root.createRequest().withUrlPath(getApiTailUrl("keys")).fetchArray(GHKey[].class))); } /** @@ -54,7 +54,7 @@ public List getKeys() throws IOException { * the io exception */ public void follow() throws IOException { - root.retrieve().method("PUT").withUrlPath("/user/following/" + login).to(); + root.createRequest().method("PUT").withUrlPath("/user/following/" + login).send(); } /** @@ -64,7 +64,7 @@ public void follow() throws IOException { * the io exception */ public void unfollow() throws IOException { - root.retrieve().method("DELETE").withUrlPath("/user/following/" + login).to(); + root.createRequest().method("DELETE").withUrlPath("/user/following/" + login).send(); } /** @@ -110,7 +110,7 @@ public PagedIterable listFollowers() { } private PagedIterable listUser(final String suffix) { - return root.retrieve().asPagedIterable(getApiTailUrl(suffix), GHUser[].class, item -> item.wrapUp(root)); + return root.createRequest().asPagedIterable(getApiTailUrl(suffix), GHUser[].class, item -> item.wrapUp(root)); } /** @@ -134,7 +134,8 @@ public PagedIterable listStarredRepositories() { } private PagedIterable listRepositories(final String suffix) { - return root.retrieve().asPagedIterable(getApiTailUrl(suffix), GHRepository[].class, item -> item.wrap(root)); + return root.createRequest() + .asPagedIterable(getApiTailUrl(suffix), GHRepository[].class, item -> item.wrap(root)); } /** @@ -187,9 +188,9 @@ static GHUser[] wrap(GHUser[] users, GitHub root) { public GHPersonSet getOrganizations() throws IOException { GHPersonSet orgs = new GHPersonSet(); Set names = new HashSet(); - for (GHOrganization o : root.retrieve() + for (GHOrganization o : root.createRequest() .withUrlPath("/users/" + login + "/orgs") - .toArray(GHOrganization[].class)) { + .fetchArray(GHOrganization[].class)) { if (names.add(o.getLogin())) // I've seen some duplicates in the data orgs.add(root.getOrganization(o.getLogin())); } @@ -200,7 +201,7 @@ public GHPersonSet getOrganizations() throws IOException { * Lists events performed by a user (this includes private events if the caller is authenticated. */ public PagedIterable listEvents() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(String.format("/users/%s/events", login), GHEventInfo[].class, item -> item.wrapUp(root)); @@ -214,7 +215,7 @@ public PagedIterable listEvents() throws IOException { * the io exception */ public PagedIterable listGists() throws IOException { - return root.retrieve() + return root.createRequest() .asPagedIterable(String.format("/users/%s/gists", login), GHGist[].class, item -> item.wrapUp(GHUser.this)); diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 60b2ae5d41..96a1c51755 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -424,7 +424,7 @@ URL getApiURL(String tailApiUrl) throws IOException { } } - Requester retrieve() { + Requester createRequest() { return new Requester(this); } @@ -438,7 +438,7 @@ Requester retrieve() { public GHRateLimit getRateLimit() throws IOException { GHRateLimit rateLimit; try { - rateLimit = retrieve().withUrlPath("/rate_limit").to(JsonRateLimit.class).resources; + rateLimit = createRequest().withUrlPath("/rate_limit").fetch(JsonRateLimit.class).resources; } catch (FileNotFoundException e) { // GitHub Enterprise doesn't have the rate limit // return a default rate limit that @@ -544,7 +544,7 @@ public GHMyself getMyself() throws IOException { if (this.myself != null) return myself; - GHMyself u = retrieve().withUrlPath("/user").to(GHMyself.class); + GHMyself u = createRequest().withUrlPath("/user").fetch(GHMyself.class); u.root = this; this.myself = u; @@ -564,7 +564,7 @@ public GHMyself getMyself() throws IOException { public GHUser getUser(String login) throws IOException { GHUser u = users.get(login); if (u == null) { - u = retrieve().withUrlPath("/users/" + login).to(GHUser.class); + u = createRequest().withUrlPath("/users/" + login).fetch(GHUser.class); u.root = this; users.put(u.getLogin(), u); } @@ -608,7 +608,7 @@ protected GHUser getUser(GHUser orig) { public GHOrganization getOrganization(String name) throws IOException { GHOrganization o = orgs.get(name); if (o == null) { - o = retrieve().withUrlPath("/orgs/" + name).to(GHOrganization.class).wrapUp(this); + o = createRequest().withUrlPath("/orgs/" + name).fetch(GHOrganization.class).wrapUp(this); orgs.put(name, o); } return o; @@ -632,7 +632,7 @@ public PagedIterable listOrganizations() { * @see List All Orgs - Parameters */ public PagedIterable listOrganizations(final String since) { - return retrieve().with("since", since) + return createRequest().with("since", since) .asPagedIterable("/organizations", GHOrganization[].class, item -> item.wrapUp(GitHub.this)); } @@ -648,7 +648,9 @@ public PagedIterable listOrganizations(final String since) { */ public GHRepository getRepository(String name) throws IOException { String[] tokens = name.split("/"); - return retrieve().withUrlPath("/repos/" + tokens[0] + '/' + tokens[1]).to(GHRepository.class).wrap(this); + return createRequest().withUrlPath("/repos/" + tokens[0] + '/' + tokens[1]) + .fetch(GHRepository.class) + .wrap(this); } /** @@ -661,7 +663,7 @@ public GHRepository getRepository(String name) throws IOException { * the io exception */ public GHRepository getRepositoryById(String id) throws IOException { - return retrieve().withUrlPath("/repositories/" + id).to(GHRepository.class).wrap(this); + return createRequest().withUrlPath("/repositories/" + id).fetch(GHRepository.class).wrap(this); } /** @@ -673,7 +675,7 @@ public GHRepository getRepositoryById(String id) throws IOException { * @see GitHub API - Licenses */ public PagedIterable listLicenses() throws IOException { - return retrieve().asPagedIterable("/licenses", GHLicense[].class, item -> item.wrap(GitHub.this)); + return createRequest().asPagedIterable("/licenses", GHLicense[].class, item -> item.wrap(GitHub.this)); } /** @@ -684,7 +686,7 @@ public PagedIterable listLicenses() throws IOException { * the io exception */ public PagedIterable listUsers() throws IOException { - return retrieve().asPagedIterable("/users", GHUser[].class, item -> item.wrapUp(GitHub.this)); + return createRequest().asPagedIterable("/users", GHUser[].class, item -> item.wrapUp(GitHub.this)); } /** @@ -698,7 +700,7 @@ public PagedIterable listUsers() throws IOException { * @see GHLicense#getKey() GHLicense#getKey() */ public GHLicense getLicense(String key) throws IOException { - return retrieve().withUrlPath("/licenses/" + key).to(GHLicense.class); + return createRequest().withUrlPath("/licenses/" + key).fetch(GHLicense.class); } /** @@ -709,8 +711,8 @@ public GHLicense getLicense(String key) throws IOException { * the io exception */ public List getMyInvitations() throws IOException { - GHInvitation[] invitations = retrieve().withUrlPath("/user/repository_invitations") - .toArray(GHInvitation[].class); + GHInvitation[] invitations = createRequest().withUrlPath("/user/repository_invitations") + .fetchArray(GHInvitation[].class); for (GHInvitation i : invitations) { i.wrapUp(this); } @@ -728,7 +730,7 @@ public List getMyInvitations() throws IOException { * the io exception */ public Map getMyOrganizations() throws IOException { - GHOrganization[] orgs = retrieve().withUrlPath("/user/orgs").toArray(GHOrganization[].class); + GHOrganization[] orgs = createRequest().withUrlPath("/user/orgs").fetchArray(GHOrganization[].class); Map r = new HashMap(); for (GHOrganization o : orgs) { // don't put 'o' into orgs because they are shallow @@ -762,7 +764,8 @@ public Map getUserPublicOrganizations(GHUser user) throw * the io exception */ public Map getUserPublicOrganizations(String login) throws IOException { - GHOrganization[] orgs = retrieve().withUrlPath("/users/" + login + "/orgs").toArray(GHOrganization[].class); + GHOrganization[] orgs = createRequest().withUrlPath("/users/" + login + "/orgs") + .fetchArray(GHOrganization[].class); Map r = new HashMap(); for (GHOrganization o : orgs) { // don't put 'o' into orgs because they are shallow @@ -783,7 +786,7 @@ public Map getUserPublicOrganizations(String login) thro */ public Map> getMyTeams() throws IOException { Map> allMyTeams = new HashMap>(); - for (GHTeam team : retrieve().withUrlPath("/user/teams").toArray(GHTeam[].class)) { + for (GHTeam team : createRequest().withUrlPath("/user/teams").fetchArray(GHTeam[].class)) { team.wrapUp(this); String orgLogin = team.getOrganization().getLogin(); Set teamsPerOrg = allMyTeams.get(orgLogin); @@ -806,7 +809,7 @@ public Map> getMyTeams() throws IOException { * the io exception */ public GHTeam getTeam(int id) throws IOException { - return retrieve().withUrlPath("/teams/" + id).to(GHTeam.class).wrapUp(this); + return createRequest().withUrlPath("/teams/" + id).fetch(GHTeam.class).wrapUp(this); } /** @@ -817,7 +820,7 @@ public GHTeam getTeam(int id) throws IOException { * the io exception */ public List getEvents() throws IOException { - GHEventInfo[] events = retrieve().withUrlPath("/events").toArray(GHEventInfo[].class); + GHEventInfo[] events = createRequest().withUrlPath("/events").fetchArray(GHEventInfo[].class); for (GHEventInfo e : events) e.wrapUp(this); return Arrays.asList(events); @@ -833,7 +836,7 @@ public List getEvents() throws IOException { * the io exception */ public GHGist getGist(String id) throws IOException { - return retrieve().withUrlPath("/gists/" + id).to(GHGist.class).wrapUp(this); + return createRequest().withUrlPath("/gists/" + id).fetch(GHGist.class).wrapUp(this); } /** @@ -925,9 +928,9 @@ public GHCreateRepositoryBuilder createRepository(String name) { * @see Documentation */ public GHAuthorization createToken(Collection scope, String note, String noteUrl) throws IOException { - Requester requester = retrieve().with("scopes", scope).with("note", note).with("note_url", noteUrl); + Requester requester = createRequest().with("scopes", scope).with("note", note).with("note_url", noteUrl); - return requester.method("POST").withUrlPath("/authorizations").to(GHAuthorization.class).wrap(this); + return requester.method("POST").withUrlPath("/authorizations").fetch(GHAuthorization.class).wrap(this); } /** @@ -958,10 +961,10 @@ public GHAuthorization createToken(Collection scope, String note, String return createToken(scope, note, noteUrl); } catch (GHOTPRequiredException ex) { String OTPstring = OTP.get(); - Requester requester = retrieve().with("scopes", scope).with("note", note).with("note_url", noteUrl); + Requester requester = createRequest().with("scopes", scope).with("note", note).with("note_url", noteUrl); // Add the OTP from the user requester.setHeader("x-github-otp", OTPstring); - return requester.method("POST").withUrlPath("/authorizations").to(GHAuthorization.class).wrap(this); + return requester.method("POST").withUrlPath("/authorizations").fetch(GHAuthorization.class).wrap(this); } } @@ -989,12 +992,12 @@ public GHAuthorization createOrGetAuth(String clientId, List scopes, String note, String note_url) throws IOException { - Requester requester = retrieve().with("client_secret", clientSecret) + Requester requester = createRequest().with("client_secret", clientSecret) .with("scopes", scopes) .with("note", note) .with("note_url", note_url); - return requester.method("PUT").withUrlPath("/authorizations/clients/" + clientId).to(GHAuthorization.class); + return requester.method("PUT").withUrlPath("/authorizations/clients/" + clientId).fetch(GHAuthorization.class); } /** @@ -1008,7 +1011,7 @@ public GHAuthorization createOrGetAuth(String clientId, * authorization */ public void deleteAuth(long id) throws IOException { - retrieve().method("DELETE").withUrlPath("/authorizations/" + id).to(); + createRequest().method("DELETE").withUrlPath("/authorizations/" + id).send(); } /** @@ -1025,7 +1028,8 @@ public void deleteAuth(long id) throws IOException { * authorization */ public GHAuthorization checkAuth(@Nonnull String clientId, @Nonnull String accessToken) throws IOException { - return retrieve().withUrlPath("/applications/" + clientId + "/tokens/" + accessToken).to(GHAuthorization.class); + return createRequest().withUrlPath("/applications/" + clientId + "/tokens/" + accessToken) + .fetch(GHAuthorization.class); } /** @@ -1042,9 +1046,9 @@ public GHAuthorization checkAuth(@Nonnull String clientId, @Nonnull String acces * authorization */ public GHAuthorization resetAuth(@Nonnull String clientId, @Nonnull String accessToken) throws IOException { - return retrieve().method("POST") + return createRequest().method("POST") .withUrlPath("/applications/" + clientId + "/tokens/" + accessToken) - .to(GHAuthorization.class); + .fetch(GHAuthorization.class); } /** @@ -1057,7 +1061,8 @@ public GHAuthorization resetAuth(@Nonnull String clientId, @Nonnull String acces * authorizations */ public PagedIterable listMyAuthorizations() throws IOException { - return retrieve().asPagedIterable("/authorizations", GHAuthorization[].class, item -> item.wrap(GitHub.this)); + return createRequest() + .asPagedIterable("/authorizations", GHAuthorization[].class, item -> item.wrap(GitHub.this)); } /** @@ -1074,7 +1079,7 @@ public PagedIterable listMyAuthorizations() throws IOException @Preview @Deprecated public GHApp getApp() throws IOException { - return retrieve().withPreview(MACHINE_MAN).withUrlPath("/app").to(GHApp.class).wrapUp(this); + return createRequest().withPreview(MACHINE_MAN).withUrlPath("/app").fetch(GHApp.class).wrapUp(this); } /** @@ -1084,7 +1089,7 @@ public GHApp getApp() throws IOException { */ public boolean isCredentialValid() { try { - retrieve().withUrlPath("/user").to(GHUser.class); + createRequest().withUrlPath("/user").fetch(GHUser.class); return true; } catch (IOException e) { if (LOGGER.isLoggable(FINE)) @@ -1105,7 +1110,7 @@ public boolean isCredentialValid() { * @see Get Meta */ public GHMeta getMeta() throws IOException { - return retrieve().withUrlPath("/meta").to(GHMeta.class); + return createRequest().withUrlPath("/meta").fetch(GHMeta.class); } GHUser intern(GHUser user) throws IOException { @@ -1132,7 +1137,7 @@ GHUser intern(GHUser user) throws IOException { * the io exception */ public GHProject getProject(long id) throws IOException { - return retrieve().withPreview(INERTIA).withUrlPath("/projects/" + id).to(GHProject.class).wrap(this); + return createRequest().withPreview(INERTIA).withUrlPath("/projects/" + id).fetch(GHProject.class).wrap(this); } /** @@ -1145,9 +1150,9 @@ public GHProject getProject(long id) throws IOException { * the io exception */ public GHProjectColumn getProjectColumn(long id) throws IOException { - return retrieve().withPreview(INERTIA) + return createRequest().withPreview(INERTIA) .withUrlPath("/projects/columns/" + id) - .to(GHProjectColumn.class) + .fetch(GHProjectColumn.class) .wrap(this); } @@ -1161,9 +1166,9 @@ public GHProjectColumn getProjectColumn(long id) throws IOException { * the io exception */ public GHProjectCard getProjectCard(long id) throws IOException { - return retrieve().withPreview(INERTIA) + return createRequest().withPreview(INERTIA) .withUrlPath("/projects/columns/cards/" + id) - .to(GHProjectCard.class) + .fetch(GHProjectCard.class) .wrap(this); } @@ -1194,7 +1199,7 @@ void check(String apiUrl) throws IOException { */ public void checkApiUrlValidity() throws IOException { try { - retrieve().withUrlPath("/").to(GHApiInfo.class).check(apiUrl); + createRequest().withUrlPath("/").fetch(GHApiInfo.class).check(apiUrl); } catch (IOException e) { if (isPrivateModeEnabled()) { throw (IOException) new IOException( @@ -1326,7 +1331,7 @@ public PagedIterable listAllPublicRepositories() { * @see documentation */ public PagedIterable listAllPublicRepositories(final String since) { - return retrieve().with("since", since) + return createRequest().with("since", since) .asPagedIterable("/repositories", GHRepository[].class, item -> item.wrap(GitHub.this)); } @@ -1346,11 +1351,11 @@ public PagedIterable listAllPublicRepositories(final String since) */ public Reader renderMarkdown(String text) throws IOException { return new InputStreamReader( - retrieve().method("POST") + createRequest().method("POST") .with(new ByteArrayInputStream(text.getBytes("UTF-8"))) .contentType("text/plain;charset=UTF-8") .withUrlPath("/markdown/raw") - .toStream(), + .fetchStream(), "UTF-8"); } diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index f3fdb04ccf..b922f6ae12 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -43,6 +43,7 @@ import java.net.URISyntaxException; import java.net.URL; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -382,8 +383,8 @@ public Requester inBody() { * @throws IOException * the io exception */ - public void to() throws IOException { - _to(null, null); + public void send() throws IOException { + _fetch(null, null); } /** @@ -397,8 +398,8 @@ public void to() throws IOException { * @throws IOException * if the server returns 4xx/5xx responses. */ - public T to(@Nonnull Class type) throws IOException { - return _to(type, null); + public T fetch(@Nonnull Class type) throws IOException { + return _fetch(type, null); } /** @@ -412,7 +413,7 @@ public T to(@Nonnull Class type) throws IOException { * @throws IOException * if the server returns 4xx/5xx responses. */ - public T[] toArray(@Nonnull Class type) throws IOException { + public T[] fetchArray(@Nonnull Class type) throws IOException { T[] result; // for arrays we might have to loop for pagination @@ -430,7 +431,7 @@ public T[] toArray(@Nonnull Class type) throws IOException { } /** - * Like {@link #to(Class)} but updates an existing object instead of creating a new instance. + * Like {@link #fetch(Class)} but updates an existing object instead of creating a new instance. * * @param * the type parameter @@ -440,11 +441,11 @@ public T[] toArray(@Nonnull Class type) throws IOException { * @throws IOException * the io exception */ - public T to(@Nonnull T existingInstance) throws IOException { - return _to(null, existingInstance); + public T fetchInto(@Nonnull T existingInstance) throws IOException { + return _fetch(null, existingInstance); } - private T _to(Class type, T instance) throws IOException { + private T _fetch(Class type, T instance) throws IOException { T result; String tailApiUrl = buildTailApiUrl(urlPath); @@ -484,9 +485,9 @@ private String buildTailApiUrl(String tailApiUrl) { for (Iterator it = args.listIterator(); it.hasNext();) { Entry arg = it.next(); - argString.append(URLEncoder.encode(arg.key, "UTF-8")); + argString.append(URLEncoder.encode(arg.key, StandardCharsets.UTF_8.name())); argString.append('='); - argString.append(URLEncoder.encode(arg.value.toString(), "UTF-8")); + argString.append(URLEncoder.encode(arg.value.toString(), StandardCharsets.UTF_8.name())); if (it.hasNext()) { argString.append('&'); } @@ -507,7 +508,7 @@ private String buildTailApiUrl(String tailApiUrl) { * @throws IOException * the io exception */ - public int asHttpStatusCode() throws IOException { + public int fetchHttpStatusCode() throws IOException { while (true) {// loop while API rate limit is hit setupConnection(root.getApiURL(urlPath)); @@ -529,7 +530,7 @@ public int asHttpStatusCode() throws IOException { * @throws IOException * the io exception */ - public InputStream toStream() throws IOException { + public InputStream fetchStream() throws IOException { while (true) {// loop while API rate limit is hit setupConnection(root.getApiURL(urlPath)); @@ -890,7 +891,7 @@ private T parse(Class type, T instance, int timeouts) throws IOException return null; } - r = new InputStreamReader(wrapStream(uc.getInputStream()), "UTF-8"); + r = new InputStreamReader(wrapStream(uc.getInputStream()), StandardCharsets.UTF_8); String data = IOUtils.toString(r); if (type != null) try { @@ -969,7 +970,7 @@ void handleApiError(IOException e) throws IOException { InputStream es = wrapStream(uc.getErrorStream()); if (es != null) { try { - String error = IOUtils.toString(es, "UTF-8"); + String error = IOUtils.toString(es, StandardCharsets.UTF_8); if (e instanceof FileNotFoundException) { // pass through 404 Not Found to allow the caller to handle it intelligently e = (IOException) new GHFileNotFoundException(error).withResponseHeaderFields(uc).initCause(e); diff --git a/src/test/java/org/kohsuke/github/GitHubTest.java b/src/test/java/org/kohsuke/github/GitHubTest.java index c3a3449dc9..95f1a1e3eb 100644 --- a/src/test/java/org/kohsuke/github/GitHubTest.java +++ b/src/test/java/org/kohsuke/github/GitHubTest.java @@ -96,9 +96,9 @@ public void getMeta() throws IOException { ReadOnlyObjects.GHMetaGettersFinalCreator.class, }; for (Class metaClass : examples) { - ReadOnlyObjects.GHMetaExample metaExample = gitHub.retrieve() + ReadOnlyObjects.GHMetaExample metaExample = gitHub.createRequest() .withUrlPath("/meta") - .to((Class) metaClass); + .fetch((Class) metaClass); assertTrue(metaExample.isVerifiablePasswordAuthentication()); assertEquals(19, metaExample.getApi().size()); assertEquals(19, metaExample.getGit().size()); diff --git a/src/test/java/org/kohsuke/github/RepositoryMockTest.java b/src/test/java/org/kohsuke/github/RepositoryMockTest.java index d43d06930f..66ad11c025 100644 --- a/src/test/java/org/kohsuke/github/RepositoryMockTest.java +++ b/src/test/java/org/kohsuke/github/RepositoryMockTest.java @@ -42,7 +42,7 @@ public void listCollaborators() throws Exception { when(iterator.next()).thenReturn(new GHUser[]{ user1 }, new GHUser[]{ user2 }); Requester requester = Mockito.mock(Requester.class); - when(mockGitHub.retrieve()).thenReturn(requester); + when(mockGitHub.createRequest()).thenReturn(requester); when(requester.withUrlPath("/repos/*/*/collaborators")).thenReturn(requester); From 52dd90e85d0c46741f369eecbfe0c5e46470573a Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Tue, 17 Dec 2019 14:15:38 -0800 Subject: [PATCH 7/7] Additional tweaks to reduce the number of code paths --- .../java/org/kohsuke/github/Requester.java | 136 +++++++++--------- 1 file changed, 67 insertions(+), 69 deletions(-) diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index b922f6ae12..60ba91148c 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -378,17 +378,17 @@ public Requester inBody() { } /** - * To. + * Sends a request to the specified URL and checks that it is sucessful. * * @throws IOException * the io exception */ public void send() throws IOException { - _fetch(null, null); + _fetch(() -> parse(null, null)); } /** - * Sends a request to the specified URL, and parses the response into the given type via databinding. + * Sends a request and parses the response into the given type via databinding. * * @param * the type parameter @@ -399,11 +399,11 @@ public void send() throws IOException { * if the server returns 4xx/5xx responses. */ public T fetch(@Nonnull Class type) throws IOException { - return _fetch(type, null); + return _fetch(() -> parse(type, null)); } /** - * Sends a request to the specified URL, and parses the response into the given type via databinding. + * Sends a request and parses the response into an array of the given type via databinding. * * @param * the type parameter @@ -427,7 +427,7 @@ public T[] fetchArray(@Nonnull Class type) throws IOException { } result = concatenatePages(type, pages, totalSize); - return setResponseHeaders(result); + return result; } /** @@ -442,19 +442,44 @@ public T[] fetchArray(@Nonnull Class type) throws IOException { * the io exception */ public T fetchInto(@Nonnull T existingInstance) throws IOException { - return _fetch(null, existingInstance); + return _fetch(() -> parse(null, existingInstance)); } - private T _fetch(Class type, T instance) throws IOException { - T result; + /** + * Makes a request and just obtains the HTTP status code. Method does not throw exceptions for many status codes + * that would otherwise throw. + * + * @return the int + * @throws IOException + * the io exception + */ + public int fetchHttpStatusCode() throws IOException { + return _fetch(() -> uc.getResponseCode()); + } + + /** + * As stream input stream. + * + * @return the input stream + * @throws IOException + * the io exception + */ + public InputStream fetchStream() throws IOException { + return _fetch(() -> parse(InputStream.class, null)); + } + private T _fetch(SupplierThrows supplier) throws IOException { String tailApiUrl = buildTailApiUrl(urlPath); - setupConnection(root.getApiURL(tailApiUrl)); + URL url = root.getApiURL(tailApiUrl); + return _fetch(tailApiUrl, url, supplier); + } + private T _fetch(String tailApiUrl, URL url, SupplierThrows supplier) throws IOException { while (true) {// loop while API rate limit is hit + setupConnection(url); + try { - result = parse(type, instance); - return setResponseHeaders(result); + return supplier.get(); } catch (IOException e) { handleApiError(e); } finally { @@ -500,50 +525,6 @@ private String buildTailApiUrl(String tailApiUrl) { return tailApiUrl; } - /** - * Makes a request and just obtains the HTTP status code. Method does not throw exceptions for many status codes - * that would otherwise throw. - * - * @return the int - * @throws IOException - * the io exception - */ - public int fetchHttpStatusCode() throws IOException { - while (true) {// loop while API rate limit is hit - - setupConnection(root.getApiURL(urlPath)); - - try { - return uc.getResponseCode(); - } catch (IOException e) { - handleApiError(e); - } finally { - noteRateLimit(urlPath); - } - } - } - - /** - * As stream input stream. - * - * @return the input stream - * @throws IOException - * the io exception - */ - public InputStream fetchStream() throws IOException { - while (true) {// loop while API rate limit is hit - setupConnection(root.getApiURL(urlPath)); - - try { - return wrapStream(uc.getInputStream()); - } catch (IOException e) { - handleApiError(e); - } finally { - noteRateLimit(urlPath); - } - } - } - private void noteRateLimit(String tailApiUrl) { if (uc == null) { return; @@ -757,19 +738,9 @@ private void fetch() { return; // no more data to fetch try { - while (true) {// loop while API rate limit is hit - setupConnection(url); - try { - next = parse(type, null); - assert next != null; - findNextURL(); - return; - } catch (IOException e) { - handleApiError(e); - } finally { - noteRateLimit(tailApiUrl); - } - } + next = _fetch(tailApiUrl, url, () -> parse(type, null)); + assert next != null; + findNextURL(); } catch (IOException e) { throw new GHException("Failed to retrieve " + url, e); } @@ -891,6 +862,10 @@ private T parse(Class type, T instance, int timeouts) throws IOException return null; } + if (type != null && type.equals(InputStream.class)) { + return type.cast(wrapStream(uc.getInputStream())); + } + r = new InputStreamReader(wrapStream(uc.getInputStream()), StandardCharsets.UTF_8); String data = IOUtils.toString(r); if (type != null) @@ -1037,4 +1012,27 @@ public static String urlPathEncode(String value) { private static final List METHODS_WITHOUT_BODY = asList("GET", "DELETE"); private static final Logger LOGGER = Logger.getLogger(Requester.class.getName()); + + /** + * Represents a supplier of results that can throw. + * + *

+ * This is a functional interface whose functional method is {@link #get()}. + * + * @param + * the type of results supplied by this supplier + * @param + * the type of throwable that could be thrown + */ + @FunctionalInterface + interface SupplierThrows { + + /** + * Gets a result. + * + * @return a result + * @throws E + */ + T get() throws E; + } }