Skip to content

Commit 29b01f6

Browse files
committed
Streamline GitHub root handling
1 parent bb72b8d commit 29b01f6

File tree

105 files changed

+550
-705
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+550
-705
lines changed

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ public void setPermissions(Map<String, String> permissions) {
184184
}
185185

186186
GHApp wrapUp(GitHub root) {
187-
this.root = root;
188187
return this;
189188
}
190189

@@ -198,10 +197,10 @@ GHApp wrapUp(GitHub root) {
198197
*/
199198
@Preview(MACHINE_MAN)
200199
public PagedIterable<GHAppInstallation> listInstallations() {
201-
return root.createRequest()
200+
return root().createRequest()
202201
.withPreview(MACHINE_MAN)
203202
.withUrlPath("/app/installations")
204-
.toIterable(GHAppInstallation[].class, item -> item.wrapUp(root));
203+
.toIterable(GHAppInstallation[].class, item -> item.wrapUp(root()));
205204
}
206205

207206
/**
@@ -218,11 +217,11 @@ public PagedIterable<GHAppInstallation> listInstallations() {
218217
*/
219218
@Preview(MACHINE_MAN)
220219
public GHAppInstallation getInstallationById(long id) throws IOException {
221-
return root.createRequest()
220+
return root().createRequest()
222221
.withPreview(MACHINE_MAN)
223222
.withUrlPath(String.format("/app/installations/%d", id))
224223
.fetch(GHAppInstallation.class)
225-
.wrapUp(root);
224+
.wrapUp(root());
226225
}
227226

228227
/**
@@ -240,11 +239,11 @@ public GHAppInstallation getInstallationById(long id) throws IOException {
240239
*/
241240
@Preview(MACHINE_MAN)
242241
public GHAppInstallation getInstallationByOrganization(String name) throws IOException {
243-
return root.createRequest()
242+
return root().createRequest()
244243
.withPreview(MACHINE_MAN)
245244
.withUrlPath(String.format("/orgs/%s/installation", name))
246245
.fetch(GHAppInstallation.class)
247-
.wrapUp(root);
246+
.wrapUp(root());
248247
}
249248

250249
/**
@@ -264,11 +263,11 @@ public GHAppInstallation getInstallationByOrganization(String name) throws IOExc
264263
*/
265264
@Preview(MACHINE_MAN)
266265
public GHAppInstallation getInstallationByRepository(String ownerName, String repositoryName) throws IOException {
267-
return root.createRequest()
266+
return root().createRequest()
268267
.withPreview(MACHINE_MAN)
269268
.withUrlPath(String.format("/repos/%s/%s/installation", ownerName, repositoryName))
270269
.fetch(GHAppInstallation.class)
271-
.wrapUp(root);
270+
.wrapUp(root());
272271
}
273272

274273
/**
@@ -285,11 +284,11 @@ public GHAppInstallation getInstallationByRepository(String ownerName, String re
285284
*/
286285
@Preview(MACHINE_MAN)
287286
public GHAppInstallation getInstallationByUser(String name) throws IOException {
288-
return root.createRequest()
287+
return root().createRequest()
289288
.withPreview(MACHINE_MAN)
290289
.withUrlPath(String.format("/users/%s/installation", name))
291290
.fetch(GHAppInstallation.class)
292-
.wrapUp(root);
291+
.wrapUp(root());
293292
}
294293

295294
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class GHAppCreateTokenBuilder extends GitHubInteractiveObject {
2020

2121
@BetaApi
2222
GHAppCreateTokenBuilder(GitHub root, String apiUrlTail) {
23-
this.root = root;
23+
super(root);
2424
this.apiUrlTail = apiUrlTail;
2525
this.builder = root.createRequest();
2626
}
@@ -79,7 +79,7 @@ public GHAppInstallationToken create() throws IOException {
7979
.withPreview(MACHINE_MAN)
8080
.withUrlPath(apiUrlTail)
8181
.fetch(GHAppInstallationToken.class)
82-
.wrapUp(root);
82+
.wrapUp(root());
8383
}
8484

8585
}

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

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,6 @@ public URL getHtmlUrl() {
5050
return GitHubClient.parseURL(htmlUrl);
5151
}
5252

53-
/**
54-
* Gets root.
55-
*
56-
* @return the root
57-
* @deprecated This method should be used internally only.
58-
*/
59-
@Deprecated
60-
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior")
61-
public GitHub getRoot() {
62-
return root;
63-
}
64-
6553
/**
6654
* Sets root.
6755
*
@@ -136,12 +124,12 @@ public PagedSearchIterable<GHRepository> listRepositories() {
136124
GitHubRequest request;
137125

138126
try {
139-
request = root.createRequest().withPreview(MACHINE_MAN).withUrlPath("/installation/repositories").build();
127+
request = root().createRequest().withPreview(MACHINE_MAN).withUrlPath("/installation/repositories").build();
140128
} catch (MalformedURLException e) {
141129
throw new GHException("", e);
142130
}
143131

144-
return new PagedSearchIterable<>(root, request, GHAppInstallationRepositoryResult.class);
132+
return new PagedSearchIterable<>(root(), request, GHAppInstallationRepositoryResult.class);
145133
}
146134

147135
private static class GHAppInstallationRepositoryResult extends SearchResult<GHRepository> {
@@ -317,7 +305,6 @@ public void setRepositorySelection(GHRepositorySelection repositorySelection) {
317305
}
318306

319307
GHAppInstallation wrapUp(GitHub root) {
320-
this.root = root;
321308
return this;
322309
}
323310

@@ -332,7 +319,7 @@ GHAppInstallation wrapUp(GitHub root) {
332319
*/
333320
@Preview(GAMBIT)
334321
public void deleteInstallation() throws IOException {
335-
root.createRequest()
322+
root().createRequest()
336323
.method("DELETE")
337324
.withPreview(GAMBIT)
338325
.withUrlPath(String.format("/app/installations/%d", getId()))
@@ -353,7 +340,7 @@ public void deleteInstallation() throws IOException {
353340
*/
354341
@BetaApi
355342
public GHAppCreateTokenBuilder createToken(Map<String, GHPermissionType> permissions) {
356-
return new GHAppCreateTokenBuilder(root,
343+
return new GHAppCreateTokenBuilder(root(),
357344
String.format("/app/installations/%d/access_tokens", getId()),
358345
permissions);
359346
}
@@ -369,6 +356,6 @@ public GHAppCreateTokenBuilder createToken(Map<String, GHPermissionType> permiss
369356
*/
370357
@BetaApi
371358
public GHAppCreateTokenBuilder createToken() {
372-
return new GHAppCreateTokenBuilder(root, String.format("/app/installations/%d/access_tokens", getId()));
359+
return new GHAppCreateTokenBuilder(root(), String.format("/app/installations/%d/access_tokens", getId()));
373360
}
374361
}

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,6 @@ public class GHAppInstallationToken extends GitHubInteractiveObject {
1919
private List<GHRepository> repositories;
2020
private GHRepositorySelection repositorySelection;
2121

22-
/**
23-
* Gets root.
24-
*
25-
* @return the root
26-
* @deprecated This method should be used internally only.
27-
*/
28-
@Deprecated
29-
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior")
30-
public GitHub getRoot() {
31-
return root;
32-
}
33-
3422
/**
3523
* Sets root.
3624
*
@@ -145,7 +133,6 @@ private Object expiresAtStr(Date id, Class type) {
145133
}
146134

147135
GHAppInstallationToken wrapUp(GitHub root) {
148-
this.root = root;
149136
return this;
150137
}
151138
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public URL getHtmlUrl() throws IOException {
9999
* the io exception
100100
*/
101101
public void delete() throws IOException {
102-
root.createRequest().method("DELETE").withUrlPath(getApiRoute()).fetchHttpStatusCode();
102+
root().createRequest().method("DELETE").withUrlPath(getApiRoute()).fetchHttpStatusCode();
103103
}
104104

105105
/**
@@ -116,25 +116,24 @@ public void delete() throws IOException {
116116
public <T> T download(InputStreamFunction<T> streamFunction) throws IOException {
117117
requireNonNull(streamFunction, "Stream function must not be null");
118118

119-
return root.createRequest().method("GET").withUrlPath(getApiRoute(), "zip").fetchStream(streamFunction);
119+
return root().createRequest().method("GET").withUrlPath(getApiRoute(), "zip").fetchStream(streamFunction);
120120
}
121121

122122
private String getApiRoute() {
123123
if (owner == null) {
124124
// Workflow runs returned from search to do not have an owner. Attempt to use url.
125125
final URL url = Objects.requireNonNull(getUrl(), "Missing instance URL!");
126-
return StringUtils.prependIfMissing(url.toString().replace(root.getApiUrl(), ""), "/");
126+
return StringUtils.prependIfMissing(url.toString().replace(root().getApiUrl(), ""), "/");
127127
}
128128
return "/repos/" + owner.getOwnerName() + "/" + owner.getName() + "/actions/artifacts/" + getId();
129129
}
130130

131131
GHArtifact wrapUp(GHRepository owner) {
132132
this.owner = owner;
133-
return wrapUp(owner.root);
133+
return wrapUp(owner.root());
134134
}
135135

136136
GHArtifact wrapUp(GitHub root) {
137-
this.root = root;
138137
if (owner != null)
139138
owner.wrap(root);
140139
return this;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public GHArtifactsIterable(GHRepository owner, GitHubRequest.Builder<?> requestB
2727
@Override
2828
public PagedIterator<GHArtifact> _iterator(int pageSize) {
2929
return new PagedIterator<>(
30-
adapt(GitHubPageIterator.create(owner.getRoot().getClient(), GHArtifactsPage.class, request, pageSize)),
30+
adapt(GitHubPageIterator.create(owner.root().getClient(), GHArtifactsPage.class, request, pageSize)),
3131
null);
3232
}
3333

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,6 @@ public GHRepository getOwner() {
9292
return owner;
9393
}
9494

95-
/**
96-
* Gets root.
97-
*
98-
* @return the root
99-
* @deprecated This method should be used internally only.
100-
*/
101-
@Deprecated
102-
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior")
103-
public GitHub getRoot() {
104-
return root;
105-
}
106-
10795
/**
10896
* Gets size.
10997
*
@@ -140,7 +128,7 @@ public String getBrowserDownloadUrl() {
140128
}
141129

142130
private void edit(String key, Object value) throws IOException {
143-
root.createRequest().with(key, value).method("PATCH").withUrlPath(getApiRoute()).send();
131+
root().createRequest().with(key, value).method("PATCH").withUrlPath(getApiRoute()).send();
144132
}
145133

146134
/**
@@ -150,7 +138,7 @@ private void edit(String key, Object value) throws IOException {
150138
* the io exception
151139
*/
152140
public void delete() throws IOException {
153-
root.createRequest().method("DELETE").withUrlPath(getApiRoute()).send();
141+
root().createRequest().method("DELETE").withUrlPath(getApiRoute()).send();
154142
}
155143

156144
private String getApiRoute() {
@@ -159,7 +147,7 @@ private String getApiRoute() {
159147

160148
GHAsset wrap(GHRelease release) {
161149
this.owner = release.getOwner();
162-
this.root = owner.root;
150+
owner.root();
163151
return this;
164152
}
165153

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,6 @@ public class GHAuthorization extends GHObject {
4545
// TODO add some user class for https://developer.github.com/v3/oauth_authorizations/#check-an-authorization ?
4646
// private GHUser user;
4747

48-
/**
49-
* Gets root.
50-
*
51-
* @return the root
52-
* @deprecated This method should be used internally only.
53-
*/
54-
@Deprecated
55-
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior")
56-
public GitHub getRoot() {
57-
return root;
58-
}
59-
6048
/**
6149
* Gets scopes.
6250
*
@@ -159,7 +147,6 @@ public String getFingerprint() {
159147
}
160148

161149
GHAuthorization wrap(GitHub root) {
162-
this.root = root;
163150
return this;
164151
}
165152

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class GHBlobBuilder {
1212

1313
GHBlobBuilder(GHRepository repo) {
1414
this.repo = repo;
15-
req = repo.root.createRequest();
15+
req = repo.root().createRequest();
1616
}
1717

1818
/**

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,6 @@ public static class Commit {
4646
String url;
4747
}
4848

49-
/**
50-
* Gets root.
51-
*
52-
* @return the root
53-
* @deprecated This method should be used internally only.
54-
*/
55-
@Deprecated
56-
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior")
57-
public GitHub getRoot() {
58-
return root;
59-
}
60-
6149
/**
6250
* Gets owner.
6351
*
@@ -106,7 +94,7 @@ public URL getProtectionUrl() {
10694
*/
10795
@Preview(Previews.LUKE_CAGE)
10896
public GHBranchProtection getProtection() throws IOException {
109-
return root.createRequest()
97+
return root().createRequest()
11098
.withPreview(Previews.LUKE_CAGE)
11199
.setRawUrlPath(protection_url)
112100
.fetch(GHBranchProtection.class)
@@ -129,7 +117,7 @@ public String getSHA1() {
129117
* if disabling protection fails
130118
*/
131119
public void disableProtection() throws IOException {
132-
root.createRequest().method("DELETE").setRawUrlPath(protection_url).send();
120+
root().createRequest().method("DELETE").setRawUrlPath(protection_url).send();
133121
}
134122

135123
/**
@@ -207,7 +195,7 @@ public GHCommit merge(GHBranch headBranch, String commitMessage) throws IOExcept
207195
*/
208196
@CheckForNull
209197
public GHCommit merge(String head, String commitMessage) throws IOException {
210-
GHCommit result = root.createRequest()
198+
GHCommit result = root().createRequest()
211199
.withUrlPath(owner.getApiTailUrl("merges"))
212200
.method("POST")
213201
.with("commit_message", commitMessage)
@@ -234,7 +222,7 @@ public String toString() {
234222

235223
GHBranch wrap(GHRepository repo) {
236224
this.owner = repo;
237-
this.root = repo.root;
225+
repo.root();
238226
return this;
239227
}
240228
}

0 commit comments

Comments
 (0)