Skip to content

Commit

Permalink
Followup cleanup based on root streamlining
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman committed Sep 10, 2021
1 parent 29b01f6 commit b2bcced
Show file tree
Hide file tree
Showing 70 changed files with 326 additions and 624 deletions.
22 changes: 9 additions & 13 deletions src/main/java/org/kohsuke/github/GHApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,6 @@ public void setPermissions(Map<String, String> permissions) {
throw new RuntimeException("Do not use this method.");
}

GHApp wrapUp(GitHub root) {
return this;
}

/**
* Obtains all the installations associated with this app.
* <p>
Expand All @@ -200,7 +196,7 @@ public PagedIterable<GHAppInstallation> listInstallations() {
return root().createRequest()
.withPreview(MACHINE_MAN)
.withUrlPath("/app/installations")
.toIterable(GHAppInstallation[].class, item -> item.wrapUp(root()));
.toIterable(GHAppInstallation[].class, item -> root());
}

/**
Expand All @@ -217,11 +213,11 @@ public PagedIterable<GHAppInstallation> listInstallations() {
*/
@Preview(MACHINE_MAN)
public GHAppInstallation getInstallationById(long id) throws IOException {
root();
return root().createRequest()
.withPreview(MACHINE_MAN)
.withUrlPath(String.format("/app/installations/%d", id))
.fetch(GHAppInstallation.class)
.wrapUp(root());
.fetch(GHAppInstallation.class);
}

/**
Expand All @@ -239,11 +235,11 @@ public GHAppInstallation getInstallationById(long id) throws IOException {
*/
@Preview(MACHINE_MAN)
public GHAppInstallation getInstallationByOrganization(String name) throws IOException {
root();
return root().createRequest()
.withPreview(MACHINE_MAN)
.withUrlPath(String.format("/orgs/%s/installation", name))
.fetch(GHAppInstallation.class)
.wrapUp(root());
.fetch(GHAppInstallation.class);
}

/**
Expand All @@ -263,11 +259,11 @@ public GHAppInstallation getInstallationByOrganization(String name) throws IOExc
*/
@Preview(MACHINE_MAN)
public GHAppInstallation getInstallationByRepository(String ownerName, String repositoryName) throws IOException {
root();
return root().createRequest()
.withPreview(MACHINE_MAN)
.withUrlPath(String.format("/repos/%s/%s/installation", ownerName, repositoryName))
.fetch(GHAppInstallation.class)
.wrapUp(root());
.fetch(GHAppInstallation.class);
}

/**
Expand All @@ -284,11 +280,11 @@ public GHAppInstallation getInstallationByRepository(String ownerName, String re
*/
@Preview(MACHINE_MAN)
public GHAppInstallation getInstallationByUser(String name) throws IOException {
root();
return root().createRequest()
.withPreview(MACHINE_MAN)
.withUrlPath(String.format("/users/%s/installation", name))
.fetch(GHAppInstallation.class)
.wrapUp(root());
.fetch(GHAppInstallation.class);
}

}
4 changes: 2 additions & 2 deletions src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ public GHAppCreateTokenBuilder permissions(Map<String, GHPermissionType> permiss
*/
@Preview(MACHINE_MAN)
public GHAppInstallationToken create() throws IOException {
root();
return builder.method("POST")
.withPreview(MACHINE_MAN)
.withUrlPath(apiUrlTail)
.fetch(GHAppInstallationToken.class)
.wrapUp(root());
.fetch(GHAppInstallationToken.class);
}

}
8 changes: 2 additions & 6 deletions src/main/java/org/kohsuke/github/GHAppInstallation.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ private static class GHAppInstallationRepositoryResult extends SearchResult<GHRe

@Override
GHRepository[] getItems(GitHub root) {
for (GHRepository item : repositories)
item.wrap(root);
for (GHRepository item : repositories) {
}
return repositories;
}
}
Expand Down Expand Up @@ -304,10 +304,6 @@ public void setRepositorySelection(GHRepositorySelection repositorySelection) {
throw new RuntimeException("Do not use this method.");
}

GHAppInstallation wrapUp(GitHub root) {
return this;
}

