@@ -77,6 +77,21 @@ public class GithubAppClient {
7777 this .maybeRepo = Optional .empty ();
7878 }
7979
80+ /**
81+ * Gets the owner, throwing a descriptive exception if not present.
82+ *
83+ * @return the owner string
84+ * @throws IllegalStateException if owner is not present
85+ */
86+ private String requireOwner () {
87+ return maybeOwner .orElseThrow (() ->
88+ new IllegalStateException (
89+ "This operation requires an owner context. "
90+ + "Use GitHubClient.createOrganisationClient(owner).createGithubAppClient() "
91+ + "or GitHubClient.createRepositoryClient(owner, repo).createGithubAppClient() "
92+ + "instead of GitHubClient.createGithubAppClient()" ));
93+ }
94+
8095 /**
8196 * List Installations of an app.
8297 *
@@ -112,7 +127,7 @@ public CompletableFuture<Installation> getInstallation(final Integer installatio
112127 */
113128 private CompletableFuture <Installation > getRepoInstallation (final String repo ) {
114129 return github .request (
115- String .format (GET_INSTALLATION_REPO_URL , maybeOwner . get (), repo ), Installation .class );
130+ String .format (GET_INSTALLATION_REPO_URL , requireOwner (), repo ), Installation .class );
116131 }
117132
118133 /**
@@ -122,7 +137,7 @@ private CompletableFuture<Installation> getRepoInstallation(final String repo) {
122137 */
123138 private CompletableFuture <Installation > getOrgInstallation () {
124139 return github .request (
125- String .format (GET_INSTALLATION_ORG_URL , maybeOwner . get ()), Installation .class );
140+ String .format (GET_INSTALLATION_ORG_URL , requireOwner ()), Installation .class );
126141 }
127142
128143 /**
@@ -132,7 +147,7 @@ private CompletableFuture<Installation> getOrgInstallation() {
132147 */
133148 public CompletableFuture <Installation > getUserInstallation () {
134149 return github .request (
135- String .format (GET_INSTALLATION_USER_URL , maybeOwner . get ()), Installation .class );
150+ String .format (GET_INSTALLATION_USER_URL , requireOwner ()), Installation .class );
136151 }
137152
138153 /**
0 commit comments