mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-20 06:05:12 +00:00
Refactor to a RepositoryHooksClient
This commit is contained in:
@@ -113,10 +113,11 @@ namespace Octokit.Reactive
|
|||||||
|
|
||||||
public IObservable<IReadOnlyList<RepositoryHook>> GetHooks(string owner, string repositoryName)
|
public IObservable<IReadOnlyList<RepositoryHook>> GetHooks(string owner, string repositoryName)
|
||||||
{
|
{
|
||||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
throw new NotImplementedException("refactor");
|
||||||
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
|
//Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||||
|
//Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
|
||||||
|
|
||||||
return _client.GetHooks(owner, repositoryName).ToObservable();
|
//return _client.GetHooks(owner, repositoryName).ToObservable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -258,7 +258,7 @@ namespace Octokit.Tests.Clients
|
|||||||
var connection = Substitute.For<IApiConnection>();
|
var connection = Substitute.For<IApiConnection>();
|
||||||
var client = new RepositoriesClient(connection);
|
var client = new RepositoriesClient(connection);
|
||||||
|
|
||||||
client.GetHooks("fake", "repo");
|
client.Hooks.GetHooks("fake", "repo");
|
||||||
|
|
||||||
connection.Received().GetAll<RepositoryHook>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/hooks"));
|
connection.Received().GetAll<RepositoryHook>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/hooks"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,10 +137,9 @@ namespace Octokit
|
|||||||
ICommitStatusClient CommitStatus { get; }
|
ICommitStatusClient CommitStatus { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the list of hooks defined for a repository
|
/// A client for GitHub's Repository Hooks API.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#json-http">API documentation</a> for more information.</remarks>
|
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/">API documentation</a> for more information.</remarks>
|
||||||
/// <returns></returns>
|
IRepositoryHooksClient Hooks { get; }
|
||||||
Task<IReadOnlyList<RepositoryHook>> GetHooks(string owner, string repositoryName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
33
Octokit/Clients/IRepositoryHooksClient.cs
Normal file
33
Octokit/Clients/IRepositoryHooksClient.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Octokit
|
||||||
|
{
|
||||||
|
public interface IRepositoryHooksClient
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the list of hooks defined for a repository
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#json-http">API documentation</a> for more information.</remarks>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IReadOnlyList<RepositoryHook>> GetHooks(string owner, string repositoryName);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a single hook by Id
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="owner"></param>
|
||||||
|
/// <param name="repositoryName"></param>
|
||||||
|
/// <param name="hookId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#get-single-hook">API documentation</a> for more information.</remarks>
|
||||||
|
Task<RepositoryHook> GetHookById(string owner, string repositoryName, int hookId);
|
||||||
|
|
||||||
|
Task<RepositoryHook> CreateHook(string owner, string repositoryName, NewRepositoryHook hook);
|
||||||
|
|
||||||
|
Task<RepositoryHook> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,6 +21,7 @@ namespace Octokit
|
|||||||
public RepositoriesClient(IApiConnection apiConnection) : base(apiConnection)
|
public RepositoriesClient(IApiConnection apiConnection) : base(apiConnection)
|
||||||
{
|
{
|
||||||
CommitStatus = new CommitStatusClient(apiConnection);
|
CommitStatus = new CommitStatusClient(apiConnection);
|
||||||
|
_hooks = new Lazy<IRepositoryHooksClient>(() => new RepositoryHooksClient(apiConnection));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -195,17 +196,14 @@ namespace Octokit
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
public ICommitStatusClient CommitStatus { get; private set; }
|
public ICommitStatusClient CommitStatus { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
Lazy<IRepositoryHooksClient> _hooks;
|
||||||
/// Gets the list of hooks defined for a repository
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#json-http">API documentation</a> for more information.</remarks>
|
|
||||||
/// <returns></returns>
|
|
||||||
public Task<IReadOnlyList<RepositoryHook>> GetHooks(string owner, string repositoryName)
|
|
||||||
{
|
|
||||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
|
||||||
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
|
|
||||||
|
|
||||||
return ApiConnection.GetAll<RepositoryHook>(ApiUrls.RepositoryHooks(owner, repositoryName));
|
/// <summary>
|
||||||
|
/// Gets a client for GitHub's Repository Hooks
|
||||||
|
/// </summary>
|
||||||
|
public IRepositoryHooksClient Hooks
|
||||||
|
{
|
||||||
|
get { return _hooks.Value; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
71
Octokit/Clients/RepositoryHooksClient.cs
Normal file
71
Octokit/Clients/RepositoryHooksClient.cs
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Octokit
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A client for GitHub's Repository Hooks API
|
||||||
|
/// </summary>
|
||||||
|
public class RepositoryHooksClient : ApiClient, IRepositoryHooksClient
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new GitHub Repos API client.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="apiConnection">An API connection.</param>
|
||||||
|
public RepositoryHooksClient(IApiConnection apiConnection) : base(apiConnection)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the list of hooks defined for a repository
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#list">API documentation</a> for more information.</remarks>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Task<IReadOnlyList<RepositoryHook>> GetHooks(string owner, string repositoryName)
|
||||||
|
{
|
||||||
|
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||||
|
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
|
||||||
|
|
||||||
|
return ApiConnection.GetAll<RepositoryHook>(ApiUrls.RepositoryHooks(owner, repositoryName));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a single hook defined for a repository by id
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#get-single-hook">API documentation</a> for more information.</remarks>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Task<RepositoryHook> GetHookById(string owner, string repositoryName, int hookId)
|
||||||
|
{
|
||||||
|
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||||
|
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
|
||||||
|
Ensure.ArgumentNotNull(hookId, "hookId");
|
||||||
|
|
||||||
|
return ApiConnection.Get<RepositoryHook>(ApiUrls.RepositoryHooksById(owner, repositoryName, hookId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a hook for a repository
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#create-a-hook">API documentation</a> for more information.</remarks>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Task<RepositoryHook> CreateHook(string owner, string repositoryName, NewRepositoryHook hook)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<RepositoryHook> 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -257,5 +257,17 @@ namespace Octokit
|
|||||||
{
|
{
|
||||||
return "repos/{0}/{1}/hooks".FormatUri(owner, repositoryName);
|
return "repos/{0}/{1}/hooks".FormatUri(owner, repositoryName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the <see cref="Uri"/> that gets the repository hook for the specified reference.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="owner">The owner of the repository</param>
|
||||||
|
/// <param name="repositoryName">The name of the repository</param>
|
||||||
|
/// <param name="hookId">The identifier of the repository hook</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static Uri RepositoryHooksById(string owner, string repositoryName, int hookId)
|
||||||
|
{
|
||||||
|
return "repos/{0}/{1}/hooks/{2}".FormatUri(owner, repositoryName, hookId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
28
Octokit/Models/Request/EditRepositoryHook.cs
Normal file
28
Octokit/Models/Request/EditRepositoryHook.cs
Normal file
@@ -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<string> Events { get; set; }
|
||||||
|
public IEnumerable<string> AddEvents { get; set; }
|
||||||
|
public IEnumerable<string> 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
25
Octokit/Models/Request/NewRepositoryHook.cs
Normal file
25
Octokit/Models/Request/NewRepositoryHook.cs
Normal file
@@ -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<string> 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,7 +17,8 @@ namespace Octokit
|
|||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public IEnumerable<string> Events { get; set; }
|
public IEnumerable<string> Events { get; set; }
|
||||||
public bool Active { 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
|
internal string DebuggerDisplay
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -59,6 +59,7 @@
|
|||||||
<Compile Include="Clients\IOrganizationsClient.cs" />
|
<Compile Include="Clients\IOrganizationsClient.cs" />
|
||||||
<Compile Include="Clients\IReleasesClient.cs" />
|
<Compile Include="Clients\IReleasesClient.cs" />
|
||||||
<Compile Include="Clients\IRepositoriesClient.cs" />
|
<Compile Include="Clients\IRepositoriesClient.cs" />
|
||||||
|
<Compile Include="Clients\IRepositoryHooksClient.cs" />
|
||||||
<Compile Include="Clients\ISshKeysClient.cs" />
|
<Compile Include="Clients\ISshKeysClient.cs" />
|
||||||
<Compile Include="Clients\IssuesClient.cs" />
|
<Compile Include="Clients\IssuesClient.cs" />
|
||||||
<Compile Include="Clients\IUsersClient.cs" />
|
<Compile Include="Clients\IUsersClient.cs" />
|
||||||
@@ -68,6 +69,7 @@
|
|||||||
<Compile Include="Clients\OrganizationsClient.cs" />
|
<Compile Include="Clients\OrganizationsClient.cs" />
|
||||||
<Compile Include="Clients\ReleasesClient.cs" />
|
<Compile Include="Clients\ReleasesClient.cs" />
|
||||||
<Compile Include="Clients\RepositoriesClient.cs" />
|
<Compile Include="Clients\RepositoriesClient.cs" />
|
||||||
|
<Compile Include="Clients\RepositoryHooksClient.cs" />
|
||||||
<Compile Include="Clients\SshKeysClient.cs" />
|
<Compile Include="Clients\SshKeysClient.cs" />
|
||||||
<Compile Include="Clients\UsersClient.cs" />
|
<Compile Include="Clients\UsersClient.cs" />
|
||||||
<Compile Include="Exceptions\ApiException.cs" />
|
<Compile Include="Exceptions\ApiException.cs" />
|
||||||
@@ -121,6 +123,7 @@
|
|||||||
<Compile Include="Http\IResponse.cs" />
|
<Compile Include="Http\IResponse.cs" />
|
||||||
<Compile Include="Http\Request.cs" />
|
<Compile Include="Http\Request.cs" />
|
||||||
<Compile Include="Models\Request\AuthorizationUpdate.cs" />
|
<Compile Include="Models\Request\AuthorizationUpdate.cs" />
|
||||||
|
<Compile Include="Models\Request\EditRepositoryHook.cs" />
|
||||||
<Compile Include="Models\Request\IssueRequest.cs" />
|
<Compile Include="Models\Request\IssueRequest.cs" />
|
||||||
<Compile Include="Models\Request\IssueUpdate.cs" />
|
<Compile Include="Models\Request\IssueUpdate.cs" />
|
||||||
<Compile Include="Models\Request\MilestoneRequest.cs" />
|
<Compile Include="Models\Request\MilestoneRequest.cs" />
|
||||||
@@ -130,6 +133,7 @@
|
|||||||
<Compile Include="Models\Request\NewIssue.cs" />
|
<Compile Include="Models\Request\NewIssue.cs" />
|
||||||
<Compile Include="Models\Request\NewMilestone.cs" />
|
<Compile Include="Models\Request\NewMilestone.cs" />
|
||||||
<Compile Include="Models\Request\NewRepository.cs" />
|
<Compile Include="Models\Request\NewRepository.cs" />
|
||||||
|
<Compile Include="Models\Request\NewRepositoryHook.cs" />
|
||||||
<Compile Include="Models\Request\ReleaseUpdate.cs" />
|
<Compile Include="Models\Request\ReleaseUpdate.cs" />
|
||||||
<Compile Include="Models\Request\RepositoryIssueRequest.cs" />
|
<Compile Include="Models\Request\RepositoryIssueRequest.cs" />
|
||||||
<Compile Include="Models\Request\RequestParameters.cs" />
|
<Compile Include="Models\Request\RequestParameters.cs" />
|
||||||
|
|||||||
@@ -53,17 +53,21 @@
|
|||||||
<Compile Include="Clients\AssigneesClient.cs" />
|
<Compile Include="Clients\AssigneesClient.cs" />
|
||||||
<Compile Include="Clients\CommitStatusClient.cs" />
|
<Compile Include="Clients\CommitStatusClient.cs" />
|
||||||
<Compile Include="Clients\ICommitStatusClient.cs" />
|
<Compile Include="Clients\ICommitStatusClient.cs" />
|
||||||
|
<Compile Include="Clients\IRepositoryHooksClient.cs" />
|
||||||
<Compile Include="Clients\IssuesClient.cs" />
|
<Compile Include="Clients\IssuesClient.cs" />
|
||||||
<Compile Include="Clients\MilestonesClient.cs" />
|
<Compile Include="Clients\MilestonesClient.cs" />
|
||||||
|
<Compile Include="Clients\RepositoryHooksClient.cs" />
|
||||||
<Compile Include="Exceptions\NotFoundException.cs" />
|
<Compile Include="Exceptions\NotFoundException.cs" />
|
||||||
<Compile Include="Clients\IAssigneesClient.cs" />
|
<Compile Include="Clients\IAssigneesClient.cs" />
|
||||||
<Compile Include="Clients\IIssuesClient.cs" />
|
<Compile Include="Clients\IIssuesClient.cs" />
|
||||||
<Compile Include="Clients\IMilestonesClient.cs" />
|
<Compile Include="Clients\IMilestonesClient.cs" />
|
||||||
<Compile Include="Helpers\ParameterAttribute.cs" />
|
<Compile Include="Helpers\ParameterAttribute.cs" />
|
||||||
<Compile Include="Helpers\ReflectionExtensions.cs" />
|
<Compile Include="Helpers\ReflectionExtensions.cs" />
|
||||||
|
<Compile Include="Models\Request\EditRepositoryHook.cs" />
|
||||||
<Compile Include="Models\Request\MilestoneUpdate.cs" />
|
<Compile Include="Models\Request\MilestoneUpdate.cs" />
|
||||||
<Compile Include="Models\Request\NewCommitStatus.cs" />
|
<Compile Include="Models\Request\NewCommitStatus.cs" />
|
||||||
<Compile Include="Models\Request\NewMilestone.cs" />
|
<Compile Include="Models\Request\NewMilestone.cs" />
|
||||||
|
<Compile Include="Models\Request\NewRepositoryHook.cs" />
|
||||||
<Compile Include="Models\Request\RequestParameters.cs" />
|
<Compile Include="Models\Request\RequestParameters.cs" />
|
||||||
<Compile Include="Models\Response\CommitStatus.cs" />
|
<Compile Include="Models\Response\CommitStatus.cs" />
|
||||||
<Compile Include="Models\Response\Issue.cs" />
|
<Compile Include="Models\Response\Issue.cs" />
|
||||||
@@ -78,7 +82,6 @@
|
|||||||
<Compile Include="Models\Request\RepositoryIssueRequest.cs" />
|
<Compile Include="Models\Request\RepositoryIssueRequest.cs" />
|
||||||
<Compile Include="Models\Request\MilestoneRequest.cs" />
|
<Compile Include="Models\Request\MilestoneRequest.cs" />
|
||||||
<Compile Include="Models\Response\RepositoryHook.cs" />
|
<Compile Include="Models\Response\RepositoryHook.cs" />
|
||||||
<Compile Include="Models\Response\RepositoryHookConfiguration.cs" />
|
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Exceptions\TwoFactorChallengeFailedException.cs" />
|
<Compile Include="Exceptions\TwoFactorChallengeFailedException.cs" />
|
||||||
<Compile Include="Exceptions\TwoFactorRequiredException.cs" />
|
<Compile Include="Exceptions\TwoFactorRequiredException.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user