18
18
* -/-/-
19
19
*/
20
20
21
-
22
21
package com .spotify .github .v3 .clients ;
23
22
24
23
import static com .spotify .github .v3 .clients .GitHubClient .*;
28
27
import com .spotify .github .v3 .User ;
29
28
import com .spotify .github .v3 .orgs .Membership ;
30
29
import com .spotify .github .v3 .orgs .TeamInvitation ;
30
+ import com .spotify .github .v3 .orgs .requests .ImmutableTeamRepoPermissionUpdate ;
31
31
import com .spotify .github .v3 .orgs .requests .MembershipCreate ;
32
32
import com .spotify .github .v3 .orgs .requests .TeamCreate ;
33
+ import com .spotify .github .v3 .orgs .requests .TeamRepoPermissionUpdate ;
33
34
import com .spotify .github .v3 .orgs .requests .TeamUpdate ;
34
35
import java .lang .invoke .MethodHandles ;
35
36
import java .util .Iterator ;
36
37
import java .util .List ;
37
38
import java .util .concurrent .CompletableFuture ;
39
+
40
+ import com .spotify .github .v3 .repos .RepositoryPermission ;
38
41
import org .slf4j .Logger ;
39
42
import org .slf4j .LoggerFactory ;
40
43
@@ -54,6 +57,8 @@ public class TeamClient {
54
57
55
58
private static final String INVITATIONS_TEMPLATE = "/orgs/%s/teams/%s/invitations" ;
56
59
60
+ private static final String REPO_TEMPLATE = "/orgs/%s/teams/%s/repos/%s/%s" ;
61
+
57
62
private final GitHubClient github ;
58
63
59
64
private final String org ;
@@ -75,7 +80,7 @@ static TeamClient create(final GitHubClient github, final String org) {
75
80
*/
76
81
public CompletableFuture <Team > createTeam (final TeamCreate request ) {
77
82
final String path = String .format (TEAM_TEMPLATE , org );
78
- log .debug ("Creating team in: " + path );
83
+ log .debug ("Creating team in: {}" , path );
79
84
return github .post (path , github .json ().toJsonUnchecked (request ), Team .class );
80
85
}
81
86
@@ -87,7 +92,7 @@ public CompletableFuture<Team> createTeam(final TeamCreate request) {
87
92
*/
88
93
public CompletableFuture <Team > getTeam (final String slug ) {
89
94
final String path = String .format (TEAM_SLUG_TEMPLATE , org , slug );
90
- log .debug ("Fetching team from " + path );
95
+ log .debug ("Fetching team from {}" , path );
91
96
return github .request (path , Team .class );
92
97
}
93
98
@@ -98,7 +103,7 @@ public CompletableFuture<Team> getTeam(final String slug) {
98
103
*/
99
104
public CompletableFuture <List <Team >> listTeams () {
100
105
final String path = String .format (TEAM_TEMPLATE , org );
101
- log .debug ("Fetching teams from " + path );
106
+ log .debug ("Fetching teams from {}" , path );
102
107
return github .request (path , LIST_TEAMS );
103
108
}
104
109
@@ -111,7 +116,7 @@ public CompletableFuture<List<Team>> listTeams() {
111
116
*/
112
117
public CompletableFuture <Team > updateTeam (final TeamUpdate request , final String slug ) {
113
118
final String path = String .format (TEAM_SLUG_TEMPLATE , org , slug );
114
- log .debug ("Updating team in: " + path );
119
+ log .debug ("Updating team in: {}" , path );
115
120
return github .patch (path , github .json ().toJsonUnchecked (request ), Team .class );
116
121
}
117
122
@@ -123,7 +128,7 @@ public CompletableFuture<Team> updateTeam(final TeamUpdate request, final String
123
128
*/
124
129
public CompletableFuture <Void > deleteTeam (final String slug ) {
125
130
final String path = String .format (TEAM_SLUG_TEMPLATE , org , slug );
126
- log .debug ("Deleting team from: " + path );
131
+ log .debug ("Deleting team from: {}" , path );
127
132
return github .delete (path ).thenAccept (IGNORE_RESPONSE_CONSUMER );
128
133
}
129
134
@@ -133,9 +138,10 @@ public CompletableFuture<Void> deleteTeam(final String slug) {
133
138
* @param request update membership request
134
139
* @return membership
135
140
*/
136
- public CompletableFuture <Membership > updateMembership (final MembershipCreate request , final String slug , final String username ) {
141
+ public CompletableFuture <Membership > updateMembership (
142
+ final MembershipCreate request , final String slug , final String username ) {
137
143
final String path = String .format (MEMBERSHIP_TEMPLATE , org , slug , username );
138
- log .debug ("Updating membership in: " + path );
144
+ log .debug ("Updating membership in: {}" , path );
139
145
return github .put (path , github .json ().toJsonUnchecked (request ), Membership .class );
140
146
}
141
147
@@ -148,7 +154,7 @@ public CompletableFuture<Membership> updateMembership(final MembershipCreate req
148
154
*/
149
155
public CompletableFuture <Membership > getMembership (final String slug , final String username ) {
150
156
final String path = String .format (MEMBERSHIP_TEMPLATE , org , slug , username );
151
- log .debug ("Fetching membership for: " + path );
157
+ log .debug ("Fetching membership for: {}" , path );
152
158
return github .request (path , Membership .class );
153
159
}
154
160
@@ -160,7 +166,7 @@ public CompletableFuture<Membership> getMembership(final String slug, final Stri
160
166
*/
161
167
public CompletableFuture <List <User >> listTeamMembers (final String slug ) {
162
168
final String path = String .format (MEMBERS_TEMPLATE , org , slug );
163
- log .debug ("Fetching members for: " + path );
169
+ log .debug ("Fetching members for: {}" , path );
164
170
return github .request (path , LIST_TEAM_MEMBERS );
165
171
}
166
172
@@ -173,7 +179,7 @@ public CompletableFuture<List<User>> listTeamMembers(final String slug) {
173
179
*/
174
180
public Iterator <AsyncPage <User >> listTeamMembers (final String slug , final int pageSize ) {
175
181
final String path = String .format (PAGED_MEMBERS_TEMPLATE , org , slug , pageSize );
176
- log .debug ("Fetching members for: " + path );
182
+ log .debug ("Fetching members for: {}" , path );
177
183
return new GithubPageIterator <>(new GithubPage <>(github , path , LIST_TEAM_MEMBERS ));
178
184
}
179
185
@@ -185,7 +191,7 @@ public Iterator<AsyncPage<User>> listTeamMembers(final String slug, final int pa
185
191
*/
186
192
public CompletableFuture <Void > deleteMembership (final String slug , final String username ) {
187
193
final String path = String .format (MEMBERSHIP_TEMPLATE , org , slug , username );
188
- log .debug ("Deleting membership from: " + path );
194
+ log .debug ("Deleting membership from: {}" , path );
189
195
return github .delete (path ).thenAccept (IGNORE_RESPONSE_CONSUMER );
190
196
}
191
197
@@ -197,7 +203,44 @@ public CompletableFuture<Void> deleteMembership(final String slug, final String
197
203
*/
198
204
public CompletableFuture <List <TeamInvitation >> listPendingTeamInvitations (final String slug ) {
199
205
final String path = String .format (INVITATIONS_TEMPLATE , org , slug );
200
- log .debug ("Fetching pending invitations for: " + path );
206
+ log .debug ("Fetching pending invitations for: {}" , path );
201
207
return github .request (path , LIST_PENDING_TEAM_INVITATIONS );
202
208
}
209
+
210
+ /**
211
+ * Update permissions for a team on a specific repository.
212
+ *
213
+ * @param slug the team slug
214
+ * @param repo the repository name
215
+ * @param permission the permission level (pull, push, maintain, triage, admin, or a custom repo defined role name)
216
+ * @return void status code 204 if successful
217
+ */
218
+ public CompletableFuture <Void > updateTeamPermissions (
219
+ final String slug , final String repo , final String permission ) {
220
+ final String path = String .format (REPO_TEMPLATE , org , slug , org , repo );
221
+ final TeamRepoPermissionUpdate request =
222
+ ImmutableTeamRepoPermissionUpdate .builder ()
223
+ .org (org )
224
+ .repo (repo )
225
+ .teamSlug (slug )
226
+ .permission (permission )
227
+ .build ();
228
+ log .debug ("Updating team permissions for: {}" , path );
229
+ return github
230
+ .put (path , github .json ().toJsonUnchecked (request ))
231
+ .thenAccept (IGNORE_RESPONSE_CONSUMER );
232
+ }
233
+
234
+ /**
235
+ * Update permissions for a team on a specific repository.
236
+ *
237
+ * @param slug the team slug
238
+ * @param repo the repository name
239
+ * @param permission the permission level (pull, push, maintain, triage, admin, or a custom repo defined role name)
240
+ * @return void status code 204 if successful
241
+ */
242
+ public CompletableFuture <Void > updateTeamPermissions (
243
+ final String slug , final String repo , final RepositoryPermission permission ) {
244
+ return updateTeamPermissions (slug , repo , permission .toString ());
245
+ }
203
246
}
0 commit comments