mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-05-27 08:32:04 +00:00
Changed 'dynamic' to Dictionary<string, string> for configuration of hooks.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Octokit.Tests.Helpers;
|
||||
using Octokit.Tests.Integration.fixtures;
|
||||
using Xunit;
|
||||
|
||||
@@ -62,21 +64,32 @@ namespace Octokit.Tests.Integration.Clients
|
||||
var repoName = Helper.MakeNameWithTimestamp("create-hooks-test");
|
||||
var repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true });
|
||||
|
||||
var parameters = new NewRepositoryHook("tenxer", new { content_type = "json", url = "http://test.com/example" })
|
||||
var config = new Dictionary<string, string>
|
||||
{
|
||||
Events = new[] { "delete" },
|
||||
{ "content_type", "json" },
|
||||
{ "url", "http://test.com/example" },
|
||||
{ "hostname", "http://hostname.url" },
|
||||
{ "username", "username" },
|
||||
{ "password", "password" }
|
||||
};
|
||||
var parameters = new NewRepositoryHook("windowsazure", config)
|
||||
{
|
||||
Events = new[] { "push" },
|
||||
Active = false
|
||||
};
|
||||
|
||||
var hook = await github.Repository.Hooks.Create(Helper.Credentials.Login, repository.Name, parameters);
|
||||
|
||||
var baseHookUrl = CreateExpectedBaseHookUrl(repository.Url, hook.Id);
|
||||
Assert.Equal("tenxer", hook.Name);
|
||||
Assert.Equal(new[] { "delete" }.ToList(), hook.Events.ToList());
|
||||
Assert.Equal("windowsazure", hook.Name);
|
||||
Assert.Equal(new[] { "push" }.ToList(), hook.Events.ToList());
|
||||
Assert.Equal(baseHookUrl, hook.Url);
|
||||
Assert.Equal(baseHookUrl + "/test", hook.TestUrl);
|
||||
Assert.Equal(baseHookUrl + "/pings", hook.PingUrl);
|
||||
Assert.NotNull(hook.CreatedAt);
|
||||
Assert.NotNull(hook.UpdatedAt);
|
||||
Assert.Equal(config.Keys, hook.Config.Keys);
|
||||
Assert.Equal(config.Values, hook.Config.Values);
|
||||
Assert.Equal(false, hook.Active);
|
||||
}
|
||||
|
||||
@@ -97,7 +110,7 @@ namespace Octokit.Tests.Integration.Clients
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task EditHookWithNewInformation()
|
||||
public async Task EditHookWithNoNewConfigRetainsTheOldConfig()
|
||||
{
|
||||
var github = Helper.GetAuthenticatedClient();
|
||||
|
||||
@@ -105,9 +118,31 @@ namespace Octokit.Tests.Integration.Clients
|
||||
{
|
||||
AddEvents = new[] { "pull_request" }
|
||||
};
|
||||
|
||||
var actualHook = await github.Repository.Hooks.Edit(_fixture.RepositoryOwner, _fixture.RepositoryName, _fixture.ExpectedHook.Id, editRepositoryHook);
|
||||
|
||||
Assert.Equal(new[] { "delete", "pull_request" }.ToList(), actualHook.Events.ToList());
|
||||
var expectedConfig = new Dictionary<string, string> { { "content_type", "json" }, { "url", "http://test.com/example" } };
|
||||
Assert.Equal(new[] { "commit_comment", "pull_request" }.ToList(), actualHook.Events.ToList());
|
||||
Assert.Equal(expectedConfig.Keys, actualHook.Config.Keys);
|
||||
Assert.Equal(expectedConfig.Values, actualHook.Config.Values);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task EditHookWithNewInformation()
|
||||
{
|
||||
var github = Helper.GetAuthenticatedClient();
|
||||
|
||||
var editRepositoryHook = new EditRepositoryHook(new Dictionary<string, string> { { "project", "GEZDGORQFY2TCNZRGY2TSMBVGUYDK" } })
|
||||
{
|
||||
AddEvents = new[] { "pull_request" }
|
||||
};
|
||||
|
||||
var actualHook = await github.Repository.Hooks.Edit(_fixture.RepositoryOwner, _fixture.RepositoryName, _fixture.ExpectedHook.Id, editRepositoryHook);
|
||||
|
||||
var expectedConfig = new Dictionary<string, string> { { "project", "GEZDGORQFY2TCNZRGY2TSMBVGUYDK" } };
|
||||
Assert.Equal(new[] { "commit_comment", "pull_request" }.ToList(), actualHook.Events.ToList());
|
||||
Assert.Equal(expectedConfig.Keys, actualHook.Config.Keys);
|
||||
Assert.Equal(expectedConfig.Values, actualHook.Config.Values);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Octokit.Tests.Integration.fixtures
|
||||
{
|
||||
@@ -36,9 +37,10 @@ namespace Octokit.Tests.Integration.fixtures
|
||||
|
||||
static RepositoryHook CreateHook(IGitHubClient github, Repository repository)
|
||||
{
|
||||
var parameters = new NewRepositoryHook("tenxer", new { content_type = "json", url = "http://test.com/example" })
|
||||
var config = new Dictionary<string, string> { { "content_type", "json" }, { "url", "http://test.com/example" } };
|
||||
var parameters = new NewRepositoryHook("apropos", config)
|
||||
{
|
||||
Events = new[] { "delete" },
|
||||
Events = new[] { "commit_comment" },
|
||||
Active = false
|
||||
};
|
||||
var createdHook = github.Repository.Hooks.Create(Helper.Credentials.Login, repository.Name, parameters);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using NSubstitute;
|
||||
using System.Collections.Generic;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
@@ -60,7 +61,7 @@ namespace Octokit.Tests.Clients
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
var hook = new NewRepositoryHook("name", new { config = "" });
|
||||
var hook = new NewRepositoryHook("name", new Dictionary<string, string> { {"config", "" }});
|
||||
|
||||
client.Hooks.Create("fake", "repo", hook);
|
||||
|
||||
@@ -72,8 +73,9 @@ namespace Octokit.Tests.Clients
|
||||
{
|
||||
var client = new RepositoriesClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(async () => await client.Hooks.Create(null, "name", new NewRepositoryHook("name", new { config = "" })));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(async () => await client.Hooks.Create("owner", null, new NewRepositoryHook("name", new { config = "" })));
|
||||
var config = new Dictionary<string, string> { { "config", "" } };
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(async () => await client.Hooks.Create(null, "name", new NewRepositoryHook("name", config)));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(async () => await client.Hooks.Create("owner", null, new NewRepositoryHook("name", config)));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(async () => await client.Hooks.Create("owner", "name", null));
|
||||
}
|
||||
|
||||
@@ -82,7 +84,7 @@ namespace Octokit.Tests.Clients
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
var newRepositoryHook = new NewRepositoryHook("name", new { config = "" });
|
||||
var newRepositoryHook = new NewRepositoryHook("name", new Dictionary<string, string> { { "config", "" } });
|
||||
|
||||
client.Hooks.Create("owner", "repo", newRepositoryHook);
|
||||
|
||||
|
||||
@@ -9,10 +9,17 @@ namespace Octokit
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq}")]
|
||||
public class EditRepositoryHook
|
||||
{
|
||||
[Parameter(Key = "config")]
|
||||
public dynamic Config { get; set; }
|
||||
public EditRepositoryHook()
|
||||
: this(null)
|
||||
{ }
|
||||
|
||||
public EditRepositoryHook(IDictionary<string, string> config)
|
||||
{
|
||||
Config = config;
|
||||
}
|
||||
|
||||
public IDictionary<string, string> Config { get; private set; }
|
||||
|
||||
[Parameter(Key = "events")]
|
||||
public IEnumerable<string> Events { get; set; }
|
||||
|
||||
[Parameter(Key = "add_events")]
|
||||
@@ -21,7 +28,6 @@ namespace Octokit
|
||||
[Parameter(Key = "remove_events")]
|
||||
public IEnumerable<string> RemoveEvents { get; set; }
|
||||
|
||||
[Parameter(Key = "active")]
|
||||
public bool? Active { get; set; }
|
||||
|
||||
internal string DebuggerDisplay
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Octokit
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq}")]
|
||||
public class NewRepositoryHook
|
||||
{
|
||||
public NewRepositoryHook(string name, dynamic config)
|
||||
public NewRepositoryHook(string name, Dictionary<string, string> config)
|
||||
{
|
||||
Name = name;
|
||||
Config = config;
|
||||
@@ -21,13 +21,10 @@ namespace Octokit
|
||||
/// <summary>
|
||||
/// Is a key value structure determined by the web hook being created
|
||||
/// </summary>
|
||||
[Parameter(Key = "config")]
|
||||
public dynamic Config { get; set; }
|
||||
public IReadOnlyDictionary<string, string> Config { get; private set; }
|
||||
|
||||
[Parameter(Key = "events")]
|
||||
public IEnumerable<string> Events { get; set; }
|
||||
|
||||
[Parameter(Key = "active")]
|
||||
public bool Active { get; set; }
|
||||
|
||||
internal string DebuggerDisplay
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Octokit
|
||||
{
|
||||
public RepositoryHook() { }
|
||||
|
||||
public RepositoryHook(int id, string url, string testUrl, string pingUrl, DateTimeOffset createdAt, DateTimeOffset updatedAt, string name, IReadOnlyList<string> events, bool active, dynamic config)
|
||||
public RepositoryHook(int id, string url, string testUrl, string pingUrl, DateTimeOffset createdAt, DateTimeOffset updatedAt, string name, IReadOnlyList<string> events, bool active, IReadOnlyDictionary<string, string> config)
|
||||
{
|
||||
Url = url;
|
||||
TestUrl = testUrl;
|
||||
@@ -45,7 +45,7 @@ namespace Octokit
|
||||
|
||||
public bool Active { get; private set; }
|
||||
|
||||
public dynamic Config { get; private set; }
|
||||
public IReadOnlyDictionary<string, string> Config { get; private set; }
|
||||
|
||||
internal string DebuggerDisplay
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user