diff --git a/src/main/java/org/kohsuke/github/AbstractBuilder.java b/src/main/java/org/kohsuke/github/AbstractBuilder.java index b72541d43a..c52280fa9d 100644 --- a/src/main/java/org/kohsuke/github/AbstractBuilder.java +++ b/src/main/java/org/kohsuke/github/AbstractBuilder.java @@ -38,7 +38,7 @@ * Intermediate return type for this builder returned by calls to {@link #with(String, Object)}. If {@link S} * the same as {@link R}, this builder will commit changes after each call to {@link #with(String, Object)}. */ -abstract class AbstractBuilder { +abstract class AbstractBuilder extends GitHubInteractiveObject { @Nonnull private final Class returnType; @@ -75,6 +75,7 @@ protected AbstractBuilder(@Nonnull Class finalReturnType, @Nonnull Class intermediateReturnType, @Nonnull GitHub root, @CheckForNull R baseInstance) { + super(root); this.requester = root.createRequest(); this.returnType = finalReturnType; this.commitChangesImmediately = returnType.equals(intermediateReturnType); diff --git a/src/main/java/org/kohsuke/github/GHApp.java b/src/main/java/org/kohsuke/github/GHApp.java index 20e81090f1..6300887938 100644 --- a/src/main/java/org/kohsuke/github/GHApp.java +++ b/src/main/java/org/kohsuke/github/GHApp.java @@ -15,7 +15,6 @@ */ public class GHApp extends GHObject { - private GitHub root; private GHUser owner; private String name; private String description; diff --git a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java index 802c04693e..6d25d26b3f 100644 --- a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java +++ b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java @@ -14,8 +14,7 @@ * @see GHAppInstallation#createToken(Map) GHAppInstallation#createToken(Map) * @see GHAppInstallation#createToken() GHAppInstallation#createToken() */ -public class GHAppCreateTokenBuilder { - private final GitHub root; +public class GHAppCreateTokenBuilder extends GitHubInteractiveObject { protected final Requester builder; private final String apiUrlTail; diff --git a/src/main/java/org/kohsuke/github/GHAppInstallation.java b/src/main/java/org/kohsuke/github/GHAppInstallation.java index d9dc3b4197..167105aa8f 100644 --- a/src/main/java/org/kohsuke/github/GHAppInstallation.java +++ b/src/main/java/org/kohsuke/github/GHAppInstallation.java @@ -22,7 +22,6 @@ * @see GHApp#getInstallationByUser(String) GHApp#getInstallationByUser(String) */ public class GHAppInstallation extends GHObject { - private GitHub root; private GHUser account; @JsonProperty("access_tokens_url") diff --git a/src/main/java/org/kohsuke/github/GHAppInstallationToken.java b/src/main/java/org/kohsuke/github/GHAppInstallationToken.java index b236d1a6a2..cf18cc3fe2 100644 --- a/src/main/java/org/kohsuke/github/GHAppInstallationToken.java +++ b/src/main/java/org/kohsuke/github/GHAppInstallationToken.java @@ -14,9 +14,7 @@ * @author Paulo Miguel Almeida * @see GHAppInstallation#createToken(Map) GHAppInstallation#createToken(Map) */ -public class GHAppInstallationToken { - private GitHub root; - +public class GHAppInstallationToken extends GitHubInteractiveObject { private String token; protected String expires_at; private Map permissions; diff --git a/src/main/java/org/kohsuke/github/GHAsset.java b/src/main/java/org/kohsuke/github/GHAsset.java index 7822df6875..566507ec0d 100644 --- a/src/main/java/org/kohsuke/github/GHAsset.java +++ b/src/main/java/org/kohsuke/github/GHAsset.java @@ -9,7 +9,6 @@ * @see GHRelease#getAssets() GHRelease#getAssets() */ public class GHAsset extends GHObject { - GitHub root; GHRepository owner; private String name; private String label; diff --git a/src/main/java/org/kohsuke/github/GHAuthorization.java b/src/main/java/org/kohsuke/github/GHAuthorization.java index 420a742321..f66b84d015 100644 --- a/src/main/java/org/kohsuke/github/GHAuthorization.java +++ b/src/main/java/org/kohsuke/github/GHAuthorization.java @@ -33,7 +33,6 @@ public class GHAuthorization extends GHObject { public static final String WRITE_KEY = "write:public_key"; public static final String ADMIN_KEY = "admin:public_key"; - private GitHub root; private List scopes; private String token; private String token_last_eight; diff --git a/src/main/java/org/kohsuke/github/GHBranch.java b/src/main/java/org/kohsuke/github/GHBranch.java index 702b24c225..fdce55b1d2 100644 --- a/src/main/java/org/kohsuke/github/GHBranch.java +++ b/src/main/java/org/kohsuke/github/GHBranch.java @@ -20,8 +20,7 @@ value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD", "URF_UNREAD_FIELD" }, justification = "JSON API") -public class GHBranch { - private GitHub root; +public class GHBranch extends GitHubInteractiveObject { private GHRepository owner; private String name; diff --git a/src/main/java/org/kohsuke/github/GHBranchProtection.java b/src/main/java/org/kohsuke/github/GHBranchProtection.java index 4f9728fcfe..9f8aebd18c 100644 --- a/src/main/java/org/kohsuke/github/GHBranchProtection.java +++ b/src/main/java/org/kohsuke/github/GHBranchProtection.java @@ -17,14 +17,12 @@ value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD", "URF_UNREAD_FIELD" }, justification = "JSON API") -public class GHBranchProtection { +public class GHBranchProtection extends GitHubInteractiveObject { private static final String REQUIRE_SIGNATURES_URI = "/required_signatures"; @JsonProperty private EnforceAdmins enforceAdmins; - private GitHub root; - @JsonProperty("required_pull_request_reviews") private RequiredReviews requiredReviews; diff --git a/src/main/java/org/kohsuke/github/GHCheckRun.java b/src/main/java/org/kohsuke/github/GHCheckRun.java index f41b96693b..c28430022c 100644 --- a/src/main/java/org/kohsuke/github/GHCheckRun.java +++ b/src/main/java/org/kohsuke/github/GHCheckRun.java @@ -22,7 +22,6 @@ public class GHCheckRun extends GHObject { @JsonProperty("repository") GHRepository owner; - GitHub root; private String status; private String conclusion; diff --git a/src/main/java/org/kohsuke/github/GHCheckRunsIterable.java b/src/main/java/org/kohsuke/github/GHCheckRunsIterable.java index 10e7edd61b..9af3e27cd7 100644 --- a/src/main/java/org/kohsuke/github/GHCheckRunsIterable.java +++ b/src/main/java/org/kohsuke/github/GHCheckRunsIterable.java @@ -8,7 +8,7 @@ * Iterable for check-runs listing. */ class GHCheckRunsIterable extends PagedIterable { - private GitHub root; + private final transient GitHub root; private final GitHubRequest request; private GHCheckRunsPage result; diff --git a/src/main/java/org/kohsuke/github/GHCheckSuite.java b/src/main/java/org/kohsuke/github/GHCheckSuite.java index 2f4bf55430..b22aa28509 100644 --- a/src/main/java/org/kohsuke/github/GHCheckSuite.java +++ b/src/main/java/org/kohsuke/github/GHCheckSuite.java @@ -21,7 +21,6 @@ public class GHCheckSuite extends GHObject { @JsonProperty("repository") GHRepository owner; - GitHub root; private String nodeId; private String headBranch; diff --git a/src/main/java/org/kohsuke/github/GHCommitStatus.java b/src/main/java/org/kohsuke/github/GHCommitStatus.java index d1ac12bba2..442591452d 100644 --- a/src/main/java/org/kohsuke/github/GHCommitStatus.java +++ b/src/main/java/org/kohsuke/github/GHCommitStatus.java @@ -18,8 +18,6 @@ public class GHCommitStatus extends GHObject { String context; GHUser creator; - private GitHub root; - GHCommitStatus wrapUp(GitHub root) { if (creator != null) creator.wrapUp(root); diff --git a/src/main/java/org/kohsuke/github/GHContent.java b/src/main/java/org/kohsuke/github/GHContent.java index 107465ff6e..8c9a73716f 100644 --- a/src/main/java/org/kohsuke/github/GHContent.java +++ b/src/main/java/org/kohsuke/github/GHContent.java @@ -15,15 +15,13 @@ * @see GHRepository#getFileContent(String) GHRepository#getFileContent(String) */ @SuppressWarnings({ "UnusedDeclaration" }) -public class GHContent implements Refreshable { +public class GHContent extends GitHubInteractiveObject implements Refreshable { /* * In normal use of this class, repository field is set via wrap(), but in the code search API, there's a nested * 'repository' field that gets populated from JSON. */ private GHRepository repository; - private GitHub root; - private String type; private String encoding; private long size; diff --git a/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java b/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java index ed8f72a845..4228df8c16 100644 --- a/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java @@ -10,8 +10,7 @@ * * @author Kohsuke Kawaguchi */ -public class GHCreateRepositoryBuilder { - private final GitHub root; +public class GHCreateRepositoryBuilder extends GitHubInteractiveObject { protected final Requester builder; private String apiUrlTail; diff --git a/src/main/java/org/kohsuke/github/GHDeployment.java b/src/main/java/org/kohsuke/github/GHDeployment.java index 2a8f60ab5f..067d67a8d1 100644 --- a/src/main/java/org/kohsuke/github/GHDeployment.java +++ b/src/main/java/org/kohsuke/github/GHDeployment.java @@ -14,7 +14,6 @@ */ public class GHDeployment extends GHObject { private GHRepository owner; - private GitHub root; protected String sha; protected String ref; protected String task; diff --git a/src/main/java/org/kohsuke/github/GHDeploymentStatus.java b/src/main/java/org/kohsuke/github/GHDeploymentStatus.java index de423a8e33..ea242deda7 100644 --- a/src/main/java/org/kohsuke/github/GHDeploymentStatus.java +++ b/src/main/java/org/kohsuke/github/GHDeploymentStatus.java @@ -8,7 +8,6 @@ */ public class GHDeploymentStatus extends GHObject { private GHRepository owner; - private GitHub root; protected GHUser creator; protected String state; protected String description; diff --git a/src/main/java/org/kohsuke/github/GHDiscussion.java b/src/main/java/org/kohsuke/github/GHDiscussion.java index 93a9ee2328..81ea3179e3 100644 --- a/src/main/java/org/kohsuke/github/GHDiscussion.java +++ b/src/main/java/org/kohsuke/github/GHDiscussion.java @@ -1,6 +1,5 @@ package org.kohsuke.github; -import com.fasterxml.jackson.annotation.JacksonInject; import com.fasterxml.jackson.annotation.JsonProperty; import java.io.IOException; @@ -18,8 +17,6 @@ */ public class GHDiscussion extends GHObject { - @JacksonInject - private GitHub root; private GHTeam team; private long number; private String body, title, htmlUrl; diff --git a/src/main/java/org/kohsuke/github/GHEventInfo.java b/src/main/java/org/kohsuke/github/GHEventInfo.java index c26f37157d..c1ce2f0241 100644 --- a/src/main/java/org/kohsuke/github/GHEventInfo.java +++ b/src/main/java/org/kohsuke/github/GHEventInfo.java @@ -12,9 +12,7 @@ * @author Kohsuke Kawaguchi */ @SuppressFBWarnings(value = "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", justification = "JSON API") -public class GHEventInfo { - private GitHub root; - +public class GHEventInfo extends GitHubInteractiveObject { // we don't want to expose Jackson dependency to the user. This needs databinding private ObjectNode payload; diff --git a/src/main/java/org/kohsuke/github/GHEventPayload.java b/src/main/java/org/kohsuke/github/GHEventPayload.java index 591de1cb03..d0509ddf9f 100644 --- a/src/main/java/org/kohsuke/github/GHEventPayload.java +++ b/src/main/java/org/kohsuke/github/GHEventPayload.java @@ -17,9 +17,7 @@ */ @SuppressWarnings("UnusedDeclaration") @SuppressFBWarnings("UWF_UNWRITTEN_FIELD") -public class GHEventPayload { - protected GitHub root; - +public class GHEventPayload extends GitHubInteractiveObject { // https://docs.github.com/en/free-pro-team@latest/developers/webhooks-and-events/webhook-events-and-payloads#webhook-payload-object-common-properties // Webhook payload object common properties: action, sender, repository, organization, installation private String action; diff --git a/src/main/java/org/kohsuke/github/GHGist.java b/src/main/java/org/kohsuke/github/GHGist.java index cba91e6276..f326cf776b 100644 --- a/src/main/java/org/kohsuke/github/GHGist.java +++ b/src/main/java/org/kohsuke/github/GHGist.java @@ -23,7 +23,6 @@ public class GHGist extends GHObject { final GHUser owner; - final GitHub root; private String forks_url, commits_url, id, git_pull_url, git_push_url, html_url; diff --git a/src/main/java/org/kohsuke/github/GHGistBuilder.java b/src/main/java/org/kohsuke/github/GHGistBuilder.java index 8df07bb99e..e7ba88965c 100644 --- a/src/main/java/org/kohsuke/github/GHGistBuilder.java +++ b/src/main/java/org/kohsuke/github/GHGistBuilder.java @@ -13,7 +13,6 @@ * @see GitHub#createGist() GitHub#createGist() */ public class GHGistBuilder { - private final GitHub root; private final Requester req; private final LinkedHashMap files = new LinkedHashMap(); @@ -24,7 +23,6 @@ public class GHGistBuilder { * the root */ public GHGistBuilder(GitHub root) { - this.root = root; req = root.createRequest().method("POST"); } diff --git a/src/main/java/org/kohsuke/github/GHHooks.java b/src/main/java/org/kohsuke/github/GHHooks.java index 05ad6fc3b8..683f5972a3 100644 --- a/src/main/java/org/kohsuke/github/GHHooks.java +++ b/src/main/java/org/kohsuke/github/GHHooks.java @@ -12,8 +12,7 @@ * functionality */ class GHHooks { - static abstract class Context { - private final GitHub root; + static abstract class Context extends GitHubInteractiveObject { private Context(GitHub root) { this.root = root; diff --git a/src/main/java/org/kohsuke/github/GHInvitation.java b/src/main/java/org/kohsuke/github/GHInvitation.java index ff25633a24..41a07e0311 100644 --- a/src/main/java/org/kohsuke/github/GHInvitation.java +++ b/src/main/java/org/kohsuke/github/GHInvitation.java @@ -16,7 +16,6 @@ "UUF_UNUSED_FIELD" }, justification = "JSON API") public class GHInvitation extends GHObject { - /* package almost final */ GitHub root; private int id; private GHRepository repository; diff --git a/src/main/java/org/kohsuke/github/GHIssue.java b/src/main/java/org/kohsuke/github/GHIssue.java index 6a2f13fb66..63817c10e2 100644 --- a/src/main/java/org/kohsuke/github/GHIssue.java +++ b/src/main/java/org/kohsuke/github/GHIssue.java @@ -53,7 +53,6 @@ public class GHIssue extends GHObject implements Reactable { private static final String ASSIGNEES = "assignees"; - GitHub root; GHRepository owner; // API v3 diff --git a/src/main/java/org/kohsuke/github/GHIssueEvent.java b/src/main/java/org/kohsuke/github/GHIssueEvent.java index 88f38eec8d..761004f847 100644 --- a/src/main/java/org/kohsuke/github/GHIssueEvent.java +++ b/src/main/java/org/kohsuke/github/GHIssueEvent.java @@ -9,9 +9,7 @@ * * @author Martin van Zijl */ -public class GHIssueEvent { - private GitHub root; - +public class GHIssueEvent extends GitHubInteractiveObject { private long id; private String node_id; private String url; diff --git a/src/main/java/org/kohsuke/github/GHKey.java b/src/main/java/org/kohsuke/github/GHKey.java index a8e6477bee..440e4483cf 100644 --- a/src/main/java/org/kohsuke/github/GHKey.java +++ b/src/main/java/org/kohsuke/github/GHKey.java @@ -9,9 +9,7 @@ * @author Kohsuke Kawaguchi */ @SuppressFBWarnings(value = "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", justification = "JSON API") -public class GHKey { - /* package almost final */ GitHub root; - +public class GHKey extends GitHubInteractiveObject { protected String url, key, title; protected boolean verified; protected int id; diff --git a/src/main/java/org/kohsuke/github/GHLabel.java b/src/main/java/org/kohsuke/github/GHLabel.java index 07cf3bfa0a..85628d5d33 100644 --- a/src/main/java/org/kohsuke/github/GHLabel.java +++ b/src/main/java/org/kohsuke/github/GHLabel.java @@ -20,7 +20,7 @@ * @see GHIssue#getLabels() GHIssue#getLabels() * @see GHRepository#listLabels() GHRepository#listLabels() */ -public class GHLabel { +public class GHLabel extends GitHubInteractiveObject { @Nonnull private String url, name, color; @@ -28,9 +28,6 @@ public class GHLabel { @CheckForNull private String description; - @Nonnull - private final GitHub root; - @JsonCreator private GHLabel(@JacksonInject @Nonnull GitHub root) { this.root = root; diff --git a/src/main/java/org/kohsuke/github/GHLicense.java b/src/main/java/org/kohsuke/github/GHLicense.java index 9a80c6fca3..acaf19f644 100644 --- a/src/main/java/org/kohsuke/github/GHLicense.java +++ b/src/main/java/org/kohsuke/github/GHLicense.java @@ -44,9 +44,6 @@ @SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" }, justification = "JSON API") public class GHLicense extends GHObject { - @SuppressFBWarnings("IS2_INCONSISTENT_SYNC") - // root is set before the object is returned to the app - /* package almost final */ GitHub root; // these fields are always present, even in the short form protected String key, name; diff --git a/src/main/java/org/kohsuke/github/GHMarketplaceAccount.java b/src/main/java/org/kohsuke/github/GHMarketplaceAccount.java index 9279da593c..59d5f5608f 100644 --- a/src/main/java/org/kohsuke/github/GHMarketplaceAccount.java +++ b/src/main/java/org/kohsuke/github/GHMarketplaceAccount.java @@ -9,9 +9,7 @@ * @see GitHub#getMyMarketplacePurchases() * @see GHMarketplaceListAccountBuilder#createRequest() */ -public class GHMarketplaceAccount { - - protected GitHub root; +public class GHMarketplaceAccount extends GitHubInteractiveObject { private String url; private long id; private String login; diff --git a/src/main/java/org/kohsuke/github/GHMarketplaceListAccountBuilder.java b/src/main/java/org/kohsuke/github/GHMarketplaceListAccountBuilder.java index 5df0feabe0..b2e77177d0 100644 --- a/src/main/java/org/kohsuke/github/GHMarketplaceListAccountBuilder.java +++ b/src/main/java/org/kohsuke/github/GHMarketplaceListAccountBuilder.java @@ -8,8 +8,7 @@ * @author Paulo Miguel Almeida * @see GHMarketplacePlan#listAccounts() */ -public class GHMarketplaceListAccountBuilder { - private final GitHub root; +public class GHMarketplaceListAccountBuilder extends GitHubInteractiveObject { private final Requester builder; private final long planId; diff --git a/src/main/java/org/kohsuke/github/GHMarketplacePendingChange.java b/src/main/java/org/kohsuke/github/GHMarketplacePendingChange.java index 80f57f34c7..ecbcba1579 100644 --- a/src/main/java/org/kohsuke/github/GHMarketplacePendingChange.java +++ b/src/main/java/org/kohsuke/github/GHMarketplacePendingChange.java @@ -10,8 +10,7 @@ * @author Paulo Miguel Almeida * @see GHMarketplaceListAccountBuilder#createRequest() */ -public class GHMarketplacePendingChange { - private GitHub root; +public class GHMarketplacePendingChange extends GitHubInteractiveObject { private long id; @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization") private Long unitCount; diff --git a/src/main/java/org/kohsuke/github/GHMarketplacePlan.java b/src/main/java/org/kohsuke/github/GHMarketplacePlan.java index 061338588c..988a0dac9b 100644 --- a/src/main/java/org/kohsuke/github/GHMarketplacePlan.java +++ b/src/main/java/org/kohsuke/github/GHMarketplacePlan.java @@ -11,9 +11,7 @@ * @author Paulo Miguel Almeida * @see GitHub#listMarketplacePlans() */ -public class GHMarketplacePlan { - - private GitHub root; +public class GHMarketplacePlan extends GitHubInteractiveObject { private String url; private String accountsUrl; private long id; diff --git a/src/main/java/org/kohsuke/github/GHMarketplacePurchase.java b/src/main/java/org/kohsuke/github/GHMarketplacePurchase.java index eec1e344e4..78e6db7f98 100644 --- a/src/main/java/org/kohsuke/github/GHMarketplacePurchase.java +++ b/src/main/java/org/kohsuke/github/GHMarketplacePurchase.java @@ -10,9 +10,8 @@ * @author Paulo Miguel Almeida * @see GHMarketplaceListAccountBuilder#createRequest() GHMarketplaceListAccountBuilder#createRequest() */ -public class GHMarketplacePurchase { +public class GHMarketplacePurchase extends GitHubInteractiveObject { - private GitHub root; private String billingCycle; private String nextBillingDate; private boolean onFreeTrial; diff --git a/src/main/java/org/kohsuke/github/GHMarketplaceUserPurchase.java b/src/main/java/org/kohsuke/github/GHMarketplaceUserPurchase.java index 6d6de83aa0..a73b5ea157 100644 --- a/src/main/java/org/kohsuke/github/GHMarketplaceUserPurchase.java +++ b/src/main/java/org/kohsuke/github/GHMarketplaceUserPurchase.java @@ -10,8 +10,7 @@ * @author Paulo Miguel Almeida * @see GitHub#getMyMarketplacePurchases() */ -public class GHMarketplaceUserPurchase { - protected GitHub root; +public class GHMarketplaceUserPurchase extends GitHubInteractiveObject { private String billingCycle; private String nextBillingDate; private boolean onFreeTrial; diff --git a/src/main/java/org/kohsuke/github/GHMembership.java b/src/main/java/org/kohsuke/github/GHMembership.java index 68965db794..8a29b4da90 100644 --- a/src/main/java/org/kohsuke/github/GHMembership.java +++ b/src/main/java/org/kohsuke/github/GHMembership.java @@ -10,9 +10,7 @@ * @author Kohsuke Kawaguchi * @see GHMyself#listOrgMemberships() GHMyself#listOrgMemberships() */ -public class GHMembership /* extends GHObject --- but it doesn't have id, created_at, etc. */ { - GitHub root; - +public class GHMembership extends GitHubInteractiveObject { String url; String state; String role; diff --git a/src/main/java/org/kohsuke/github/GHMilestone.java b/src/main/java/org/kohsuke/github/GHMilestone.java index 6c120519e2..e33e754d86 100644 --- a/src/main/java/org/kohsuke/github/GHMilestone.java +++ b/src/main/java/org/kohsuke/github/GHMilestone.java @@ -11,7 +11,6 @@ * @author Yusuke Kokubo */ public class GHMilestone extends GHObject { - GitHub root; GHRepository owner; GHUser creator; diff --git a/src/main/java/org/kohsuke/github/GHNotificationStream.java b/src/main/java/org/kohsuke/github/GHNotificationStream.java index a6de3d3404..62084b542f 100644 --- a/src/main/java/org/kohsuke/github/GHNotificationStream.java +++ b/src/main/java/org/kohsuke/github/GHNotificationStream.java @@ -23,9 +23,7 @@ * @see GitHub#listNotifications() GitHub#listNotifications() * @see GHRepository#listNotifications() GHRepository#listNotifications() */ -public class GHNotificationStream implements Iterable { - private final GitHub root; - +public class GHNotificationStream extends GitHubInteractiveObject implements Iterable { private Boolean all, participating; private String since; private String apiUrl; diff --git a/src/main/java/org/kohsuke/github/GHObject.java b/src/main/java/org/kohsuke/github/GHObject.java index 299fc53425..c45c1404a1 100644 --- a/src/main/java/org/kohsuke/github/GHObject.java +++ b/src/main/java/org/kohsuke/github/GHObject.java @@ -20,7 +20,7 @@ */ @SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" }, justification = "JSON API") -public abstract class GHObject { +public abstract class GHObject extends GitHubInteractiveObject { /** * Capture response HTTP headers on the state object. */ diff --git a/src/main/java/org/kohsuke/github/GHPerson.java b/src/main/java/org/kohsuke/github/GHPerson.java index 3f4dade226..479dc6d04b 100644 --- a/src/main/java/org/kohsuke/github/GHPerson.java +++ b/src/main/java/org/kohsuke/github/GHPerson.java @@ -18,7 +18,6 @@ * @author Kohsuke Kawaguchi */ public abstract class GHPerson extends GHObject { - /* package almost final */ GitHub root; // core data fields that exist even for "small" user data (such as the user info in pull request) protected String login, avatar_url; diff --git a/src/main/java/org/kohsuke/github/GHProject.java b/src/main/java/org/kohsuke/github/GHProject.java index 76ec6aca50..033770d403 100644 --- a/src/main/java/org/kohsuke/github/GHProject.java +++ b/src/main/java/org/kohsuke/github/GHProject.java @@ -37,7 +37,6 @@ * @see Projects */ public class GHProject extends GHObject { - protected GitHub root; protected GHObject owner; private String owner_url; diff --git a/src/main/java/org/kohsuke/github/GHProjectCard.java b/src/main/java/org/kohsuke/github/GHProjectCard.java index d86f34b690..089b535880 100644 --- a/src/main/java/org/kohsuke/github/GHProjectCard.java +++ b/src/main/java/org/kohsuke/github/GHProjectCard.java @@ -14,7 +14,6 @@ * @author Gunnar Skjold */ public class GHProjectCard extends GHObject { - private GitHub root; private GHProject project; private GHProjectColumn column; diff --git a/src/main/java/org/kohsuke/github/GHProjectColumn.java b/src/main/java/org/kohsuke/github/GHProjectColumn.java index 4d42a9127e..5a6a407244 100644 --- a/src/main/java/org/kohsuke/github/GHProjectColumn.java +++ b/src/main/java/org/kohsuke/github/GHProjectColumn.java @@ -12,7 +12,6 @@ * @author Gunnar Skjold */ public class GHProjectColumn extends GHObject { - protected GitHub root; protected GHProject project; private String name; diff --git a/src/main/java/org/kohsuke/github/GHQueryBuilder.java b/src/main/java/org/kohsuke/github/GHQueryBuilder.java index b9ee5e061d..06bf92bcbe 100644 --- a/src/main/java/org/kohsuke/github/GHQueryBuilder.java +++ b/src/main/java/org/kohsuke/github/GHQueryBuilder.java @@ -7,8 +7,7 @@ * the type parameter * @author Kohsuke Kawaguchi */ -public abstract class GHQueryBuilder { - protected final GitHub root; +public abstract class GHQueryBuilder extends GitHubInteractiveObject { protected final Requester req; GHQueryBuilder(GitHub root) { diff --git a/src/main/java/org/kohsuke/github/GHReaction.java b/src/main/java/org/kohsuke/github/GHReaction.java index e7da06ee03..04be4c103a 100644 --- a/src/main/java/org/kohsuke/github/GHReaction.java +++ b/src/main/java/org/kohsuke/github/GHReaction.java @@ -14,7 +14,6 @@ @Preview(SQUIRREL_GIRL) @Deprecated public class GHReaction extends GHObject { - private GitHub root; private GHUser user; private ReactionContent content; diff --git a/src/main/java/org/kohsuke/github/GHRef.java b/src/main/java/org/kohsuke/github/GHRef.java index 7eac15dca2..0643f0ce2e 100644 --- a/src/main/java/org/kohsuke/github/GHRef.java +++ b/src/main/java/org/kohsuke/github/GHRef.java @@ -11,9 +11,7 @@ * * @author Michael Clarke */ -public class GHRef { - /* package almost final */ GitHub root; - +public class GHRef extends GitHubInteractiveObject { private String ref, url; private GHObject object; diff --git a/src/main/java/org/kohsuke/github/GHRelease.java b/src/main/java/org/kohsuke/github/GHRelease.java index 7ab145bcbe..219c3e28b5 100644 --- a/src/main/java/org/kohsuke/github/GHRelease.java +++ b/src/main/java/org/kohsuke/github/GHRelease.java @@ -19,7 +19,6 @@ * @see GHRepository#createRelease(String) GHRepository#createRelease(String) */ public class GHRelease extends GHObject { - GitHub root; GHRepository owner; private String html_url; diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index ba4a16de93..ca6c5a205f 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -66,7 +66,6 @@ @SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" }, justification = "JSON API") public class GHRepository extends GHObject { - /* package almost final */ transient GitHub root; private String nodeId, description, homepage, name, full_name; @@ -2202,7 +2201,12 @@ public GHHook createWebHook(URL url) throws IOException { justification = "It causes a performance degradation, but we have already exposed it to the API") @Deprecated public Set getPostCommitHooks() { - return postCommitHooks; + synchronized (this) { + if (postCommitHooks == null) { + postCommitHooks = setupPostCommitHooks(); + } + return postCommitHooks; + } } /** @@ -2211,57 +2215,63 @@ public Set getPostCommitHooks() { @SuppressFBWarnings(value = "DMI_COLLECTION_OF_URLS", justification = "It causes a performance degradation, but we have already exposed it to the API") @SkipFromToString - private final Set postCommitHooks = new AbstractSet() { - private List getPostCommitHooks() { - try { - List r = new ArrayList<>(); - for (GHHook h : getHooks()) { - if (h.getName().equals("web")) { - r.add(new URL(h.getConfig().get("url"))); + private /* final */ transient Set postCommitHooks; + + @SuppressFBWarnings(value = "DMI_COLLECTION_OF_URLS", + justification = "It causes a performance degradation, but we have already exposed it to the API") + private Set setupPostCommitHooks() { + return new AbstractSet() { + private List getPostCommitHooks() { + try { + List r = new ArrayList<>(); + for (GHHook h : getHooks()) { + if (h.getName().equals("web")) { + r.add(new URL(h.getConfig().get("url"))); + } } + return r; + } catch (IOException e) { + throw new GHException("Failed to retrieve post-commit hooks", e); } - return r; - } catch (IOException e) { - throw new GHException("Failed to retrieve post-commit hooks", e); } - } - @Override - public Iterator iterator() { - return getPostCommitHooks().iterator(); - } + @Override + public Iterator iterator() { + return getPostCommitHooks().iterator(); + } - @Override - public int size() { - return getPostCommitHooks().size(); - } + @Override + public int size() { + return getPostCommitHooks().size(); + } - @Override - public boolean add(URL url) { - try { - createWebHook(url); - return true; - } catch (IOException e) { - throw new GHException("Failed to update post-commit hooks", e); + @Override + public boolean add(URL url) { + try { + createWebHook(url); + return true; + } catch (IOException e) { + throw new GHException("Failed to update post-commit hooks", e); + } } - } - @Override - public boolean remove(Object url) { - try { - String _url = ((URL) url).toExternalForm(); - for (GHHook h : getHooks()) { - if (h.getName().equals("web") && h.getConfig().get("url").equals(_url)) { - h.delete(); - return true; + @Override + public boolean remove(Object url) { + try { + String _url = ((URL) url).toExternalForm(); + for (GHHook h : getHooks()) { + if (h.getName().equals("web") && h.getConfig().get("url").equals(_url)) { + h.delete(); + return true; + } } + return false; + } catch (IOException e) { + throw new GHException("Failed to update post-commit hooks", e); } - return false; - } catch (IOException e) { - throw new GHException("Failed to update post-commit hooks", e); } - } - }; + }; + } GHRepository wrap(GitHub root) { this.root = root; diff --git a/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java b/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java index 0f20a86835..fee68fffcb 100644 --- a/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java +++ b/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java @@ -16,10 +16,9 @@ * * @author Martin van Zijl */ -public class GHRepositoryStatistics { +public class GHRepositoryStatistics extends GitHubInteractiveObject { private final GHRepository repo; - private final GitHub root; private static final int MAX_WAIT_ITERATIONS = 3; private static final int WAIT_SLEEP_INTERVAL = 5000; @@ -99,7 +98,6 @@ private PagedIterable getContributorStatsImpl() throws IOExcep "URF_UNREAD_FIELD" }, justification = "JSON API") public static class ContributorStats extends GHObject { - /* package almost final */ private GitHub root; private GHUser author; private int total; private List weeks; @@ -255,7 +253,6 @@ public PagedIterable getCommitActivity() throws IOException { value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" }, justification = "JSON API") public static class CommitActivity extends GHObject { - /* package almost final */ private GitHub root; private List days; private int total; private long week; @@ -398,7 +395,6 @@ public Participation getParticipation() throws IOException { * The type Participation. */ public static class Participation extends GHObject { - /* package almost final */ private GitHub root; private List all; private List owner; diff --git a/src/main/java/org/kohsuke/github/GHRequestedAction.java b/src/main/java/org/kohsuke/github/GHRequestedAction.java index 36f7ec5cc2..e272b885f6 100644 --- a/src/main/java/org/kohsuke/github/GHRequestedAction.java +++ b/src/main/java/org/kohsuke/github/GHRequestedAction.java @@ -8,7 +8,6 @@ justification = "JSON API") public class GHRequestedAction extends GHObject { private GHRepository owner; - private GitHub root; private String identifier; private String label; private String description; diff --git a/src/main/java/org/kohsuke/github/GHSubscription.java b/src/main/java/org/kohsuke/github/GHSubscription.java index 5d5219541c..7b9d0731bf 100644 --- a/src/main/java/org/kohsuke/github/GHSubscription.java +++ b/src/main/java/org/kohsuke/github/GHSubscription.java @@ -10,11 +10,10 @@ * @see GHRepository#getSubscription() GHRepository#getSubscription() * @see GHThread#getSubscription() GHThread#getSubscription() */ -public class GHSubscription { +public class GHSubscription extends GitHubInteractiveObject { private String created_at, url, repository_url, reason; private boolean subscribed, ignored; - private GitHub root; private GHRepository repo; /** diff --git a/src/main/java/org/kohsuke/github/GHTag.java b/src/main/java/org/kohsuke/github/GHTag.java index 3832199253..305e8c07ff 100644 --- a/src/main/java/org/kohsuke/github/GHTag.java +++ b/src/main/java/org/kohsuke/github/GHTag.java @@ -9,9 +9,8 @@ */ @SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" }, justification = "JSON API") -public class GHTag { +public class GHTag extends GitHubInteractiveObject { private GHRepository owner; - private GitHub root; private String name; private GHCommit commit; diff --git a/src/main/java/org/kohsuke/github/GHTagObject.java b/src/main/java/org/kohsuke/github/GHTagObject.java index 73c51c13ac..6dcc48fe00 100644 --- a/src/main/java/org/kohsuke/github/GHTagObject.java +++ b/src/main/java/org/kohsuke/github/GHTagObject.java @@ -9,9 +9,8 @@ */ @SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" }, justification = "JSON API") -public class GHTagObject { +public class GHTagObject extends GitHubInteractiveObject { private GHRepository owner; - private GitHub root; private String tag; private String sha; diff --git a/src/main/java/org/kohsuke/github/GHTeam.java b/src/main/java/org/kohsuke/github/GHTeam.java index 98bf41655a..c6c32daedd 100644 --- a/src/main/java/org/kohsuke/github/GHTeam.java +++ b/src/main/java/org/kohsuke/github/GHTeam.java @@ -24,8 +24,6 @@ public class GHTeam extends GHObject implements Refreshable { private GHOrganization organization; // populated by GET /user/teams where Teams+Orgs are returned together - protected /* final */ GitHub root; - public enum Privacy { SECRET, // only visible to organization owners and members of this team. CLOSED // visible to all members of this organization. diff --git a/src/main/java/org/kohsuke/github/GHTeamBuilder.java b/src/main/java/org/kohsuke/github/GHTeamBuilder.java index 4e5706f967..f8e41c0f5b 100644 --- a/src/main/java/org/kohsuke/github/GHTeamBuilder.java +++ b/src/main/java/org/kohsuke/github/GHTeamBuilder.java @@ -7,9 +7,7 @@ * * https://developer.github.com/v3/teams/#create-team */ -public class GHTeamBuilder { - - private final GitHub root; +public class GHTeamBuilder extends GitHubInteractiveObject { protected final Requester builder; private final String orgName; diff --git a/src/main/java/org/kohsuke/github/GHThread.java b/src/main/java/org/kohsuke/github/GHThread.java index 2334c7967d..49db0f279d 100644 --- a/src/main/java/org/kohsuke/github/GHThread.java +++ b/src/main/java/org/kohsuke/github/GHThread.java @@ -17,7 +17,6 @@ @SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" }, justification = "JSON API") public class GHThread extends GHObject { - private GitHub root; private GHRepository repository; private Subject subject; private String reason; diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 2c4f64b371..3fc075b0dd 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -1208,26 +1208,34 @@ public Reader renderMarkdown(String text) throws IOException { } /** - * Do not use this method. This method will be removed and should never have been needed in the first place. + * Gets an {@link ObjectWriter} that can be used to convert data objects in this library to JSON. + * + * If you must convert data object in this library to JSON, the {@link ObjectWriter} returned by this method is the + * only supported way of doing so. This {@link ObjectWriter} can be used to convert any library data object to JSON + * without throwing an exception. + * + * WARNING: While the JSON generated is generally expected to be stable, it is not part of the API of this library + * and may change without warning. Use with extreme caution. * * @return an {@link ObjectWriter} instance that can be further configured. - * @deprecated DO NOT USE THIS METHOD. Provided for backward compatibility with projects that did their own jackson - * mapping of this project's data objects, such as Jenkins Blue Ocean. */ - @Deprecated @Nonnull public static ObjectWriter getMappingObjectWriter() { return GitHubClient.getMappingObjectWriter(); } /** - * Do not use this method. This method will be removed and should never have been needed in the first place. + * Gets an {@link ObjectReader} that can be used to convert JSON into library data objects. + * + * If you must manually create library data objects from JSON, the {@link ObjectReader} returned by this method is + * the only supported way of doing so. + * + * WARNING: Objects generated from this method have limited functionality. They will not throw when being crated + * from valid JSON matching the expected object, but they are not guaranteed to be usable beyond that. Use with + * extreme caution. * * @return an {@link ObjectReader} instance that can be further configured. - * @deprecated DO NOT USE THIS METHOD. Provided for backward compatibility with projects that did their own jackson - * mapping of this project's data objects, such as Jenkins Blue Ocean. */ - @Deprecated @Nonnull public static ObjectReader getMappingObjectReader() { return GitHubClient.getMappingObjectReader(GitHub.offline()); diff --git a/src/main/java/org/kohsuke/github/GitHubInteractiveObject.java b/src/main/java/org/kohsuke/github/GitHubInteractiveObject.java new file mode 100644 index 0000000000..a31b623fa4 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GitHubInteractiveObject.java @@ -0,0 +1,23 @@ +package org.kohsuke.github; + +import com.fasterxml.jackson.annotation.JacksonInject; + +/** + * Defines a base class that all classes in this library that interact with GitHub inherit from. + * + * Ensures that all data references to GitHub connection are transient. + * + * Classes that do not need to interact with GitHub after they are instantiated do not need to inherit from this class. + */ +abstract class GitHubInteractiveObject { + @JacksonInject + /* package almost final */ transient GitHub root; + + GitHubInteractiveObject() { + root = null; + } + + GitHubInteractiveObject(GitHub root) { + this.root = root; + } +} diff --git a/src/main/java/org/kohsuke/github/PagedSearchIterable.java b/src/main/java/org/kohsuke/github/PagedSearchIterable.java index 833db80b8e..ec7c61da06 100644 --- a/src/main/java/org/kohsuke/github/PagedSearchIterable.java +++ b/src/main/java/org/kohsuke/github/PagedSearchIterable.java @@ -18,7 +18,7 @@ "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" }, justification = "Constructed by JSON API") public class PagedSearchIterable extends PagedIterable { - private final GitHub root; + private final transient GitHub root; private final GitHubRequest request; diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index e7ee6640f0..8166323514 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -40,7 +40,7 @@ * @author Kohsuke Kawaguchi */ class Requester extends GitHubRequest.Builder { - /* private */ final GitHubClient client; + /* private */ final transient GitHubClient client; Requester(GitHubClient client) { this.client = client; diff --git a/src/test/java/org/kohsuke/github/AppTest.java b/src/test/java/org/kohsuke/github/AppTest.java index 1e499309df..320ef6cb68 100755 --- a/src/test/java/org/kohsuke/github/AppTest.java +++ b/src/test/java/org/kohsuke/github/AppTest.java @@ -220,6 +220,7 @@ public void testGetIssues() throws Exception { .getIssues(GHIssueState.CLOSED); // prior to using PagedIterable GHRepository.getIssues(GHIssueState) would only retrieve 30 issues assertTrue(closedIssues.size() > 150); + String readRepoString = GitHub.getMappingObjectWriter().writeValueAsString(closedIssues.get(0)); } private GHRepository getTestRepository() throws IOException { diff --git a/src/test/java/org/kohsuke/github/GitHubStaticTest.java b/src/test/java/org/kohsuke/github/GitHubStaticTest.java index 2b5a4b4303..a09cc3f6d4 100644 --- a/src/test/java/org/kohsuke/github/GitHubStaticTest.java +++ b/src/test/java/org/kohsuke/github/GitHubStaticTest.java @@ -226,15 +226,25 @@ public void testMappingReaderWriter() throws Exception { GHRepository repo = getTempRepository(); assertThat(repo.root, not(nullValue())); + assertThat(repo.getResponseHeaderFields(), not(nullValue())); String repoString = GitHub.getMappingObjectWriter().writeValueAsString(repo); assertThat(repoString, not(nullValue())); assertThat(repoString, containsString("testMappingReaderWriter")); - GHRepository readRepo = GitHub.getMappingObjectReader().forType(GHRepository.class).readValue(repoString); + GHRepository readRepo = GitHubClient.getMappingObjectReader((GitHubResponse.ResponseInfo) null) + .forType(GHRepository.class) + .readValue(repoString); - // This should never happen if these methods aren't used + // This should never happen if the internal method isn't used assertThat(readRepo.root, nullValue()); + assertThat(readRepo.getResponseHeaderFields(), nullValue()); + + readRepo = GitHub.getMappingObjectReader().forType(GHRepository.class).readValue(repoString); + + // This should never happen if the internal method isn't used + assertThat(readRepo.root.getConnector(), equalTo(HttpConnector.OFFLINE)); + assertThat(readRepo.getResponseHeaderFields(), nullValue()); String readRepoString = GitHub.getMappingObjectWriter().writeValueAsString(readRepo); assertThat(readRepoString, equalTo(repoString));