From 528d8c58ffe1fe8361ecf5e68f5168edc31f34ad Mon Sep 17 00:00:00 2001 From: Andy Cross Date: Sun, 19 Jan 2014 20:36:47 +0000 Subject: [PATCH] Implement Get Hooks on Repository Client --- .../Clients/RepositoriesClientTests.cs | 23 ++++++++++++++ Octokit/Clients/IRepositoriesClient.cs | 7 +++++ Octokit/Clients/RepositoriesClient.cs | 8 +++++ Octokit/Helpers/ApiUrls.cs | 11 +++++++ Octokit/Models/Response/RepositoryHook.cs | 31 +++++++++++++++++++ .../Response/RepositoryHookConfiguration.cs | 22 +++++++++++++ Octokit/Octokit-netcore45.csproj | 2 ++ Octokit/Octokit.csproj | 2 ++ 8 files changed, 106 insertions(+) create mode 100644 Octokit/Models/Response/RepositoryHook.cs create mode 100644 Octokit/Models/Response/RepositoryHookConfiguration.cs diff --git a/Octokit.Tests/Clients/RepositoriesClientTests.cs b/Octokit.Tests/Clients/RepositoriesClientTests.cs index bb517f26..cfa25f5f 100644 --- a/Octokit.Tests/Clients/RepositoriesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoriesClientTests.cs @@ -249,5 +249,28 @@ namespace Octokit.Tests.Clients Assert.Equal("README", readme); } } + + public class TheGetMethodForRepositoryHooks + { + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoriesClient(connection); + + client.GetHooks("fake", "repo"); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/hooks")); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new RepositoriesClient(Substitute.For()); + + await AssertEx.Throws(async () => await client.Get(null, "name")); + await AssertEx.Throws(async () => await client.Get("owner", null)); + } + } } } diff --git a/Octokit/Clients/IRepositoriesClient.cs b/Octokit/Clients/IRepositoriesClient.cs index 0e08da1c..a9a63396 100644 --- a/Octokit/Clients/IRepositoriesClient.cs +++ b/Octokit/Clients/IRepositoriesClient.cs @@ -135,5 +135,12 @@ namespace Octokit /// that announced this feature. /// ICommitStatusClient CommitStatus { get; } + + /// + /// Gets the list of hooks defined for a repository + /// + /// See API documentation for more information. + /// + Task> GetHooks(string owner, string repositoryName);//todo: clarify type of collection } } diff --git a/Octokit/Clients/RepositoriesClient.cs b/Octokit/Clients/RepositoriesClient.cs index 023651ca..7fc35581 100644 --- a/Octokit/Clients/RepositoriesClient.cs +++ b/Octokit/Clients/RepositoriesClient.cs @@ -194,5 +194,13 @@ namespace Octokit /// that announced this feature. /// public ICommitStatusClient CommitStatus { get; private set; } + + public Task> GetHooks(string owner, string repositoryName) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); + + return ApiConnection.GetAll(ApiUrls.RepositoryHooks(owner, repositoryName)); + } } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index ac2ee83f..38cbd14d 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -246,5 +246,16 @@ namespace Octokit { return "repos/{0}/{1}/statuses/{2}".FormatUri(owner, name, reference); } + + /// + /// Returns the that lists the repository hooks for the specified reference. + /// + /// The owner of the repository + /// The name of the repository + /// + public static Uri RepositoryHooks(string owner, string repositoryName) + { + return "repos/{0}/{1}/hooks".FormatUri(owner, repositoryName); + } } } diff --git a/Octokit/Models/Response/RepositoryHook.cs b/Octokit/Models/Response/RepositoryHook.cs new file mode 100644 index 00000000..e7aab83b --- /dev/null +++ b/Octokit/Models/Response/RepositoryHook.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class RepositoryHook + { + public string Url { get; set; } + public DateTimeOffset CreatedAt { get; set; } + public DateTimeOffset UpdatedAt { get; set; } + public string Name { get; set; } + public IEnumerable Events { get; set; } + public bool Active { get; set; } + public RepositoryHookConfiguration Config { get; set; } + + internal string DebuggerDisplay + { + get + { + return String.Format(CultureInfo.InvariantCulture, + "Repository Hook: Name: {0} Url: {1}, Events: {2}", Name, Url, string.Join(", ", Events)); + } + } + } +} diff --git a/Octokit/Models/Response/RepositoryHookConfiguration.cs b/Octokit/Models/Response/RepositoryHookConfiguration.cs new file mode 100644 index 00000000..603967f2 --- /dev/null +++ b/Octokit/Models/Response/RepositoryHookConfiguration.cs @@ -0,0 +1,22 @@ +using System; +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class RepositoryHookConfiguration + { + public string Url { get; set; } + public string ContentType { get; set; } + + internal string DebuggerDisplay + { + get + { + return String.Format(CultureInfo.InvariantCulture, + "Send {0} to {1}", ContentType, Url); + } + } + } +} \ No newline at end of file diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 23698df4..e50cadb6 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -156,6 +156,8 @@ + + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 2134323a..f5894965 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -77,6 +77,8 @@ + +