Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 22d4154

Browse filesBrowse files
authored
Merge pull request hub4j#1748 from dunningdan/main
Allow query parameters for listInstallations query
2 parents fd5285c + 2ee0bcc commit 22d4154
Copy full SHA for 22d4154

File tree

Expand file treeCollapse file tree

6 files changed

+212
-4
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+212
-4
lines changed

‎src/main/java/org/kohsuke/github/GHApp.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHApp.java
+21-4Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.io.IOException;
77
import java.net.URL;
88
import java.util.Collections;
9+
import java.util.Date;
910
import java.util.List;
1011
import java.util.Map;
1112
import java.util.stream.Collectors;
@@ -209,10 +210,26 @@ public void setPermissions(Map<String, String> permissions) {
209210
*/
210211
@Preview(MACHINE_MAN)
211212
public PagedIterable<GHAppInstallation> listInstallations() {
212-
return root().createRequest()
213-
.withPreview(MACHINE_MAN)
214-
.withUrlPath("/app/installations")
215-
.toIterable(GHAppInstallation[].class, null);
213+
return listInstallations(null);
214+
}
215+
216+
/**
217+
* Obtains all the installations associated with this app since a given date.
218+
* <p>
219+
* You must use a JWT to access this endpoint.
220+
*
221+
* @param since
222+
* - Allows users to get installations that have been updated since a given date.
223+
* @return a list of App installations since a given time.
224+
* @see <a href="https://developer.github.com/v3/apps/#list-installations">List installations</a>
225+
*/
226+
@Preview(MACHINE_MAN)
227+
public PagedIterable<GHAppInstallation> listInstallations(final Date since) {
228+
Requester requester = root().createRequest().withPreview(MACHINE_MAN).withUrlPath("/app/installations");
229+
if (since != null) {
230+
requester.with("since", GitHubClient.printDate(since));
231+
}
232+
return requester.toIterable(GHAppInstallation[].class, null);
216233
}
217234

218235
/**

‎src/test/java/org/kohsuke/github/GHAppTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/GHAppTest.java
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
import org.junit.Test;
44

55
import java.io.IOException;
6+
import java.text.ParseException;
7+
import java.text.SimpleDateFormat;
68
import java.util.Arrays;
79
import java.util.Collections;
10+
import java.util.Date;
811
import java.util.HashMap;
912
import java.util.List;
1013
import java.util.Map;
14+
import java.util.TimeZone;
1115

1216
import static org.hamcrest.Matchers.*;
1317
import static org.junit.Assert.assertThrows;
@@ -85,6 +89,28 @@ public void listInstallations() throws IOException {
8589
testAppInstallation(appInstallation);
8690
}
8791

92+
/**
93+
* List installations that have been updated since a given date.
94+
*
95+
* @throws IOException
96+
* Signals that an I/O exception has occurred.
97+
*
98+
* @throws ParseException
99+
* Issue parsing date string.
100+
*/
101+
@Test
102+
public void listInstallationsSince() throws IOException, ParseException {
103+
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
104+
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
105+
Date localDate = simpleDateFormat.parse("2023-11-01");
106+
GHApp app = gitHub.getApp();
107+
List<GHAppInstallation> installations = app.listInstallations(localDate).toList();
108+
assertThat(installations.size(), is(1));
109+
110+
GHAppInstallation appInstallation = installations.get(0);
111+
testAppInstallation(appInstallation);
112+
}
113+
88114
/**
89115
* Gets the installation by id.
90116
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"id": 11111,
3+
"node_id": "MDM6QXBwMzI2MTY=",
4+
"owner": {
5+
"login": "bogus",
6+
"id": 111111111,
7+
"node_id": "asdfasdfasdf",
8+
"avatar_url": "https://avatars2.githubusercontent.com/u/111111111?v=4",
9+
"gravatar_id": "",
10+
"url": "https://api.github.com/users/bogus",
11+
"html_url": "https://github.com/bogus",
12+
"followers_url": "https://api.github.com/users/bogus/followers",
13+
"following_url": "https://api.github.com/users/bogus/following{/other_user}",
14+
"gists_url": "https://api.github.com/users/bogus/gists{/gist_id}",
15+
"starred_url": "https://api.github.com/users/bogus/starred{/owner}{/repo}",
16+
"subscriptions_url": "https://api.github.com/users/bogus/subscriptions",
17+
"organizations_url": "https://api.github.com/users/bogus/orgs",
18+
"repos_url": "https://api.github.com/users/bogus/repos",
19+
"events_url": "https://api.github.com/users/bogus/events{/privacy}",
20+
"received_events_url": "https://api.github.com/users/bogus/received_events",
21+
"type": "Organization",
22+
"site_admin": false
23+
},
24+
"name": "Bogus-Development",
25+
"description": "",
26+
"external_url": "https://bogus.domain.com",
27+
"html_url": "https://github.com/apps/bogus-development",
28+
"created_at": "2019-06-10T04:21:41Z",
29+
"updated_at": "2019-06-10T04:21:41Z",
30+
"permissions": {
31+
"checks": "write",
32+
"contents": "read",
33+
"metadata": "read",
34+
"pull_requests": "write"
35+
},
36+
"events": [
37+
"pull_request",
38+
"push"
39+
],
40+
"installations_count": 1
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[
2+
{
3+
"id": 11111111,
4+
"account": {
5+
"login": "bogus",
6+
"id": 111111111,
7+
"node_id": "asdfasdfasdf",
8+
"avatar_url": "https://avatars2.githubusercontent.com/u/111111111?v=4",
9+
"gravatar_id": "",
10+
"url": "https://api.github.com/users/bogus",
11+
"html_url": "https://github.com/bogus",
12+
"followers_url": "https://api.github.com/users/bogus/followers",
13+
"following_url": "https://api.github.com/users/bogus/following{/other_user}",
14+
"gists_url": "https://api.github.com/users/bogus/gists{/gist_id}",
15+
"starred_url": "https://api.github.com/users/bogus/starred{/owner}{/repo}",
16+
"subscriptions_url": "https://api.github.com/users/bogus/subscriptions",
17+
"organizations_url": "https://api.github.com/users/bogus/orgs",
18+
"repos_url": "https://api.github.com/users/bogus/repos",
19+
"events_url": "https://api.github.com/users/bogus/events{/privacy}",
20+
"received_events_url": "https://api.github.com/users/bogus/received_events",
21+
"type": "Organization",
22+
"site_admin": false
23+
},
24+
"repository_selection": "selected",
25+
"access_tokens_url": "https://api.github.com/app/installations/11111111/access_tokens",
26+
"repositories_url": "https://api.github.com/installation/repositories",
27+
"html_url": "https://github.com/organizations/bogus/settings/installations/11111111",
28+
"app_id": 11111,
29+
"target_id": 111111111,
30+
"target_type": "Organization",
31+
"permissions": {
32+
"checks": "write",
33+
"pull_requests": "write",
34+
"contents": "read",
35+
"metadata": "read"
36+
},
37+
"events": [
38+
"pull_request",
39+
"push"
40+
],
41+
"created_at": "2019-07-04T01:19:36.000Z",
42+
"updated_at": "2019-07-30T22:48:09.000Z",
43+
"single_file_name": null
44+
}
45+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"request": {
3+
"url": "/app",
4+
"method": "GET",
5+
"headers": {
6+
"Accept": {
7+
"equalTo": "application/vnd.github.machine-man-preview+json"
8+
}
9+
}
10+
},
11+
"response": {
12+
"status": 200,
13+
"bodyFileName": "body-mapping-githubapp-app.json",
14+
"headers": {
15+
"Server": "GitHub.com",
16+
"Date": "Fri, 09 Aug 2019 05:36:38 GMT",
17+
"Content-Type": "application/json; charset=utf-8",
18+
"Status": "200 OK",
19+
"Cache-Control": "public, max-age=60, s-maxage=60",
20+
"Vary": [
21+
"Accept",
22+
"Accept-Encoding"
23+
],
24+
"ETag": "W/\"01163b1a237898d328ed56cd0e9aefca\"",
25+
"X-GitHub-Media-Type": "github.machine-man-preview; format=json",
26+
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type",
27+
"Access-Control-Allow-Origin": "*",
28+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
29+
"Content-Security-Policy": "default-src 'none'",
30+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
31+
"X-Content-Type-Options": "nosniff",
32+
"X-Frame-Options": "deny",
33+
"X-XSS-Protection": "1; mode=block",
34+
"X-GitHub-Request-Id": "E0C4:3088:300C54:3ACB77:5D4D0666"
35+
}
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"request": {
3+
"urlPathPattern": "/app/installations",
4+
"method": "GET",
5+
"headers": {
6+
"Accept": {
7+
"equalTo": "application/vnd.github.machine-man-preview+json"
8+
}
9+
},
10+
"queryParameters": {
11+
"since": {
12+
"equalTo": "2023-11-01T00:00:00Z"
13+
}
14+
}
15+
},
16+
"response": {
17+
"status": 200,
18+
"bodyFileName": "body-mapping-githubapp-installations.json",
19+
"headers": {
20+
"Server": "GitHub.com",
21+
"Date": "Fri, 09 Aug 2019 05:36:38 GMT",
22+
"Content-Type": "application/json; charset=utf-8",
23+
"Status": "200 OK",
24+
"Cache-Control": "public, max-age=60, s-maxage=60",
25+
"Vary": [
26+
"Accept",
27+
"Accept-Encoding"
28+
],
29+
"ETag": "W/\"01163b1a237898d328ed56cd0e9aefca\"",
30+
"X-GitHub-Media-Type": "github.machine-man-preview; format=json",
31+
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type",
32+
"Access-Control-Allow-Origin": "*",
33+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
34+
"Content-Security-Policy": "default-src 'none'",
35+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
36+
"X-Content-Type-Options": "nosniff",
37+
"X-Frame-Options": "deny",
38+
"X-XSS-Protection": "1; mode=block",
39+
"X-GitHub-Request-Id": "E0C4:3088:300C54:3ACB77:5D4D0666"
40+
}
41+
}
42+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.