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 ;
@@ -54,6 +55,8 @@ public class TeamClient {
5455
5556 private static final String INVITATIONS_TEMPLATE = "/orgs/%s/teams/%s/invitations" ;
5657
58+ private static final String REPO_TEMPLATE = "/orgs/%s/teams/%s/repos/%s/%s" ;
59+
5760 private final GitHubClient github ;
5861
5962 private final String org ;
@@ -75,7 +78,7 @@ static TeamClient create(final GitHubClient github, final String org) {
7578 */
7679 public CompletableFuture <Team > createTeam (final TeamCreate request ) {
7780 final String path = String .format (TEAM_TEMPLATE , org );
78- log .debug ("Creating team in: " + path );
81+ log .debug ("Creating team in: {}" , path );
7982 return github .post (path , github .json ().toJsonUnchecked (request ), Team .class );
8083 }
8184
@@ -87,7 +90,7 @@ public CompletableFuture<Team> createTeam(final TeamCreate request) {
8790 */
8891 public CompletableFuture <Team > getTeam (final String slug ) {
8992 final String path = String .format (TEAM_SLUG_TEMPLATE , org , slug );
90- log .debug ("Fetching team from " + path );
93+ log .debug ("Fetching team from {}" , path );
9194 return github .request (path , Team .class );
9295 }
9396
@@ -98,7 +101,7 @@ public CompletableFuture<Team> getTeam(final String slug) {
98101 */
99102 public CompletableFuture <List <Team >> listTeams () {
100103 final String path = String .format (TEAM_TEMPLATE , org );
101- log .debug ("Fetching teams from " + path );
104+ log .debug ("Fetching teams from {}" , path );
102105 return github .request (path , LIST_TEAMS );
103106 }
104107
@@ -111,7 +114,7 @@ public CompletableFuture<List<Team>> listTeams() {
111114 */
112115 public CompletableFuture <Team > updateTeam (final TeamUpdate request , final String slug ) {
113116 final String path = String .format (TEAM_SLUG_TEMPLATE , org , slug );
114- log .debug ("Updating team in: " + path );
117+ log .debug ("Updating team in: {}" , path );
115118 return github .patch (path , github .json ().toJsonUnchecked (request ), Team .class );
116119 }
117120
@@ -123,7 +126,7 @@ public CompletableFuture<Team> updateTeam(final TeamUpdate request, final String
123126 */
124127 public CompletableFuture <Void > deleteTeam (final String slug ) {
125128 final String path = String .format (TEAM_SLUG_TEMPLATE , org , slug );
126- log .debug ("Deleting team from: " + path );
129+ log .debug ("Deleting team from: {}" , path );
127130 return github .delete (path ).thenAccept (IGNORE_RESPONSE_CONSUMER );
128131 }
129132
@@ -133,9 +136,10 @@ public CompletableFuture<Void> deleteTeam(final String slug) {
133136 * @param request update membership request
134137 * @return membership
135138 */
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 ) {
137141 final String path = String .format (MEMBERSHIP_TEMPLATE , org , slug , username );
138- log .debug ("Updating membership in: " + path );
142+ log .debug ("Updating membership in: {}" , path );
139143 return github .put (path , github .json ().toJsonUnchecked (request ), Membership .class );
140144 }
141145
@@ -148,7 +152,7 @@ public CompletableFuture<Membership> updateMembership(final MembershipCreate req
148152 */
149153 public CompletableFuture <Membership > getMembership (final String slug , final String username ) {
150154 final String path = String .format (MEMBERSHIP_TEMPLATE , org , slug , username );
151- log .debug ("Fetching membership for: " + path );
155+ log .debug ("Fetching membership for: {}" , path );
152156 return github .request (path , Membership .class );
153157 }
154158
@@ -160,7 +164,7 @@ public CompletableFuture<Membership> getMembership(final String slug, final Stri
160164 */
161165 public CompletableFuture <List <User >> listTeamMembers (final String slug ) {
162166 final String path = String .format (MEMBERS_TEMPLATE , org , slug );
163- log .debug ("Fetching members for: " + path );
167+ log .debug ("Fetching members for: {}" , path );
164168 return github .request (path , LIST_TEAM_MEMBERS );
165169 }
166170
@@ -173,7 +177,7 @@ public CompletableFuture<List<User>> listTeamMembers(final String slug) {
173177 */
174178 public Iterator <AsyncPage <User >> listTeamMembers (final String slug , final int pageSize ) {
175179 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 );
177181 return new GithubPageIterator <>(new GithubPage <>(github , path , LIST_TEAM_MEMBERS ));
178182 }
179183
@@ -185,7 +189,7 @@ public Iterator<AsyncPage<User>> listTeamMembers(final String slug, final int pa
185189 */
186190 public CompletableFuture <Void > deleteMembership (final String slug , final String username ) {
187191 final String path = String .format (MEMBERSHIP_TEMPLATE , org , slug , username );
188- log .debug ("Deleting membership from: " + path );
192+ log .debug ("Deleting membership from: {}" , path );
189193 return github .delete (path ).thenAccept (IGNORE_RESPONSE_CONSUMER );
190194 }
191195
@@ -197,7 +201,31 @@ public CompletableFuture<Void> deleteMembership(final String slug, final String
197201 */
198202 public CompletableFuture <List <TeamInvitation >> listPendingTeamInvitations (final String slug ) {
199203 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 );
201205 return github .request (path , LIST_PENDING_TEAM_INVITATIONS );
202206 }
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+ }
203231}
0 commit comments