diff --git a/Octokit.Tests.Integration/Clients/Enterprise/EnterpriseOrganizationSearchIndexingClientTests.cs b/Octokit.Tests.Integration/Clients/Enterprise/EnterpriseOrganizationSearchIndexingClientTests.cs new file mode 100644 index 0000000000..fc56492019 --- /dev/null +++ b/Octokit.Tests.Integration/Clients/Enterprise/EnterpriseOrganizationSearchIndexingClientTests.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 EnterpriseOrganizationSearchIndexingClientTests +{ + readonly IGitHubClient _github; + + public EnterpriseOrganizationSearchIndexingClientTests() + { + _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/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 7781ebbcaf..0886652b5d 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -79,6 +79,7 @@ + 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..c34185540e 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -88,6 +88,7 @@ + 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..572f545957 --- /dev/null +++ b/Octokit/Clients/Enterprise/EnterpriseSearchIndexingClient.cs @@ -0,0 +1,106 @@ +using System; +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) + { } + + /// + /// Queues an indexing job on GitHub Enterprise for a user or organization account (must be Site Admin user). + /// + /// + /// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job + /// + /// Text response + 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); + } + + 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); + } + + 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); + } + + 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); + } + + 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); + } + + 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); + } + + 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..86d3e7cf94 --- /dev/null +++ b/Octokit/Clients/Enterprise/IEnterpriseSearchIndexingClient.cs @@ -0,0 +1,36 @@ +using System.Diagnostics.CodeAnalysis; +using System.Threading.Tasks; + +namespace Octokit +{ + /// + /// A client for GitHub's Enterprise License API + /// + /// + /// See the Enterprise License API documentation for more information. + /// + public interface IEnterpriseSearchIndexingClient + { + /// + /// Gets GitHub Enterprise License Information (must be Site Admin user). + /// + /// + /// https://developer.github.com/v3/enterprise/license/#get-license-information + /// + /// The statistics. + [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")] + Task Queue(string owner); + + Task Queue(string owner, string repository); + + Task QueueAll(string owner); + + Task QueueAllIssues(string owner, string repository); + + Task QueueAllIssues(string owner); + + Task QueueAllCode(string owner, string repository); + + Task QueueAllCode(string owner); + } +} diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 0bcfdadfe6..b7cbc0d131 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -1663,6 +1663,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 10e79fc7e4..2cb91477d6 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -62,10 +62,12 @@ + + @@ -110,13 +112,14 @@ - + + @@ -147,6 +150,7 @@ +