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 ;
@@ -54,6 +55,8 @@ public class TeamClient {
54
55
55
56
private static final String INVITATIONS_TEMPLATE = "/orgs/%s/teams/%s/invitations" ;
56
57
58
+ private static final String REPO_TEMPLATE = "/orgs/%s/teams/%s/repos/%s/%s" ;
59
+
57
60
private final GitHubClient github ;
58
61
59
62
private final String org ;
@@ -75,7 +78,7 @@ static TeamClient create(final GitHubClient github, final String org) {
75
78
*/
76
79
public CompletableFuture <Team > createTeam (final TeamCreate request ) {
77
80
final String path = String .format (TEAM_TEMPLATE , org );
78
- log .debug ("Creating team in: " + path );
81
+ log .debug ("Creating team in: {}" , path );
79
82
return github .post (path , github .json ().toJsonUnchecked (request ), Team .class );
80
83
}
81
84
@@ -87,7 +90,7 @@ public CompletableFuture<Team> createTeam(final TeamCreate request) {
87
90
*/
88
91
public CompletableFuture <Team > getTeam (final String slug ) {
89
92
final String path = String .format (TEAM_SLUG_TEMPLATE , org , slug );
90
- log .debug ("Fetching team from " + path );
93
+ log .debug ("Fetching team from {}" , path );
91
94
return github .request (path , Team .class );
92
95
}
93
96
@@ -98,7 +101,7 @@ public CompletableFuture<Team> getTeam(final String slug) {
98
101
*/
99
102
public CompletableFuture <List <Team >> listTeams () {
100
103
final String path = String .format (TEAM_TEMPLATE , org );
101
- log .debug ("Fetching teams from " + path );
104
+ log .debug ("Fetching teams from {}" , path );
102
105
return github .request (path , LIST_TEAMS );
103
106
}
104
107
@@ -111,7 +114,7 @@ public CompletableFuture<List<Team>> listTeams() {
111
114
*/
112
115
public CompletableFuture <Team > updateTeam (final TeamUpdate request , final String slug ) {
113
116
final String path = String .format (TEAM_SLUG_TEMPLATE , org , slug );
114
- log .debug ("Updating team in: " + path );
117
+ log .debug ("Updating team in: {}" , path );
115
118
return github .patch (path , github .json ().toJsonUnchecked (request ), Team .class );
116
119
}
117
120
@@ -123,7 +126,7 @@ public CompletableFuture<Team> updateTeam(final TeamUpdate request, final String
123
126
*/
124
127
public CompletableFuture <Void > deleteTeam (final String slug ) {
125
128
final String path = String .format (TEAM_SLUG_TEMPLATE , org , slug );
126
- log .debug ("Deleting team from: " + path );
129
+ log .debug ("Deleting team from: {}" , path );
127
130
return github .delete (path ).thenAccept (IGNORE_RESPONSE_CONSUMER );
128
131
}
129
132
@@ -133,9 +136,10 @@ public CompletableFuture<Void> deleteTeam(final String slug) {
133
136
* @param request update membership request
134
137
* @return membership
135
138
*/
136
- public CompletableFuture <Membership > updateMembership (final MembershipCreate request , final String slug , final String username ) {
139
+ public CompletableFuture <Membership > updateMembership (
140
+ final MembershipCreate request , final String slug , final String username ) {
137
141
final String path = String .format (MEMBERSHIP_TEMPLATE , org , slug , username );
138
- log .debug ("Updating membership in: " + path );
142
+ log .debug ("Updating membership in: {}" , path );
139
143
return github .put (path , github .json ().toJsonUnchecked (request ), Membership .class );
140
144
}
141
145
@@ -148,7 +152,7 @@ public CompletableFuture<Membership> updateMembership(final MembershipCreate req
148
152
*/
149
153
public CompletableFuture <Membership > getMembership (final String slug , final String username ) {
150
154
final String path = String .format (MEMBERSHIP_TEMPLATE , org , slug , username );
151
- log .debug ("Fetching membership for: " + path );
155
+ log .debug ("Fetching membership for: {}" , path );
152
156
return github .request (path , Membership .class );
153
157
}
154
158
@@ -160,7 +164,7 @@ public CompletableFuture<Membership> getMembership(final String slug, final Stri
160
164
*/
161
165
public CompletableFuture <List <User >> listTeamMembers (final String slug ) {
162
166
final String path = String .format (MEMBERS_TEMPLATE , org , slug );
163
- log .debug ("Fetching members for: " + path );
167
+ log .debug ("Fetching members for: {}" , path );
164
168
return github .request (path , LIST_TEAM_MEMBERS );
165
169
}
166
170
@@ -173,7 +177,7 @@ public CompletableFuture<List<User>> listTeamMembers(final String slug) {
173
177
*/
174
178
public Iterator <AsyncPage <User >> listTeamMembers (final String slug , final int pageSize ) {
175
179
final String path = String .format (PAGED_MEMBERS_TEMPLATE , org , slug , pageSize );
176
- log .debug ("Fetching members for: " + path );
180
+ log .debug ("Fetching members for: {}" , path );
177
181
return new GithubPageIterator <>(new GithubPage <>(github , path , LIST_TEAM_MEMBERS ));
178
182
}
179
183
@@ -185,7 +189,7 @@ public Iterator<AsyncPage<User>> listTeamMembers(final String slug, final int pa
185
189
*/
186
190
public CompletableFuture <Void > deleteMembership (final String slug , final String username ) {
187
191
final String path = String .format (MEMBERSHIP_TEMPLATE , org , slug , username );
188
- log .debug ("Deleting membership from: " + path );
192
+ log .debug ("Deleting membership from: {}" , path );
189
193
return github .delete (path ).thenAccept (IGNORE_RESPONSE_CONSUMER );
190
194
}
191
195
@@ -197,7 +201,31 @@ public CompletableFuture<Void> deleteMembership(final String slug, final String
197
201
*/
198
202
public CompletableFuture <List <TeamInvitation >> listPendingTeamInvitations (final String slug ) {
199
203
final String path = String .format (INVITATIONS_TEMPLATE , org , slug );
200
- log .debug ("Fetching pending invitations for: " + path );
204
+ log .debug ("Fetching pending invitations for: {}" , path );
201
205
return github .request (path , LIST_PENDING_TEAM_INVITATIONS );
202
206
}
207
+
208
+ /**
209
+ * Update permissions for a team on a specific repository.
210
+ *
211
+ * @param slug the team slug
212
+ * @param repo the repository name
213
+ * @param permission the permission level (pull, push, maintain, triage, admin, or a custom repo defined role name)
214
+ * @return void status code 204 if successful
215
+ */
216
+ public CompletableFuture <Void > updateTeamPermissions (
217
+ final String slug , final String repo , final String permission ) {
218
+ final String path = String .format (REPO_TEMPLATE , org , slug , org , repo );
219
+ final TeamRepoPermissionUpdate request =
220
+ ImmutableTeamRepoPermissionUpdate .builder ()
221
+ .org (org )
222
+ .repo (repo )
223
+ .teamSlug (slug )
224
+ .permission (permission )
225
+ .build ();
226
+ log .debug ("Updating team permissions for: {}" , path );
227
+ return github
228
+ .put (path , github .json ().toJsonUnchecked (request ))
229
+ .thenAccept (IGNORE_RESPONSE_CONSUMER );
230
+ }
203
231
}
0 commit comments