-
Notifications
You must be signed in to change notification settings - Fork 775
Expand file tree
/
Copy pathGHAppInstallation.java
More file actions
270 lines (244 loc) · 8.11 KB
/
GHAppInstallation.java
File metadata and controls
270 lines (244 loc) · 8.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
package org.kohsuke.github;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.kohsuke.github.internal.EnumUtils;
import java.io.IOException;
import java.net.URL;
import java.time.Instant;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
// TODO: Auto-generated Javadoc
/**
* A Github App Installation.
*
* @author Paulo Miguel Almeida
* @see GHApp#listInstallations() GHApp#listInstallations()
* @see GHApp#getInstallationById(long) GHApp#getInstallationById(long)
* @see GHApp#getInstallationByOrganization(String) GHApp#getInstallationByOrganization(String)
* @see GHApp#getInstallationByRepository(String, String) GHApp#getInstallationByRepository(String, String)
* @see GHApp#getInstallationByUser(String) GHApp#getInstallationByUser(String)
*/
public class GHAppInstallation extends GHObject {
private static class GHAppInstallationRepositoryResult extends SearchResult<GHRepository> {
private GHRepository[] repositories;
@Override
GHRepository[] getItems(GitHub root) {
return repositories;
}
}
@JsonProperty("access_tokens_url")
private String accessTokenUrl;
private GHUser account;
@JsonProperty("app_id")
private long appId;
private List<String> events;
private String htmlUrl;
private Map<String, GHPermissionType> permissions;
@JsonProperty("repositories_url")
private String repositoriesUrl;
@JsonProperty("repository_selection")
private GHRepositorySelection repositorySelection;
@JsonProperty("single_file_name")
private String singleFileName;
private String suspendedAt;
private GHUser suspendedBy;
@JsonProperty("target_id")
private long targetId;
@JsonProperty("target_type")
private GHTargetType targetType;
/**
* Create default GHAppInstallation instance
*/
public GHAppInstallation() {
}
/**
* Starts a builder that creates a new App Installation Token.
*
* <p>
* You use the returned builder to set various properties, then call {@link GHAppCreateTokenBuilder#create()} to
* finally create an access token.
*
* @return a GHAppCreateTokenBuilder instance
*/
public GHAppCreateTokenBuilder createToken() {
return new GHAppCreateTokenBuilder(root(), String.format("/app/installations/%d/access_tokens", getId()));
}
/**
* Starts a builder that creates a new App Installation Token.
*
* <p>
* You use the returned builder to set various properties, then call {@link GHAppCreateTokenBuilder#create()} to
* finally create an access token.
*
* @param permissions
* map of permissions for the created token
* @return a GHAppCreateTokenBuilder instance
* @deprecated Use {@link GHAppInstallation#createToken()} instead.
*/
@Deprecated
public GHAppCreateTokenBuilder createToken(Map<String, GHPermissionType> permissions) {
return createToken().permissions(permissions);
}
/**
* Delete a Github App installation
* <p>
* You must use a JWT to access this endpoint.
*
* @throws IOException
* on error
* @see <a href="https://developer.github.com/v3/apps/#delete-an-installation">Delete an installation</a>
*/
public void deleteInstallation() throws IOException {
root().createRequest().method("DELETE").withUrlPath(String.format("/app/installations/%d", getId())).send();
}
/**
* Gets access token url.
*
* @return the access token url
*/
public String getAccessTokenUrl() {
return accessTokenUrl;
}
/**
* Gets account.
*
* @return the account
*/
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior")
public GHUser getAccount() {
return account;
}
/**
* Gets app id.
*
* @return the app id
*/
public long getAppId() {
return appId;
}
/**
* Gets events.
*
* @return the events
*/
public List<GHEvent> getEvents() {
return events.stream()
.map(e -> EnumUtils.getEnumOrDefault(GHEvent.class, e, GHEvent.UNKNOWN))
.collect(Collectors.toList());
}
/**
* Gets the html url.
*
* @return the html url
*/
public URL getHtmlUrl() {
return GitHubClient.parseURL(htmlUrl);
}
/**
* Shows whether the user or organization account actively subscribes to a plan listed by the authenticated GitHub
* App. When someone submits a plan change that won't be processed until the end of their billing cycle, you will
* also see the upcoming pending change.
*
* <p>
* GitHub Apps must use a JWT to access this endpoint.
* <p>
* OAuth Apps must use basic authentication with their client ID and client secret to access this endpoint.
*
* @return a GHMarketplaceAccountPlan instance
* @throws IOException
* it may throw an {@link IOException}
* @see <a href=
* "https://docs.github.com/en/rest/apps/marketplace?apiVersion=2022-11-28#get-a-subscription-plan-for-an-account">Get
* a subscription plan for an account</a>
*/
public GHMarketplaceAccountPlan getMarketplaceAccount() throws IOException {
return new GHMarketplacePlanForAccountBuilder(root(), account.getId()).createRequest();
}
/**
* Gets permissions.
*
* @return the permissions
*/
public Map<String, GHPermissionType> getPermissions() {
return Collections.unmodifiableMap(permissions);
}
/**
* Gets repositories url.
*
* @return the repositories url
*/
public String getRepositoriesUrl() {
return repositoriesUrl;
}
/**
* Gets repository selection.
*
* @return the repository selection
*/
public GHRepositorySelection getRepositorySelection() {
return repositorySelection;
}
/**
* Gets single file name.
*
* @return the single file name
*/
public String getSingleFileName() {
return singleFileName;
}
/**
* Gets suspended at.
*
* @return the suspended at
*/
@WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate")
public Instant getSuspendedAt() {
return GitHubClient.parseInstant(suspendedAt);
}
/**
* Gets suspended by.
*
* @return the suspended by
*/
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior")
public GHUser getSuspendedBy() {
return suspendedBy;
}
/**
* Gets target id.
*
* @return the target id
*/
public long getTargetId() {
return targetId;
}
/**
* Gets target type.
*
* @return the target type
*/
public GHTargetType getTargetType() {
return targetType;
}
/**
* List repositories that this app installation can access.
*
* @return the paged iterable
* @deprecated This method cannot work on a {@link GHAppInstallation} retrieved from
* {@link GHApp#listInstallations()} (for example), except when resorting to unsupported hacks involving
* setRoot(GitHub) to switch from an application client to an installation client. This method will be
* removed. You should instead use an installation client (with an installation token, not a JWT),
* retrieve a {@link GHAuthenticatedAppInstallation} from {@link GitHub#getInstallation()}, then call
* {@link GHAuthenticatedAppInstallation#listRepositories()}.
*/
@Deprecated
public PagedSearchIterable<GHRepository> listRepositories() {
return new PagedSearchIterable<>(root().createRequest()
.withUrlPath("/installation/repositories")
.toPaginatedEndpoint(GHAppInstallationRepositoryResult.class, GHRepository.class, null));
}
}