diff --git a/Octokit.Reactive/Clients/IObservableRepositoriesClient.cs b/Octokit.Reactive/Clients/IObservableRepositoriesClient.cs index ac6fc2b2..165f784d 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoriesClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoriesClient.cs @@ -98,5 +98,94 @@ namespace Octokit.Reactive /// that announced this feature. /// IObservableCommitStatusClient CommitStatus { get; } + + /// + /// Gets all the branches for the specified repository. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// Thrown when a general API error occurs. + /// All es of the repository + IObservable GetAllBranches(string owner, string name); + + /// + /// Gets all contributors for the specified repository. Does not include anonymous contributors. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// All contributors of the repository. + IObservable GetAllContributors(string owner, string name); + + /// + /// Gets all contributors for the specified repository. With the option to include anonymous contributors. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// True if anonymous contributors should be included in result; Otherwise false + /// All contributors of the repository. + IObservable GetAllContributors(string owner, string name, bool includeAnonymous); + + /// + /// Gets all languages for the specified repository. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// All languages used in the repository and the number of bytes of each language. + IObservable GetAllLanguages(string owner, string name); + + /// + /// Gets all teams for the specified repository. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// All s associated with the repository + IObservable GetAllTeams(string owner, string name); + + /// + /// Gets all tags for the specified repository. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// All of the repositorys tags. + IObservable GetAllTags(string owner, string name); + + /// + /// Gets the specified branch. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// The specified + IObservable GetBranch(string owner, string repositoryName, string branchName); + + /// + /// Updates the specified repository with the values given in + /// + /// The owner of the repository + /// The name of the repository + /// New values to update the repository with + /// The updated + IObservable Edit(string owner, string name, RepositoryUpdate update); } } diff --git a/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs b/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs index efe5bd81..4ab1237e 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using System.Reactive; +using System.Reactive.Linq; using System.Reactive.Threading.Tasks; using Octokit.Reactive.Internal; @@ -156,5 +158,144 @@ namespace Octokit.Reactive /// that announced this feature. /// public IObservableCommitStatusClient CommitStatus { get; private set; } + + /// + /// Gets all the branches for the specified repository. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// Thrown when a general API error occurs. + /// All es of the repository + public IObservable GetAllBranches(string owner, string name) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + var endpoint = ApiUrls.RepoBranches(owner, name); + return _connection.GetAndFlattenAllPages(endpoint); + } + + /// + /// Gets all contributors for the specified repository. Does not include anonymous contributors. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// All contributors of the repository. + public IObservable GetAllContributors(string owner, string name) + { + return GetAllContributors(owner, name, false); + } + + /// + /// Gets all contributors for the specified repository. With the option to include anonymous contributors. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// True if anonymous contributors should be included in result; Otherwise false + /// All contributors of the repository. + public IObservable GetAllContributors(string owner, string name, bool includeAnonymous) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + var endpoint = ApiUrls.RepositoryContributors(owner, name); + var parameters = new Dictionary(); + if (includeAnonymous) + parameters.Add("anon", "1"); + + return _connection.GetAndFlattenAllPages(endpoint, parameters); + } + + /// + /// Gets all languages for the specified repository. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// All languages used in the repository and the number of bytes of each language. + public IObservable GetAllLanguages(string owner, string name) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + var endpoint = ApiUrls.RepositoryLanguages(owner, name); + return _connection + .GetAndFlattenAllPages>(endpoint) + .Select(t => new RepositoryLanguage(t.Item1, t.Item2)); + } + + /// + /// Gets all teams for the specified repository. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// All s associated with the repository + public IObservable GetAllTeams(string owner, string name) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + var endpoint = ApiUrls.RepositoryTeams(owner, name); + return _connection.GetAndFlattenAllPages(endpoint); + } + + /// + /// Gets all tags for the specified repository. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// All of the repositorys tags. + public IObservable GetAllTags(string owner, string name) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + var endpoint = ApiUrls.RepositoryTags(owner, name); + return _connection.GetAndFlattenAllPages(endpoint); + } + + /// + /// Gets the specified branch. + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// The specified + public IObservable GetBranch(string owner, string repositoryName, string branchName) + { + return _client.GetBranch(owner, repositoryName, branchName).ToObservable(); + } + + /// + /// Updates the specified repository with the values given in + /// + /// The owner of the repository + /// The name of the repository + /// New values to update the repository with + /// The updated + public IObservable Edit(string owner, string name, RepositoryUpdate update) + { + return _client.Edit(owner, name, update).ToObservable(); + } } } diff --git a/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs index c48ceb0e..9347be37 100644 --- a/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs @@ -162,6 +162,202 @@ namespace Octokit.Tests.Reactive } } + public class TheGetAllBranchesMethod + { + [Fact] + public void EnsuresArguments() + { + var client = new ObservableRepositoriesClient(Substitute.For()); + + Assert.Throws(() => client.GetAllBranches(null, "repo")); + Assert.Throws(() => client.GetAllBranches("owner", null)); + Assert.Throws(() => client.GetAllBranches("", "repo")); + Assert.Throws(() => client.GetAllBranches("owner", "")); + } + + [Fact] + public void GetsCorrectUrl() + { + var github = Substitute.For(); + var client = new ObservableRepositoriesClient(github); + var expected = new Uri("repos/owner/repo/branches", UriKind.Relative); + + client.GetAllBranches("owner", "repo"); + + github.Connection.Received(1).GetAsync>(expected); + } + } + + public class TheGetAllContributorsMethod + { + [Fact] + public void EnsuresArguments() + { + var client = new ObservableRepositoriesClient(Substitute.For()); + + Assert.Throws(() => client.GetAllContributors(null, "repo")); + Assert.Throws(() => client.GetAllContributors("owner", null)); + Assert.Throws(() => client.GetAllContributors("", "repo")); + Assert.Throws(() => client.GetAllContributors("owner", "")); + } + + [Fact] + public void GetsCorrectUrl() + { + var github = Substitute.For(); + var client = new ObservableRepositoriesClient(github); + var expected = new Uri("repos/owner/repo/contributors", UriKind.Relative); + + client.GetAllContributors("owner", "repo"); + + github.Connection.Received(1) + .GetAsync>(expected, + Arg.Any>(), + Arg.Any()); + } + + // TODO: Needs test for 'includeAnonymous' + } + + public class TheGetAllLanguagesMethod + { + [Fact] + public void EnsuresNonNullArguments() + { + var client = new ObservableRepositoriesClient(Substitute.For()); + + Assert.Throws(() => client.GetAllLanguages(null, "repo")); + Assert.Throws(() => client.GetAllLanguages("owner", null)); + Assert.Throws(() => client.GetAllLanguages("", "repo")); + Assert.Throws(() => client.GetAllLanguages("owner", "")); + } + + [Fact] + public void GetsCorrectUrl() + { + var github = Substitute.For(); + var client = new ObservableRepositoriesClient(github); + var expected = new Uri("repos/owner/repo/languages", UriKind.Relative); + + client.GetAllLanguages("owner", "repo"); + + github.Connection.Received(1).GetAsync>>(expected); + } + } + + public class TheGetAllTeamsMethod + { + [Fact] + public void EnsuresArguments() + { + var client = new ObservableRepositoriesClient(Substitute.For()); + + Assert.Throws(() => client.GetAllTeams(null, "repo")); + Assert.Throws(() => client.GetAllTeams("owner", null)); + Assert.Throws(() => client.GetAllTeams("", "repo")); + Assert.Throws(() => client.GetAllTeams("owner", "")); + } + + [Fact] + public void GetsCorrectUrl() + { + var github = Substitute.For(); + var client = new ObservableRepositoriesClient(github); + var expected = new Uri("repos/owner/repo/teams", UriKind.Relative); + + client.GetAllTeams("owner", "repo"); + + github.Connection.Received(1).GetAsync>(expected); + } + } + + public class TheGetAllTagsMethod + { + [Fact] + public void EnsuresArguments() + { + var client = new ObservableRepositoriesClient(Substitute.For()); + + Assert.Throws(() => client.GetAllTags(null, "repo")); + Assert.Throws(() => client.GetAllTags("owner", null)); + Assert.Throws(() => client.GetAllTags("", "repo")); + Assert.Throws(() => client.GetAllTags("owner", "")); + } + + [Fact] + public void GetsCorrectUrl() + { + var github = Substitute.For(); + var client = new ObservableRepositoriesClient(github); + var expected = new Uri("repos/owner/repo/tags", UriKind.Relative); + + client.GetAllTags("owner", "repo"); + + github.Connection.Received(1).GetAsync>(expected); + } + } + + public class TheGetBranchMethod + { + [Fact] + public async Task EnsuresArguments() + { + var github = Substitute.For(); + var nonreactiveClient = new RepositoriesClient(Substitute.For()); + github.Repository.Returns(nonreactiveClient); + var client = new ObservableRepositoriesClient(github); + + Assert.Throws(() => client.GetBranch(null, "repo", "branch")); + Assert.Throws(() => client.GetBranch("owner", null, "branch")); + Assert.Throws(() => client.GetBranch("owner", "repo", null)); + Assert.Throws(() => client.GetBranch("", "repo", "branch")); + Assert.Throws(() => client.GetBranch("owner", "", "branch")); + Assert.Throws(() => client.GetBranch("owner", "repo", "")); + } + + [Fact] + public void CallsIntoClient() + { + var github = Substitute.For(); + var client = new ObservableRepositoriesClient(github); + + client.GetBranch("owner", "repo", "branch"); + + github.Repository.Received(1).GetBranch("owner", "repo", "branch"); + } + } + + public class TheEditMethod + { + [Fact] + public async Task EnsuresArguments() + { + var github = Substitute.For(); + var nonreactiveClient = new RepositoriesClient(Substitute.For()); + github.Repository.Returns(nonreactiveClient); + var client = new ObservableRepositoriesClient(github); + var update = new RepositoryUpdate(); + + Assert.Throws(() => client.Edit(null, "repo", update)); + Assert.Throws(() => client.Edit("owner", null, update)); + Assert.Throws(() => client.Edit("owner", "repo", null)); + Assert.Throws(() => client.Edit("", "repo", update)); + Assert.Throws(() => client.Edit("owner", "", update)); + } + + [Fact] + public void CallsIntoClient() + { + var github = Substitute.For(); + var client = new ObservableRepositoriesClient(github); + var update = new RepositoryUpdate(); + + client.Edit("owner", "repo", update); + + github.Repository.Received(1).Edit("owner", "repo", update); + } + } + static ApiInfo CreateApiInfo(IDictionary links) { return new ApiInfo(links, new List(), new List(), "etag", new RateLimit(new Dictionary()));