8000 Merge branch 'main' into Issue-576-collaborator-by-username · hub4j/github-api@be1aaa5 · GitHub
[go: up one dir, main page]

Skip to content

Commit be1aaa5

Browse files
authored
Merge branch 'main' into Issue-576-collaborator-by-username
2 parents e10e284 + 262cf84 commit be1aaa5

File tree

9 files changed

+363
-6
lines changed

9 files changed

+363
-6
lines changed

pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333

3434
<properties>
3535
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
36-
<spotbugs-maven-plugin.version>4.7.0.0</spotbugs-maven-plugin.version>
37-
<spotbugs.version>4.6.0</spotbugs.version>
36+
<spotbugs-maven-plugin.version>4.7.1.1</spotbugs-maven-plugin.version>
37+
<spotbugs.version>4.7.1</spotbugs.version>
3838
<spotbugs-maven-plugin.failOnError>true</spotbugs-maven-plugin.failOnError>
3939
<hamcrest.version>2.2</hamcrest.version>
4040
<okhttp3.version>4.9.2</okhttp3.version>
@@ -258,7 +258,7 @@
258258
<plugin>
259259
<groupId>org.apache.maven.plugins</groupId>
260260
<artifactId>maven-site-plugin</artifactId>
261-
<version>3.12.0</version>
261+
<version>3.12.1</version>
262262
</plugin>
263263
<plugin>
264264
<groupId>org.apache.maven.plugins</groupId>
@@ -278,7 +278,7 @@
278278
<plugin>
279279
<groupId>org.apache.maven.plugins</groupId>
280280
<artifactId>maven-project-info-reports-plugin</artifactId>
281-
<version>3.3.0</version>
281+
<version>3.4.0</version>
282282
<dependencies>
283283
<dependency>
284284
<groupId>org.apache.bcel</groupId>
@@ -333,7 +333,7 @@
333333
<plugin>
334334
<groupId>com.diffplug.spotless</groupId>
335335
<artifactId>spotless-maven-plugin</artifactId>
336-
<version>2.22.8</version>
336+
<version>2.24.0</version>
337337
<executions>
338338
<execution>
339339
<id>spotless-check</id>
@@ -585,7 +585,7 @@
585585
<dependency>
586586
<groupId>com.google.code.gson</groupId>
587587
<artifactId>gson</artifactId>
588-
<version>2.9.0</version>
588+
<version>2.9.1</version>
589589
<scope>test</scope>
590590
</dependency>
591591
<dependency>

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ public GHAppCreateTokenBuilder repositoryIds(List<Long> repositoryIds) {
4646
return this;
4747
}
4848