/**
* Delete a Github App installation
* <p>
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/org/kohsuke/github/GHAppInstallationToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,4 @@ public Date getExpiresAt() throws IOException {
private Object expiresAtStr(Date id, Class type) {
return expires_at;
}

GHAppInstallationToken wrapUp(GitHub root) {
return this;
}
}
8 changes: 2 additions & 6 deletions src/main/java/org/kohsuke/github/GHArtifact.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,8 @@ private String getApiRoute() {

GHArtifact wrapUp(GHRepository owner) {
this.owner = owner;
return wrapUp(owner.root());
}

GHArtifact wrapUp(GitHub root) {
if (owner != null)
owner.wrap(root);
this.owner = owner;
return this;
}

}
1 change: 0 additions & 1 deletion src/main/java/org/kohsuke/github/GHAsset.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ private String getApiRoute() {

GHAsset wrap(GHRelease release) {
this.owner = release.getOwner();
owner.root();
return this;
}

Expand Down
4 changes: 0 additions & 4 deletions src/main/java/org/kohsuke/github/GHAuthorization.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,6 @@ public String getFingerprint() {
return fingerprint;
}

GHAuthorization wrap(GitHub root) {
return this;
}

@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD" },
justification = "JSON API")
private static class App {
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/kohsuke/github/GHBranch.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ public GHBranchProtection getProtection() throws IOException {
return root().createRequest()
.withPreview(Previews.LUKE_CAGE)
.setRawUrlPath(protection_url)
.fetch(GHBranchProtection.class)
.wrap(this);
.fetch(GHBranchProtection.class);
}

/**
Expand Down Expand Up @@ -222,7 +221,6 @@ public String toString() {

GHBranch wrap(GHRepository repo) {
this.owner = repo;
repo.root();
return this;
}
}
5 changes: 0 additions & 5 deletions src/main/java/org/kohsuke/github/GHBranchProtection.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,6 @@ public String getUrl() {
return url;
}

GHBranchProtection wrap(GHBranch branch) {
branch.root();
return this;
}

private Requester requester() {
return root().createRequest().withPreview(ZZZAX);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ public GHBranchProtection enable() throws IOException {
.withNullable("restrictions", restrictions)
.withNullable("enforce_admins", enforceAdmins)
.withUrlPath(branch.getProtectionUrl().toString())
.fetch(GHBranchProtection.class)
.wrap(branch);
.fetch(GHBranchProtection.class);
}

/**
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/org/kohsuke/github/GHCheckRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ GHCheckRun wrap(GHRepository owner) {

GHCheckRun wrap(GitHub root) {
if (owner != null) {
owner.wrap(root);
for (GHPullRequest singlePull : pullRequests) {
singlePull.wrap(owner);
}
Expand All @@ -62,9 +61,6 @@ GHCheckRun wrap(GitHub root) {
checkSuite.wrap(root);
}
}
if (app != null) {
app.wrapUp(root);
}

return this;
}
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/org/kohsuke/github/GHCheckSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,12 @@ GHCheckSuite wrap(GHRepository owner) {

GHCheckSuite wrap(GitHub root) {
if (owner != null) {
owner.wrap(root);
if (pullRequests != null && pullRequests.length != 0) {
for (GHPullRequest singlePull : pullRequests) {
singlePull.wrap(owner);
}
}
}
if (app != null) {
app.wrapUp(root);
}
return this;
}

Expand Down
10 changes: 3 additions & 7 deletions src/main/java/org/kohsuke/github/GHCommitComment.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public int getLine() {
* the io exception
*/
public GHUser getUser() throws IOException {
return owner == null || owner.root().isOffline() ? user : owner.root().getUser(user.login);
return owner == null || owner.isOffline() ? user : owner.root().getUser(user.login);
}

