Skip to content

Commit

Permalink
Expose affiliation parameter when listing collaborators (#2043)
Browse files Browse the repository at this point in the history
  • Loading branch information
hnrkndrssn authored and shiftkey committed Nov 18, 2019
1 parent fd6bca9 commit a05d49e
Show file tree
Hide file tree
Showing 7 changed files with 511 additions and 28 deletions.
48 changes: 48 additions & 0 deletions Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,54 @@ public interface IObservableRepoCollaboratorsClient
/// <param name="options">Options for changing the API response</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
IObservable<User> GetAll(long repositoryId, ApiOptions options);

/// <summary>
/// Gets all the collaborators on a repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="request">Used to request and filter a list of repository collaborators</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
IObservable<User> GetAll(string owner, string name, RepositoryCollaboratorListRequest request);

/// <summary>
/// Gets all the collaborators on a repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The id of the repository</param>
/// <param name="request">Used to request and filter a list of repository collaborators</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
IObservable<User> GetAll(long repositoryId, RepositoryCollaboratorListRequest request);

/// <summary>
/// Gets all the collaborators on a repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="request">Used to request and filter a list of repository collaborators</param>
/// <param name="options">Options for changing the API response</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
IObservable<User> GetAll(string owner, string name, RepositoryCollaboratorListRequest request, ApiOptions options);

/// <summary>
/// Gets all the collaborators on a repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The id of the repository</param>
/// <param name="request">Used to request and filter a list of repository collaborators</param>
/// <param name="options">Options for changing the API response</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
IObservable<User> GetAll(long repositoryId, RepositoryCollaboratorListRequest request, ApiOptions options);

/// <summary>
/// Checks if a user is a collaborator on a repository.
Expand Down
78 changes: 76 additions & 2 deletions Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public IObservable<User> GetAll(string owner, string name, ApiOptions options)
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(options, nameof(options));

return _connection.GetAndFlattenAllPages<User>(ApiUrls.RepoCollaborators(owner, name), options);
return GetAll(owner, name, new RepositoryCollaboratorListRequest(), options);
}

/// <summary>
Expand All @@ -89,8 +89,82 @@ public IObservable<User> GetAll(string owner, string name, ApiOptions options)
public IObservable<User> GetAll(long repositoryId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, nameof(options));

return GetAll(repositoryId, new RepositoryCollaboratorListRequest(), options);
}

/// <summary>
/// Gets all the collaborators on a repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="request">Used to request and filter a list of repository collaborators</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<User> GetAll(string owner, string name, RepositoryCollaboratorListRequest request)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(request, nameof(request));

return GetAll(owner, name, request, ApiOptions.None);
}

/// <summary>
/// Gets all the collaborators on a repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The id of the repository</param>
/// <param name="request">Used to request and filter a list of repository collaborators</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<User> GetAll(long repositoryId, RepositoryCollaboratorListRequest request)
{
Ensure.ArgumentNotNull(request, nameof(request));

return GetAll(repositoryId, request, ApiOptions.None);
}

/// <summary>
/// Gets all the collaborators on a repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="request">Used to request and filter a list of repository collaborators</param>
/// <param name="options">Options for changing the API response</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<User> GetAll(string owner, string name, RepositoryCollaboratorListRequest request, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(request, nameof(request));
Ensure.ArgumentNotNull(options, nameof(options));

return _connection.GetAndFlattenAllPages<User>(ApiUrls.RepoCollaborators(owner, name), request.ToParametersDictionary(), AcceptHeaders.NestedTeamsPreview, options);
}

/// <summary>
/// Gets all the collaborators on a repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The id of the repository</param>
/// <param name="request">Used to request and filter a list of repository collaborators</param>
/// <param name="options">Options for changing the API response</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<User> GetAll(long repositoryId, RepositoryCollaboratorListRequest request, ApiOptions options)
{
Ensure.ArgumentNotNull(request, nameof(request));
Ensure.ArgumentNotNull(options, nameof(options));

return _connection.GetAndFlattenAllPages<User>(ApiUrls.RepoCollaborators(repositoryId), options);
return _connection.GetAndFlattenAllPages<User>(ApiUrls.RepoCollaborators(repositoryId), request.ToParametersDictionary(), AcceptHeaders.NestedTeamsPreview, options);
}

/// <summary>
Expand Down
118 changes: 112 additions & 6 deletions Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ public void RequestsCorrectUrl()

client.GetAll("owner", "test");