49+
/**
50+
* By default the installation token has access to all repositories that the installation can access. To restrict
51+
* the access to specific repositories, you can provide repository names when creating the token.
52+
*
53+
* @param repositories
54+
* Array containing the repository names
55+
* @return a GHAppCreateTokenBuilder
56+
*/
57+
@BetaApi
58+
public GHAppCreateTokenBuilder repositories(List<String> repositories) {
59+
this.builder.with("repositories", repositories);
60+
return this;
61+
}
62+
4963
/**
5064
* Set the permissions granted to the access token. The permissions object includes the permission names and their
5165
* access type.

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,27 @@ public void createToken() throws IOException {
146146
assertThat(installationToken2.getRepositories(), nullValue());;
147147
}
148148

149+
@Test
150+
public void createTokenWithRepositories() throws IOException {
151+
GHApp app = gitHub.getApp();
152+
GHAppInstallation installation = app.getInstallationByUser("bogus");
153+
154+
// Create token specifying repositories (not repository_ids!)
155+
GHAppInstallationToken installationToken = installation.createToken()
156+
.repositories(Collections.singletonList("bogus"))
157+
.create();
158+
159+
assertThat(installationToken.getToken(), is("bogus"));
160+
assertThat(installationToken.getPermissions().entrySet(), hasSize(4));
161+
assertThat(installationToken.getRepositorySelection(), is(GHRepositorySelection.SELECTED));
162+
assertThat(installationToken.getExpiresAt(), is(GitHubClient.parseDate("2022-07-27T21:38:33Z")));
163+
164+
GHRepository repository = installationToken.getRepositories().get(0);
165+
assertThat(installationToken.getRepositories().size(), is(1));
166+
assertThat(repository.getId(), is((long) 11111111));
167+
assertThat(repository.getName(), is("bogus"));
168+
}
169+
149170
private void testAppInstallation(GHAppInstallation appInstallation) throws IOException {
150171
Map<String, GHPermissionType> appPermissions = appInstallation.getPermissions();
151172
GHUser appAccount = appInstallation.getAccount();
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"id": 11111111,
3+
"slug": "bogus-testing",
4+
"node_id": "asdfasdfasdf",
5+
"owner": {
6+
"login": "bogus",
7+
"id": 11111111,
8+
"node_id": "asdfasfasdf",
9+
"avatar_url": "https://avatars.githubusercontent.com/u/11111111?v=4",
10+
"gravatar_id": "",
11+
"url": "https://api.github.com/users/bogus",
12+
"html_url": "https://github.com/bogus",
13+
"followers_url": "https://api.github.com/users/bogus/followers",
14+
"following_url": "https://api.github.com/users/bogus/following{/other_user}",
15+
"gists_url": "https://api.github.com/users/bogus/gists{/gist_id}",
16+
"starred_url": "https://api.github.com/users/bogus/starred{/owner}{/repo}",
17+
"subscriptions_url": "https://api.github.com/users/bogus/subscriptions",
18+
"organizations_url": "https://api.github.com/users/bogus/orgs",
19+
"repos_url": "https://api.github.com/users/bogus/repos",
20+
"events_url": "https://api.github.com/users/bogus/events{/privacy}",
21+
"received_events_url": "https://api.github.com/users/bogus/received_events",
22+
"type": "User",
23+
"site_admin": false
24+
},
25+
"name": "bogus-testing",
26+
"description": "description here",
27+
"external_url": "https://github.com/bogus",
28+
"html_url": "https://github.com/apps/bogus-testing",
29+
"created_at": "2022-07-15T17:51:32Z",
30+
"updated_at": "2022-07-15T17:51:32Z",
31+
"permissions": {
32+
"contents": "write",
33+
"metadata": "read",
34+
"organization_plan": "read",
35+
"plan": "read",
36+
"pull_requests": "read",
37+
"statuses": "write"
38+
},
39+
"events": [],
40+
"installations_count": 1
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
{
2+
"token": "bogus",
3+
"expires_at": "2022-07-27T21:38:33Z",
4+
"permissions": {
5+
"contents": "write",
6+
"metadata": "read",
7+
"pull_requests": "read",
8+
"statuses": "write"
9+
},
10+
"repository_selection": "selected",
11+
"repositories": [
12+
{
13+
"id": 11111111,
14+
"node_id": "asdfasdf",
15+
"name": "bogus",
16+
"full_name": "bogus/bogus",
17+
"private": true,
18+
"owner": {
19+
"login": "bogus",
20+
"id": 11111111,
21+
"node_id": "asdfasdf",
22+
"avatar_url": "https://avatars.githubusercontent.com/u/11111111?v=4",
23+
"gravatar_id": "",
24+
"url": "https://api.github.com/users/bogus",
25+
"html_url": "https://github.com/bogus",
26+
"followers_url": "https://api.github.com/users/bogus/followers",
27+
"following_url": "https://api.github.com/users/bogus/following{/other_user}",
28+
"gists_url": "https://api.github.com/users/bogus/gists{/gist_id}",
29+
"starred_url": "https://api.github.com/users/bogus/starred{/owner}{/repo}",
30+
"subscriptions_url": "https://api.github.com/users/bogus/subscriptions",
31+
"organizations_url": "https://api.github.com/users/bogus/orgs",
32+
"repos_url": "https://api.github.com/users/bogus/repos",
33+
"events_url": "https://api.github.com/users/bogus/events{/privacy}",
34+
"received_events_url": "https://api.github.com/users/bogus/received_events",
35+
"type": "User",
36+
"site_admin": false
37+
},
38+
"html_url": "https://github.com/bogus/bogus",
39+
"description": null,
40+
"fork": false,
41+
"url": "https://api.github.com/repos/bogus/bogus",
42+
"forks_url": "https://api.github.com/repos/bogus/bogus/forks",
43+
"keys_url": "https://api.github.com/repos/bogus/bogus/keys{/key_id}",
44+
"collaborators_url": "https://api.github.com/repos/bogus/bogus/collaborators{/collaborator}",
45+
"teams_url": "https://api.github.com/repos/bogus/bogus/teams",
46+
"hooks_url": "https://api.github.com/repos/bogus/bogus/hooks",
47+
"issue_events_url": "https://api.github.com/repos/bogus/bogus/issues/events{/number}",
48+
"events_url": "https://api.github.com/repos/bogus/bogus/events",
49+
"assignees_url": "https://api.github.com/repos/bogus/bogus/assignees{/user}",
50+
"branches_url": "https://api.github.com/repos/bogus/bogus/branches{/branch}",
51+
"tags_url": "https://api.github.com/repos/bogus/bogus/tags",
52+
"blobs_url": "https://api.github.com/repos/bogus/bogus/git/blobs{/sha}",
53+
"git_tags_url": "https://api.github.com/repos/bogus/bogus/git/tags{/sha}",
54+
"git_refs_url": "https://api.github.com/repos/bogus/bogus/git/refs{/sha}",
55+
"trees_url": "https://api.github.com/repos/bogus/bogus/git/trees{/sha}",
56+
"statuses_url": "https://api.github.com/repos/bogus/bogus/statuses/{sha}",
57+
"languages_url": "https://api.github.com/repos/bogus/bogus/languages",
58+
"stargazers_url": "https://api.github.com/repos/bogus/bogus/stargazers",
59+
"contributors_url": "https://api.github.com/repos/bogus/bogus/contributors",
60+
"subscribers_url": "https://api.github.com/repos/bogus/bogus/subscribers",
61+
"subscription_url": "https://api.github.com/repos/bogus/bogus/subscription",
62+
"commits_url": "https://api.github.com/repos/bogus/bogus/commits{/sha}",
63+
"git_commits_url": "https://api.github.com/repos/bogus/bogus/git/commits{/sha}",
64+
"comments_url": "https://api.github.com/repos/bogus/bogus/comments{/number}",
65+
"issue_comment_url": "https://api.github.com/repos/bogus/bogus/issues/comments{/number}",
66+
"contents_url": "https://api.github.com/repos/bogus/bogus/contents/{+path}",
67+
"compare_url": "https://api.github.com/repos/bogus/bogus/compare/{base}...{head}",
68+
"merges_url": "https://api.github.com/repos/bogus/bogus/merges",
69+
"archive_url": "https://api.github.com/repos/bogus/bogus/{archive_format}{/ref}",
70+
"downloads_url": "https://api.github.com/repos/bogus/bogus/downloads",
71+
"issues_url": "https://api.github.com/repos/bogus/bogus/issues{/number}",
72+
"pulls_url": "https://api.github.com/repos/bogus/bogus/pulls{/number}",
73+
"milestones_url": "https://api.github.com/repos/bogus/bogus/milestones{/number}",
74+
"notifications_url": "https://api.github.com/repos/bogus/bogus/notifications{?since,all,participating}",
75+
"labels_url": "https://api.github.com/repos/bogus/bogus/labels{/name}",
76+
"releases_url": "https://api.github.com/repos/bogus/bogus/releases{/id}",
77+
"deployments_url": "https://api.github.com/repos/bogus/bogus/deployments",
78+
"created_at": "2018-08-30T17:18:24Z",
79+
"updated_at": "2022-06-14T22:15:20Z",
80+
"pushed_at": "2022-07-15T20:04:26Z",
81+
"git_url": "git://github.com/bogus/bogus.git",
82+
"ssh_url": "git@github.com:bogus/bogus.git",
83+
"clone_url": "https://github.com/bogus/bogus.git",
84+
"svn_url": "https://github.com/bogus/bogus",
85+
"homepage": null,
86+
"size": 36,
87+
"stargazers_count": 0,
88+
"watchers_count": 0,
89+
"language": "Groovy",
90+
"has_issues": true,
91+
"has_projects": true,
92+
"has_downloads": true,
93+
"has_wiki": true,
94+
"has_pages": false,
95+
"forks_count": 0,
96+
"mirror_url": null,
97+
"archived": false,
98+
"disabled": false,
99+
"open_issues_count": 0,
100+
"license": null,
101+
"allow_forking": true,
102+
"is_template": false,
103+
"web_commit_signoff_required": false,
104+
"topics": [],
105+
"visibility": "private",
106+
"forks": 0,
107+
"open_issues": 0,
108+
"watchers": 0,
109+
"default_branch": "master"
110+
}
111+
]
112+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"id": 11111111,
3+
"account": {
4+
"login": "bogus",
5+
"id": 11111111,
6+
"node_id": "asdfasdfasdf=",
7+
"avatar_url": "https://avatars2.githubusercontent.com/u/111111111?v=4",
8+
"gravatar_id": "",
9+
"url": "https://api.github.com/users/bogus",
10+
"html_url": "https://github.com/bogus",
11+
"followers_url": "https://api.github.com/users/bogus/followers",
12+
"following_url": "https://api.github.com/users/bogus/following{/other_user}",
13+
"gists_url": "https://api.github.com/users/bogus/gists{/gist_id}",
14+
"starred_url": "https://api.github.com/users/bogus/starred{/owner}{/repo}",
15+
"subscriptions_url": "https://api.github.com/users/bogus/subscriptions",
16+
"organizations_url": "https://api.github.com/users/bogus/orgs",
17+
"repos_url": "https://api.github.com/users/bogus/repos",
18+
"events_url": "https://api.github.com/users/bogus/events{/privacy}",
19+
"received_events_url": "https://api.github.com/users/bogus/received_events",
20+
"type": "Organization",
21+
"site_admin": false
22+
},
23+
"repository_selection": "all",
24+
"access_tokens_url": "https://api.github.com/app/installations/11111111/access_tokens",
25+
"repositories_url": "https://api.github.com/installation/repositories",
26+
"html_url": "https://github.com/settings/installations/11111111",
27+
"app_id": 111111,
28+
"app_slug": "bogus-testing",
29+
"target_id": 11111111,
30+
"target_type": "Organization",
31+
"permissions": {
32+
"checks": "write",
33+
"pull_requests": "write",
34+
"contents": "read",
35+
"metadata": "read"
36+
},
37+
"events": [],
38+
"created_at": "2022-07-15T17:55:36.000Z",
39+
"updated_at": "2022-07-15T19:15:12.000Z",
40+
"single_file_name": null,
41+
"has_multiple_single_files": false,
42+
"single_file_paths": [],
43+
"suspended_by": null,
44+
"suspended_at": null
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"id": "32a6d293-46e2-48e0-a7f5-cf9ec061cd02",
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": "app-1.json",
16+
"headers": {
17+
"Server": "GitHub.com",
18+
"Date": "Wed, 27 Jul 2022 20:38:33 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/\"139628cbc6b3b04a0aa89130c8d2d7eb6935386aeaa396cbef97166394e38723\"",
26+
"X-GitHub-Media-Type": "github.v3; param=machine-man-preview; format=json",
27+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
28+
"X-Frame-Options": "deny",
29+
"X-Content-Type-Options": "nosniff",
30+
"X-XSS-Protection": "0",
31+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
32+
"Content-Security-Policy": "default-src 'none'",
33+
"X-GitHub-Request-Id": "F861:6983:622AD5:115FE5B:62E1A249"
34+
}
35+
},
36+
"uuid": "32a6d293-46e2-48e0-a7f5-cf9ec061cd02",
37+
"persistent": true,
38+
"insertionIndex": 1
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"id": "9e9f33d9-1b63-4f67-81a3-82ec45bd0afa",
3+
"name": "app_installations_27419505_access_tokens",
4+
"request": {
5+
"url": "/app/installations/11111111/access_tokens",
6+
"method": "POST",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "application/vnd.github.machine-man-preview+json"
10+
}
11+
},
12+
"bodyPatterns": [
13+
{
14+
"equalToJson": "{\"repositories\":[\"bogus\"]}",
15+
"ignoreArrayOrder": true,
16+
"ignoreExtraElements": false
17+
}
18+
]
19+
},
20+
"response": {
21+
"status": 201,
22+
"bodyFileName": "app_installations_27419505_access_tokens-3.json",
23+
"headers": {
24+
"Server": "GitHub.com",
25+
"Date": "Wed, 27 Jul 2022 20:38:33 GMT",
26+
"Content-Type": "application/json; charset=utf-8",
27+
"Cache-Control": "public, max-age=60, s-maxage=60",
28+
"Vary": [
29+
"Accept",
30+
"Accept-Encoding, Accept, X-Requested-With"
31+
],
32+
"ETag": "\"6cfb04630611056af08d2652a018429d37ca8e0df7d861b918a985d5e646e2de\"",
33+
"X-GitHub-Media-Type": "github.v3; param=machine-man-preview; format=json",
34+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
35+
"X-Frame-Options": "deny",
36+
"X-Content-Type-Options": "nosniff",
37+
"X-XSS-Protection": "0",
38+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
39+
"Content-Security-Policy": "default-src 'none'",
40+
"X-GitHub-Request-Id": "F863:32FC:5F7C97:10FD23D:62E1A249"
41+
}
42+
},
43+
"uuid": "9e9f33d9-1b63-4f67-81a3-82ec45bd0afa",
44+
"persistent": true,
45+
"insertionIndex": 3
46+
}

0 commit comments

Comments
 (0)
0