-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add membership APIs to manage team members #137
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
87c36a0
feat: create a membership client
ebk45 1b8dfc0
feat: refactor into teamclient
ebk45 490aeb3
feat: add ability to list team members
ebk45 75e3420
docs: update readme to address nested APIs
ebk45 c0e39e9
feat: add update membership functionality
ebk45 7b6a00b
feat: add delete membership functionality
ebk45 341d5f2
feat: add list pending team invitations logic
ebk45 f39960a
chore: cleanup
ebk45 26519a0
feat: cleanup
ebk45 29f2532
docs: update wording in readme
ebk45 7f38976
fix: naming
ebk45 00341cf
fix: update wording
ebk45 36d1521
chore: formatting
ebk45 b40ca62
feat: add test to test team client creation
ebk45 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
188 changes: 188 additions & 0 deletions
188
src/main/java/com/spotify/github/v3/clients/TeamClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
/*- | ||
* -\-\- | ||
* github-api | ||
* -- | ||
* Copyright (C) 2016 - 2020 Spotify AB | ||
* -- | ||
* 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.spotify.github.v3.clients; | ||
|
||
import static com.spotify.github.v3.clients.GitHubClient.IGNORE_RESPONSE_CONSUMER; | ||
import static com.spotify.github.v3.clients.GitHubClient.LIST_PENDING_TEAM_INVITATIONS; | ||
import static com.spotify.github.v3.clients.GitHubClient.LIST_TEAMS; | ||
import static com.spotify.github.v3.clients.GitHubClient.LIST_TEAM_MEMBERS; | ||
|
||
import com.spotify.github.v3.Team; | ||
import com.spotify.github.v3.User; | ||
import com.spotify.github.v3.orgs.Membership; | ||
import com.spotify.github.v3.orgs.TeamInvitation; | ||
import com.spotify.github.v3.orgs.requests.MembershipCreate; | ||
import com.spotify.github.v3.orgs.requests.TeamCreate; | ||
import java.lang.invoke.MethodHandles; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class TeamClient { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); | ||
|
||
private static final String TEAM_TEMPLATE = "/orgs/%s/teams"; | ||
|
||
private static final String TEAM_SLUG_TEMPLATE = "/orgs/%s/teams/%s"; | ||
|
||
private static final String MEMBERS_TEMPLATE = "/orgs/%s/teams/%s/members"; | ||
|
||
private static final String MEMBERSHIP_TEMPLATE = "/orgs/%s/teams/%s/memberships/%s"; | ||
|
||
private static final String INVITATIONS_TEMPLATE = "/orgs/%s/teams/%s/invitations"; | ||
|
||
private final GitHubClient github; | ||
|
||
private final String org; | ||
|
||
TeamClient(final GitHubClient github, final String org) { | ||
this.github = github; | ||
this.org = org; | ||
} | ||
|
||
static TeamClient create(final GitHubClient github, final String org) { | ||
return new TeamClient(github, org); | ||
} | ||
|
||
/** | ||
* Create a team in an organisation. | ||
* | ||
* @param request create team request | ||
* @return team | ||
*/ | ||
public CompletableFuture<Team> createTeam(final TeamCreate request) { | ||
final String path = String.format(TEAM_TEMPLATE, org); | ||
log.debug("Creating team in: " + path); | ||
return github.post(path, github.json().toJsonUnchecked(request), Team.class); | ||
} | ||
|
||
/** | ||
* Get a specific team in an organisation. | ||
* | ||
* @param slug slug of the team name | ||
* @return team | ||
*/ | ||
public CompletableFuture<Team> getTeam(final String slug) { | ||
final String path = String.format(TEAM_SLUG_TEMPLATE, org, slug); | ||
log.debug("Fetching team from " + path); | ||
return github.request(path, Team.class); | ||
} | ||
|
||
/** | ||
* List teams within an organisation. | ||
* | ||
* @return list of all teams in an organisation | ||
*/ | ||
public CompletableFuture<List<Team>> listTeams() { | ||
final String path = String.format(TEAM_TEMPLATE, org); | ||
log.debug("Fetching teams from " + path); | ||
return github.request(path, LIST_TEAMS); | ||
} | ||
|
||
/** | ||
* Update a team in an organisation. | ||
* | ||
* @param request update team request | ||
* @param slug slug of the team name | ||
* @return team | ||
*/ | ||
public CompletableFuture<Team> updateTeam(final TeamCreate request, final String slug) { | ||
final String path = String.format(TEAM_SLUG_TEMPLATE, org, slug); | ||
log.debug("Updating team in: " + path); | ||
return github.patch(path, github.json().toJsonUnchecked(request), Team.class); | ||
} | ||
|
||
/** | ||
* Delete a specific team in an organisation. | ||
* | ||
* @param slug slug of the team name | ||
* @return team | ||
*/ | ||
public CompletableFuture<Void> deleteTeam(final String slug) { | ||
final String path = String.format(TEAM_SLUG_TEMPLATE, org, slug); | ||
log.debug("Deleting team from: " + path); | ||
return github.delete(path).thenAccept(IGNORE_RESPONSE_CONSUMER); | ||
} | ||
|
||
/** | ||
* Add or update a team membership for a user. | ||
* | ||
* @param request update membership request | ||
* @return membership | ||
*/ | ||
public CompletableFuture<Membership> updateMembership(final MembershipCreate request, final String slug, final String username) { | ||
final String path = String.format(MEMBERSHIP_TEMPLATE, org, slug, username); | ||
log.debug("Updating membership in: " + path); | ||
return github.put(path, github.json().toJsonUnchecked(request), Membership.class); | ||
} | ||
|
||
/** | ||
* Get a team membership of a user. | ||
* | ||
* @param slug the team slug | ||
* @param username username of the team member | ||
* @return membership | ||
*/ | ||
public CompletableFuture<Membership> getMembership(final String slug, final String username) { | ||
final String path = String.format(MEMBERSHIP_TEMPLATE, org, slug, username); | ||
log.debug("Fetching membership for: " + path); | ||
return github.request(path, Membership.class); | ||
} | ||
|
||
/** | ||
* List members of a specific team. | ||
* | ||
* @param slug the team slug | ||
* @return list of all users in a team | ||
*/ | ||
public CompletableFuture<List<User>> listTeamMembers(final String slug) { | ||
final String path = String.format(MEMBERS_TEMPLATE, org, slug); | ||
log.debug("Fetching members for: " + path); | ||
return github.request(path, LIST_TEAM_MEMBERS); | ||
} | ||
|
||
/** | ||
* Delete a membership for a user. | ||
* | ||
* @param slug slug of the team name | ||
* @return membership | ||
*/ | ||
public CompletableFuture<Void> deleteMembership(final String slug, final String username) { | ||
final String path = String.format(MEMBERSHIP_TEMPLATE, org, slug, username); | ||
log.debug("Deleting membership from: " + path); | ||
return github.delete(path).thenAccept(IGNORE_RESPONSE_CONSUMER); | ||
} | ||
|
||
/** | ||
* List pending invitations for a team. | ||
* | ||
* @param slug the team slug | ||
* @return list of pending invitations for a team | ||
*/ | ||
public CompletableFuture<List<TeamInvitation>> listPendingTeamInvitations(final String slug) { | ||
final String path = String.format(INVITATIONS_TEMPLATE, org, slug); | ||
log.debug("Fetching pending invitations for: " + path); | ||
return github.request(path, LIST_PENDING_TEAM_INVITATIONS); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/*- | ||
* -\-\- | ||
* github-api | ||
* -- | ||
* Copyright (C) 2016 - 2020 Spotify AB | ||
* -- | ||
* 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.spotify.github.v3.orgs; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import com.spotify.github.GithubStyle; | ||
import java.net.URI; | ||
import javax.annotation.Nullable; | ||
import org.immutables.value.Value; | ||
|
||
/** | ||
* Membership resource represents data returned by a single Membership get operation. | ||
*/ | ||
@Value.Immutable | ||
@GithubStyle | ||
@JsonSerialize(as = ImmutableMembership.class) | ||
@JsonDeserialize(as = ImmutableMembership.class) | ||
public interface Membership { | ||
|
||
/** URL */ | ||
@Nullable | ||
URI url(); | ||
|
||
/** ROLE */ | ||
@Nullable | ||
String role(); | ||
|
||
/** STATE */ | ||
@Nullable | ||
String state(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a breaking change from the earlier version 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same thought, but I think it's fine since we just released the code that we're breaking here last week (#135), therefore nobody is using it yet probably.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point that hopefully no one is using it. Can we also unpublish the earlier version somehow? In case someone decide to use it in future?
Other than that I agree it's not worth the effort to fix the breakage.