Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.

Commit 77590b4

Browse files
committed
eliminate the need for path manipulation and consolidate them to 'with'
1 parent 72fc313 commit 77590b4

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,10 +1029,7 @@ public GHContent getFileContent(String path, String ref) throws IOException {
10291029
Requester requester = root.retrieve();
10301030
String target = getApiTailUrl("contents/" + path);
10311031

1032-
if (ref != null)
1033-
target = target + "?ref=" + ref;
1034-
1035-
return requester.to(target, GHContent.class).wrap(this);
1032+
return requester.with("ref",ref).to(target, GHContent.class).wrap(this);
10361033
}
10371034

10381035
public List<GHContent> getDirectoryContent(String path) throws IOException {
@@ -1043,10 +1040,7 @@ public List<GHContent> getDirectoryContent(String path, String ref) throws IOExc
10431040
Requester requester = root.retrieve();
10441041
String target = getApiTailUrl("contents/" + path);
10451042

1046-
if (ref != null)
1047-
target = target + "?ref=" + ref;
1048-
1049-
GHContent[] files = requester.to(target, GHContent[].class);
1043+
GHContent[] files = requester.with("ref",ref).to(target, GHContent[].class);
10501044

10511045
GHContent.wrap(files, this);
10521046

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ public <T> T to(String tailApiUrl, Class<T> type, String method) throws IOExcept
191191

192192
private <T> T _to(String tailApiUrl, Class<T> type, T instance) throws IOException {
193193
while (true) {// loop while API rate limit is hit
194+
if (method.equals("GET") && !args.isEmpty()) {
195+
StringBuilder qs=new StringBuilder();
196+
for (Entry arg : args) {
197+
qs.append(qs.length()==0 ? '?' : '&');
198+
qs.append(arg.key).append('=').append(URLEncoder.encode(arg.value.toString(),"UTF-8"));
199+
}
200+
tailApiUrl += qs.toString();
201+
}
194202
HttpURLConnection uc = setupConnection(root.getApiURL(tailApiUrl));
195203

196204
buildRequest(uc);

0 commit comments

Comments
 (0)