diff --git a/Octokit.Reactive/Clients/Enterprise/IObservableEnterpriseClient.cs b/Octokit.Reactive/Clients/Enterprise/IObservableEnterpriseClient.cs index 72e2d25efe..74186a8f67 100644 --- a/Octokit.Reactive/Clients/Enterprise/IObservableEnterpriseClient.cs +++ b/Octokit.Reactive/Clients/Enterprise/IObservableEnterpriseClient.cs @@ -31,5 +31,13 @@ public interface IObservableEnterpriseClient /// 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 0000000000..89b7d3fe6f --- /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 7a52afcd5b..0aa4c9201f 100644 --- a/Octokit.Reactive/Clients/Enterprise/ObservableEnterpriseClient.cs +++ b/Octokit.Reactive/Clients/Enterprise/ObservableEnterpriseClient.cs @@ -15,6 +15,7 @@ public ObservableEnterpriseClient(IGitHubClient client) AdminStats = new ObservableEnterpriseAdminStatsClient(client); License = new ObservableEnterpriseLicenseClient(client); Organization = new ObservableEnterpriseOrganizationClient(client); + SearchIndexing = new ObservableEnterpriseSearchIndexingClient(client); } /// @@ -40,5 +41,13 @@ public ObservableEnterpriseClient(IGitHubClient client) /// 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 0000000000..feb093db73 --- /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-Mono.csproj b/Octokit.Reactive/Octokit.Reactive-Mono.csproj index 3c0f28aa59..10d634574d 100644 --- a/Octokit.Reactive/Octokit.Reactive-Mono.csproj +++ b/Octokit.Reactive/Octokit.Reactive-Mono.csproj @@ -169,6 +169,8 @@ + + diff --git a/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj b/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj index a808ba9188..d0f878da13 100644 --- a/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj +++ b/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj @@ -177,6 +177,8 @@ + + diff --git a/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj b/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj index 616d3ad0d3..ce3efdbed0 100644 --- a/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj +++ b/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj @@ -173,6 +173,8 @@ + + diff --git a/Octokit.Reactive/Octokit.Reactive.csproj b/Octokit.Reactive/Octokit.Reactive.csproj index 0841fbb46e..607a71eb74 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/Clients/Enterprise/EnterpriseSearchIndexingClientTests.cs b/Octokit.Tests.Integration/Clients/Enterprise/EnterpriseSearchIndexingClientTests.cs new file mode 100644 index 0000000000..2180397598 --- /dev/null +++ b/Octokit.Tests.Integration/Clients/Enterprise/EnterpriseSearchIndexingClientTests.cs @@ -0,0 +1,106 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using Octokit; +using Octokit.Tests.Integration; +using Octokit.Tests.Integration.Helpers; +using Xunit; + +public class EnterpriseSearchIndexingClientTests +{ + readonly IGitHubClient _github; + + public EnterpriseSearchIndexingClientTests() + { + _github = EnterpriseHelper.GetAuthenticatedClient(); + } + + [GitHubEnterpriseTest] + public async Task CanQueueOwner() + { + var response = await + _github.Enterprise.SearchIndexing.Queue(EnterpriseHelper.UserName); + + 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 response = await + _github.Enterprise.SearchIndexing.Queue(EnterpriseHelper.UserName, context.RepositoryName); + + 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 response = await + _github.Enterprise.SearchIndexing.QueueAll(EnterpriseHelper.UserName); + + 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 response = await + _github.Enterprise.SearchIndexing.QueueAllCode(EnterpriseHelper.UserName); + + 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 response = await + _github.Enterprise.SearchIndexing.QueueAllCode(EnterpriseHelper.UserName, context.RepositoryName); + + 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 response = await + _github.Enterprise.SearchIndexing.QueueAllIssues(EnterpriseHelper.UserName); + + 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 response = await + _github.Enterprise.SearchIndexing.QueueAllIssues(EnterpriseHelper.UserName, context.RepositoryName); + + Assert.NotNull(response); + Assert.NotNull(response.Message); + Assert.True(response.Message.All(m => m.Contains("were added to the indexing queue"))); + } + } +} diff --git a/Octokit.Tests.Integration/Helpers/ObservableGithubClientExtensions.cs b/Octokit.Tests.Integration/Helpers/ObservableGithubClientExtensions.cs new file mode 100644 index 0000000000..8a5919ade6 --- /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 7781ebbcaf..d8df0040de 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -79,6 +79,7 @@ + @@ -111,6 +112,7 @@ + @@ -126,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 0000000000..b741fec91d --- /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/Clients/Enterprise/EnterpriseSearchIndexingClientTests.cs b/Octokit.Tests/Clients/Enterprise/EnterpriseSearchIndexingClientTests.cs new file mode 100644 index 0000000000..e347c005ed --- /dev/null +++ b/Octokit.Tests/Clients/Enterprise/EnterpriseSearchIndexingClientTests.cs @@ -0,0 +1,198 @@ +using System; +using System.Threading.Tasks; +using NSubstitute; +using Xunit; + +namespace Octokit.Tests.Clients +{ + public class EnterpriseSearchIndexingClientTests + { + public class TheQueueMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new EnterpriseSearchIndexingClient(connection); + + string expectedUri = "staff/indexing_jobs"; + + client.Queue("org"); + connection.Received().Post(Arg.Is(u => u.ToString() == expectedUri), Arg.Any()); + + client.Queue("org", "repo"); + connection.Received().Post(Arg.Is(u => u.ToString() == expectedUri), Arg.Any()); + } + + [Fact] + public void PassesRequestObject() + { + var connection = Substitute.For(); + var client = new EnterpriseSearchIndexingClient(connection); + + client.Queue("org"); + connection.Received().Post( + Arg.Any(), + Arg.Is(t => + t.Target == "org" + )); + + client.Queue("org", "repo"); + connection.Received().Post( + Arg.Any(), + Arg.Is(t => + t.Target == "org/repo" + )); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new EnterpriseSearchIndexingClient(connection); + + await Assert.ThrowsAsync(() => client.Queue(null)); + await Assert.ThrowsAsync(() => client.Queue("org", null)); + await Assert.ThrowsAsync(() => client.Queue(null, "repo")); + } + } + + public class TheQueueAllMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new EnterpriseSearchIndexingClient(connection); + + string expectedUri = "staff/indexing_jobs"; + client.QueueAll("org"); + + connection.Received().Post(Arg.Is(u => u.ToString() == expectedUri), Arg.Any()); + } + + [Fact] + public void PassesRequestObject() + { + var connection = Substitute.For(); + var client = new EnterpriseSearchIndexingClient(connection); + + client.QueueAll("org"); + connection.Received().Post( + Arg.Any(), + Arg.Is(t => + t.Target == "org/*" + )); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new EnterpriseSearchIndexingClient(connection); + + await Assert.ThrowsAsync(() => client.QueueAll(null)); + } + } + + public class TheQueueAllCodeMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new EnterpriseSearchIndexingClient(connection); + + string expectedUri = "staff/indexing_jobs"; + + client.QueueAllCode("org"); + connection.Received().Post(Arg.Is(u => u.ToString() == expectedUri), Arg.Any()); + + client.QueueAllCode("org", "repo"); + connection.Received().Post(Arg.Is(u => u.ToString() == expectedUri), Arg.Any()); + } + + [Fact] + public void PassesRequestObject() + { + var connection = Substitute.For(); + var client = new EnterpriseSearchIndexingClient(connection); + + client.QueueAllCode("org"); + connection.Received().Post( + Arg.Any(), + Arg.Is(t => + t.Target == "org/*/code" + )); + + client.QueueAllCode("org", "repo"); + connection.Received().Post( + Arg.Any(), + Arg.Is(t => + t.Target == "org/repo/code" + )); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new EnterpriseSearchIndexingClient(connection); + + await Assert.ThrowsAsync(() => client.QueueAllCode(null)); + await Assert.ThrowsAsync(() => client.QueueAllCode("org", null)); + await Assert.ThrowsAsync(() => client.QueueAllCode(null, "repo")); + } + } + + public class TheQueueAllIssuesMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new EnterpriseSearchIndexingClient(connection); + + string expectedUri = "staff/indexing_jobs"; + + client.QueueAllIssues("org"); + connection.Received().Post(Arg.Is(u => u.ToString() == expectedUri), Arg.Any()); + + client.QueueAllIssues("org", "repo"); + connection.Received().Post(Arg.Is(u => u.ToString() == expectedUri), Arg.Any()); + } + + [Fact] + public void PassesRequestObject() + { + var connection = Substitute.For(); + var client = new EnterpriseSearchIndexingClient(connection); + + client.QueueAllIssues("org"); + connection.Received().Post( + Arg.Any(), + Arg.Is(t => + t.Target == "org/*/issues" + )); + + client.QueueAllIssues("org", "repo"); + connection.Received().Post( + Arg.Any(), + Arg.Is(t => + t.Target == "org/repo/issues" + )); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new EnterpriseSearchIndexingClient(connection); + + await Assert.ThrowsAsync(() => client.QueueAllIssues(null)); + await Assert.ThrowsAsync(() => client.QueueAllIssues("org", null)); + await Assert.ThrowsAsync(() => client.QueueAllIssues(null, "repo")); + } + } + } +} diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index a916d248ea..bc124880c8 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -88,6 +88,7 @@ + @@ -190,6 +191,7 @@ + diff --git a/Octokit.Tests/Reactive/Enterprise/ObservableEnterpriseSearchIndexingClientTests.cs b/Octokit.Tests/Reactive/Enterprise/ObservableEnterpriseSearchIndexingClientTests.cs new file mode 100644 index 0000000000..491acbfc10 --- /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")); + } + } + } +} diff --git a/Octokit/Clients/Enterprise/EnterpriseClient.cs b/Octokit/Clients/Enterprise/EnterpriseClient.cs index e0109d1556..614d9bce4b 100644 --- a/Octokit/Clients/Enterprise/EnterpriseClient.cs +++ b/Octokit/Clients/Enterprise/EnterpriseClient.cs @@ -17,6 +17,7 @@ public EnterpriseClient(IApiConnection apiConnection) : base(apiConnection) AdminStats = new EnterpriseAdminStatsClient(apiConnection); License = new EnterpriseLicenseClient(apiConnection); Organization = new EnterpriseOrganizationClient(apiConnection); + SearchIndexing = new EnterpriseSearchIndexingClient(apiConnection); } /// @@ -42,5 +43,13 @@ public EnterpriseClient(IApiConnection apiConnection) : base(apiConnection) /// See the Enterprise Organization API documentation for more information. /// public IEnterpriseOrganizationClient Organization { get; private set; } + + /// + /// A client for GitHub's Enterprise Search Indexing API + /// + /// + /// See the Enterprise Search Indexing API documentation for more information. + /// + public IEnterpriseSearchIndexingClient SearchIndexing { get; private set; } } } diff --git a/Octokit/Clients/Enterprise/EnterpriseSearchIndexingClient.cs b/Octokit/Clients/Enterprise/EnterpriseSearchIndexingClient.cs new file mode 100644 index 0000000000..7e157bfbcf --- /dev/null +++ b/Octokit/Clients/Enterprise/EnterpriseSearchIndexingClient.cs @@ -0,0 +1,157 @@ +using System.Globalization; +using System.Threading.Tasks; + +namespace Octokit +{ + /// + /// A client for GitHub's Enterprise Search Indexing API + /// + /// + /// See the Enterprise Search Indexing API documentation for more information. + /// + public class EnterpriseSearchIndexingClient : ApiClient, IEnterpriseSearchIndexingClient + { + public EnterpriseSearchIndexingClient(IApiConnection apiConnection) + : base(apiConnection) + { } + + /// + /// 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 async Task Queue(string owner) + { + Ensure.ArgumentNotNull(owner, "owner"); + + var endpoint = ApiUrls.EnterpriseSearchIndexing(); + var target = new SearchIndexTarget(string.Format(CultureInfo.InvariantCulture, "{0}", owner)); + + return await ApiConnection.Post(endpoint, target) + .ConfigureAwait(false); + } + + /// + /// 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 async Task Queue(string owner, string repository) + { + Ensure.ArgumentNotNull(owner, "owner"); + Ensure.ArgumentNotNull(repository, "repository"); + + var endpoint = ApiUrls.EnterpriseSearchIndexing(); + var target = new SearchIndexTarget(string.Format(CultureInfo.InvariantCulture, "{0}/{1}", owner, repository)); + + return await ApiConnection.Post(endpoint, target) + .ConfigureAwait(false); + } + + /// + /// 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 async Task QueueAll(string owner) + { + Ensure.ArgumentNotNull(owner, "owner"); + + var endpoint = ApiUrls.EnterpriseSearchIndexing(); + var target = new SearchIndexTarget(string.Format(CultureInfo.InvariantCulture, "{0}/*", owner)); + + return await ApiConnection.Post(endpoint, target) + .ConfigureAwait(false); + } + + /// + /// 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 async Task QueueAllIssues(string owner, string repository) + { + Ensure.ArgumentNotNull(owner, "owner"); + Ensure.ArgumentNotNull(repository, "repository"); + + var endpoint = ApiUrls.EnterpriseSearchIndexing(); + var target = new SearchIndexTarget(string.Format(CultureInfo.InvariantCulture, "{0}/{1}/issues", owner, repository)); + + return await ApiConnection.Post(endpoint, target) + .ConfigureAwait(false); + } + + /// + /// 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 async Task QueueAllIssues(string owner) + { + Ensure.ArgumentNotNull(owner, "owner"); + + var endpoint = ApiUrls.EnterpriseSearchIndexing(); + var target = new SearchIndexTarget(string.Format(CultureInfo.InvariantCulture, "{0}/*/issues", owner)); + + return await ApiConnection.Post(endpoint, target) + .ConfigureAwait(false); + } + + /// + /// 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 async Task QueueAllCode(string owner, string repository) + { + Ensure.ArgumentNotNull(owner, "owner"); + Ensure.ArgumentNotNull(repository, "repository"); + + var endpoint = ApiUrls.EnterpriseSearchIndexing(); + var target = new SearchIndexTarget(string.Format(CultureInfo.InvariantCulture, "{0}/{1}/code", owner, repository)); + + return await ApiConnection.Post(endpoint, target) + .ConfigureAwait(false); + } + + /// + /// 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 async Task QueueAllCode(string owner) + { + Ensure.ArgumentNotNull(owner, "owner"); + + var endpoint = ApiUrls.EnterpriseSearchIndexing(); + var target = new SearchIndexTarget(string.Format(CultureInfo.InvariantCulture, "{0}/*/code", owner)); + + return await ApiConnection.Post(endpoint, target) + .ConfigureAwait(false); + } + } +} diff --git a/Octokit/Clients/Enterprise/IEnterpriseClient.cs b/Octokit/Clients/Enterprise/IEnterpriseClient.cs index f1c6209fc3..899751c063 100644 --- a/Octokit/Clients/Enterprise/IEnterpriseClient.cs +++ b/Octokit/Clients/Enterprise/IEnterpriseClient.cs @@ -31,5 +31,13 @@ public interface IEnterpriseClient /// See the Enterprise Organization API documentation for more information. /// IEnterpriseOrganizationClient Organization { get; } + + /// + /// A client for GitHub's Enterprise Search Indexing API + /// + /// + /// See the Enterprise Search Indexing API documentation for more information. + /// + IEnterpriseSearchIndexingClient SearchIndexing { get; } } } diff --git a/Octokit/Clients/Enterprise/IEnterpriseSearchIndexingClient.cs b/Octokit/Clients/Enterprise/IEnterpriseSearchIndexingClient.cs new file mode 100644 index 0000000000..91c7f5eb55 --- /dev/null +++ b/Octokit/Clients/Enterprise/IEnterpriseSearchIndexingClient.cs @@ -0,0 +1,86 @@ +using System.Threading.Tasks; + +namespace Octokit +{ + /// + /// A client for GitHub's Enterprise Search Indexing API + /// + /// + /// See the Enterprise Search Indexing API documentation for more information. + /// + public interface IEnterpriseSearchIndexingClient + { + /// + /// 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. + Task 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. + Task 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. + Task 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. + Task 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. + Task 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. + Task 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. + Task QueueAllCode(string owner); + } +} diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 974dba11fc..30436b85a0 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -1674,6 +1674,11 @@ public static Uri EnterpriseOrganization() return "admin/organizations".FormatUri(); } + public static Uri EnterpriseSearchIndexing() + { + return "staff/indexing_jobs".FormatUri(); + } + /// /// Creates the relative for altering administration status of a user. /// diff --git a/Octokit/Models/Request/NewOrganization.cs b/Octokit/Models/Request/Enterprise/NewOrganization.cs similarity index 100% rename from Octokit/Models/Request/NewOrganization.cs rename to Octokit/Models/Request/Enterprise/NewOrganization.cs diff --git a/Octokit/Models/Request/Enterprise/SearchIndexingTarget.cs b/Octokit/Models/Request/Enterprise/SearchIndexingTarget.cs new file mode 100644 index 0000000000..9a55bc31bf --- /dev/null +++ b/Octokit/Models/Request/Enterprise/SearchIndexingTarget.cs @@ -0,0 +1,12 @@ +namespace Octokit +{ + public class SearchIndexTarget + { + public SearchIndexTarget(string target) + { + Target = target; + } + + public string Target { get; protected set; } + } +} diff --git a/Octokit/Models/Response/Enterprise/SearchIndexingResponse.cs b/Octokit/Models/Response/Enterprise/SearchIndexingResponse.cs new file mode 100644 index 0000000000..90c054c838 --- /dev/null +++ b/Octokit/Models/Response/Enterprise/SearchIndexingResponse.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.Linq; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class SearchIndexingResponse + { + public SearchIndexingResponse() { } + + public SearchIndexingResponse(IReadOnlyList message) + { + Message = message; + } + + public IReadOnlyList Message + { + get; + private set; + } + + internal string DebuggerDisplay + { + get + { + return String.Format(CultureInfo.InvariantCulture, "Message: {0}", string.Join("\r\n", Message)); + } + } + } +} \ No newline at end of file diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index 7611c68317..cf4adab828 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -442,7 +442,11 @@ - + + + + + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index d865a56ae1..ca3641e9d8 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -450,6 +450,11 @@ + + + + + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 0788df85b4..9b911c8719 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -446,6 +446,11 @@ + + + + + diff --git a/Octokit/Octokit-Portable.csproj b/Octokit/Octokit-Portable.csproj index 974475ebf5..54301735c3 100644 --- a/Octokit/Octokit-Portable.csproj +++ b/Octokit/Octokit-Portable.csproj @@ -439,7 +439,11 @@ - + + + + + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 359b023b97..4727643229 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -446,7 +446,11 @@ - + + + + + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index bc8fea372d..d293cab7a5 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -62,10 +62,12 @@ + + @@ -110,13 +112,14 @@ - + + @@ -147,6 +150,7 @@ +