connection.Received().GetAll<User>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/test/collaborators"), Args.ApiOptions);
connection.Received().GetAll<User>(
Arg.Is<Uri>(u => u.ToString() == "repos/owner/test/collaborators"),
Arg.Any<Dictionary<string, string>>(),
"application/vnd.github.hellcat-preview+json",
Args.ApiOptions);
}

[Fact]
Expand All @@ -44,7 +48,11 @@ public void RequestsCorrectUrlWithRepositoryId()

client.GetAll(1);

connection.Received().GetAll<User>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/collaborators"), Args.ApiOptions);
connection.Received().GetAll<User>(
Arg.Is<Uri>(u => u.ToString() == "repositories/1/collaborators"),
Arg.Any<Dictionary<string, string>>(),
"application/vnd.github.hellcat-preview+json",
Args.ApiOptions);
}

[Fact]
Expand All @@ -63,7 +71,53 @@ public void RequestsCorrectUrlWithApiOptions()
client.GetAll("owner", "test", options);

connection.Received()
.GetAll<User>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/test/collaborators"), options);
.GetAll<User>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/test/collaborators"),
Arg.Any<Dictionary<string, string>>(),
"application/vnd.github.hellcat-preview+json",
options);
}

[Fact]
public void RequestsCorrectUrlWithCollaboratorFilter()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepoCollaboratorsClient(connection);

var request = new RepositoryCollaboratorListRequest();

client.GetAll("owner", "test", request);

connection.Received()
.GetAll<User>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/test/collaborators"),
Arg.Is<Dictionary<string, string>>(d => d["affiliation"] == "all"),
"application/vnd.github.hellcat-preview+json",
Args.ApiOptions);

request = new RepositoryCollaboratorListRequest
{
Affiliation = CollaboratorAffiliation.Direct
};

client.GetAll("owner", "test", request);

connection.Received()
.GetAll<User>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/test/collaborators"),
Arg.Is<Dictionary<string, string>>(d => d["affiliation"] == "direct"),
"application/vnd.github.hellcat-preview+json",
Args.ApiOptions);

request = new RepositoryCollaboratorListRequest
{
Affiliation = CollaboratorAffiliation.Outside
};

client.GetAll("owner", "test", request);

connection.Received()
.GetAll<User>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/test/collaborators"),
Arg.Is<Dictionary<string, string>>(d => d["affiliation"] == "outside"),
"application/vnd.github.hellcat-preview+json",
Args.ApiOptions);
}

[Fact]
Expand All @@ -82,7 +136,57 @@ public void RequestsCorrectUrlWithApiOptionsAndRepositoryId()
client.GetAll(1, options);

connection.Received()
.GetAll<User>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/collaborators"), options);
.GetAll<User>(
Arg.Is<Uri>(u => u.ToString() == "repositories/1/collaborators"),
Arg.Any<Dictionary<string, string>>(),
"application/vnd.github.hellcat-preview+json",
options);
}

[Fact]
public void RequestsCorrectUrlWithCollaboratorFilterAndRepositoryId()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepoCollaboratorsClient(connection);

var request = new RepositoryCollaboratorListRequest();

client.GetAll(1, request);

connection.Received()
.GetAll<User>(
Arg.Is<Uri>(u => u.ToString() == "repositories/1/collaborators"),
Arg.Is<Dictionary<string, string>>(d => d["affiliation"] == "all"),
"application/vnd.github.hellcat-preview+json",
Args.ApiOptions);

request = new RepositoryCollaboratorListRequest
{
Affiliation = CollaboratorAffiliation.Direct
};

client.GetAll(1, request);

connection.Received()
.GetAll<User>(
Arg.Is<Uri>(u => u.ToString() == "repositories/1/collaborators"),
Arg.Is<Dictionary<string, string>>(d => d["affiliation"] == "direct"),
"application/vnd.github.hellcat-preview+json",
Args.ApiOptions);

request = new RepositoryCollaboratorListRequest
{
Affiliation = CollaboratorAffiliation.Outside
};

client.GetAll(1, request);

connection.Received()
.GetAll<User>(
Arg.Is<Uri>(u => u.ToString() == "repositories/1/collaborators"),
Arg.Is<Dictionary<string, string>>(d => d["affiliation"] == "outside"),
"application/vnd.github.hellcat-preview+json",
Args.ApiOptions);
}

[Fact]
Expand All @@ -97,9 +201,11 @@ public async Task EnsuresNonNullArguments()

await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null, "test", ApiOptions.None));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", null, ApiOptions.None));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", "test", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", "test", options: null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", "test", request: null));

await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(1, null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(1, options: null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(1, request: null));
}
}

Expand Down
Loading

0 comments on commit a05d49e

Please sign in to comment.