/**
Expand Down Expand Up @@ -131,8 +131,7 @@ public GHReaction createReaction(ReactionContent content) throws IOException {
.withPreview(SQUIRREL_GIRL)
.with("content", content.getContent())
.withUrlPath(getApiTail() + "/reactions")
.fetch(GHReaction.class)
.wrap(owner.root());
.fetch(GHReaction.class);
}

@Preview(SQUIRREL_GIRL)
Expand All @@ -141,7 +140,7 @@ public PagedIterable<GHReaction> listReactions() {
.createRequest()
.withPreview(SQUIRREL_GIRL)
.withUrlPath(getApiTail() + "/reactions")
.toIterable(GHReaction[].class, item -> item.wrap(owner.root()));
.toIterable(GHReaction[].class, item -> owner.root());
}

/**
Expand All @@ -160,9 +159,6 @@ private String getApiTail() {

GHCommitComment wrap(GHRepository owner) {
this.owner = owner;
if (owner.root().isOffline()) {
user.wrapUp(owner.root());
}
return this;
}
}
6 changes: 0 additions & 6 deletions src/main/java/org/kohsuke/github/GHCommitPointer.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,4 @@ public GHCommit getCommit() throws IOException {
return getRepository().getCommit(getSha());
}

void wrapUp(GitHub root) {
if (user != null) {
}
if (repo != null)
repo.wrap(root);
}
}
6 changes: 0 additions & 6 deletions src/main/java/org/kohsuke/github/GHCommitStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ public class GHCommitStatus extends GHObject {
String context;
GHUser creator;

GHCommitStatus wrapUp(GitHub root) {
if (creator != null)
creator.wrapUp(root);
return this;
}

/**
* Gets state.
*
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/org/kohsuke/github/GHContent.java
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,6 @@ static String getApiRoute(GHRepository repository, String path) {

GHContent wrap(GHRepository owner) {
this.repository = owner;
owner.root();
return this;
}

GHContent wrap(GitHub root) {
if (repository != null)
repository.wrap(root);
return this;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/kohsuke/github/GHContentSearchBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ private static class ContentSearchResult extends SearchResult<GHContent> {

@Override
GHContent[] getItems(GitHub root) {
for (GHContent item : items)
item.wrap(root);
for (GHContent item : items) {
}
return items;
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/kohsuke/github/GHContentWithLicense.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class GHContentWithLicense extends GHContent {
@Override
GHContentWithLicense wrap(GHRepository owner) {
super.wrap(owner);
if (license != null)
license.wrap(owner.root());
return this;
}
}
7 changes: 4 additions & 3 deletions src/main/java/org/kohsuke/github/GHDeployment.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ public class GHDeployment extends GHObject {

GHDeployment wrap(GHRepository owner) {
this.owner = owner;
owner.root();
if (creator != null)
creator.wrapUp(root());
return this;
}

Expand Down Expand Up @@ -201,4 +198,8 @@ public PagedIterable<GHDeploymentStatus> listStatuses() {
.toIterable(GHDeploymentStatus[].class, item -> item.lateBind(owner));
}

// test only
GHRepository getOwner() {
return owner;
}
}
8 changes: 5 additions & 3 deletions src/main/java/org/kohsuke/github/GHDeploymentStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ public GHDeploymentStatus wrap(GHRepository owner) {
*/
GHDeploymentStatus lateBind(GHRepository owner) {
this.owner = owner;
owner.root();
if (creator != null)
creator.wrapUp(root());
return this;
}

Expand Down Expand Up @@ -120,4 +117,9 @@ public GHDeploymentState getState() {
public URL getHtmlUrl() {
return null;
}

// test only
GHRepository getOwner() {
return owner;
}
}
6 changes: 1 addition & 5 deletions src/main/java/org/kohsuke/github/GHEventInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ public GHEvent getType() {
return transformTypeToGHEvent(type);
}

GHEventInfo wrapUp(GitHub root) {
return this;
}

/**
* Gets id.
*
Expand Down Expand Up @@ -177,7 +173,7 @@ public GHOrganization getOrganization() throws IOException {
*/
public <T extends GHEventPayload> T getPayload(Class<T> type) throws IOException {
T v = GitHubClient.getMappingObjectReader(root()).readValue(payload.traverse(), type);
v.wrapUp(root());
v.lateBind();
return v;
}
}
Loading

0 comments on commit b2bcced

Please sign in to comment.