diff --git a/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs b/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs index f714c37e..e3b3fd4a 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs @@ -113,10 +113,11 @@ namespace Octokit.Reactive public IObservable> GetHooks(string owner, string repositoryName) { - Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); - Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); + throw new NotImplementedException("refactor"); + //Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + //Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); - return _client.GetHooks(owner, repositoryName).ToObservable(); + //return _client.GetHooks(owner, repositoryName).ToObservable(); } } } diff --git a/Octokit.Tests/Clients/RepositoriesClientTests.cs b/Octokit.Tests/Clients/RepositoriesClientTests.cs index cfa25f5f..c3f9e4ee 100644 --- a/Octokit.Tests/Clients/RepositoriesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoriesClientTests.cs @@ -258,7 +258,7 @@ namespace Octokit.Tests.Clients var connection = Substitute.For(); var client = new RepositoriesClient(connection); - client.GetHooks("fake", "repo"); + client.Hooks.GetHooks("fake", "repo"); connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/hooks")); } diff --git a/Octokit/Clients/IRepositoriesClient.cs b/Octokit/Clients/IRepositoriesClient.cs index 61091695..82216e03 100644 --- a/Octokit/Clients/IRepositoriesClient.cs +++ b/Octokit/Clients/IRepositoriesClient.cs @@ -137,10 +137,9 @@ namespace Octokit ICommitStatusClient CommitStatus { get; } /// - /// Gets the list of hooks defined for a repository + /// A client for GitHub's Repository Hooks API. /// - /// See API documentation for more information. - /// - Task> GetHooks(string owner, string repositoryName); + /// See API documentation for more information. + IRepositoryHooksClient Hooks { get; } } } diff --git a/Octokit/Clients/IRepositoryHooksClient.cs b/Octokit/Clients/IRepositoryHooksClient.cs new file mode 100644 index 00000000..a431c8dc --- /dev/null +++ b/Octokit/Clients/IRepositoryHooksClient.cs @@ -0,0 +1,33 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit +{ + public interface IRepositoryHooksClient + { + /// + /// Gets the list of hooks defined for a repository + /// + /// See API documentation for more information. + /// + Task> GetHooks(string owner, string repositoryName); + + /// + /// Gets a single hook by Id + /// + /// + /// + /// + /// + /// See API documentation for more information. + Task GetHookById(string owner, string repositoryName, int hookId); + + Task CreateHook(string owner, string repositoryName, NewRepositoryHook hook); + + Task EditHook(string owner, string repositoryName, string hookId, EditRepositoryHook hook); + + Task TestHook(string owner, string repositoryName, string hookId); + + Task DeleteHook(string owner, string repositoryName, string hookId); + } +} diff --git a/Octokit/Clients/RepositoriesClient.cs b/Octokit/Clients/RepositoriesClient.cs index 40f87a3c..0b699092 100644 --- a/Octokit/Clients/RepositoriesClient.cs +++ b/Octokit/Clients/RepositoriesClient.cs @@ -21,6 +21,7 @@ namespace Octokit public RepositoriesClient(IApiConnection apiConnection) : base(apiConnection) { CommitStatus = new CommitStatusClient(apiConnection); + _hooks = new Lazy(() => new RepositoryHooksClient(apiConnection)); } /// @@ -195,17 +196,14 @@ namespace Octokit /// public ICommitStatusClient CommitStatus { get; private set; } - /// - /// Gets the list of hooks defined for a repository - /// - /// See API documentation for more information. - /// - public Task> GetHooks(string owner, string repositoryName) - { - Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); - Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); + Lazy _hooks; - return ApiConnection.GetAll(ApiUrls.RepositoryHooks(owner, repositoryName)); + /// + /// Gets a client for GitHub's Repository Hooks + /// + public IRepositoryHooksClient Hooks + { + get { return _hooks.Value; } } } } diff --git a/Octokit/Clients/RepositoryHooksClient.cs b/Octokit/Clients/RepositoryHooksClient.cs new file mode 100644 index 00000000..2279284c --- /dev/null +++ b/Octokit/Clients/RepositoryHooksClient.cs @@ -0,0 +1,71 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit +{ + /// + /// A client for GitHub's Repository Hooks API + /// + public class RepositoryHooksClient : ApiClient, IRepositoryHooksClient + { + /// + /// Initializes a new GitHub Repos API client. + /// + /// An API connection. + public RepositoryHooksClient(IApiConnection apiConnection) : base(apiConnection) + { + } + + /// + /// Gets the list of hooks defined for a repository + /// + /// See API documentation for more information. + /// + public Task> GetHooks(string owner, string repositoryName) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); + + return ApiConnection.GetAll(ApiUrls.RepositoryHooks(owner, repositoryName)); + } + + /// + /// Gets a single hook defined for a repository by id + /// + /// See API documentation for more information. + /// + public Task GetHookById(string owner, string repositoryName, int hookId) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); + Ensure.ArgumentNotNull(hookId, "hookId"); + + return ApiConnection.Get(ApiUrls.RepositoryHooksById(owner, repositoryName, hookId)); + } + + /// + /// Creates a hook for a repository + /// + /// See API documentation for more information. + /// + public Task CreateHook(string owner, string repositoryName, NewRepositoryHook hook) + { + throw new System.NotImplementedException(); + } + + public Task EditHook(string owner, string repositoryName, string hookId, EditRepositoryHook hook) + { + throw new System.NotImplementedException(); + } + + public Task TestHook(string owner, string repositoryName, string hookId) + { + throw new System.NotImplementedException(); + } + + public Task DeleteHook(string owner, string repositoryName, string hookId) + { + throw new System.NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 38cbd14d..ffe0ab57 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -257,5 +257,17 @@ namespace Octokit { return "repos/{0}/{1}/hooks".FormatUri(owner, repositoryName); } + + /// + /// Returns the that gets the repository hook for the specified reference. + /// + /// The owner of the repository + /// The name of the repository + /// The identifier of the repository hook + /// + public static Uri RepositoryHooksById(string owner, string repositoryName, int hookId) + { + return "repos/{0}/{1}/hooks/{2}".FormatUri(owner, repositoryName, hookId); + } } } diff --git a/Octokit/Models/Request/EditRepositoryHook.cs b/Octokit/Models/Request/EditRepositoryHook.cs new file mode 100644 index 00000000..acff18c0 --- /dev/null +++ b/Octokit/Models/Request/EditRepositoryHook.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class EditRepositoryHook + { + public dynamic Config { get; set; } + public IEnumerable Events { get; set; } + public IEnumerable AddEvents { get; set; } + public IEnumerable RemoveEvents { get; set; } + public bool Active { get; set; } + + internal string DebuggerDisplay + { + get + { + return String.Format(CultureInfo.InvariantCulture, + "Repository Hook: Replacing Events: {0}, Adding Events: {1}, Removing Events: {2}", Events == null ? "no" : string.Join(", ", Events), + AddEvents == null ? "no" : string.Join(", ", AddEvents), + RemoveEvents == null ? "no" : string.Join(", ", RemoveEvents)); + } + } + } +} \ No newline at end of file diff --git a/Octokit/Models/Request/NewRepositoryHook.cs b/Octokit/Models/Request/NewRepositoryHook.cs new file mode 100644 index 00000000..2f9f5ac0 --- /dev/null +++ b/Octokit/Models/Request/NewRepositoryHook.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class NewRepositoryHook + { + public string Name { get; set; } + public dynamic Config { get; set; } + public IEnumerable Events { get; set; } + public bool Active { get; set; } + + internal string DebuggerDisplay + { + get + { + return String.Format(CultureInfo.InvariantCulture, + "Repository Hook: Name: {0}, Events: {1}", Name,string.Join(", ", Events)); + } + } + } +} diff --git a/Octokit/Models/Response/RepositoryHook.cs b/Octokit/Models/Response/RepositoryHook.cs index e7aab83b..92e22fdc 100644 --- a/Octokit/Models/Response/RepositoryHook.cs +++ b/Octokit/Models/Response/RepositoryHook.cs @@ -17,7 +17,8 @@ namespace Octokit public string Name { get; set; } public IEnumerable Events { get; set; } public bool Active { get; set; } - public RepositoryHookConfiguration Config { get; set; } + public dynamic Config { get; set; } + public int Id { get; set; } internal string DebuggerDisplay { diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index e50cadb6..96567512 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -59,6 +59,7 @@ + @@ -68,6 +69,7 @@ + @@ -121,6 +123,7 @@ + @@ -130,6 +133,7 @@ + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index f5894965..a1e23c54 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -53,17 +53,21 @@ + + + + @@ -78,7 +82,6 @@ -