Create RepositoryBranchesClient (#1437)

* Tidy up location of existing EditBranch tests

* Create RepositoryBranchesClient and move the GetBranch GetAllBranches and EditBranch methods to it, obsoleting the old ones

* Add tests for the new RepositoryBranchesClient (keeping old tests for RepositoriesClient around for now)

* Disable obsolete warning on reactive client temporarily

* Create observable repository branches client and move GetBranch, GetAllBranches, EditBranch methods to it, obsoleting the old ones

* Add tests for observable repository branches client, leave old tests in place for now

* Fix projects...

* Fix whitespace
This commit is contained in:
Ryan Gribble
2016-08-08 22:00:37 +10:00
committed by GitHub
parent 23d9310133
commit ef0da2f84d
26 changed files with 1424 additions and 173 deletions
@@ -0,0 +1,151 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive
{
public class ObservableRepositoryBranchesClient : IObservableRepositoryBranchesClient
{
readonly IRepositoryBranchesClient _client;
readonly IConnection _connection;
public ObservableRepositoryBranchesClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");
_client = client.Repository.Branch;
_connection = client.Connection;
}
/// <summary>
/// Gets all the branches for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/branches/#list-branches">API documentation</a> for more details
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
public IObservable<Branch> GetAll(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return GetAll(owner, name, ApiOptions.None);
}
/// <summary>
/// Gets all the branches for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/branches/#list-branches">API documentation</a> for more details
/// </remarks>
/// <param name="repositoryId">The ID of the repository</param>
public IObservable<Branch> GetAll(int repositoryId)
{
return GetAll(repositoryId, ApiOptions.None);
}
/// <summary>
/// Gets all the branches for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/branches/#list-branches">API documentation</a> for more details
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="options">Options for changing the API response</param>
public IObservable<Branch> GetAll(string owner, string name, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages<Branch>(ApiUrls.RepoBranches(owner, name), options);
}
/// <summary>
/// Gets all the branches for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/branches/#list-branches">API documentation</a> for more details
/// </remarks>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="options">Options for changing the API response</param>
public IObservable<Branch> GetAll(int repositoryId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages<Branch>(ApiUrls.RepoBranches(repositoryId), options);
}
/// <summary>
/// Gets the specified branch.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/branches/#get-branch">API documentation</a> for more details
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="branch">The name of the branch</param>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
public IObservable<Branch> Get(string owner, string name, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
return _client.Get(owner, name, branch).ToObservable();
}
/// <summary>
/// Gets the specified branch.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/branches/#get-branch">API documentation</a> for more details
/// </remarks>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="branch">The name of the branch</param>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
public IObservable<Branch> Get(int repositoryId, string branch)
{
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
return _client.Get(repositoryId, branch).ToObservable();
}
/// <summary>
/// Edit the specified branch with the values given in <paramref name="update"/>
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="branch">The name of the branch</param>
/// <param name="update">New values to update the branch with</param>
[Obsolete("BranchProtection preview functionality in the GitHub API has had breaking changes. This existing implementation will cease to work when the preview period ends.")]
public IObservable<Branch> Edit(string owner, string name, string branch, BranchUpdate update)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
Ensure.ArgumentNotNull(update, "update");
return _client.Edit(owner, name, branch, update).ToObservable();
}
/// <summary>
/// Edit the specified branch with the values given in <paramref name="update"/>
/// </summary>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="branch">The name of the branch</param>
/// <param name="update">New values to update the branch with</param>
[Obsolete("BranchProtection preview functionality in the GitHub API has had breaking changes. This existing implementation will cease to work when the preview period ends.")]
public IObservable<Branch> Edit(int repositoryId, string branch, BranchUpdate update)
{
Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
Ensure.ArgumentNotNull(update, "update");
return _client.Edit(repositoryId, branch, update).ToObservable();
}
}
}