diff --git a/Octokit.Reactive/Clients/Enterprise/IObservableEnterpriseClient.cs b/Octokit.Reactive/Clients/Enterprise/IObservableEnterpriseClient.cs index 72e2d25e..74186a8f 100644 --- a/Octokit.Reactive/Clients/Enterprise/IObservableEnterpriseClient.cs +++ b/Octokit.Reactive/Clients/Enterprise/IObservableEnterpriseClient.cs @@ -31,5 +31,13 @@ /// See the Enterprise Organization API documentation for more information. /// IObservableEnterpriseOrganizationClient Organization { get; } + + /// + /// A client for GitHub's Enterprise Search Indexing API + /// + /// + /// See the Enterprise Search Indexing API documentation for more information. + /// + IObservableEnterpriseSearchIndexingClient SearchIndexing { get; } } } diff --git a/Octokit.Reactive/Clients/Enterprise/IObservableEnterpriseSearchIndexingClient.cs b/Octokit.Reactive/Clients/Enterprise/IObservableEnterpriseSearchIndexingClient.cs new file mode 100644 index 00000000..89b7d3fe --- /dev/null +++ b/Octokit.Reactive/Clients/Enterprise/IObservableEnterpriseSearchIndexingClient.cs @@ -0,0 +1,88 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Reactive.Threading.Tasks; + +namespace Octokit.Reactive +{ + /// + /// A client for GitHub's Enterprise Search Indexing API + /// + /// + /// See the Enterprise Search Indexing API documentation for more information. + /// + public interface IObservableEnterpriseSearchIndexingClient + { + /// + /// Queue an indexing job for a user or organization account (must be Site Admin user). + /// + /// + /// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job + /// + /// A user or organization account + /// The message. + IObservable Queue(string owner); + + /// + /// Queue an indexing job for a repository (must be Site Admin user). + /// + /// + /// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job + /// + /// A user or organization account + /// A repository + /// The message. + IObservable Queue(string owner, string repository); + + /// + /// Queue an indexing job for all of a user or organization's repositories (must be Site Admin user). + /// + /// + /// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job + /// + /// A user or organization account + /// The message. + IObservable QueueAll(string owner); + + /// + /// Queue an indexing job for all the issues in a repository (must be Site Admin user). + /// + /// + /// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job + /// + /// A user or organization account + /// A repository + /// The message. + IObservable QueueAllIssues(string owner, string repository); + + /// + /// Queue an indexing job for all the issues in all of a user or organization's repositories (must be Site Admin user). + /// + /// + /// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job + /// + /// A user or organization account + /// The message. + IObservable QueueAllIssues(string owner); + + /// + /// Queue an indexing job for all the source code in a repository (must be Site Admin user). + /// + /// + /// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job + /// + /// A user or organization account + /// A repository + /// The message. + IObservable QueueAllCode(string owner, string repository); + + /// + /// Queue an indexing job for all the source code in all of a user or organization's repositories (must be Site Admin user). + /// + /// + /// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job + /// + /// A user or organization account + /// The message. + IObservable QueueAllCode(string owner); + } +} diff --git a/Octokit.Reactive/Clients/Enterprise/ObservableEnterpriseClient.cs b/Octokit.Reactive/Clients/Enterprise/ObservableEnterpriseClient.cs index 7a52afcd..0aa4c920 100644 --- a/Octokit.Reactive/Clients/Enterprise/ObservableEnterpriseClient.cs +++ b/Octokit.Reactive/Clients/Enterprise/ObservableEnterpriseClient.cs @@ -15,6 +15,7 @@ AdminStats = new ObservableEnterpriseAdminStatsClient(client); License = new ObservableEnterpriseLicenseClient(client); Organization = new ObservableEnterpriseOrganizationClient(client); + SearchIndexing = new ObservableEnterpriseSearchIndexingClient(client); } /// @@ -40,5 +41,13 @@ /// See the Enterprise Organization API documentation for more information. /// public IObservableEnterpriseOrganizationClient Organization { get; private set; } + + /// + /// A client for GitHub's Enterprise Search Indexing API + /// + /// + /// See the Enterprise Search Indexing API documentation for more information. + /// + public IObservableEnterpriseSearchIndexingClient SearchIndexing { get; private set; } } } diff --git a/Octokit.Reactive/Clients/Enterprise/ObservableEnterpriseSearchIndexingClient.cs b/Octokit.Reactive/Clients/Enterprise/ObservableEnterpriseSearchIndexingClient.cs new file mode 100644 index 00000000..feb093db --- /dev/null +++ b/Octokit.Reactive/Clients/Enterprise/ObservableEnterpriseSearchIndexingClient.cs @@ -0,0 +1,118 @@ +using System; +using System.Reactive.Threading.Tasks; +using Octokit; + +namespace Octokit.Reactive +{ + /// + /// A client for GitHub's Enterprise Search Indexing API + /// + /// + /// See the Enterprise Search Indexing API documentation for more information. + /// + public class ObservableEnterpriseSearchIndexingClient : IObservableEnterpriseSearchIndexingClient + { + readonly IEnterpriseSearchIndexingClient _client; + + public ObservableEnterpriseSearchIndexingClient(IGitHubClient client) + { + Ensure.ArgumentNotNull(client, "client"); + + _client = client.Enterprise.SearchIndexing; + } + + /// + /// Queue an indexing job for a user or organization account (must be Site Admin user). + /// + /// + /// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job + /// + /// A user or organization account + /// The message. + public IObservable Queue(string owner) + { + return _client.Queue(owner).ToObservable(); + } + + /// + /// Queue an indexing job for a repository (must be Site Admin user). + /// + /// + /// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job + /// + /// A user or organization account + /// A repository + /// The message. + public IObservable Queue(string owner, string repository) + { + return _client.Queue(owner, repository).ToObservable(); + } + + /// + /// Queue an indexing job for all of a user or organization's repositories (must be Site Admin user). + /// + /// + /// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job + /// + /// A user or organization account + /// The message. + public IObservable QueueAll(string owner) + { + return _client.QueueAll(owner).ToObservable(); + } + + /// + /// Queue an indexing job for all the issues in a repository (must be Site Admin user). + /// + /// + /// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job + /// + /// A user or organization account + /// A repository + /// The message. + public IObservable QueueAllIssues(string owner, string repository) + { + return _client.QueueAllIssues(owner, repository).ToObservable(); + } + + /// + /// Queue an indexing job for all the issues in all of a user or organization's repositories (must be Site Admin user). + /// + /// + /// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job + /// + /// A user or organization account + /// The message. + public IObservable QueueAllIssues(string owner) + { + return _client.QueueAllIssues(owner).ToObservable(); + } + + /// + /// Queue an indexing job for all the source code in a repository (must be Site Admin user). + /// + /// + /// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job + /// + /// A user or organization account + /// A repository + /// The message. + public IObservable QueueAllCode(string owner, string repository) + { + return _client.QueueAllCode(owner, repository).ToObservable(); + } + + /// + /// Queue an indexing job for all the source code in all of a user or organization's repositories (must be Site Admin user). + /// + /// + /// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job + /// + /// A user or organization account + /// The message. + public IObservable QueueAllCode(string owner) + { + return _client.QueueAllCode(owner).ToObservable(); + } + } +} diff --git a/Octokit.Reactive/Octokit.Reactive.csproj b/Octokit.Reactive/Octokit.Reactive.csproj index 0841fbb4..607a71eb 100644 --- a/Octokit.Reactive/Octokit.Reactive.csproj +++ b/Octokit.Reactive/Octokit.Reactive.csproj @@ -75,12 +75,14 @@ Properties\SolutionInfo.cs + + diff --git a/Octokit.Tests.Integration/Helpers/ObservableGithubClientExtensions.cs b/Octokit.Tests.Integration/Helpers/ObservableGithubClientExtensions.cs new file mode 100644 index 00000000..8a5919ad --- /dev/null +++ b/Octokit.Tests.Integration/Helpers/ObservableGithubClientExtensions.cs @@ -0,0 +1,31 @@ +using Octokit.Reactive; +using System.Threading.Tasks; +using System.Reactive.Linq; + +namespace Octokit.Tests.Integration.Helpers +{ + internal static class ObservableGithubClientExtensions + { + internal async static Task CreateRepositoryContext(this IObservableGitHubClient client, string repositoryName) + { + var repoName = Helper.MakeNameWithTimestamp(repositoryName); + var repo = await client.Repository.Create(new NewRepository(repoName) { AutoInit = true }); + + return new RepositoryContext(repo); + } + + internal async static Task CreateRepositoryContext(this IObservableGitHubClient client, string organizationLogin, NewRepository newRepository) + { + var repo = await client.Repository.Create(organizationLogin, newRepository); + + return new RepositoryContext(repo); + } + + internal async static Task CreateRepositoryContext(this IObservableGitHubClient client, NewRepository newRepository) + { + var repo = await client.Repository.Create(newRepository); + + return new RepositoryContext(repo); + } + } +} \ No newline at end of file diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 74a06d90..d8df0040 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -112,6 +112,7 @@ + @@ -127,6 +128,7 @@ + diff --git a/Octokit.Tests.Integration/Reactive/Enterprise/ObservableEnterpriseSearchIndexingClientTests.cs b/Octokit.Tests.Integration/Reactive/Enterprise/ObservableEnterpriseSearchIndexingClientTests.cs new file mode 100644 index 00000000..b741fec9 --- /dev/null +++ b/Octokit.Tests.Integration/Reactive/Enterprise/ObservableEnterpriseSearchIndexingClientTests.cs @@ -0,0 +1,108 @@ +using System.Linq; +using System.Reactive.Linq; +using System.Threading.Tasks; +using Octokit.Reactive; +using Octokit.Tests.Integration.Helpers; +using Xunit; + +namespace Octokit.Tests.Integration +{ + public class ObservableEnterpriseSearchIndexingClientTests + { + readonly IObservableGitHubClient _github; + + public ObservableEnterpriseSearchIndexingClientTests() + { + _github = new ObservableGitHubClient(EnterpriseHelper.GetAuthenticatedClient()); + } + + [GitHubEnterpriseTest] + public async Task CanQueueOwner() + { + var observable = _github.Enterprise.SearchIndexing.Queue(EnterpriseHelper.UserName); + var response = await observable; + + Assert.NotNull(response); + Assert.NotNull(response.Message); + Assert.True(response.Message.All(m => m.Contains("was added to the indexing queue"))); + } + + [GitHubEnterpriseTest] + public async Task CanQueueRepository() + { + var newRepository = new NewRepository(Helper.MakeNameWithTimestamp("public-repo")); + using (var context = await _github.CreateRepositoryContext(newRepository)) + { + var observable = _github.Enterprise.SearchIndexing.Queue(EnterpriseHelper.UserName, context.RepositoryName); + var response = await observable; + + Assert.NotNull(response); + Assert.NotNull(response.Message); + Assert.True(response.Message.All(m => m.Contains("was added to the indexing queue"))); + } + } + + [GitHubEnterpriseTest] + public async Task CanQueueAll() + { + var observable = _github.Enterprise.SearchIndexing.QueueAll(EnterpriseHelper.UserName); + var response = await observable; + + Assert.NotNull(response); + Assert.NotNull(response.Message); + Assert.True(response.Message.All(m => m.Contains("was added to the indexing queue"))); + } + + [GitHubEnterpriseTest] + public async Task CanQueueAllCodeOwner() + { + var observable = _github.Enterprise.SearchIndexing.QueueAllCode(EnterpriseHelper.UserName); + var response = await observable; + + Assert.NotNull(response); + Assert.NotNull(response.Message); + Assert.True(response.Message.All(m => m.Contains("was added to the indexing queue"))); + } + + [GitHubEnterpriseTest] + public async Task CanQueueAllCodeRepository() + { + var newRepository = new NewRepository(Helper.MakeNameWithTimestamp("public-repo")); + using (var context = await _github.CreateRepositoryContext(newRepository)) + { + var observable = _github.Enterprise.SearchIndexing.QueueAllCode(EnterpriseHelper.UserName, context.RepositoryName); + var response = await observable; + + Assert.NotNull(response); + Assert.NotNull(response.Message); + Assert.True(response.Message.All(m => m.Contains("was added to the indexing queue"))); + } + } + + [GitHubEnterpriseTest] + public async Task CanQueueAllIssuesOwner() + { + var observable = _github.Enterprise.SearchIndexing.QueueAllIssues(EnterpriseHelper.UserName); + var response = await observable; + + Assert.NotNull(response); + Assert.NotNull(response.Message); + Assert.True(response.Message.All(m => m.Contains("were added to the indexing queue"))); + } + + [GitHubEnterpriseTest] + public async Task CanQueueAllIssuesRepository() + { + var newRepository = new NewRepository(Helper.MakeNameWithTimestamp("public-repo")); + using (var context = await _github.CreateRepositoryContext(newRepository)) + { + var observable = _github.Enterprise.SearchIndexing.QueueAllIssues(EnterpriseHelper.UserName, context.RepositoryName); + var response = await observable; + + Assert.NotNull(response); + Assert.NotNull(response.Message); + Assert.True(response.Message.All(m => m.Contains("were added to the indexing queue"))); + } + } + } +} \ No newline at end of file diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index c3418554..bc124880 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -191,6 +191,7 @@ + diff --git a/Octokit.Tests/Reactive/Enterprise/ObservableEnterpriseSearchIndexingClientTests.cs b/Octokit.Tests/Reactive/Enterprise/ObservableEnterpriseSearchIndexingClientTests.cs new file mode 100644 index 00000000..491acbfc --- /dev/null +++ b/Octokit.Tests/Reactive/Enterprise/ObservableEnterpriseSearchIndexingClientTests.cs @@ -0,0 +1,81 @@ +using System; +using NSubstitute; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests +{ + public class ObservableEnterpriseSearchIndexingClientTests + { + public class TheQueueMethod + { + [Fact] + public void CallsIntoClient() + { + var github = Substitute.For(); + var client = new ObservableEnterpriseSearchIndexingClient(github); + + client.Queue("org"); + github.Enterprise.SearchIndexing.Received(1). + Queue(Arg.Is( "org" )); + + client.Queue("org", "repo"); + github.Enterprise.SearchIndexing.Received(1). + Queue(Arg.Is("org"), + Arg.Is("repo")); + } + } + + public class TheQueueAllMethod + { + [Fact] + public void CallsIntoClient() + { + var github = Substitute.For(); + var client = new ObservableEnterpriseSearchIndexingClient(github); + + client.QueueAll("org"); + github.Enterprise.SearchIndexing.Received(1). + QueueAll(Arg.Is("org")); + } + } + + public class TheQueueAllCodeMethod + { + [Fact] + public void CallsIntoClient() + { + var github = Substitute.For(); + var client = new ObservableEnterpriseSearchIndexingClient(github); + + client.QueueAllCode("org"); + github.Enterprise.SearchIndexing.Received(1). + QueueAllCode(Arg.Is("org")); + + client.QueueAllCode("org", "repo"); + github.Enterprise.SearchIndexing.Received(1). + QueueAllCode(Arg.Is("org"), + Arg.Is("repo")); + } + } + + public class TheQueueAllIssuesMethod + { + [Fact] + public void CallsIntoClient() + { + var github = Substitute.For(); + var client = new ObservableEnterpriseSearchIndexingClient(github); + + client.QueueAllIssues("org"); + github.Enterprise.SearchIndexing.Received(1). + QueueAllIssues(Arg.Is("org")); + + client.QueueAllIssues("org", "repo"); + github.Enterprise.SearchIndexing.Received(1). + QueueAllIssues(Arg.Is("org"), + Arg.Is("repo")); + } + } + } +}