Skip to content

Commit ddbbc7a

Browse files
gildaybitwiseman
andauthored
Add Suspended Installation Properties to GHAppInstallation (hub4j#1780)
* Add Suspended Installation Properties to GHAppInstallation A suspended app installation has suspended_at and suspended_by properties that were missing from the GHAppInstallation class. * Store suspendedAt as String --------- Co-authored-by: Liam Newman <bitwiseman@gmail.com>
1 parent ee450b6 commit ddbbc7a

6 files changed

Lines changed: 232 additions & 0 deletions

File tree

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.io.IOException;
88
import java.net.URL;
99
import java.util.Collections;
10+
import java.util.Date;
1011
import java.util.List;
1112
import java.util.Map;
1213
import java.util.stream.Collectors;
@@ -45,6 +46,8 @@ public class GHAppInstallation extends GHObject {
4546
@JsonProperty("repository_selection")
4647
private GHRepositorySelection repositorySelection;
4748
private String htmlUrl;
49+
private String suspendedAt;
50+
private GHUser suspendedBy;
4851

4952
/**
5053
* Gets the html url.
@@ -311,6 +314,25 @@ public void setRepositorySelection(GHRepositorySelection repositorySelection) {
311314
throw new RuntimeException("Do not use this method.");
312315
}
313316

317+
/**
318+
* Gets suspended at.
319+
*
320+
* @return the suspended at
321+
*/
322+
public Date getSuspendedAt() {
323+
return GitHubClient.parseDate(suspendedAt);
324+
}
325+
326+
/**
327+
* Gets suspended by.
328+
*
329+
* @return the suspended by
330+
*/
331+
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior")
332+
public GHUser getSuspendedBy() {
333+
return suspendedBy;
334+
}
335+
314336
/**
315337
* Delete a Github App installation
316338
* <p>

src/test/java/org/kohsuke/github/GHAppInstallationTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
import org.junit.Test;
44

55
import java.io.IOException;
6+
import java.time.LocalDateTime;
7+
import java.time.Month;
8+
import java.time.ZoneOffset;
9+
import java.util.Date;
610
import java.util.List;
711

812
import static org.hamcrest.Matchers.*;
913

1014
// TODO: Auto-generated Javadoc
15+
1116
/**
1217
* The Class GHAppInstallationTest.
1318
*/
@@ -61,4 +66,23 @@ public void testGetMarketplaceAccount() throws IOException {
6166
assertThat(plan.getType(), equalTo(GHMarketplaceAccountType.ORGANIZATION));
6267
}
6368

69+
/**
70+
* Test list installations, and one of the installations has been suspended.
71+
*
72+
* @throws IOException
73+
* Signals that an I/O exception has occurred.
74+
*/
75+
@Test
76+
public void testListSuspendedInstallation() throws IOException {
77+
GHAppInstallation appInstallation = getAppInstallationWithToken(jwtProvider1.getEncodedAuthorization());
78+
79+
final GHUser suspendedBy = appInstallation.getSuspendedBy();
80+
assertThat(suspendedBy.getLogin(), equalTo("gilday"));
81+
82+
final Date suspendedAt = appInstallation.getSuspendedAt();
83+
final Date expectedSuspendedAt = Date
84+
.from(LocalDateTime.of(2024, Month.FEBRUARY, 26, 2, 43, 12).toInstant(ZoneOffset.UTC));
85+
assertThat(suspendedAt, equalTo(expectedSuspendedAt));
86+
}
87+
6488
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"id": 83009,
3+
"slug": "cleanthat",
4+
"node_id": "MDM6QXBwNjU1NTA=",
5+
"owner": {
6+
"login": "solven-eu",
7+
"id": 34552197,
8+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjM0NTUyMTk3",
9+
"avatar_url": "https://avatars.githubusercontent.com/u/34552197?v=4",
10+
"gravatar_id": "",
11+
"url": "https://api.github.com/users/solven-eu",
12+
"html_url": "https://github.com/solven-eu",
13+
"followers_url": "https://api.github.com/users/solven-eu/followers",
14+
"following_url": "https://api.github.com/users/solven-eu/following{/other_user}",
15+
"gists_url": "https://api.github.com/users/solven-eu/gists{/gist_id}",
16+
"starred_url": "https://api.github.com/users/solven-eu/starred{/owner}{/repo}",
17+
"subscriptions_url": "https://api.github.com/users/solven-eu/subscriptions",
18+
"organizations_url": "https://api.github.com/users/solven-eu/orgs",
19+
"repos_url": "https://api.github.com/users/solven-eu/repos",
20+
"events_url": "https://api.github.com/users/solven-eu/events{/privacy}",
21+
"received_events_url": "https://api.github.com/users/solven-eu/received_events",
22+
"type": "Organization",
23+
"site_admin": false
24+
},
25+
"name": "CleanThat",
26+
"description": "Cleanthat cleans branches automatically to fix/improve your code.\r\n\r\nFeatures :\r\n- Fix branches a pull_requests head\r\n- Open pull_request to fix protected branches\r\n- Format `.md`, `.java`, `.scala`, `.json`, `.yaml` with the help of [Spotless](https://github.com/diffplug/spotless)\r\n- Refactor `.java` files to improve code-style, security and stability",
27+
"external_url": "https://github.com/solven-eu/cleanthat",
28+
"html_url": "https://github.com/apps/cleanthat",
29+
"created_at": "2020-05-19T13:45:43Z",
30+
"updated_at": "2023-01-27T06:10:21Z",
31+
"permissions": {
32+
"checks": "write",
33+
"contents": "write",
34+
"metadata": "read",
35+
"pull_requests": "write"
36+
},
37+
"events": [
38+
"pull_request",
39+
"push"
40+
],
41+
"installations_count": 280
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
[
2+
{
3+
"id": 12131496,
4+
"account": {
5+
"login": "hub4j-test-org",
6+
"id": 7544739,
7+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
8+
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
9+
"gravatar_id": "",
10+
"url": "https://api.github.com/users/hub4j-test-org",
11+
"html_url": "https://github.com/hub4j-test-org",
12+
"followers_url": "https://api.github.com/users/hub4j-test-org/followers",
13+
"following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
14+
"gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
15+
"starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
16+
"subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
17+
"organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
18+
"repos_url": "https://api.github.com/users/hub4j-test-org/repos",
19+
"events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
20+
"received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
21+
"type": "Organization",
22+
"site_admin": false
23+
},
24+
"repository_selection": "selected",
25+
"access_tokens_url": "https://api.github.com/app/installations/12131496/access_tokens",
26+
"repositories_url": "https://api.github.com/installation/repositories",
27+
"html_url": "https://github.com/organizations/hub4j-test-org/settings/installations/12131496",
28+
"app_id": 83009,
29+
"app_slug": "ghapi-test-app-2",
30+
"target_id": 7544739,
31+
"target_type": "Organization",
32+
"permissions": {},
33+
"events": [],
34+
"created_at": "2020-09-30T15:05:32.000Z",
35+
"updated_at": "2020-09-30T15:05:32.000Z",
36+
"single_file_name": null,
37+
"has_multiple_single_files": false,
38+
"single_file_paths": [],
39+
"suspended_by": {
40+
"login": "gilday",
41+
"id": 1431609,
42+
"node_id": "MDQ6VXNlcjE0MzE2MDk=",
43+
"avatar_url": "https://avatars.githubusercontent.com/u/1431609?v=4",
44+
"gravatar_id": "",
45+
"url": "https://api.github.com/users/gilday",
46+
"html_url": "https://github.com/gilday",
47+
"followers_url": "https://api.github.com/users/gilday/followers",
48+
"following_url": "https://api.github.com/users/gilday/following{/other_user}",
49+
"gists_url": "https://api.github.com/users/gilday/gists{/gist_id}",
50+
"starred_url": "https://api.github.com/users/gilday/starred{/owner}{/repo}",
51+
"subscriptions_url": "https://api.github.com/users/gilday/subscriptions",
52+
"organizations_url": "https://api.github.com/users/gilday/orgs",
53+
"repos_url": "https://api.github.com/users/gilday/repos",
54+
"events_url": "https://api.github.com/users/gilday/events{/privacy}",
55+
"received_events_url": "https://api.github.com/users/gilday/received_events",
56+
"type": "User",
57+
"site_admin": false
58+
},
59+
"suspended_at": "2024-02-26T02:43:12Z"
60+
}
61+
]
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"id": "144fdb7f-667e-4cf4-bd37-67ed11bdc421",
3+
"name": "app",
4+
"request": {
5+
"url": "/app",
6+
"method": "GET",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "application/vnd.github.machine-man-preview+json"
10+
}
11+
}
12+
},
13+
"response": {
14+
"status": 200,
15+
"bodyFileName": "1-app.json",
16+
"headers": {
17+
"Server": "GitHub.com",
18+
"Date": "Sun, 19 Mar 2023 13:02:50 GMT",
19+
"Content-Type": "application/json; charset=utf-8",
20+
"Cache-Control": "public, max-age=60, s-maxage=60",
21+
"Vary": [
22+
"Accept",
23+
"Accept-Encoding, Accept, X-Requested-With"
24+
],
25+
"ETag": "W/\"00fa67d861eb73a934cd9229b76c2dc7c2c235babf8d281e2dd4a1e31ca3b930\"",
26+
"X-GitHub-Media-Type": "github.v3; param=machine-man-preview; format=json",
27+
"x-github-api-version-selected": "2022-11-28",
28+
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset",
29+
"Access-Control-Allow-Origin": "*",
30+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
31+
"X-Frame-Options": "deny",
32+
"X-Content-Type-Options": "nosniff",
33+
"X-XSS-Protection": "0",
34+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
35+
"Content-Security-Policy": "default-src 'none'",
36+
"X-GitHub-Request-Id": "C09A:5A83:172C70C:179D1FD:641707FA"
37+
}
38+
},
39+
"uuid": "144fdb7f-667e-4cf4-bd37-67ed11bdc421",
40+
"persistent": true,
41+
"insertionIndex": 1
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"id": "45ac2593-8123-49ae-ad1a-ded446491b14",
3+
"name": "app_installations",
4+
"request": {
5+
"url": "/app/installations",
6+
"method": "GET",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "application/vnd.github.machine-man-preview+json"
10+
}
11+
}
12+
},
13+
"response": {
14+
"status": 200,
15+
"bodyFileName": "2-app_installations.json",
16+
"headers": {
17+
"Date": "Thu, 05 Nov 2020 20:42:31 GMT",
18+
"Content-Type": "application/json; charset=utf-8",
19+
"Server": "GitHub.com",
20+
"Status": "200 OK",
21+
"Cache-Control": "public, max-age=60, s-maxage=60",
22+
"Vary": [
23+
"Accept",
24+
"Accept-Encoding, Accept, X-Requested-With",
25+
"Accept-Encoding"
26+
],
27+
"ETag": "W/\"60d3ec5c9014799f5e12b88e16e771a386b905ad8d41cd18aed34e58b11c58d4\"",
28+
"X-GitHub-Media-Type": "github.v3; param=machine-man-preview; format=json",
29+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
30+
"X-Frame-Options": "deny",
31+
"X-Content-Type-Options": "nosniff",
32+
"X-XSS-Protection": "1; mode=block",
33+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
34+
"Content-Security-Policy": "default-src 'none'",
35+
"X-GitHub-Request-Id": "9294:AE05:BDAC831:DB35870:5FA463B7"
36+
}
37+
},
38+
"uuid": "45ac2593-8123-49ae-ad1a-ded446491b14",
39+
"persistent": true,
40+
"insertionIndex": 2
41+
}

0 commit comments

Comments
 (0)