mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-06 20:13:40 +00:00
Implement Get Hooks on Repository Client
This commit is contained in:
@@ -249,5 +249,28 @@ namespace Octokit.Tests.Clients
|
||||
Assert.Equal("<html>README</html>", readme);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetMethodForRepositoryHooks
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
|
||||
client.GetHooks("fake", "repo");
|
||||
|
||||
connection.Received().GetAll<RepositoryHook>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/hooks"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new RepositoriesClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Get(null, "name"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Get("owner", null));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,5 +135,12 @@ namespace Octokit
|
||||
/// that announced this feature.
|
||||
/// </remarks>
|
||||
ICommitStatusClient CommitStatus { get; }
|
||||
|
||||
/// <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);//todo: clarify type of collection
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,5 +194,13 @@ namespace Octokit
|
||||
/// that announced this feature.
|
||||
/// </remarks>
|
||||
public ICommitStatusClient CommitStatus { get; private set; }
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,5 +246,16 @@ namespace Octokit
|
||||
{
|
||||
return "repos/{0}/{1}/statuses/{2}".FormatUri(owner, name, reference);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Uri"/> that lists the repository hooks for the specified reference.
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="repositoryName">The name of the repository</param>
|
||||
/// <returns></returns>
|
||||
public static Uri RepositoryHooks(string owner, string repositoryName)
|
||||
{
|
||||
return "repos/{0}/{1}/hooks".FormatUri(owner, repositoryName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<string> 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -156,6 +156,8 @@
|
||||
<Compile Include="Models\Response\ReleaseAsset.cs" />
|
||||
<Compile Include="Models\Response\ReleaseAssetUpload.cs" />
|
||||
<Compile Include="Models\Response\Repository.cs" />
|
||||
<Compile Include="Models\Response\RepositoryHook.cs" />
|
||||
<Compile Include="Models\Response\RepositoryHookConfiguration.cs" />
|
||||
<Compile Include="Models\Response\SshKey.cs" />
|
||||
<Compile Include="Models\Response\SshKeyInfo.cs" />
|
||||
<Compile Include="Models\Response\User.cs" />
|
||||
|
||||
@@ -77,6 +77,8 @@
|
||||
<Compile Include="Models\Response\PullRequest.cs" />
|
||||
<Compile Include="Models\Request\RepositoryIssueRequest.cs" />
|
||||
<Compile Include="Models\Request\MilestoneRequest.cs" />
|
||||
<Compile Include="Models\Response\RepositoryHook.cs" />
|
||||
<Compile Include="Models\Response\RepositoryHookConfiguration.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Exceptions\TwoFactorChallengeFailedException.cs" />
|
||||
<Compile Include="Exceptions\TwoFactorRequiredException.cs" />
|
||||
|
||||
Reference in New Issue
Block a user