1818 * -/-/-
1919 */
2020
21-
2221package com .spotify .github .v3 .clients ;
2322
2423import static com .spotify .github .v3 .clients .GitHubClient .*;
2827import com .spotify .github .v3 .User ;
2928import com .spotify .github .v3 .orgs .Membership ;
3029import com .spotify .github .v3 .orgs .TeamInvitation ;
30+ import com .spotify .github .v3 .orgs .requests .ImmutableTeamRepoPermissionUpdate ;
3131import com .spotify .github .v3 .orgs .requests .MembershipCreate ;
3232import com .spotify .github .v3 .orgs .requests .TeamCreate ;
33+ import com .spotify .github .v3 .orgs .requests .TeamRepoPermissionUpdate ;
3334import com .spotify .github .v3 .orgs .requests .TeamUpdate ;
3435import java .lang .invoke .MethodHandles ;
3536import java .util .Iterator ;
3637import java .util .List ;
3738import java .util .concurrent .CompletableFuture ;
39+
40+ import com .spotify .github .v3 .repos .RepositoryPermission ;
3841import org .slf4j .Logger ;
3942import org .slf4j .LoggerFactory ;
4043
@@ -54,6 +57,8 @@ public class TeamClient {
5457
5558 private static final String INVITATIONS_TEMPLATE = "/orgs/%s/teams/%s/invitations" ;
5659
60+ private static final String REPO_TEMPLATE = "/orgs/%s/teams/%s/repos/%s/%s" ;
61+
5762 private final GitHubClient github ;
5863
5964 private final String org ;
@@ -75,7 +80,7 @@ static TeamClient create(final GitHubClient github, final String org) {
7580 */
7681 public CompletableFuture <Team > createTeam (final TeamCreate request ) {
7782 final String path = String .format (TEAM_TEMPLATE , org );
78- log .debug ("Creating team in: " + path );
83+ log .debug ("Creating team in: {}" , path );
7984 return github .post (path , github .json ().toJsonUnchecked (request ), Team .class );
8085 }
8186
@@ -87,7 +92,7 @@ public CompletableFuture<Team> createTeam(final TeamCreate request) {
8792 */
8893 public CompletableFuture <Team > getTeam (final String slug ) {
8994 final String path = String .format (TEAM_SLUG_TEMPLATE , org , slug );
90- log .debug ("Fetching team from " + path );
95+ log .debug ("Fetching team from {}" , path );
9196 return github .request (path , Team .class );
9297 }
9398
@@ -98,7 +103,7 @@ public CompletableFuture<Team> getTeam(final String slug) {
98103 */
99104 public CompletableFuture <List <Team >> listTeams () {
100105 final String path = String .format (TEAM_TEMPLATE , org );
101- log .debug ("Fetching teams from " + path );
106+ log .debug ("Fetching teams from {}" , path );
102107 return github .request (path , LIST_TEAMS );
103108 }
104109
@@ -111,7 +116,7 @@ public CompletableFuture<List<Team>> listTeams() {
111116 */
112117 public CompletableFuture <Team > updateTeam (final TeamUpdate request , final String slug ) {
113118 final String path = String .format (TEAM_SLUG_TEMPLATE , org , slug );
114- log .debug ("Updating team in: " + path );
119+ log .debug ("Updating team in: {}" , path );
115120 return github .patch (path , github .json ().toJsonUnchecked (request ), Team .class );
116121 }
117122
@@ -123,7 +128,7 @@ public CompletableFuture<Team> updateTeam(final TeamUpdate request, final String
123128 */
124129 public CompletableFuture <Void > deleteTeam (final String slug ) {
125130 final String path = String .format (TEAM_SLUG_TEMPLATE , org , slug );
126- log .debug ("Deleting team from: " + path );
131+ log .debug ("Deleting team from: {}" , path );
127132 return github .delete (path ).thenAccept (IGNORE_RESPONSE_CONSUMER );
128133 }
129134
@@ -133,9 +138,10 @@ public CompletableFuture<Void> deleteTeam(final String slug) {
133138 * @param request update membership request
134139 * @return membership
135140 */
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 ) {
137143 final String path = String .format (MEMBERSHIP_TEMPLATE , org , slug , username );
138- log .debug ("Updating membership in: " + path );
144+ log .debug ("Updating membership in: {}" , path );
139145 return github .put (path , github .json ().toJsonUnchecked (request ), Membership .class );
140146 }
141147
@@ -148,7 +154,7 @@ public CompletableFuture<Membership> updateMembership(final MembershipCreate req
148154 */
149155 public CompletableFuture <Membership > getMembership (final String slug , final String username ) {
150156 final String path = String .format (MEMBERSHIP_TEMPLATE , org , slug , username );
151- log .debug ("Fetching membership for: " + path );
157+ log .debug ("Fetching membership for: {}" , path );
152158 return github .request (path , Membership .class );
153159 }
154160
@@ -160,7 +166,7 @@ public CompletableFuture<Membership> getMembership(final String slug, final Stri
160166 */
161167 public CompletableFuture <List <User >> listTeamMembers (final String slug ) {
162168 final String path = String .format (MEMBERS_TEMPLATE , org , slug );
163- log .debug ("Fetching members for: " + path );
169+ log .debug ("Fetching members for: {}" , path );
164170 return github .request (path , LIST_TEAM_MEMBERS );
165171 }
166172
@@ -173,7 +179,7 @@ public CompletableFuture<List<User>> listTeamMembers(final String slug) {
173179 */
174180 public Iterator <AsyncPage <User >> listTeamMembers (final String slug , final int pageSize ) {
175181 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 );
177183 return new GithubPageIterator <>(new GithubPage <>(github , path , LIST_TEAM_MEMBERS ));
178184 }
179185
@@ -185,7 +191,7 @@ public Iterator<AsyncPage<User>> listTeamMembers(final String slug, final int pa
185191 */
186192 public CompletableFuture <Void > deleteMembership (final String slug , final String username ) {
187193 final String path = String .format (MEMBERSHIP_TEMPLATE , org , slug , username );
188- log .debug ("Deleting membership from: " + path );
194+ log .debug ("Deleting membership from: {}" , path );
189195 return github .delete (path ).thenAccept (IGNORE_RESPONSE_CONSUMER );
190196 }
191197
@@ -197,7 +203,44 @@ public CompletableFuture<Void> deleteMembership(final String slug, final String
197203 */
198204 public CompletableFuture <List <TeamInvitation >> listPendingTeamInvitations (final String slug ) {
199205 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 );
201207 return github .request (path , LIST_PENDING_TEAM_INVITATIONS );
202208 }
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+ }
203246}
0 commit comments