Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/com/spotify/github/v3/clients/GitHubClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.spotify.github.v3.repos.FolderContent;
import com.spotify.github.v3.repos.Repository;
import com.spotify.github.v3.repos.Status;
import com.spotify.github.v3.repos.RepositoryInvitation;

import java.io.*;
import java.lang.invoke.MethodHandles;
Expand Down Expand Up @@ -94,6 +95,7 @@ public class GitHubClient {
new TypeReference<>() {};
static final TypeReference<List<Reference>> LIST_REFERENCES =
new TypeReference<>() {};
static final TypeReference<List<RepositoryInvitation>> LIST_REPOSITORY_INVITATION = new TypeReference<>() {};

private static final String GET_ACCESS_TOKEN_URL = "app/installations/%s/access_tokens";

Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/spotify/github/v3/clients/RepositoryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static com.spotify.github.v3.clients.GitHubClient.LIST_PR_TYPE_REFERENCE;
import static com.spotify.github.v3.clients.GitHubClient.LIST_REPOSITORY;
import static com.spotify.github.v3.clients.GitHubClient.LIST_STATUS_TYPE_REFERENCE;
import static com.spotify.github.v3.clients.GitHubClient.LIST_REPOSITORY_INVITATION;

import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -88,6 +89,8 @@ public class RepositoryClient {
private static final String LIST_REPOSITORY_TEMPLATE = "/orgs/%s/repos";
private static final String LIST_REPOSITORIES_FOR_AUTHENTICATED_USER = "/user/repos";
private static final String REPOSITORY_COLLABORATOR = "/repos/%s/%s/collaborators/%s";
private static final String REPOSITORY_INVITATION = "/repos/%s/%s/invitations/%s";
private static final String REPOSITORY_INVITATIONS = "/repos/%s/%s/invitations";
private final String owner;
private final String repo;
private final GitHubClient github;
Expand Down Expand Up @@ -229,6 +232,16 @@ public CompletableFuture<Void> removeCollaborator(final String user) {
return github.delete(path).thenAccept(IGNORE_RESPONSE_CONSUMER);
}

public CompletableFuture<Void> removeInvite(final String invitationId) {
final String path = String.format(REPOSITORY_INVITATION, owner, repo, invitationId);
return github.delete(path).thenAccept(IGNORE_RESPONSE_CONSUMER);
}

public CompletableFuture<List<RepositoryInvitation>> listInvitations() {
final String path = String.format(REPOSITORY_INVITATIONS, owner, repo);
return github.request(path, LIST_REPOSITORY_INVITATION);
}

/**
* Create a webhook.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static com.spotify.github.v3.clients.GitHubClient.LIST_FOLDERCONTENT_TYPE_REFERENCE;
import static com.spotify.github.v3.clients.GitHubClient.LIST_PR_TYPE_REFERENCE;
import static com.spotify.github.v3.clients.GitHubClient.LIST_REPOSITORY;
import static com.spotify.github.v3.clients.GitHubClient.LIST_REPOSITORY_INVITATION;
import static com.spotify.github.v3.clients.MockHelper.createMockResponse;
import static com.spotify.github.v3.clients.RepositoryClient.STATUS_URI_TEMPLATE;
import static java.lang.String.format;
Expand Down Expand Up @@ -207,6 +208,33 @@ public void removeCollaborator() throws Exception {
assertThat(capture.getValue(), is("/repos/someowner/somerepo/collaborators/user"));
}

@Test
public void removeInvite() throws Exception {
CompletableFuture<Response> response = completedFuture(mock(Response.class));
final ArgumentCaptor<String> capture = ArgumentCaptor.forClass(String.class);
when(github.delete(capture.capture())).thenReturn(response);

CompletableFuture<Void> deleteResponse = repoClient.removeInvite("invitation1");
deleteResponse.get();

assertThat(capture.getValue(), is("/repos/someowner/somerepo/invitations/invitation1"));
}

@Test
public void listInvites() throws Exception {
final CompletableFuture<List<RepositoryInvitation>> fixture =
completedFuture(
json.fromJson("[" + getFixture("repository_invitation.json") + "]", LIST_REPOSITORY_INVITATION));
when(github.request("/repos/someowner/somerepo/invitations", LIST_REPOSITORY_INVITATION))
.thenReturn(fixture);

final List<RepositoryInvitation> invitations = repoClient.listInvitations().get();
assertThat(invitations.size(), is(1));
assertThat(invitations.get(0).repository().name(), is("Hello-World"));
assertThat(
invitations.get(0).inviter().login(), is("octocat"));
}

@Test
public void listCommits() throws Exception {
final CompletableFuture<List<CommitItem>> fixture =
Expand Down