mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-04 19:26:51 +00:00
Expose affiliation parameter when listing collaborators (#2043)
This commit is contained in:
committed by
Brendan Forster
parent
fd6bca910c
commit
a05d49e81d
@@ -54,6 +54,54 @@ namespace Octokit.Reactive
|
||||
/// <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.
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace Octokit.Reactive
|
||||
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>
|
||||
@@ -89,8 +89,82 @@ namespace Octokit.Reactive
|
||||
public IObservable<User> GetAll(long repositoryId, ApiOptions options)
|
||||
{
|
||||
Ensure.ArgumentNotNull(options, nameof(options));
|
||||
|
||||
return GetAll(repositoryId, new RepositoryCollaboratorListRequest(), options);
|
||||
}
|
||||
|
||||
return _connection.GetAndFlattenAllPages<User>(ApiUrls.RepoCollaborators(repositoryId), 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), request.ToParametersDictionary(), AcceptHeaders.NestedTeamsPreview, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -33,7 +33,11 @@ namespace Octokit.Tests.Clients
|
||||
|
||||
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]
|
||||
@@ -44,7 +48,11 @@ namespace Octokit.Tests.Clients
|
||||
|
||||
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]
|
||||
@@ -63,7 +71,53 @@ namespace Octokit.Tests.Clients
|
||||
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]
|
||||
@@ -82,7 +136,57 @@ namespace Octokit.Tests.Clients
|
||||
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]
|
||||
@@ -97,9 +201,11 @@ namespace Octokit.Tests.Clients
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,8 +39,10 @@ namespace Octokit.Tests.Reactive
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => _client.GetAll(null, name));
|
||||
Assert.Throws<ArgumentNullException>(() => _client.GetAll(owner, null));
|
||||
Assert.Throws<ArgumentNullException>(() => _client.GetAll(owner, name, null));
|
||||
Assert.Throws<ArgumentNullException>(() => _client.GetAll(repositoryId, null));
|
||||
Assert.Throws<ArgumentNullException>(() => _client.GetAll(owner, name, options: null));
|
||||
Assert.Throws<ArgumentNullException>(() => _client.GetAll(repositoryId, options: null));
|
||||
Assert.Throws<ArgumentNullException>(() => _client.GetAll(owner, name, request: null));
|
||||
Assert.Throws<ArgumentNullException>(() => _client.GetAll(repositoryId, request: null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -67,8 +69,8 @@ namespace Octokit.Tests.Reactive
|
||||
_client.GetAll(owner, name);
|
||||
_githubClient.Connection.Received(1)
|
||||
.Get<List<User>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
||||
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 0),
|
||||
Arg.Any<string>());
|
||||
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 1),
|
||||
"application/vnd.github.hellcat-preview+json");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -79,8 +81,8 @@ namespace Octokit.Tests.Reactive
|
||||
_client.GetAll(repositoryId);
|
||||
_githubClient.Connection.Received(1)
|
||||
.Get<List<User>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
||||
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 0),
|
||||
Arg.Any<string>());
|
||||
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 1),
|
||||
"application/vnd.github.hellcat-preview+json");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -99,8 +101,8 @@ namespace Octokit.Tests.Reactive
|
||||
_client.GetAll(owner, name, options);
|
||||
_githubClient.Connection.Received(1)
|
||||
.Get<List<User>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
||||
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 2),
|
||||
null);
|
||||
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 3),
|
||||
"application/vnd.github.hellcat-preview+json");
|
||||
|
||||
// StartPage is setted => only 1 option (StartPage) in dictionary
|
||||
options = new ApiOptions
|
||||
@@ -111,8 +113,8 @@ namespace Octokit.Tests.Reactive
|
||||
_client.GetAll(owner, name, options);
|
||||
_githubClient.Connection.Received(1)
|
||||
.Get<List<User>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
||||
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 1),
|
||||
null);
|
||||
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 2),
|
||||
"application/vnd.github.hellcat-preview+json");
|
||||
|
||||
// PageCount is setted => none of options in dictionary
|
||||
options = new ApiOptions
|
||||
@@ -123,8 +125,45 @@ namespace Octokit.Tests.Reactive
|
||||
_client.GetAll(owner, name, options);
|
||||
_githubClient.Connection.Received(1)
|
||||
.Get<List<User>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
||||
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 0),
|
||||
null);
|
||||
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 1),
|
||||
"application/vnd.github.hellcat-preview+json");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithCollaboratorFilter()
|
||||
{
|
||||
var expectedUrl = string.Format("repos/{0}/{1}/collaborators", owner, name);
|
||||
|
||||
var request = new RepositoryCollaboratorListRequest();
|
||||
|
||||
_client.GetAll(owner, name, request);
|
||||
_githubClient.Connection.Received(1)
|
||||
.Get<List<User>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
||||
Arg.Is<IDictionary<string, string>>(d => d["affiliation"] == "all"),
|
||||
"application/vnd.github.hellcat-preview+json");
|
||||
|
||||
request = new RepositoryCollaboratorListRequest
|
||||
{
|
||||
Affiliation = CollaboratorAffiliation.Direct
|
||||
};
|
||||
|
||||
_client.GetAll(owner, name, request);
|
||||
_githubClient.Connection.Received(1)
|
||||
.Get<List<User>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
||||
Arg.Is<IDictionary<string, string>>(d => d["affiliation"] == "direct"),
|
||||
"application/vnd.github.hellcat-preview+json");
|
||||
|
||||
// PageCount is setted => none of options in dictionary
|
||||
request = new RepositoryCollaboratorListRequest
|
||||
{
|
||||
Affiliation = CollaboratorAffiliation.Outside
|
||||
};
|
||||
|
||||
_client.GetAll(owner, name, request);
|
||||
_githubClient.Connection.Received(1)
|
||||
.Get<List<User>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
||||
Arg.Is<IDictionary<string, string>>(d => d["affiliation"] == "outside"),
|
||||
"application/vnd.github.hellcat-preview+json");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -143,8 +182,8 @@ namespace Octokit.Tests.Reactive
|
||||
_client.GetAll(repositoryId, options);
|
||||
_githubClient.Connection.Received(1)
|
||||
.Get<List<User>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
||||
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 2),
|
||||
null);
|
||||
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 3),
|
||||
"application/vnd.github.hellcat-preview+json");
|
||||
|
||||
// StartPage is setted => only 1 option (StartPage) in dictionary
|
||||
options = new ApiOptions
|
||||
@@ -155,8 +194,8 @@ namespace Octokit.Tests.Reactive
|
||||
_client.GetAll(repositoryId, options);
|
||||
_githubClient.Connection.Received(1)
|
||||
.Get<List<User>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
||||
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 1),
|
||||
null);
|
||||
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 2),
|
||||
"application/vnd.github.hellcat-preview+json");
|
||||
|
||||
// PageCount is setted => none of options in dictionary
|
||||
options = new ApiOptions
|
||||
@@ -167,8 +206,44 @@ namespace Octokit.Tests.Reactive
|
||||
_client.GetAll(repositoryId, options);
|
||||
_githubClient.Connection.Received(1)
|
||||
.Get<List<User>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
||||
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 0),
|
||||
null);
|
||||
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 1),
|
||||
"application/vnd.github.hellcat-preview+json");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithCollaboratorFilterAndRepositoryId()
|
||||
{
|
||||
var expectedUrl = string.Format("repositories/{0}/collaborators", repositoryId);
|
||||
|
||||
var request = new RepositoryCollaboratorListRequest();
|
||||
|
||||
_client.GetAll(repositoryId, request);
|
||||
_githubClient.Connection.Received(1)
|
||||
.Get<List<User>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
||||
Arg.Is<IDictionary<string, string>>(d => d["affiliation"] == "all"),
|
||||
"application/vnd.github.hellcat-preview+json");
|
||||
|
||||
request = new RepositoryCollaboratorListRequest
|
||||
{
|
||||
Affiliation = CollaboratorAffiliation.Direct
|
||||
};
|
||||
|
||||
_client.GetAll(repositoryId, request);
|
||||
_githubClient.Connection.Received(1)
|
||||
.Get<List<User>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
||||
Arg.Is<IDictionary<string, string>>(d => d["affiliation"] == "direct"),
|
||||
"application/vnd.github.hellcat-preview+json");
|
||||
|
||||
request = new RepositoryCollaboratorListRequest
|
||||
{
|
||||
Affiliation = CollaboratorAffiliation.Outside
|
||||
};
|
||||
|
||||
_client.GetAll(repositoryId, request);
|
||||
_githubClient.Connection.Received(1)
|
||||
.Get<List<User>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
||||
Arg.Is<IDictionary<string, string>>(d => d["affiliation"] == "outside"),
|
||||
"application/vnd.github.hellcat-preview+json");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,54 @@ namespace Octokit
|
||||
/// <param name="options">Options for changing the API response</param>
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
Task<IReadOnlyList<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>
|
||||
Task<IReadOnlyList<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>
|
||||
Task<IReadOnlyList<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>
|
||||
Task<IReadOnlyList<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>
|
||||
Task<IReadOnlyList<User>> GetAll(long repositoryId, RepositoryCollaboratorListRequest request, ApiOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a user is a collaborator on a repository.
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
|
||||
Ensure.ArgumentNotNull(options, nameof(options));
|
||||
|
||||
return ApiConnection.GetAll<User>(ApiUrls.RepoCollaborators(owner, name), options);
|
||||
return GetAll(owner, name, new RepositoryCollaboratorListRequest(), options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -81,8 +81,83 @@ namespace Octokit
|
||||
public Task<IReadOnlyList<User>> GetAll(long repositoryId, ApiOptions options)
|
||||
{
|
||||
Ensure.ArgumentNotNull(options, nameof(options));
|
||||
|
||||
return GetAll(repositoryId, new RepositoryCollaboratorListRequest(), options);
|
||||
}
|
||||
|
||||
return ApiConnection.GetAll<User>(ApiUrls.RepoCollaborators(repositoryId), 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 Task<IReadOnlyList<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 Task<IReadOnlyList<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 Task<IReadOnlyList<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 ApiConnection.GetAll<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 Task<IReadOnlyList<User>> GetAll(long repositoryId, RepositoryCollaboratorListRequest request, ApiOptions options)
|
||||
{
|
||||
Ensure.ArgumentNotNull(request, nameof(request));
|
||||
Ensure.ArgumentNotNull(options, nameof(options));
|
||||
|
||||
return ApiConnection.GetAll<User>(ApiUrls.RepoCollaborators(repositoryId), request.ToParametersDictionary(), AcceptHeaders.NestedTeamsPreview, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using Octokit.Internal;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to request and filter a list of repository collaborators
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq}")]
|
||||
public class RepositoryCollaboratorListRequest : RequestParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RepositoryCollaboratorListRequest" /> class.
|
||||
/// </summary>
|
||||
public RepositoryCollaboratorListRequest()
|
||||
{
|
||||
Affiliation = CollaboratorAffiliation.All; // Default in accordance with the documentation
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the collaborator affiliation property.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The collaborator affiliation
|
||||
/// </value>
|
||||
public CollaboratorAffiliation Affiliation { get; set; }
|
||||
|
||||
internal string DebuggerDisplay
|
||||
{
|
||||
get { return string.Format(CultureInfo.InvariantCulture, "Affiliation: {0}", Affiliation); }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The collaborator affiliation
|
||||
/// </summary>
|
||||
public enum CollaboratorAffiliation
|
||||
{
|
||||
/// <summary>
|
||||
/// All collaborators the authenticated user can see.
|
||||
/// </summary>
|
||||
[Parameter(Value = "all")]
|
||||
All,
|
||||
/// <summary>
|
||||
/// All collaborators with permissions to an organization-owned repository,
|
||||
/// regardless of organization membership status.
|
||||
/// </summary>
|
||||
[Parameter(Value = "direct")]
|
||||
Direct,
|
||||
/// <summary>
|
||||
/// All outside collaborators of an organization-owned repository.
|
||||
/// </summary>
|
||||
[Parameter(Value = "outside")]
|
||||
Outside
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user