From 9e847b1a920f7005e9f8855d09f8311143609388 Mon Sep 17 00:00:00 2001 From: Thomas Schaaf Date: Tue, 1 Mar 2022 20:48:29 +0100 Subject: [PATCH] fix(github): Use new github teams api as old one is deprecated (#907) * fix(github): Use new github teams api https://github.blog/changelog/2022-02-22-sunset-notice-deprecated-teams-api-endpoints/ * refactor(github): Remove unused function * chore(gradle): spotless apply Co-authored-by: David Constenla <1520001+daconstenla@users.noreply.github.com> * refactor(github): clean up unused functions * refactor(github): delete unused model Co-authored-by: David Constenla <1520001+daconstenla@users.noreply.github.com> (cherry picked from commit 665b5fe2812f060416c71cde354c5f97b36b4761) --- .../github/GithubTeamsUserRolesProvider.java | 10 ++++--- .../roles/github/client/GitHubClient.java | 19 ++++--------- .../roles/github/model/TeamMembership.java | 27 ------------------- 3 files changed, 12 insertions(+), 44 deletions(-) delete mode 100644 fiat-github/src/main/java/com/netflix/spinnaker/fiat/roles/github/model/TeamMembership.java diff --git a/fiat-github/src/main/java/com/netflix/spinnaker/fiat/roles/github/GithubTeamsUserRolesProvider.java b/fiat-github/src/main/java/com/netflix/spinnaker/fiat/roles/github/GithubTeamsUserRolesProvider.java index d6ccfdfcf..357ec48f2 100644 --- a/fiat-github/src/main/java/com/netflix/spinnaker/fiat/roles/github/GithubTeamsUserRolesProvider.java +++ b/fiat-github/src/main/java/com/netflix/spinnaker/fiat/roles/github/GithubTeamsUserRolesProvider.java @@ -175,7 +175,9 @@ public Set load(Long key) { int page = 1; boolean hasMorePages = true; do { - List members = getMembersInTeamPaginated(key, page++); + List members = + getMembersInTeamPaginated( + gitHubProperties.getOrganization(), key, page++); members.forEach(m -> memberships.add(m.getLogin().toLowerCase())); if (members.size() != gitHubProperties.paginationValue) { hasMorePages = false; @@ -295,11 +297,13 @@ private List getMembersInOrgPaginated(String organization, int page) { return members; } - private List getMembersInTeamPaginated(Long teamId, int page) { + private List getMembersInTeamPaginated(String organization, Long teamId, int page) { List members = new ArrayList<>(); try { log.debug("Requesting page " + page + " of members team " + teamId + "."); - members = gitHubClient.getMembersOfTeam(teamId, page, gitHubProperties.paginationValue); + members = + gitHubClient.getMembersOfTeam( + organization, teamId, page, gitHubProperties.paginationValue); } catch (RetrofitError e) { if (e.getResponse().getStatus() != 404) { handleNon404s(e); diff --git a/fiat-github/src/main/java/com/netflix/spinnaker/fiat/roles/github/client/GitHubClient.java b/fiat-github/src/main/java/com/netflix/spinnaker/fiat/roles/github/client/GitHubClient.java index e2a7cc6bf..ba35f0eb2 100644 --- a/fiat-github/src/main/java/com/netflix/spinnaker/fiat/roles/github/client/GitHubClient.java +++ b/fiat-github/src/main/java/com/netflix/spinnaker/fiat/roles/github/client/GitHubClient.java @@ -18,9 +18,7 @@ import com.netflix.spinnaker.fiat.roles.github.model.Member; import com.netflix.spinnaker.fiat.roles.github.model.Team; -import com.netflix.spinnaker.fiat.roles.github.model.TeamMembership; import java.util.List; -import retrofit.client.Response; import retrofit.http.GET; import retrofit.http.Path; import retrofit.http.Query; @@ -28,13 +26,6 @@ /** Retrofit interface for interacting with a GitHub REST API. */ public interface GitHubClient { - @GET("/orgs/{org}/members/{username}") - Response isMemberOfOrganization(@Path("org") String org, @Path("username") String username); - - /** This one should use the Current User credentials */ - @GET("/user/teams") - List getUserTeams(); - @GET("/orgs/{org}/teams") List getOrgTeams( @Path("org") String org, @Query("page") int page, @Query("per_page") int paginationValue); @@ -43,10 +34,10 @@ List getOrgTeams( List getOrgMembers( @Path("org") String org, @Query("page") int page, @Query("per_page") int paginationValue); - @GET("/teams/{idTeam}/members") + @GET("/orgs/{org}/teams/{idTeam}/members") List getMembersOfTeam( - @Path("idTeam") Long idTeam, @Query("page") int page, @Query("per_page") int paginationValue); - - @GET("/teams/{idTeam}/memberships/{username}") - TeamMembership isMemberOfTeam(@Path("idTeam") Long idTeam, @Path("username") String username); + @Path("org") String org, + @Path("idTeam") Long idTeam, + @Query("page") int page, + @Query("per_page") int paginationValue); } diff --git a/fiat-github/src/main/java/com/netflix/spinnaker/fiat/roles/github/model/TeamMembership.java b/fiat-github/src/main/java/com/netflix/spinnaker/fiat/roles/github/model/TeamMembership.java deleted file mode 100644 index c941c48de..000000000 --- a/fiat-github/src/main/java/com/netflix/spinnaker/fiat/roles/github/model/TeamMembership.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2017 Google, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License") - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.netflix.spinnaker.fiat.roles.github.model; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import lombok.Data; - -@Data -@JsonIgnoreProperties(ignoreUnknown = true) -public class TeamMembership { - private String role; - private String state; -}