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

Commit 541dac1

Browse files
committed
Use getApiTailUrl for consistency
1 parent e2e2329 commit 541dac1

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

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

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public GHUser getOwner() throws IOException {
195195
}
196196

197197
public GHIssue getIssue(int id) throws IOException {
198-
return root.retrieve().to("/repos/" + owner.login + "/" + name + "/issues/" + id, GHIssue.class).wrap(this);
198+
return root.retrieve().to(getApiTailUrl("issues/" + id), GHIssue.class).wrap(this);
199199
}
200200

201201
public GHIssueBuilder createIssue(String title) {
@@ -208,8 +208,8 @@ public List<GHIssue> getIssues(GHIssueState state) throws IOException {
208208

209209
public List<GHIssue> getIssues(GHIssueState state, GHMilestone milestone) throws IOException {
210210
return Arrays.asList(GHIssue.wrap(root.retrieve()
211-
.to(String.format("/repos/%s/%s/issues?state=%s&milestone=%s", owner.login, name,
212-
state.toString().toLowerCase(), milestone == null ? "none" : "" + milestone.getNumber()),
211+
.to(getApiTailUrl(String.format("issues?state=%s&milestone=%s",
212+
state.toString().toLowerCase(), milestone == null ? "none" : "" + milestone.getNumber())),
213213
GHIssue[].class
214214
), this));
215215
}
@@ -371,7 +371,7 @@ public PagedIterable<GHUser> listCollaborators() throws IOException {
371371
return new PagedIterable<GHUser>() {
372372
public PagedIterator<GHUser> iterator() {
373373

374-
return new PagedIterator<GHUser>(root.retrieve().asIterator("/repos/" + owner.login + "/" + name + "/collaborators", GHUser[].class)) {
374+
return new PagedIterator<GHUser>(root.retrieve().asIterator(getApiTailUrl("collaborators"), GHUser[].class)) {
375375

376376
@Override
377377
protected void wrapUp(GHUser[] users) {
@@ -392,7 +392,7 @@ protected void wrapUp(GHUser[] users) {
392392
*/
393393
public Set<String> getCollaboratorNames() throws IOException {
394394
Set<String> r = new HashSet<String>();
395-
for (GHUser u : GHUser.wrap(root.retrieve().to("/repos/" + owner.login + "/" + name + "/collaborators", GHUser[].class),root))
395+
for (GHUser u : GHUser.wrap(root.retrieve().to(getApiTailUrl("collaborators"), GHUser[].class),root))
396396
r.add(u.login);
397397
return r;
398398
}
@@ -401,7 +401,7 @@ public Set<String> getCollaboratorNames() throws IOException {
401401
* If this repository belongs to an organization, return a set of teams.
402402
*/
403403
public Set<GHTeam> getTeams() throws IOException {
404-
return Collections.unmodifiableSet(new HashSet<GHTeam>(Arrays.asList(GHTeam.wrapUp(root.retrieve().to("/repos/" + owner.login + "/" + name + "/teams", GHTeam[].class), root.getOrganization(owner.login)))));
404+
return Collections.unmodifiableSet(new HashSet<GHTeam>(Arrays.asList(GHTeam.wrapUp(root.retrieve().to(getApiTailUrl("teams"), GHTeam[].class), root.getOrganization(owner.login)))));
405405
}
406406

407407
public void addCollaborators(GHUser... users) throws IOException {
@@ -423,22 +423,22 @@ public void removeCollaborators(Collection<GHUser> users) throws IOException {
423423
private void modifyCollaborators(Collection<GHUser> users, String method) throws IOException {
424424
verifyMine();
425425
for (GHUser user : users) {
426-
new Requester(root).method(method).to("/repos/" + owner.login + "/" + name + "/collaborators/" + user.getLogin());
426+
new Requester(root).method(method).to(getApiTailUrl("collaborators/" + user.getLogin()));
427427
}
428428
}
429429

430430
public void setEmailServiceHook(String address) throws IOException {
431431
Map<String, String> config = new HashMap<String, String>();
432432
config.put("address", address);
433433
new Requester(root).method("POST").with("name", "email").with("config", config).with("active", "true")
434-
.to(String.format("/repos/%s/%s/hooks", owner.login, name));
434+
.to(getApiTailUrl("hooks"));
435435
}
436436

437437
private void edit(String key, String value) throws IOException {
438438
Requester requester = new Requester(root);
439439
if (!key.equals("name"))
440440
requester.with("name", name); // even when we don't change the name, we need to send it in
441-
requester.with(key, value).method("PATCH").to("/repos/" + owner.login + "/" + name);
441+
requester.with(key, value).method("PATCH").to(getApiTailUrl(""));
442442
}
443443

444444
/**
@@ -479,7 +479,7 @@ public void setHomepage(String value) throws IOException {
479479
*/
480480
public void delete() throws IOException {
481481
try {
482-
new Requester(root).method("DELETE").to("/repos/" + owner.login + "/" + name);
482+
new Requester(root).method("DELETE").to(getApiTailUrl(""));
483483
} catch (FileNotFoundException x) {
484484
throw (FileNotFoundException) new FileNotFoundException("Failed to delete " + owner.login + "/" + name + "; might not exist, or you might need the delete_repo scope in your token: http://stackoverflow.com/a/19327004/12916").initCause(x);
485485
}
@@ -492,7 +492,7 @@ public void delete() throws IOException {
492492
* Newly forked repository that belong to you.
493493
*/
494494
public GHRepository fork() throws IOException {
495-
return new Requester(root).method("POST").to("/repos/" + owner.login + "/" + name + "/forks", GHRepository.class).wrap(root);
495+
return new Requester(root).method("POST").to(getApiTailUrl("forks"), GHRepository.class).wrap(root);
496496
}
497497

498498
/**
@@ -502,7 +502,7 @@ public GHRepository fork() throws IOException {
502502
* Newly forked repository that belong to you.
503503
*/
504504
public GHRepository forkTo(GHOrganization org) throws IOException {
505-
new Requester(root).to(String.format("/repos/%s/%s/forks?org=%s", owner.login, name, org.getLogin()));
505+
new Requester(root).to(getApiTailUrl("forks?org="+org.getLogin()));
506506

507507
// this API is asynchronous. we need to wait for a bit
508508
for (int i=0; i<10; i++) {
@@ -521,7 +521,7 @@ public GHRepository forkTo(GHOrganization org) throws IOException {
521521
* Retrieves a specified pull request.
522522
*/
523523
public GHPullRequest getPullRequest(int i) throws IOException {
524-
return root.retrieve().to("/repos/" + owner.login + '/' + name + "/pulls/" + i, GHPullRequest.class).wrapUp(this);
524+
return root.retrieve().to(getApiTailUrl("pulls/" + i), GHPullRequest.class).wrapUp(this);
525525
}
526526

527527
/**
@@ -539,7 +539,7 @@ public List<GHPullRequest> getPullRequests(GHIssueState state) throws IOExceptio
539539
public PagedIterable<GHPullRequest> listPullRequests(final GHIssueState state) {
540540
return new PagedIterable<GHPullRequest>() {
541541
public PagedIterator<GHPullRequest> iterator() {
542-
return new PagedIterator<GHPullRequest>(root.retrieve().asIterator(String.format("/repos/%s/%s/pulls?state=%s", owner.login, name, state.name().toLowerCase(Locale.ENGLISH)), GHPullRequest[].class)) {
542+
return new PagedIterator<GHPullRequest>(root.retrieve().asIterator(getApiTailUrl("pulls?state="+state.name().toLowerCase(Locale.ENGLISH)), GHPullRequest[].class)) {
543543
@Override
544544
protected void wrapUp(GHPullRequest[] page) {
545545
for (GHPullRequest pr : page)
@@ -578,14 +578,14 @@ public GHPullRequest createPullRequest(String title, String head, String base, S
578578
*/
579579
public List<GHHook> getHooks() throws IOException {
580580
List<GHHook> list = new ArrayList<GHHook>(Arrays.asList(
581-
root.retrieve().to(String.format("/repos/%s/%s/hooks", owner.login, name), GHHook[].class)));
581+
root.retrieve().to(getApiTailUrl("hooks"), GHHook[].class)));
582582
for (GHHook h : list)
583583
h.wrap(this);
584584
return list;
585585
}
586586

587587
public GHHook getHook(int id) throws IOException {
588-
return root.retrieve().to(String.format("/repos/%s/%s/hooks/%d", owner.login, name, id), GHHook.class).wrap(this);
588+
return root.retrieve().to(getApiTailUrl("hooks/"+id), GHHook.class).wrap(this);
589589
}
590590

591591
/**
@@ -597,7 +597,7 @@ public GHHook getHook(int id) throws IOException {
597597
* @throws IOException on failure communicating with GitHub
598598
*/
599599
public GHCompare getCompare(String id1, String id2) throws IOException {
600-
GHCompare compare = root.retrieve().to(String.format("/repos/%s/%s/compare/%s...%s", owner.login, name, id1, id2), GHCompare.class);
600+
GHCompare compare = root.retrieve().to(getApiTailUrl(String.format("compare/%s...%s", id1, id2)), GHCompare.class);
601601
return compare.wrap(this);
602602
}
603603

@@ -968,7 +968,7 @@ public GHContent getFileContent(String path) throws IOException {
968968

969969
public GHContent getFileContent(String path, String ref) throws IOException {
970970
Requester requester = root.retrieve();
971-
String target = String.format("/repos/%s/%s/contents/%s", owner.login, name, path);
971+
String target = getApiTailUrl("contents/"+path);
972972

973973
if (ref != null)
974974
target = target + "?ref=" + ref;
@@ -982,7 +982,7 @@ public List<GHContent> getDirectoryContent(String path) throws IOException {
982982

983983
public List<GHContent> getDirectoryContent(String path, String ref) throws IOException {
984984
Requester requester = root.retrieve();
985-
String target = String.format("/repos/%s/%s/contents/%s", owner.login, name, path);
985+
String target = getApiTailUrl("contents/"+path);
986986

987987
if (ref != null)
988988
target = target + "?ref=" + ref;
@@ -1046,7 +1046,7 @@ public GHDeployKey addDeployKey(String title,String key) throws IOException {
10461046

10471047
public List<GHDeployKey> getDeployKeys() throws IOException{
10481048
List<GHDeployKey> list = new ArrayList<GHDeployKey>(Arrays.asList(
1049-
root.retrieve().to(String.format("/repos/%s/%s/keys", owner.login, name), GHDeployKey[].class)));
1049+
root.retrieve().to(getApiTailUrl("keys"), GHDeployKey[].class)));
10501050
for (GHDeployKey h : list)
10511051
h.wrap(this);
10521052
return list;
@@ -1075,6 +1075,7 @@ public boolean equals(Object obj) {
10751075
}
10761076

10771077
String getApiTailUrl(String tail) {
1078-
return "/repos/" + owner.login + "/" + name +'/'+tail;
1078+
if (tail.length()>0 && !tail.startsWith("/")) tail='/'+tail;
1079+
return "/repos/" + owner.login + "/" + name +tail;
10791080
}
10801081
}

0 commit comments

Comments
 (0)