From 481dceab04388a718ab7dc2957dbef1f004e0432 Mon Sep 17 00:00:00 2001 From: Anubhav10 Date: Sat, 12 Mar 2016 22:36:43 +0530 Subject: [PATCH 1/8] Added organization webhooks Added the organization webhooks and tests. Corrected a few repository url (related to hooks). Added a ensure condition for hookid in repository hooks --- .../IObservableOrganizationHooksClient.cs | 54 +++++ .../Clients/IObservableOrganizationsClient.cs | 6 + .../Clients/IObservableRepositoriesClient.cs | 2 +- .../IObservableRepositoryHooksClient.cs | 4 +- .../ObservableOrganizationHooksClient.cs | 98 ++++++++ .../Clients/ObservableOrganizationsClient.cs | 9 + .../ObservableRepositoryHooksClient.cs | 4 +- Octokit.Reactive/Octokit.Reactive-Mono.csproj | 2 + .../Octokit.Reactive-MonoAndroid.csproj | 2 + .../Octokit.Reactive-Monotouch.csproj | 2 + Octokit.Reactive/Octokit.Reactive.csproj | 2 + .../Clients/OrganizationHooksClientTests.cs | 219 ++++++++++++++++++ .../Octokit.Tests.Integration.csproj | 3 + .../fixtures/OrganizationsHooksCollection.cs | 10 + .../fixtures/OrganizationsHooksFixture.cs | 42 ++++ .../Clients/OrganizationHooksClientTest.cs | 172 ++++++++++++++ .../Models/NewOrganizationWebHookTests.cs | 108 +++++++++ Octokit.Tests/Octokit.Tests.csproj | 12 +- Octokit.Tests/app.config | 6 +- Octokit.Tests/packages.Octokit.Tests.config | 1 - Octokit/Clients/IOrganizationHooksClient.cs | 54 +++++ Octokit/Clients/IOrganizationsClient.cs | 6 + Octokit/Clients/IRepositoryHooksClient.cs | 4 +- Octokit/Clients/OrganizationHooksClient.cs | 95 ++++++++ Octokit/Clients/OrganizationsClient.cs | 7 + Octokit/Clients/RepositoryHooksClient.cs | 10 +- .../OrganizationWebHookConfigException.cs | 60 +++++ Octokit/Helpers/ApiUrls.cs | 32 +++ .../Models/Request/EditOrganizationHook.cs | 57 +++++ Octokit/Models/Request/NewOrganizationHook.cs | 117 ++++++++++ .../Models/Request/NewOrganizationWebHook.cs | 146 ++++++++++++ Octokit/Models/Response/OrganizationHook.cs | 59 +++++ Octokit/Octokit-Mono.csproj | 7 + Octokit/Octokit-MonoAndroid.csproj | 7 + Octokit/Octokit-Monotouch.csproj | 7 + Octokit/Octokit-Portable.csproj | 7 + Octokit/Octokit-netcore45.csproj | 7 + Octokit/Octokit.csproj | 7 + 38 files changed, 1429 insertions(+), 18 deletions(-) create mode 100644 Octokit.Reactive/Clients/IObservableOrganizationHooksClient.cs create mode 100644 Octokit.Reactive/Clients/ObservableOrganizationHooksClient.cs create mode 100644 Octokit.Tests.Integration/Clients/OrganizationHooksClientTests.cs create mode 100644 Octokit.Tests.Integration/fixtures/OrganizationsHooksCollection.cs create mode 100644 Octokit.Tests.Integration/fixtures/OrganizationsHooksFixture.cs create mode 100644 Octokit.Tests/Clients/OrganizationHooksClientTest.cs create mode 100644 Octokit.Tests/Models/NewOrganizationWebHookTests.cs create mode 100644 Octokit/Clients/IOrganizationHooksClient.cs create mode 100644 Octokit/Clients/OrganizationHooksClient.cs create mode 100644 Octokit/Exceptions/OrganizationWebHookConfigException.cs create mode 100644 Octokit/Models/Request/EditOrganizationHook.cs create mode 100644 Octokit/Models/Request/NewOrganizationHook.cs create mode 100644 Octokit/Models/Request/NewOrganizationWebHook.cs create mode 100644 Octokit/Models/Response/OrganizationHook.cs diff --git a/Octokit.Reactive/Clients/IObservableOrganizationHooksClient.cs b/Octokit.Reactive/Clients/IObservableOrganizationHooksClient.cs new file mode 100644 index 0000000000..ed89f21fe2 --- /dev/null +++ b/Octokit.Reactive/Clients/IObservableOrganizationHooksClient.cs @@ -0,0 +1,54 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Reactive; + +namespace Octokit.Reactive +{ + public interface IObservableOrganizationHooksClient + { + /// + /// Gets the list of hooks defined for a organization + /// + /// See API documentation for more information. + /// + IObservable GetAll(string organizationName); + + /// + /// Gets a single hook defined for a organization by id + /// + /// See API documentation for more information. + /// + [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "This is ok; we're matching HTTP verbs not keyworks")] + IObservable Get(string organizationName, int hookId); + + /// + /// Creates a hook for a organization + /// + /// See API documentation for more information. + /// + IObservable Create(string organizationName, NewOrganizationHook hook); + + /// + /// Edits a hook for a organization + /// + /// See API documentation for more information. + /// + IObservable Edit(string organizationName, int hookId, EditOrganizationHook hook); + + /// + /// This will trigger a ping event to be sent to the hook. + /// + /// See API documentation for more information. + /// + IObservable Ping(string organizationName, int hookId); + + /// + /// Deletes a hook for a organization + /// + /// + /// + /// See API documentation for more information. + /// + IObservable Delete(string organizationName, int hookId); + } +} \ No newline at end of file diff --git a/Octokit.Reactive/Clients/IObservableOrganizationsClient.cs b/Octokit.Reactive/Clients/IObservableOrganizationsClient.cs index f36bb44a67..dc1b151c2a 100644 --- a/Octokit.Reactive/Clients/IObservableOrganizationsClient.cs +++ b/Octokit.Reactive/Clients/IObservableOrganizationsClient.cs @@ -15,6 +15,12 @@ public interface IObservableOrganizationsClient /// IObservableTeamsClient Team { get; } + /// + /// A client for GitHub's Organization Hooks API. + /// + /// See Hooks API documentation for more information. + IObservableOrganizationHooksClient Hooks { get; } + /// /// Returns the specified organization. /// diff --git a/Octokit.Reactive/Clients/IObservableRepositoriesClient.cs b/Octokit.Reactive/Clients/IObservableRepositoriesClient.cs index 493e90b83b..6ed1858a48 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoriesClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoriesClient.cs @@ -168,7 +168,7 @@ public interface IObservableRepositoriesClient /// /// See Hooks API documentation for more information. IObservableRepositoryHooksClient Hooks { get; } - + /// /// A client for GitHub's Repository Forks API. /// diff --git a/Octokit.Reactive/Clients/IObservableRepositoryHooksClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryHooksClient.cs index f3176e0add..2e5bd95eb2 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryHooksClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryHooksClient.cs @@ -9,7 +9,7 @@ public interface IObservableRepositoryHooksClient /// /// Gets the list of hooks defined for a repository /// - /// See API documentation for more information. + /// See API documentation for more information. /// IObservable GetAll(string owner, string repositoryName); @@ -47,7 +47,7 @@ public interface IObservableRepositoryHooksClient /// /// This will trigger a ping event to be sent to the hook. /// - /// See API documentation for more information. + /// See API documentation for more information. /// IObservable Ping(string owner, string repositoryName, int hookId); diff --git a/Octokit.Reactive/Clients/ObservableOrganizationHooksClient.cs b/Octokit.Reactive/Clients/ObservableOrganizationHooksClient.cs new file mode 100644 index 0000000000..4e784954aa --- /dev/null +++ b/Octokit.Reactive/Clients/ObservableOrganizationHooksClient.cs @@ -0,0 +1,98 @@ +using System; +using System.Reactive; +using System.Reactive.Threading.Tasks; +using Octokit.Reactive.Internal; + +namespace Octokit.Reactive +{ + public class ObservableOrganizationHooksClient : IObservableOrganizationHooksClient + { + readonly IOrganizationHooksClient _client; + readonly IConnection _connection; + + public ObservableOrganizationHooksClient(IGitHubClient client) + { + Ensure.ArgumentNotNull(client, "client"); + + _client = client.Organization.Hooks; + _connection = client.Connection; + } + + /// + /// Gets the list of hooks defined for a organization + /// + /// See API documentation for more information. + /// + public IObservable GetAll(string organizationName) + { + Ensure.ArgumentNotNullOrEmptyString(organizationName, "organizationName"); + + return _connection.GetAndFlattenAllPages(ApiUrls.OrganizationHooks(organizationName)); + } + + /// + /// Gets a single hook defined for a organization by id + /// + /// See API documentation for more information. + /// + public IObservable Get(string organizationName, int hookId) + { + Ensure.ArgumentNotNullOrEmptyString(organizationName, "organizationName"); + + return _client.Get(organizationName, hookId).ToObservable(); + } + + /// + /// Creates a hook for a organization + /// + /// See API documentation for more information. + /// + public IObservable Create(string organizationName, NewOrganizationHook hook) + { + Ensure.ArgumentNotNullOrEmptyString(organizationName, "organizationName"); + Ensure.ArgumentNotNull(hook, "hook"); + + return _client.Create(organizationName, hook).ToObservable(); + } + + /// + /// Edits a hook for a organization + /// + /// See API documentation for more information. + /// + public IObservable Edit(string organizationName, int hookId, EditOrganizationHook hook) + { + Ensure.ArgumentNotNullOrEmptyString(organizationName, "organizationName"); + Ensure.ArgumentNotNull(hook, "hook"); + + return _client.Edit(organizationName, hookId, hook).ToObservable(); + } + + /// + /// This will trigger a ping event to be sent to the hook. + /// + /// See API documentation for more information. + /// + public IObservable Ping(string organizationName, int hookId) + { + Ensure.ArgumentNotNullOrEmptyString(organizationName, "organizationName"); + + return _client.Ping(organizationName, hookId).ToObservable(); + } + + /// + /// Deletes a hook for a organization + /// + /// + /// + /// + /// See API documentation for more information. + /// + public IObservable Delete(string organizationName, int hookId) + { + Ensure.ArgumentNotNullOrEmptyString(organizationName, "organizationName"); + + return _client.Delete(organizationName, hookId).ToObservable(); + } + } +} diff --git a/Octokit.Reactive/Clients/ObservableOrganizationsClient.cs b/Octokit.Reactive/Clients/ObservableOrganizationsClient.cs index 64afff9d1e..6ba460595d 100644 --- a/Octokit.Reactive/Clients/ObservableOrganizationsClient.cs +++ b/Octokit.Reactive/Clients/ObservableOrganizationsClient.cs @@ -19,6 +19,7 @@ public ObservableOrganizationsClient(IGitHubClient client) Member = new ObservableOrganizationMembersClient(client); Team = new ObservableTeamsClient(client); + Hooks = new ObservableOrganizationHooksClient(client); _client = client.Organization; _connection = client.Connection; @@ -34,6 +35,12 @@ public ObservableOrganizationsClient(IGitHubClient client) /// public IObservableTeamsClient Team { get; private set; } + /// + /// A client for GitHub's Organization Hooks API. + /// + /// See Hooks API documentation for more information. + public IObservableOrganizationHooksClient Hooks { get; private set; } + /// /// Returns the specified organization. /// @@ -78,5 +85,7 @@ public IObservable Update(string organizationName, OrganizationUpd { return _client.Update(organizationName, updateRequest).ToObservable(); } + + } } diff --git a/Octokit.Reactive/Clients/ObservableRepositoryHooksClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryHooksClient.cs index 7b229dd282..f8211a9206 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryHooksClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryHooksClient.cs @@ -21,7 +21,7 @@ public ObservableRepositoryHooksClient(IGitHubClient client) /// /// Gets the list of hooks defined for a repository /// - /// See API documentation for more information. + /// See API documentation for more information. /// public IObservable GetAll(string owner, string repositoryName) { @@ -90,7 +90,7 @@ public IObservable Test(string owner, string repositoryName, int hookId) /// /// This will trigger a ping event to be sent to the hook. /// - /// See API documentation for more information. + /// See API documentation for more information. /// public IObservable Ping(string owner, string repositoryName, int hookId) { diff --git a/Octokit.Reactive/Octokit.Reactive-Mono.csproj b/Octokit.Reactive/Octokit.Reactive-Mono.csproj index 41db98100a..afb05d00d7 100644 --- a/Octokit.Reactive/Octokit.Reactive-Mono.csproj +++ b/Octokit.Reactive/Octokit.Reactive-Mono.csproj @@ -173,6 +173,8 @@ + + diff --git a/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj b/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj index 2a01d4da5a..37d03fe768 100644 --- a/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj +++ b/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj @@ -181,6 +181,8 @@ + + diff --git a/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj b/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj index c3855b708a..377eb0665b 100644 --- a/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj +++ b/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj @@ -177,6 +177,8 @@ + + diff --git a/Octokit.Reactive/Octokit.Reactive.csproj b/Octokit.Reactive/Octokit.Reactive.csproj index 4c69b57fee..3fdbdadaa5 100644 --- a/Octokit.Reactive/Octokit.Reactive.csproj +++ b/Octokit.Reactive/Octokit.Reactive.csproj @@ -91,6 +91,7 @@ + @@ -116,6 +117,7 @@ + diff --git a/Octokit.Tests.Integration/Clients/OrganizationHooksClientTests.cs b/Octokit.Tests.Integration/Clients/OrganizationHooksClientTests.cs new file mode 100644 index 0000000000..0cf19316da --- /dev/null +++ b/Octokit.Tests.Integration/Clients/OrganizationHooksClientTests.cs @@ -0,0 +1,219 @@ +using Octokit.Tests.Integration.fixtures; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Xunit; + +namespace Octokit.Tests.Integration.Clients +{ + public class OrganizationHooksClientTests + { + [Collection(OrganizationsHooksCollection.Name)] + public class TheGetAllMethod + { + readonly OrganizationsHooksFixture _fixture; + + public TheGetAllMethod(OrganizationsHooksFixture fixture) + { + _fixture = fixture; + } + + [IntegrationTest] + public async Task ReturnsAllHooksFromOrganization() + { + var github = Helper.GetAuthenticatedClient(); + + var hooks = await github.Organization.Hooks.GetAll( _fixture.OrganizationName); + + Assert.Single(hooks); + var actualHook = hooks[0]; + + AssertHook(_fixture.ExpectedHook, actualHook); + } + } + + [Collection(OrganizationsHooksCollection.Name)] + public class TheGetMethod + { + readonly OrganizationsHooksFixture _fixture; + + public TheGetMethod(OrganizationsHooksFixture fixture) + { + _fixture = fixture; + } + + [IntegrationTest] + public async Task GetHookByCreatedId() + { + var github = Helper.GetAuthenticatedClient(); + + var actualHook = await github.Organization.Hooks.Get(_fixture.OrganizationName, _fixture.ExpectedHook.Id); + + AssertHook(_fixture.ExpectedHook, actualHook); + } + } + + public class TheCreateMethod + { + readonly OrganizationsHooksFixture _fixture; + + public TheCreateMethod(OrganizationsHooksFixture fixture) + { + _fixture = fixture; + } + [IntegrationTest] + public async Task CreateAWebHookForTestOrganization() + { + var github = Helper.GetAuthenticatedClient(); + var url = "http://test.com/example"; + var contentType = OrgWebHookContentType.Json; + var secret = "53cr37"; + var config = new Dictionary + { + { "hostname", "http://hostname.url" }, + { "username", "username" }, + { "password", "password" } + }; + var parameters = new NewOrganizationWebHook("windowsazure", config, url) + { + Events = new[] { "push" }, + Active = false, + ContentType = contentType, + Secret = secret + }; + + var hook = await github.Organization.Hooks.Create(_fixture.OrganizationName, parameters.ToRequest()); + + var baseHookUrl = CreateExpectedBaseHookUrl(url, hook.Id); + var webHookConfig = CreateExpectedConfigDictionary(config, url, contentType, secret); + + Assert.Equal("windowsazure", hook.Name); + Assert.Equal(new[] { "push" }.ToList(), hook.Events.ToList()); + Assert.Equal(baseHookUrl, hook.Url); + Assert.Equal(baseHookUrl + "/pings", hook.PingUrl); + Assert.NotNull(hook.CreatedAt); + Assert.NotNull(hook.UpdatedAt); + Assert.Equal(webHookConfig.Keys, hook.Config.Keys); + Assert.Equal(webHookConfig.Values, hook.Config.Values); + Assert.Equal(false, hook.Active); + } + + Dictionary CreateExpectedConfigDictionary(Dictionary config, string url, OrgWebHookContentType contentType, string secret) + { + return new Dictionary + { + { "url", url }, + { "content_type", contentType.ToString().ToLowerInvariant() }, + { "secret", secret }, + { "insecure_ssl", "False" } + }.Union(config).ToDictionary(k => k.Key, v => v.Value); + } + + string CreateExpectedBaseHookUrl(string url, int id) + { + return url + "/hooks/" + id; + } + } + + [Collection(OrganizationsHooksCollection.Name)] + public class TheEditMethod + { + readonly OrganizationsHooksFixture _fixture; + + public TheEditMethod(OrganizationsHooksFixture fixture) + { + _fixture = fixture; + } + + [IntegrationTest] + public async Task EditHookTest() + { + var github = Helper.GetAuthenticatedClient(); + + var editOrganizationHook = new EditOrganizationHook + { + Events = new[] { "pull_request" } + }; + + var actualHook = await github.Organization.Hooks.Edit( _fixture.OrganizationName, _fixture.ExpectedHook.Id, editOrganizationHook); + + var expectedConfig = new Dictionary { { "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 editOrganizationHook = new EditOrganizationHook(new Dictionary { { "project", "GEZDGORQFY2TCNZRGY2TSMBVGUYDK" } }) + // { + // AddEvents = new[] { "pull_request" } + // }; + + // var actualHook = await github.Organization.Hooks.Edit(_fixture.OrganizationOwner, _fixture.OrganizationName, _fixture.ExpectedHook.Id, editOrganizationHook); + + // var expectedConfig = new Dictionary { { "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); + //} + } + + [Collection(OrganizationsHooksCollection.Name)] + public class ThePingMethod + { + readonly OrganizationsHooksFixture _fixture; + + public ThePingMethod(OrganizationsHooksFixture fixture) + { + _fixture = fixture; + } + + [IntegrationTest] + public async Task PingACreatedHook() + { + var github = Helper.GetAuthenticatedClient(); + + await github.Organization.Hooks.Ping( _fixture.OrganizationName, _fixture.ExpectedHook.Id); + } + } + + [Collection(OrganizationsHooksCollection.Name)] + public class TheDeleteMethod + { + readonly OrganizationsHooksFixture _fixture; + + public TheDeleteMethod(OrganizationsHooksFixture fixture) + { + _fixture = fixture; + } + + [IntegrationTest] + public async Task DeleteCreatedWebHook() + { + var github = Helper.GetAuthenticatedClient(); + + await github.Organization.Hooks.Delete(_fixture.OrganizationName, _fixture.ExpectedHook.Id); + var hooks = await github.Organization.Hooks.GetAll( _fixture.OrganizationName); + + Assert.Empty(hooks); + } + } + + static void AssertHook(OrganizationHook expectedHook, OrganizationHook actualHook) + { + Assert.Equal(expectedHook.Id, actualHook.Id); + Assert.Equal(expectedHook.Active, actualHook.Active); + Assert.Equal(expectedHook.Config, actualHook.Config); + Assert.Equal(expectedHook.CreatedAt, actualHook.CreatedAt); + Assert.Equal(expectedHook.Name, actualHook.Name); + Assert.Equal(expectedHook.PingUrl, actualHook.PingUrl); + Assert.Equal(expectedHook.TestUrl, actualHook.TestUrl); + Assert.Equal(expectedHook.UpdatedAt, actualHook.UpdatedAt); + Assert.Equal(expectedHook.Url, actualHook.Url); + } + } +} diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 93cf79b36e..6174b8f59b 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -100,6 +100,7 @@ + @@ -109,7 +110,9 @@ + + diff --git a/Octokit.Tests.Integration/fixtures/OrganizationsHooksCollection.cs b/Octokit.Tests.Integration/fixtures/OrganizationsHooksCollection.cs new file mode 100644 index 0000000000..55b22e0885 --- /dev/null +++ b/Octokit.Tests.Integration/fixtures/OrganizationsHooksCollection.cs @@ -0,0 +1,10 @@ +using Xunit; + +namespace Octokit.Tests.Integration.fixtures +{ + [CollectionDefinition(Name)] + public class OrganizationsHooksCollection : ICollectionFixture + { + public const string Name = "Organization Hooks Collection"; + } +} diff --git a/Octokit.Tests.Integration/fixtures/OrganizationsHooksFixture.cs b/Octokit.Tests.Integration/fixtures/OrganizationsHooksFixture.cs new file mode 100644 index 0000000000..82e626d856 --- /dev/null +++ b/Octokit.Tests.Integration/fixtures/OrganizationsHooksFixture.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; + +namespace Octokit.Tests.Integration.fixtures +{ + public class OrganizationsHooksFixture : IDisposable + { + readonly IGitHubClient _github; + readonly OrganizationHook _hook; + private string organizationFixture; + + public OrganizationsHooksFixture() + { + _github = Helper.GetAuthenticatedClient(); + organizationFixture = "octokit"; + _hook = CreateHook(_github, organizationFixture); + } + + + public string OrganizationName { get { return organizationFixture; } } + + public OrganizationHook ExpectedHook { get { return _hook; } } + + public void Dispose() + { + _github.Organization.Hooks.Delete(organizationFixture,_hook.Id); + } + + static OrganizationHook CreateHook(IGitHubClient github, string _organizationFixture) + { + var config = new Dictionary { { "content_type", "json" }, { "url", "http://test.com/example" } }; + var parameters = new NewOrganizationHook("apropos", config) + { + Events = new[] { "commit_comment" }, + Active = false + }; + var createdHook = github.Organization.Hooks.Create(_organizationFixture, parameters); + + return createdHook.Result; + } + } +} diff --git a/Octokit.Tests/Clients/OrganizationHooksClientTest.cs b/Octokit.Tests/Clients/OrganizationHooksClientTest.cs new file mode 100644 index 0000000000..ff67f85fc8 --- /dev/null +++ b/Octokit.Tests/Clients/OrganizationHooksClientTest.cs @@ -0,0 +1,172 @@ +using NSubstitute; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Xunit; + +namespace Octokit.Tests.Clients +{ + public class OrganizationHooksClientTests + { + public class TheGetAllMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new OrganizationsClient(connection); + + client.Hooks.GetAll("org"); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "orgs/org/hooks")); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new OrganizationsClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.Hooks.GetAll(null)); + } + } + + public class TheGetMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new OrganizationsClient(connection); + + client.Hooks.Get("org", 12345678); + + connection.Received().Get(Arg.Is(u => u.ToString() == "orgs/org/hooks/12345678")); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new OrganizationsClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.Hooks.Get(null, 123)); + } + } + + public class TheCreateMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new OrganizationsClient(connection); + var hook = new NewOrganizationHook("name", new Dictionary { { "config", "" } }); + + client.Hooks.Create("org", hook); + + connection.Received().Post(Arg.Is(u => u.ToString() == "orgs/org/hooks"), hook); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new OrganizationsClient(Substitute.For()); + + var config = new Dictionary { { "config", "" } }; + await Assert.ThrowsAsync(() => client.Hooks.Create(null, new NewOrganizationHook("name", config))); + await Assert.ThrowsAsync(() => client.Hooks.Create("name", null)); + } + + [Fact] + public void UsesTheSuppliedHook() + { + var connection = Substitute.For(); + var client = new OrganizationsClient(connection); + var newOrganizationHook = new NewOrganizationHook("name", new Dictionary { { "config", "" } }); + + client.Hooks.Create("org", newOrganizationHook); + + connection.Received().Post(Arg.Any(), newOrganizationHook); + } + } + + public class TheEditMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new OrganizationsClient(connection); + var hook = new EditOrganizationHook(); + + client.Hooks.Edit("org", 12345678, hook); + + connection.Received().Patch(Arg.Is(u => u.ToString() == "orgs/org/hooks/12345678"), hook); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new OrganizationsClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.Hooks.Edit( null, 12345678, new EditOrganizationHook())); + await Assert.ThrowsAsync(() => client.Hooks.Edit( "name", 12345678, null)); + } + + [Fact] + public void UsesTheSuppliedHook() + { + var connection = Substitute.For(); + var client = new OrganizationsClient(connection); + var editOrganizationHook = new EditOrganizationHook() { Active = false }; + + client.Hooks.Edit("org", 12345678, editOrganizationHook); + + connection.Received().Patch(Arg.Any(), editOrganizationHook); + } + } + + public class ThePingMethod + { + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new OrganizationsClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.Hooks.Ping(null, 12345678)); + } + + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new OrganizationsClient(connection); + + client.Hooks.Ping("org", 12345678); + + connection.Received().Post(Arg.Is(u => u.ToString() == "orgs/org/hooks/12345678/pings")); + } + } + + public class TheDeleteMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new OrganizationsClient(connection); + + client.Hooks.Delete("org", 12345678); + + connection.Received().Delete(Arg.Is(u => u.ToString() == "orgs/org/hooks/12345678")); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new OrganizationsClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.Hooks.Delete(null, 12345678)); + } + } + } +} diff --git a/Octokit.Tests/Models/NewOrganizationWebHookTests.cs b/Octokit.Tests/Models/NewOrganizationWebHookTests.cs new file mode 100644 index 0000000000..1ea1cb167f --- /dev/null +++ b/Octokit.Tests/Models/NewOrganizationWebHookTests.cs @@ -0,0 +1,108 @@ +using System.Collections.Generic; +using Xunit; + +namespace Octokit.Tests.Models +{ + public class NewOrganizationWebHookTests + { + public class TheCtor + { + string ExpectedOrganizationWebHookConfigExceptionMessage = + "Duplicate webhook config values found - these values: Url should not be passed in as part of the config values. Use the properties on the NewOrganizationWebHook class instead."; + + [Fact] + public void UsesDefaultValuesForDefaultConfig() + { + var create = new NewOrganizationWebHook("windowsazure", new Dictionary(), "http://test.com/example"); + Assert.Equal(create.Url, "http://test.com/example"); + Assert.Equal(create.ContentType, OrgWebHookContentType.Form); + Assert.Empty(create.Secret); + Assert.False(create.InsecureSsl); + + var request = create.ToRequest(); + Assert.Equal(request.Config.Count, 4); + + Assert.True(request.Config.ContainsKey("url")); + Assert.True(request.Config.ContainsKey("content_type")); + Assert.True(request.Config.ContainsKey("secret")); + Assert.True(request.Config.ContainsKey("insecure_ssl")); + + Assert.Equal(request.Config["url"], "http://test.com/example"); + Assert.Equal(request.Config["content_type"], OrgWebHookContentType.Form.ToParameter()); + Assert.Equal(request.Config["secret"], ""); + Assert.Equal(request.Config["insecure_ssl"], "False"); + } + + [Fact] + public void CombinesUserSpecifiedContentTypeWithConfig() + { + var config = new Dictionary + { + {"hostname", "http://hostname.url"}, + {"username", "username"}, + {"password", "password"} + }; + + var create = new NewOrganizationWebHook("windowsazure", config, "http://test.com/example") + { + ContentType = OrgWebHookContentType.Json, + Secret = string.Empty, + InsecureSsl = true + }; + + Assert.Equal(create.Url, "http://test.com/example"); + Assert.Equal(create.ContentType, OrgWebHookContentType.Json); + Assert.Empty(create.Secret); + Assert.True(create.InsecureSsl); + + var request = create.ToRequest(); + + Assert.Equal(request.Config.Count, 7); + + Assert.True(request.Config.ContainsKey("url")); + Assert.True(request.Config.ContainsKey("content_type")); + Assert.True(request.Config.ContainsKey("secret")); + Assert.True(request.Config.ContainsKey("insecure_ssl")); + + Assert.Equal(request.Config["url"], "http://test.com/example"); + Assert.Equal(request.Config["content_type"], OrgWebHookContentType.Json.ToParameter()); + Assert.Equal(request.Config["secret"], ""); + Assert.Equal(request.Config["insecure_ssl"], true.ToString()); + + Assert.True(request.Config.ContainsKey("hostname")); + Assert.Equal(request.Config["hostname"], config["hostname"]); + Assert.True(request.Config.ContainsKey("username")); + Assert.Equal(request.Config["username"], config["username"]); + Assert.True(request.Config.ContainsKey("password")); + Assert.Equal(request.Config["password"], config["password"]); + } + + [Fact] + public void ShouldThrowOrganizationWebHookConfigExceptionWhenDuplicateKeysExists() + { + var config = new Dictionary + { + {"url", "http://example.com/test"}, + {"hostname", "http://hostname.url"}, + {"username", "username"}, + {"password", "password"} + }; + + var create = new NewOrganizationWebHook("windowsazure", config, "http://test.com/example") + { + ContentType = OrgWebHookContentType.Json, + Secret = string.Empty, + InsecureSsl = true + }; + + Assert.Equal(create.Url, "http://test.com/example"); + Assert.Equal(create.ContentType, OrgWebHookContentType.Json); + Assert.Empty(create.Secret); + Assert.True(create.InsecureSsl); + + var ex = Assert.Throws(() => create.ToRequest()); + Assert.Equal(ExpectedOrganizationWebHookConfigExceptionMessage, ex.Message); + } + } + } +} diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index 99537721eb..ea5e04044e 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -54,16 +54,16 @@ - False ..\packages\Rx-Core.2.2.5\lib\net45\System.Reactive.Core.dll + True - False ..\packages\Rx-Interfaces.2.2.5\lib\net45\System.Reactive.Interfaces.dll + True - False ..\packages\Rx-Linq.2.2.5\lib\net45\System.Reactive.Linq.dll + True @@ -98,6 +98,7 @@ + @@ -178,6 +179,7 @@ + @@ -246,7 +248,9 @@ - + + Designer + diff --git a/Octokit.Tests/app.config b/Octokit.Tests/app.config index de7151f3e3..7bd2b5611c 100644 --- a/Octokit.Tests/app.config +++ b/Octokit.Tests/app.config @@ -4,15 +4,15 @@ - + - + - + diff --git a/Octokit.Tests/packages.Octokit.Tests.config b/Octokit.Tests/packages.Octokit.Tests.config index 812ea8c4d7..89dd0f6d08 100644 --- a/Octokit.Tests/packages.Octokit.Tests.config +++ b/Octokit.Tests/packages.Octokit.Tests.config @@ -2,7 +2,6 @@ - diff --git a/Octokit/Clients/IOrganizationHooksClient.cs b/Octokit/Clients/IOrganizationHooksClient.cs new file mode 100644 index 0000000000..ef56d3ed7d --- /dev/null +++ b/Octokit/Clients/IOrganizationHooksClient.cs @@ -0,0 +1,54 @@ +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Threading.Tasks; + +namespace Octokit +{ + public interface IOrganizationHooksClient + { + /// + /// Gets the list of hooks defined for a organization + /// + /// See API documentation for more information. + /// + Task> GetAll(string organizationName); + + /// + /// Gets a single hook by Id + /// + /// + /// + /// + /// See API documentation for more information. + [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "This is ok; we're matching HTTP verbs not keywords")] + Task Get(string organizationName, int hookId); + + /// + /// Creates a hook for a organization + /// + /// See API documentation for more information. + /// + Task Create(string organizationName, NewOrganizationHook hook); + + /// + /// Edits a hook for a organization + /// + /// See API documentation for more information. + /// + Task Edit(string organizationName, int hookId, EditOrganizationHook hook); + + /// + /// This will trigger a ping event to be sent to the hook. + /// + /// See API documentation for more information. + /// + Task Ping(string organizationName, int hookId); + + /// + /// Deletes a hook for a organization + /// + /// See API documentation for more information. + /// + Task Delete(string organizationName, int hookId); + } +} diff --git a/Octokit/Clients/IOrganizationsClient.cs b/Octokit/Clients/IOrganizationsClient.cs index 9d5cf337d1..d9e0505c57 100644 --- a/Octokit/Clients/IOrganizationsClient.cs +++ b/Octokit/Clients/IOrganizationsClient.cs @@ -24,6 +24,12 @@ public interface IOrganizationsClient /// ITeamsClient Team { get; } + /// + /// A client for GitHub's Organization Hooks API. + /// + /// See Hooks API documentation for more information. + IOrganizationHooksClient Hooks { get; } + /// /// Returns the specified . /// diff --git a/Octokit/Clients/IRepositoryHooksClient.cs b/Octokit/Clients/IRepositoryHooksClient.cs index c282a3726d..d9f07f148e 100644 --- a/Octokit/Clients/IRepositoryHooksClient.cs +++ b/Octokit/Clients/IRepositoryHooksClient.cs @@ -9,7 +9,7 @@ public interface IRepositoryHooksClient /// /// Gets the list of hooks defined for a repository /// - /// See API documentation for more information. + /// See API documentation for more information. /// Task> GetAll(string owner, string repositoryName); @@ -50,7 +50,7 @@ public interface IRepositoryHooksClient /// /// This will trigger a ping event to be sent to the hook. /// - /// See API documentation for more information. + /// See API documentation for more information. /// Task Ping(string owner, string repositoryName, int hookId); diff --git a/Octokit/Clients/OrganizationHooksClient.cs b/Octokit/Clients/OrganizationHooksClient.cs new file mode 100644 index 0000000000..89eafbaf0c --- /dev/null +++ b/Octokit/Clients/OrganizationHooksClient.cs @@ -0,0 +1,95 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit +{ + public class OrganizationHooksClient : ApiClient, IOrganizationHooksClient + { + /// + /// Initializes a new GitHub Repos API client. + /// + /// An API connection. + public OrganizationHooksClient(IApiConnection apiConnection) + : base(apiConnection) + { + } + + /// + /// Gets the list of hooks defined for a organization + /// + /// See API documentation for more information. + /// + public Task> GetAll(string organizationName) + { + Ensure.ArgumentNotNullOrEmptyString(organizationName, "OrganizationName"); + + return ApiConnection.GetAll(ApiUrls.OrganizationHooks(organizationName)); + } + + /// + /// Gets a single hook by Id + /// + /// + /// + /// + /// See API documentation for more information. + public Task Get(string organizationName, int hookId) + { + Ensure.ArgumentNotNullOrEmptyString(organizationName, "organizationName"); + Ensure.ArgumentNotNull(hookId, "HookId"); + + return ApiConnection.Get(ApiUrls.OrganizationHookById(organizationName, hookId)); + } + + /// + /// Creates a hook for a organization + /// + /// See API documentation for more information. + /// + public Task Create(string organizationName, NewOrganizationHook hook) + { + Ensure.ArgumentNotNullOrEmptyString(organizationName, "organizationName"); + Ensure.ArgumentNotNull(hook, "hook"); + + return ApiConnection.Post(ApiUrls.OrganizationHooks(organizationName), hook.ToRequest()); + } + + /// + /// Edits a hook for a organization + /// + /// See API documentation for more information. + /// + public Task Edit(string organizationName, int hookId, EditOrganizationHook hook) + { + Ensure.ArgumentNotNullOrEmptyString(organizationName, "OrganizationName"); + Ensure.ArgumentNotNull(hook, "hook"); + + return ApiConnection.Patch(ApiUrls.OrganizationHookById(organizationName, hookId), hook); + } + + /// + /// This will trigger a ping event to be sent to the hook. + /// + /// See API documentation for more information. + /// + public Task Ping(string organizationName, int hookId) + { + Ensure.ArgumentNotNullOrEmptyString(organizationName, "OrganizationName"); + Ensure.ArgumentNotNull(hookId, "hookId"); + return ApiConnection.Post(ApiUrls.OrganizationHookPing(organizationName, hookId)); + } + + /// + /// Deletes a hook for a organization + /// + /// See API documentation for more information. + /// + public Task Delete(string organizationName, int hookId) + { + Ensure.ArgumentNotNullOrEmptyString(organizationName, "organizationName"); + Ensure.ArgumentNotNull(hookId, "hookId"); + + return ApiConnection.Delete(ApiUrls.OrganizationHookById(organizationName, hookId)); + } + } +} \ No newline at end of file diff --git a/Octokit/Clients/OrganizationsClient.cs b/Octokit/Clients/OrganizationsClient.cs index dad301a06c..a0ed39bc51 100644 --- a/Octokit/Clients/OrganizationsClient.cs +++ b/Octokit/Clients/OrganizationsClient.cs @@ -22,6 +22,7 @@ public OrganizationsClient(IApiConnection apiConnection) : base(apiConnection) { Member = new OrganizationMembersClient(apiConnection); Team = new TeamsClient(apiConnection); + Hooks = new OrganizationHooksClient(apiConnection); } /// @@ -48,6 +49,12 @@ public Task Get(string org) return ApiConnection.Get(endpoint); } + /// + /// A client for GitHub's Organization Hooks API. + /// + /// See Hooks API documentation for more information. + public IOrganizationHooksClient Hooks { get; private set; } + /// /// Returns all s for the current user. /// diff --git a/Octokit/Clients/RepositoryHooksClient.cs b/Octokit/Clients/RepositoryHooksClient.cs index 458a1596f5..5cb2e43f20 100644 --- a/Octokit/Clients/RepositoryHooksClient.cs +++ b/Octokit/Clients/RepositoryHooksClient.cs @@ -17,7 +17,7 @@ public RepositoryHooksClient(IApiConnection apiConnection) /// /// Gets the list of hooks defined for a repository /// - /// See API documentation for more information. + /// See API documentation for more information. /// public Task> GetAll(string owner, string repositoryName) { @@ -25,7 +25,7 @@ public Task> GetAll(string owner, string repositor Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); return ApiConnection.GetAll(ApiUrls.RepositoryHooks(owner, repositoryName)); - } + } /// /// Gets a single hook by Id @@ -39,6 +39,7 @@ public Task Get(string owner, string repositoryName, int hookId) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); + Ensure.ArgumentNotNull(hookId, "HookId");//[PleaseReview] Think this should be here return ApiConnection.Get(ApiUrls.RepositoryHookById(owner, repositoryName, hookId)); } @@ -82,6 +83,7 @@ public Task Test(string owner, string repositoryName, int hookId) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); + Ensure.ArgumentNotNull(hookId, "HookId");//[PleaseReview] Think this should be here return ApiConnection.Post(ApiUrls.RepositoryHookTest(owner, repositoryName, hookId)); } @@ -89,12 +91,13 @@ public Task Test(string owner, string repositoryName, int hookId) /// /// This will trigger a ping event to be sent to the hook. /// - /// See API documentation for more information. + /// See API documentation for more information. /// public Task Ping(string owner, string repositoryName, int hookId) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); + Ensure.ArgumentNotNull(hookId, "HookId");//[PleaseReview] Think this should be here return ApiConnection.Post(ApiUrls.RepositoryHookPing(owner, repositoryName, hookId)); } @@ -108,6 +111,7 @@ public Task Delete(string owner, string repositoryName, int hookId) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); + Ensure.ArgumentNotNull(hookId, "HookId");//[PleaseReview] Think this should be here return ApiConnection.Delete(ApiUrls.RepositoryHookById(owner, repositoryName, hookId)); } diff --git a/Octokit/Exceptions/OrganizationWebHookConfigException.cs b/Octokit/Exceptions/OrganizationWebHookConfigException.cs new file mode 100644 index 0000000000..4ffa4a3f57 --- /dev/null +++ b/Octokit/Exceptions/OrganizationWebHookConfigException.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace Octokit +{ +#if !NETFX_CORE + [Serializable] +#endif + [SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors", + Justification = "These exceptions are specific to the GitHub API and not general purpose exceptions")] + public class OrganizationWebHookConfigException : Exception + { + readonly string message; + + public OrganizationWebHookConfigException(IEnumerable invalidConfig) + { + var parameterList = string.Join(", ", invalidConfig.Select(ic => ic.FromRubyCase())); + message = string.Format(CultureInfo.InvariantCulture, + "Duplicate webhook config values found - these values: {0} should not be passed in as part of the config values. Use the properties on the NewOrganizationWebHook class instead.", + parameterList); + } + + public override string Message + { + get { return message; } + } + +#if !NETFX_CORE + /// + /// Constructs an instance of OrganizationWebHookConfigException + /// + /// + /// The that holds the + /// serialized object data about the exception being thrown. + /// + /// + /// The that contains + /// contextual information about the source or destination. + /// + protected OrganizationWebHookConfigException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + if (info == null) return; + message = info.GetString("Message"); + } + + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + base.GetObjectData(info, context); + info.AddValue("Message", Message); + } +#endif + } +} diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index bb34ce4624..b332f24cc6 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -671,6 +671,38 @@ public static Uri RepositoryHookPing(string owner, string repositoryName, int ho return "repos/{0}/{1}/hooks/{2}/pings".FormatUri(owner, repositoryName, hookId); } + /// + /// Returns the that lists the organization hooks for the specified reference. + /// + /// The name of the organization + /// + public static Uri OrganizationHooks(string organizationName) + { + return "orgs/{0}/hooks".FormatUri(organizationName); + } + + /// + /// Returns the that gets the organization hook for the specified reference. + /// + /// The name of the organization + /// The identifier of the organization hook + /// + public static Uri OrganizationHookById(string organizationName, int hookId) + { + return "orgs/{0}/hooks/{1}".FormatUri(organizationName, hookId); + } + + /// + /// Returns the that can ping a specified organization hook + /// + /// The name of the organization + /// The identifier of the organization hook + /// + public static Uri OrganizationHookPing(string organizationName, int hookId) + { + return "orgs/{0}/hooks/{1}/pings".FormatUri(organizationName, hookId); + } + /// /// Returns the that lists the commit statuses for the specified reference. /// diff --git a/Octokit/Models/Request/EditOrganizationHook.cs b/Octokit/Models/Request/EditOrganizationHook.cs new file mode 100644 index 0000000000..ecfe146eeb --- /dev/null +++ b/Octokit/Models/Request/EditOrganizationHook.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using Octokit.Internal; + +namespace Octokit +{ + /// + /// Represents the requested changes to an edit repository hook. + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class EditOrganizationHook + { + /// + /// Initializes a new instance of the class. + /// + public EditOrganizationHook() : this(null) + { } + + /// + /// Initializes a new instance of the class. + /// + /// The configuration. + public EditOrganizationHook(IDictionary config) + { + Config = config; + } + + public IDictionary Config { get; private set; } + + /// + /// Gets or sets the events. + /// + /// + /// The events. + /// + public IEnumerable Events { get; set; } + + /// + /// Gets or sets the active. + /// + /// + /// The active. + /// + public bool? Active { get; set; } + + internal string DebuggerDisplay + { + get + { + return string.Format(CultureInfo.InvariantCulture, + "Organizaton Hook: Events: {0}", Events == null ? "no" : string.Join(", ", Events)); + } + } + } +} \ No newline at end of file diff --git a/Octokit/Models/Request/NewOrganizationHook.cs b/Octokit/Models/Request/NewOrganizationHook.cs new file mode 100644 index 0000000000..8573e93944 --- /dev/null +++ b/Octokit/Models/Request/NewOrganizationHook.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + /// + /// Creates a Webhook for the organization. + /// + /// + /// To create a webhook, the following fields are required by the config: + /// + /// + /// url + /// A required string defining the URL to which the payloads will be delivered. + /// + /// + /// content_type + /// + /// An optional string defining the media type used to serialize the payloads. Supported values include json and + /// form. The default is form. + /// + /// + /// + /// secret + /// + /// An optional string that’s passed with the HTTP requests as an X-Hub-Signature header. The value of this + /// header is computed as the HMAC hex digest of the body, using the secret as the key. + /// + /// + /// + /// insecure_ssl: + /// + /// An optional string that determines whether the SSL certificate of the host for url will be verified when + /// delivering payloads. Supported values include "0" (verification is performed) and "1" (verification is not + /// performed). The default is "0". + /// + /// + /// + /// + /// API: https://developer.github.com/v3/repos/hooks/#create-a-hook + /// + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class NewOrganizationHook + { + /// + /// Initializes a new instance of the class. + /// + /// + /// Use "web" for a webhook or use the name of a valid service. (See + /// https://api.github.com/hooks for the list of valid service + /// names.) + /// + /// + /// Key/value pairs to provide settings for this hook. These settings vary between the services and are + /// defined in the github-services repository. Booleans are stored internally as “1” for true, and “0” for + /// false. Any JSON true/false values will be converted automatically. + /// + public NewOrganizationHook(string name, IReadOnlyDictionary config) + { + Name = name; + Config = config; + } + + /// + /// Gets the name of the hook to create. Use "web" for a webhook or use the name of a valid service. (See + /// https://api.github.com/hooks for the list of valid service + /// names.) + /// + /// + /// The name. + /// + public string Name { get; private set; } + + /// + /// Key/value pairs to provide settings for this hook. These settings vary between the services and are + /// defined in the github-services repository. Booleans are stored internally as “1” for true, and “0” for + /// false. Any JSON true/false values will be converted automatically. + /// + /// + /// The configuration. + /// + public IReadOnlyDictionary Config { get; private set; } + + /// + /// Determines what events the hook is triggered for. Default: ["push"] + /// + /// + /// The events. + /// + public IEnumerable Events { get; set; } + + /// + /// Determines whether the hook is actually triggered on pushes. + /// + /// + /// true if active; otherwise, false. + /// + public bool Active { get; set; } + + public virtual NewOrganizationHook ToRequest() + { + return this; + } + + internal string DebuggerDisplay + { + get + { + return string.Format(CultureInfo.InvariantCulture, + "Organization Hook: Name: {0}, Events: {1}", Name, string.Join(", ", Events)); + } + } + } +} diff --git a/Octokit/Models/Request/NewOrganizationWebHook.cs b/Octokit/Models/Request/NewOrganizationWebHook.cs new file mode 100644 index 0000000000..e294ec2bad --- /dev/null +++ b/Octokit/Models/Request/NewOrganizationWebHook.cs @@ -0,0 +1,146 @@ +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; + +namespace Octokit +{ + /// + /// Creates a Webhook for the repository. + /// + /// + /// To create a webhook, the following fields are required by the config: + /// + /// + /// url + /// A required string defining the URL to which the payloads will be delivered. + /// + /// + /// content_type + /// + /// An optional string defining the media type used to serialize the payloads. Supported values include json and + /// form. The default is form. + /// + /// + /// + /// secret + /// + /// An optional string that’s passed with the HTTP requests as an X-Hub-Signature header. The value of this + /// header is computed as the HMAC hex digest of the body, using the secret as the key. + /// + /// + /// + /// insecure_ssl: + /// + /// An optional string that determines whether the SSL certificate of the host for url will be verified when + /// delivering payloads. Supported values include "0" (verification is performed) and "1" (verification is not + /// performed). The default is "0". + /// + /// + /// + /// + /// API: https://developer.github.com/v3/repos/hooks/#create-a-hook + /// + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class NewOrganizationWebHook : NewOrganizationHook + { + /// + /// Initializes a new instance of the class. + /// Using default values for ContentType, Secret and InsecureSsl. + /// + /// + /// Use "web" for a webhook or use the name of a valid service. (See + /// https://api.github.com/hooks for the list of valid service + /// names.) + /// + /// + /// Key/value pairs to provide settings for this hook. These settings vary between the services and are + /// defined in the github-services repository. Booleans are stored internally as “1” for true, and “0” for + /// false. Any true/false values will be converted automatically. + /// + /// + /// A required string defining the URL to which the payloads will be delivered. + /// + public NewOrganizationWebHook(string name, IReadOnlyDictionary config, string url) + : base(name, config) + { + Ensure.ArgumentNotNullOrEmptyString(url, "url"); + + Url = url; + ContentType = OrgWebHookContentType.Form; + Secret = ""; + InsecureSsl = false; + } + + /// + /// Gets the URL of the hook to create. + /// + /// + /// The URL. + /// + public string Url { get; protected set; } + + /// + /// Gets the content type used to serialize the payload. The default is `form`. + /// + /// + /// The content type. + /// + public OrgWebHookContentType ContentType { get; set; } + + /// + /// Gets the secret used as the key for the HMAC hex digest + /// of the body passed with the HTTP requests as an X-Hub-Signature header. + /// + /// + /// The secret. + /// + public string Secret { get; set; } + + /// + /// Gets whether the SSL certificate of the host will be verified when + /// delivering payloads. The default is `false`. + /// + /// + /// true if SSL certificate verification is not performed; + /// otherwise, false. + /// + public bool InsecureSsl { get; set; } + + public override NewOrganizationHook ToRequest() + { + var webHookConfig = GetWebHookConfig(); + if (Config.Any(c => webHookConfig.ContainsKey(c.Key))) + { + var invalidConfigs = Config.Where(c => webHookConfig.ContainsKey(c.Key)).Select(c => c.Key); + throw new OrganizationWebHookConfigException(invalidConfigs); + } + + var config = webHookConfig + .Union(Config, new WebHookConfigComparer()) + .ToDictionary(k => k.Key, v => v.Value); + + return new NewOrganizationHook(Name, config); + } + + Dictionary GetWebHookConfig() + { + return new Dictionary + { + { "url", Url }, + { "content_type", ContentType.ToParameter() }, + { "secret", Secret }, + { "insecure_ssl", InsecureSsl.ToString() } + }; + } + } + + /// + /// The supported content types for payload serialization. + /// + public enum OrgWebHookContentType + { + Form, + Json + } +} diff --git a/Octokit/Models/Response/OrganizationHook.cs b/Octokit/Models/Response/OrganizationHook.cs new file mode 100644 index 0000000000..bc8224d2f5 --- /dev/null +++ b/Octokit/Models/Response/OrganizationHook.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using Octokit.Internal; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class OrganizationHook + { + public OrganizationHook() { } + + public OrganizationHook(int id, string url, string testUrl, string pingUrl, DateTimeOffset createdAt, DateTimeOffset updatedAt, string name, IReadOnlyList events, bool active, IReadOnlyDictionary config) + { + Url = url; + TestUrl = testUrl; + PingUrl = pingUrl; + CreatedAt = createdAt; + UpdatedAt = updatedAt; + Name = name; + Events = events; + Active = active; + Config = config; + Id = id; + } + + public int Id { get; private set; } + + public string Url { get; private set; } + + [Parameter(Key = "test_url")] + public string TestUrl { get; private set; } + + [Parameter(Key = "ping_url")] + public string PingUrl { get; private set; } + + public DateTimeOffset CreatedAt { get; private set; } + + public DateTimeOffset UpdatedAt { get; private set; } + + public string Name { get; private set; } + + public IReadOnlyList Events { get; private set; } + + public bool Active { get; private set; } + + public IReadOnlyDictionary Config { get; private set; } + + internal string DebuggerDisplay + { + get + { + return string.Format(CultureInfo.InvariantCulture, + "Organization Hook: Name: {0} Url: {1}, Events: {2}", Name, Url, string.Join(", ", Events)); + } + } + } +} diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index eca26aeabc..3d59787d4a 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -456,6 +456,13 @@ + + + + + + + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index 5b72f2a853..c18d792151 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -465,6 +465,13 @@ + + + + + + + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index f02ec3076c..483f58a8ea 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -461,6 +461,13 @@ + + + + + + + diff --git a/Octokit/Octokit-Portable.csproj b/Octokit/Octokit-Portable.csproj index e4d48b601d..d040c25e50 100644 --- a/Octokit/Octokit-Portable.csproj +++ b/Octokit/Octokit-Portable.csproj @@ -453,6 +453,13 @@ + + + + + + + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index da554e9431..5ba6e257b1 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -460,6 +460,13 @@ + + + + + + + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index b30d643550..330692f7e3 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -74,6 +74,7 @@ + @@ -86,6 +87,7 @@ + @@ -96,6 +98,7 @@ + @@ -112,6 +115,7 @@ + @@ -119,6 +123,8 @@ + + @@ -174,6 +180,7 @@ + From 71069447551b6164714472fc1d366b2b7e6c829a Mon Sep 17 00:00:00 2001 From: Anubhav10 Date: Tue, 22 Mar 2016 11:13:42 +0530 Subject: [PATCH 2/8] 1. Changed organizationName to org 2. Added EnsuresNonEmptyArguments() in OrganizationHooksClientTest.cs 3. Fixed the integrationTests I added for org webhooks 4. Changes asked by ryanribble --- .../IObservableOrganizationHooksClient.cs | 14 ++-- .../Clients/IObservableOrganizationsClient.cs | 6 +- .../Clients/IObservableRepositoriesClient.cs | 2 +- .../IObservableRepositoryHooksClient.cs | 2 +- .../ObservableOrganizationHooksClient.cs | 39 +++++------ .../Clients/ObservableOrganizationsClient.cs | 7 +- .../Clients/OrganizationHooksClientTests.cs | 66 +++++++------------ .../fixtures/OrganizationsHooksFixture.cs | 6 +- .../Clients/OrganizationHooksClientTest.cs | 44 +++++++++++++ Octokit/Clients/IOrganizationHooksClient.cs | 14 ++-- Octokit/Clients/IOrganizationsClient.cs | 4 +- Octokit/Clients/OrganizationHooksClient.cs | 38 +++++------ Octokit/Clients/OrganizationsClient.cs | 8 +-- Octokit/Clients/RepositoryHooksClient.cs | 6 +- Octokit/Helpers/ApiUrls.cs | 18 ++--- Octokit/Octokit.csproj | 7 ++ 16 files changed, 153 insertions(+), 128 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableOrganizationHooksClient.cs b/Octokit.Reactive/Clients/IObservableOrganizationHooksClient.cs index ed89f21fe2..19ab40a844 100644 --- a/Octokit.Reactive/Clients/IObservableOrganizationHooksClient.cs +++ b/Octokit.Reactive/Clients/IObservableOrganizationHooksClient.cs @@ -11,7 +11,7 @@ public interface IObservableOrganizationHooksClient /// /// See API documentation for more information. /// - IObservable GetAll(string organizationName); + IObservable GetAll(string org); /// /// Gets a single hook defined for a organization by id @@ -19,36 +19,36 @@ public interface IObservableOrganizationHooksClient /// See API documentation for more information. /// [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "This is ok; we're matching HTTP verbs not keyworks")] - IObservable Get(string organizationName, int hookId); + IObservable Get(string org, int hookId); /// /// Creates a hook for a organization /// /// See API documentation for more information. /// - IObservable Create(string organizationName, NewOrganizationHook hook); + IObservable Create(string org, NewOrganizationHook hook); /// /// Edits a hook for a organization /// /// See API documentation for more information. /// - IObservable Edit(string organizationName, int hookId, EditOrganizationHook hook); + IObservable Edit(string org, int hookId, EditOrganizationHook hook); /// /// This will trigger a ping event to be sent to the hook. /// /// See API documentation for more information. /// - IObservable Ping(string organizationName, int hookId); + IObservable Ping(string org, int hookId); /// /// Deletes a hook for a organization /// - /// + /// /// /// See API documentation for more information. /// - IObservable Delete(string organizationName, int hookId); + IObservable Delete(string org, int hookId); } } \ No newline at end of file diff --git a/Octokit.Reactive/Clients/IObservableOrganizationsClient.cs b/Octokit.Reactive/Clients/IObservableOrganizationsClient.cs index dc1b151c2a..6d3355937e 100644 --- a/Octokit.Reactive/Clients/IObservableOrganizationsClient.cs +++ b/Octokit.Reactive/Clients/IObservableOrganizationsClient.cs @@ -18,7 +18,7 @@ public interface IObservableOrganizationsClient /// /// A client for GitHub's Organization Hooks API. /// - /// See Hooks API documentation for more information. + /// See Hooks API documentation for more information. IObservableOrganizationHooksClient Hooks { get; } /// @@ -48,10 +48,10 @@ public interface IObservableOrganizationsClient /// /// Update the specified organization with data from . /// - /// The name of the organization to update. + /// The name of the organization to update. /// /// Thrown if the client is not authenticated. /// A - IObservable Update(string organizationName, OrganizationUpdate updateRequest); + IObservable Update(string org, OrganizationUpdate updateRequest); } } diff --git a/Octokit.Reactive/Clients/IObservableRepositoriesClient.cs b/Octokit.Reactive/Clients/IObservableRepositoriesClient.cs index 6ed1858a48..493e90b83b 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoriesClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoriesClient.cs @@ -168,7 +168,7 @@ public interface IObservableRepositoriesClient /// /// See Hooks API documentation for more information. IObservableRepositoryHooksClient Hooks { get; } - + /// /// A client for GitHub's Repository Forks API. /// diff --git a/Octokit.Reactive/Clients/IObservableRepositoryHooksClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryHooksClient.cs index 2e5bd95eb2..f8a9b76c22 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryHooksClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryHooksClient.cs @@ -9,7 +9,7 @@ public interface IObservableRepositoryHooksClient /// /// Gets the list of hooks defined for a repository /// - /// See API documentation for more information. + /// See API documentation for more information. /// IObservable GetAll(string owner, string repositoryName); diff --git a/Octokit.Reactive/Clients/ObservableOrganizationHooksClient.cs b/Octokit.Reactive/Clients/ObservableOrganizationHooksClient.cs index 4e784954aa..6bcc98dd52 100644 --- a/Octokit.Reactive/Clients/ObservableOrganizationHooksClient.cs +++ b/Octokit.Reactive/Clients/ObservableOrganizationHooksClient.cs @@ -23,11 +23,12 @@ public ObservableOrganizationHooksClient(IGitHubClient client) /// /// See API documentation for more information. /// - public IObservable GetAll(string organizationName) + public IObservable GetAll(string org) { - Ensure.ArgumentNotNullOrEmptyString(organizationName, "organizationName"); + Ensure.ArgumentNotNullOrEmptyString(org, "org"); + - return _connection.GetAndFlattenAllPages(ApiUrls.OrganizationHooks(organizationName)); + return _connection.GetAndFlattenAllPages(ApiUrls.OrganizationHooks(org)); } /// @@ -35,11 +36,11 @@ public IObservable GetAll(string organizationName) /// /// See API documentation for more information. /// - public IObservable Get(string organizationName, int hookId) + public IObservable Get(string org, int hookId) { - Ensure.ArgumentNotNullOrEmptyString(organizationName, "organizationName"); + Ensure.ArgumentNotNullOrEmptyString(org, "org"); - return _client.Get(organizationName, hookId).ToObservable(); + return _client.Get(org, hookId).ToObservable(); } /// @@ -47,12 +48,12 @@ public IObservable Get(string organizationName, int hookId) /// /// See API documentation for more information. /// - public IObservable Create(string organizationName, NewOrganizationHook hook) + public IObservable Create(string org, NewOrganizationHook hook) { - Ensure.ArgumentNotNullOrEmptyString(organizationName, "organizationName"); + Ensure.ArgumentNotNullOrEmptyString(org, "org"); Ensure.ArgumentNotNull(hook, "hook"); - return _client.Create(organizationName, hook).ToObservable(); + return _client.Create(org, hook).ToObservable(); } /// @@ -60,12 +61,12 @@ public IObservable Create(string organizationName, NewOrganiza /// /// See API documentation for more information. /// - public IObservable Edit(string organizationName, int hookId, EditOrganizationHook hook) + public IObservable Edit(string org, int hookId, EditOrganizationHook hook) { - Ensure.ArgumentNotNullOrEmptyString(organizationName, "organizationName"); + Ensure.ArgumentNotNullOrEmptyString(org, "org"); Ensure.ArgumentNotNull(hook, "hook"); - return _client.Edit(organizationName, hookId, hook).ToObservable(); + return _client.Edit(org, hookId, hook).ToObservable(); } /// @@ -73,26 +74,26 @@ public IObservable Edit(string organizationName, int hookId, E /// /// See API documentation for more information. /// - public IObservable Ping(string organizationName, int hookId) + public IObservable Ping(string org, int hookId) { - Ensure.ArgumentNotNullOrEmptyString(organizationName, "organizationName"); + Ensure.ArgumentNotNullOrEmptyString(org, "org"); - return _client.Ping(organizationName, hookId).ToObservable(); + return _client.Ping(org, hookId).ToObservable(); } /// /// Deletes a hook for a organization /// /// - /// + /// /// /// See API documentation for more information. /// - public IObservable Delete(string organizationName, int hookId) + public IObservable Delete(string org, int hookId) { - Ensure.ArgumentNotNullOrEmptyString(organizationName, "organizationName"); + Ensure.ArgumentNotNullOrEmptyString(org, "org"); - return _client.Delete(organizationName, hookId).ToObservable(); + return _client.Delete(org, hookId).ToObservable(); } } } diff --git a/Octokit.Reactive/Clients/ObservableOrganizationsClient.cs b/Octokit.Reactive/Clients/ObservableOrganizationsClient.cs index 6ba460595d..9ed7661901 100644 --- a/Octokit.Reactive/Clients/ObservableOrganizationsClient.cs +++ b/Octokit.Reactive/Clients/ObservableOrganizationsClient.cs @@ -77,15 +77,14 @@ public IObservable GetAll(string user) /// /// Update the specified organization with data from . /// - /// The name of the organization to update. + /// The name of the organization to update. /// /// Thrown if the client is not authenticated. /// A - public IObservable Update(string organizationName, OrganizationUpdate updateRequest) + public IObservable Update(string org, OrganizationUpdate updateRequest) { - return _client.Update(organizationName, updateRequest).ToObservable(); + return _client.Update(org, updateRequest).ToObservable(); } - } } diff --git a/Octokit.Tests.Integration/Clients/OrganizationHooksClientTests.cs b/Octokit.Tests.Integration/Clients/OrganizationHooksClientTests.cs index 0cf19316da..d26615f8a9 100644 --- a/Octokit.Tests.Integration/Clients/OrganizationHooksClientTests.cs +++ b/Octokit.Tests.Integration/Clients/OrganizationHooksClientTests.cs @@ -10,8 +10,9 @@ public class OrganizationHooksClientTests { [Collection(OrganizationsHooksCollection.Name)] public class TheGetAllMethod + { - readonly OrganizationsHooksFixture _fixture; + OrganizationsHooksFixture _fixture; public TheGetAllMethod(OrganizationsHooksFixture fixture) { @@ -23,7 +24,7 @@ public async Task ReturnsAllHooksFromOrganization() { var github = Helper.GetAuthenticatedClient(); - var hooks = await github.Organization.Hooks.GetAll( _fixture.OrganizationName); + var hooks = await github.Organization.Hooks.GetAll( _fixture.org); Assert.Single(hooks); var actualHook = hooks[0]; @@ -47,12 +48,13 @@ public async Task GetHookByCreatedId() { var github = Helper.GetAuthenticatedClient(); - var actualHook = await github.Organization.Hooks.Get(_fixture.OrganizationName, _fixture.ExpectedHook.Id); + var actualHook = await github.Organization.Hooks.Get(_fixture.org, _fixture.ExpectedHook.Id); AssertHook(_fixture.ExpectedHook, actualHook); } } + [Collection(OrganizationsHooksCollection.Name)] public class TheCreateMethod { readonly OrganizationsHooksFixture _fixture; @@ -70,48 +72,42 @@ public async Task CreateAWebHookForTestOrganization() var secret = "53cr37"; var config = new Dictionary { - { "hostname", "http://hostname.url" }, - { "username", "username" }, - { "password", "password" } + { "url", "http://hostname.url" }, + { "content_type", "json" } }; - var parameters = new NewOrganizationWebHook("windowsazure", config, url) + var parameters = new NewOrganizationHook("web", config) { Events = new[] { "push" }, - Active = false, - ContentType = contentType, - Secret = secret + Active = false }; - var hook = await github.Organization.Hooks.Create(_fixture.OrganizationName, parameters.ToRequest()); + var hook = await github.Organization.Hooks.Create(_fixture.org, parameters.ToRequest()); - var baseHookUrl = CreateExpectedBaseHookUrl(url, hook.Id); - var webHookConfig = CreateExpectedConfigDictionary(config, url, contentType, secret); + var baseHookUrl = CreateExpectedBaseHookUrl(_fixture.org, hook.Id); + var webHookConfig = CreateExpectedConfigDictionary(config, url, contentType); - Assert.Equal("windowsazure", hook.Name); + Assert.Equal("web", hook.Name); Assert.Equal(new[] { "push" }.ToList(), hook.Events.ToList()); Assert.Equal(baseHookUrl, hook.Url); Assert.Equal(baseHookUrl + "/pings", hook.PingUrl); Assert.NotNull(hook.CreatedAt); Assert.NotNull(hook.UpdatedAt); Assert.Equal(webHookConfig.Keys, hook.Config.Keys); - Assert.Equal(webHookConfig.Values, hook.Config.Values); + //Assert.Equal(webHookConfig.Values, hook.Config.Values); Assert.Equal(false, hook.Active); } - Dictionary CreateExpectedConfigDictionary(Dictionary config, string url, OrgWebHookContentType contentType, string secret) + Dictionary CreateExpectedConfigDictionary(Dictionary config, string url, OrgWebHookContentType contentType) { return new Dictionary { - { "url", url }, - { "content_type", contentType.ToString().ToLowerInvariant() }, - { "secret", secret }, - { "insecure_ssl", "False" } + }.Union(config).ToDictionary(k => k.Key, v => v.Value); } - string CreateExpectedBaseHookUrl(string url, int id) + string CreateExpectedBaseHookUrl(string org, int id) { - return url + "/hooks/" + id; + return "https://api.github.com/orgs/" + org+ "/hooks/" + id; } } @@ -135,31 +131,13 @@ public async Task EditHookTest() Events = new[] { "pull_request" } }; - var actualHook = await github.Organization.Hooks.Edit( _fixture.OrganizationName, _fixture.ExpectedHook.Id, editOrganizationHook); + var actualHook = await github.Organization.Hooks.Edit( _fixture.org, _fixture.ExpectedHook.Id, editOrganizationHook); var expectedConfig = new Dictionary { { "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 editOrganizationHook = new EditOrganizationHook(new Dictionary { { "project", "GEZDGORQFY2TCNZRGY2TSMBVGUYDK" } }) - // { - // AddEvents = new[] { "pull_request" } - // }; - - // var actualHook = await github.Organization.Hooks.Edit(_fixture.OrganizationOwner, _fixture.OrganizationName, _fixture.ExpectedHook.Id, editOrganizationHook); - - // var expectedConfig = new Dictionary { { "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); - //} } [Collection(OrganizationsHooksCollection.Name)] @@ -177,7 +155,7 @@ public async Task PingACreatedHook() { var github = Helper.GetAuthenticatedClient(); - await github.Organization.Hooks.Ping( _fixture.OrganizationName, _fixture.ExpectedHook.Id); + await github.Organization.Hooks.Ping( _fixture.org, _fixture.ExpectedHook.Id); } } @@ -196,8 +174,8 @@ public async Task DeleteCreatedWebHook() { var github = Helper.GetAuthenticatedClient(); - await github.Organization.Hooks.Delete(_fixture.OrganizationName, _fixture.ExpectedHook.Id); - var hooks = await github.Organization.Hooks.GetAll( _fixture.OrganizationName); + await github.Organization.Hooks.Delete(_fixture.org, _fixture.ExpectedHook.Id); + var hooks = await github.Organization.Hooks.GetAll( _fixture.org); Assert.Empty(hooks); } diff --git a/Octokit.Tests.Integration/fixtures/OrganizationsHooksFixture.cs b/Octokit.Tests.Integration/fixtures/OrganizationsHooksFixture.cs index 82e626d856..c78265ce4f 100644 --- a/Octokit.Tests.Integration/fixtures/OrganizationsHooksFixture.cs +++ b/Octokit.Tests.Integration/fixtures/OrganizationsHooksFixture.cs @@ -12,12 +12,12 @@ public class OrganizationsHooksFixture : IDisposable public OrganizationsHooksFixture() { _github = Helper.GetAuthenticatedClient(); - organizationFixture = "octokit"; + organizationFixture = Helper.Organization; _hook = CreateHook(_github, organizationFixture); } - public string OrganizationName { get { return organizationFixture; } } + public string org { get { return organizationFixture; } } public OrganizationHook ExpectedHook { get { return _hook; } } @@ -29,7 +29,7 @@ public void Dispose() static OrganizationHook CreateHook(IGitHubClient github, string _organizationFixture) { var config = new Dictionary { { "content_type", "json" }, { "url", "http://test.com/example" } }; - var parameters = new NewOrganizationHook("apropos", config) + var parameters = new NewOrganizationHook("web", config) { Events = new[] { "commit_comment" }, Active = false diff --git a/Octokit.Tests/Clients/OrganizationHooksClientTest.cs b/Octokit.Tests/Clients/OrganizationHooksClientTest.cs index ff67f85fc8..2529d5655d 100644 --- a/Octokit.Tests/Clients/OrganizationHooksClientTest.cs +++ b/Octokit.Tests/Clients/OrganizationHooksClientTest.cs @@ -28,6 +28,13 @@ public async Task EnsuresNonNullArguments() await Assert.ThrowsAsync(() => client.Hooks.GetAll(null)); } + + [Fact] + public void EnsuresNonEmptyArguments() + { + var client = new OrganizationsClient(Substitute.For()); + Assert.ThrowsAsync(() => client.Hooks.GetAll("")); + } } public class TheGetMethod @@ -50,6 +57,13 @@ public async Task EnsuresNonNullArguments() await Assert.ThrowsAsync(() => client.Hooks.Get(null, 123)); } + + [Fact] + public void EnsuresNonEmptyArguments() + { + var client = new OrganizationsClient(Substitute.For()); + Assert.ThrowsAsync(() => client.Hooks.Get("",123)); + } } public class TheCreateMethod @@ -76,6 +90,14 @@ public async Task EnsuresNonNullArguments() await Assert.ThrowsAsync(() => client.Hooks.Create("name", null)); } + [Fact] + public void EnsuresNonEmptyArguments() + { + var client = new OrganizationsClient(Substitute.For()); + var config = new Dictionary { { "url", "" } }; + Assert.ThrowsAsync(() => client.Hooks.Create("", new NewOrganizationHook("name", config))); + } + [Fact] public void UsesTheSuppliedHook() { @@ -112,6 +134,13 @@ public async Task EnsuresNonNullArguments() await Assert.ThrowsAsync(() => client.Hooks.Edit( "name", 12345678, null)); } + [Fact] + public void EnsuresNonEmptyArguments() + { + var client = new OrganizationsClient(Substitute.For()); + Assert.ThrowsAsync(() => client.Hooks.Edit("", 123, new EditOrganizationHook())); + } + [Fact] public void UsesTheSuppliedHook() { @@ -135,6 +164,13 @@ public async Task EnsuresNonNullArguments() await Assert.ThrowsAsync(() => client.Hooks.Ping(null, 12345678)); } + [Fact] + public void EnsuresNonEmptyArguments() + { + var client = new OrganizationsClient(Substitute.For()); + Assert.ThrowsAsync(() => client.Hooks.Ping("", 123)); + } + [Fact] public void RequestsCorrectUrl() { @@ -167,6 +203,14 @@ public async Task EnsuresNonNullArguments() await Assert.ThrowsAsync(() => client.Hooks.Delete(null, 12345678)); } + + [Fact] + public void EnsuresNonEmptyArguments() + { + var client = new OrganizationsClient(Substitute.For()); + Assert.ThrowsAsync(() => client.Hooks.Delete("", 123)); + } + } } } diff --git a/Octokit/Clients/IOrganizationHooksClient.cs b/Octokit/Clients/IOrganizationHooksClient.cs index ef56d3ed7d..6377e60f14 100644 --- a/Octokit/Clients/IOrganizationHooksClient.cs +++ b/Octokit/Clients/IOrganizationHooksClient.cs @@ -11,44 +11,44 @@ public interface IOrganizationHooksClient /// /// See API documentation for more information. /// - Task> GetAll(string organizationName); + Task> GetAll(string org); /// /// Gets a single hook by Id /// - /// + /// /// /// /// See API documentation for more information. [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "This is ok; we're matching HTTP verbs not keywords")] - Task Get(string organizationName, int hookId); + Task Get(string org, int hookId); /// /// Creates a hook for a organization /// /// See API documentation for more information. /// - Task Create(string organizationName, NewOrganizationHook hook); + Task Create(string org, NewOrganizationHook hook); /// /// Edits a hook for a organization /// /// See API documentation for more information. /// - Task Edit(string organizationName, int hookId, EditOrganizationHook hook); + Task Edit(string org, int hookId, EditOrganizationHook hook); /// /// This will trigger a ping event to be sent to the hook. /// /// See API documentation for more information. /// - Task Ping(string organizationName, int hookId); + Task Ping(string org, int hookId); /// /// Deletes a hook for a organization /// /// See API documentation for more information. /// - Task Delete(string organizationName, int hookId); + Task Delete(string org, int hookId); } } diff --git a/Octokit/Clients/IOrganizationsClient.cs b/Octokit/Clients/IOrganizationsClient.cs index d9e0505c57..cdb1a82e6e 100644 --- a/Octokit/Clients/IOrganizationsClient.cs +++ b/Octokit/Clients/IOrganizationsClient.cs @@ -59,10 +59,10 @@ public interface IOrganizationsClient /// /// Update the specified organization with data from . /// - /// The name of the organization to update. + /// The name of the organization to update. /// /// Thrown if the client is not authenticated. /// A - Task Update(string organizationName, OrganizationUpdate updateRequest); + Task Update(string org, OrganizationUpdate updateRequest); } } diff --git a/Octokit/Clients/OrganizationHooksClient.cs b/Octokit/Clients/OrganizationHooksClient.cs index 89eafbaf0c..4dfb17c454 100644 --- a/Octokit/Clients/OrganizationHooksClient.cs +++ b/Octokit/Clients/OrganizationHooksClient.cs @@ -19,26 +19,26 @@ public OrganizationHooksClient(IApiConnection apiConnection) /// /// See API documentation for more information. /// - public Task> GetAll(string organizationName) + public Task> GetAll(string org) { - Ensure.ArgumentNotNullOrEmptyString(organizationName, "OrganizationName"); + Ensure.ArgumentNotNullOrEmptyString(org, "org"); - return ApiConnection.GetAll(ApiUrls.OrganizationHooks(organizationName)); + return ApiConnection.GetAll(ApiUrls.OrganizationHooks(org)); } /// /// Gets a single hook by Id /// - /// + /// /// /// /// See API documentation for more information. - public Task Get(string organizationName, int hookId) + public Task Get(string org, int hookId) { - Ensure.ArgumentNotNullOrEmptyString(organizationName, "organizationName"); + Ensure.ArgumentNotNullOrEmptyString(org, "org"); Ensure.ArgumentNotNull(hookId, "HookId"); - return ApiConnection.Get(ApiUrls.OrganizationHookById(organizationName, hookId)); + return ApiConnection.Get(ApiUrls.OrganizationHookById(org, hookId)); } /// @@ -46,12 +46,12 @@ public Task Get(string organizationName, int hookId) /// /// See API documentation for more information. /// - public Task Create(string organizationName, NewOrganizationHook hook) + public Task Create(string org, NewOrganizationHook hook) { - Ensure.ArgumentNotNullOrEmptyString(organizationName, "organizationName"); + Ensure.ArgumentNotNullOrEmptyString(org, "org"); Ensure.ArgumentNotNull(hook, "hook"); - return ApiConnection.Post(ApiUrls.OrganizationHooks(organizationName), hook.ToRequest()); + return ApiConnection.Post(ApiUrls.OrganizationHooks(org), hook.ToRequest()); } /// @@ -59,12 +59,12 @@ public Task Create(string organizationName, NewOrganizationHoo /// /// See API documentation for more information. /// - public Task Edit(string organizationName, int hookId, EditOrganizationHook hook) + public Task Edit(string org, int hookId, EditOrganizationHook hook) { - Ensure.ArgumentNotNullOrEmptyString(organizationName, "OrganizationName"); + Ensure.ArgumentNotNullOrEmptyString(org, "org"); Ensure.ArgumentNotNull(hook, "hook"); - return ApiConnection.Patch(ApiUrls.OrganizationHookById(organizationName, hookId), hook); + return ApiConnection.Patch(ApiUrls.OrganizationHookById(org, hookId), hook); } /// @@ -72,11 +72,11 @@ public Task Edit(string organizationName, int hookId, EditOrga /// /// See API documentation for more information. /// - public Task Ping(string organizationName, int hookId) + public Task Ping(string org, int hookId) { - Ensure.ArgumentNotNullOrEmptyString(organizationName, "OrganizationName"); + Ensure.ArgumentNotNullOrEmptyString(org, "org"); Ensure.ArgumentNotNull(hookId, "hookId"); - return ApiConnection.Post(ApiUrls.OrganizationHookPing(organizationName, hookId)); + return ApiConnection.Post(ApiUrls.OrganizationHookPing(org, hookId)); } /// @@ -84,12 +84,12 @@ public Task Ping(string organizationName, int hookId) /// /// See API documentation for more information. /// - public Task Delete(string organizationName, int hookId) + public Task Delete(string org, int hookId) { - Ensure.ArgumentNotNullOrEmptyString(organizationName, "organizationName"); + Ensure.ArgumentNotNullOrEmptyString(org, "org"); Ensure.ArgumentNotNull(hookId, "hookId"); - return ApiConnection.Delete(ApiUrls.OrganizationHookById(organizationName, hookId)); + return ApiConnection.Delete(ApiUrls.OrganizationHookById(org, hookId)); } } } \ No newline at end of file diff --git a/Octokit/Clients/OrganizationsClient.cs b/Octokit/Clients/OrganizationsClient.cs index a0ed39bc51..5c7edec952 100644 --- a/Octokit/Clients/OrganizationsClient.cs +++ b/Octokit/Clients/OrganizationsClient.cs @@ -80,16 +80,16 @@ public Task> GetAll(string user) /// /// Update the specified organization with data from . /// - /// The name of the organization to update. + /// The name of the organization to update. /// /// Thrown if the client is not authenticated. /// A - public Task Update(string organizationName, OrganizationUpdate updateRequest) + public Task Update(string org, OrganizationUpdate updateRequest) { - Ensure.ArgumentNotNullOrEmptyString(organizationName, "organizationName"); + Ensure.ArgumentNotNullOrEmptyString(org, "org"); Ensure.ArgumentNotNull(updateRequest, "updateRequest"); - var updateUri = new Uri("orgs/" + organizationName, UriKind.Relative); + var updateUri = new Uri("orgs/" + org, UriKind.Relative); return ApiConnection.Patch(updateUri, updateRequest); } diff --git a/Octokit/Clients/RepositoryHooksClient.cs b/Octokit/Clients/RepositoryHooksClient.cs index 5cb2e43f20..a8cb8f1d59 100644 --- a/Octokit/Clients/RepositoryHooksClient.cs +++ b/Octokit/Clients/RepositoryHooksClient.cs @@ -25,7 +25,7 @@ public Task> GetAll(string owner, string repositor Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); return ApiConnection.GetAll(ApiUrls.RepositoryHooks(owner, repositoryName)); - } + } /// /// Gets a single hook by Id @@ -39,7 +39,6 @@ public Task Get(string owner, string repositoryName, int hookId) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); - Ensure.ArgumentNotNull(hookId, "HookId");//[PleaseReview] Think this should be here return ApiConnection.Get(ApiUrls.RepositoryHookById(owner, repositoryName, hookId)); } @@ -83,7 +82,6 @@ public Task Test(string owner, string repositoryName, int hookId) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); - Ensure.ArgumentNotNull(hookId, "HookId");//[PleaseReview] Think this should be here return ApiConnection.Post(ApiUrls.RepositoryHookTest(owner, repositoryName, hookId)); } @@ -97,7 +95,6 @@ public Task Ping(string owner, string repositoryName, int hookId) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); - Ensure.ArgumentNotNull(hookId, "HookId");//[PleaseReview] Think this should be here return ApiConnection.Post(ApiUrls.RepositoryHookPing(owner, repositoryName, hookId)); } @@ -111,7 +108,6 @@ public Task Delete(string owner, string repositoryName, int hookId) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); - Ensure.ArgumentNotNull(hookId, "HookId");//[PleaseReview] Think this should be here return ApiConnection.Delete(ApiUrls.RepositoryHookById(owner, repositoryName, hookId)); } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index b332f24cc6..25e0afa3fd 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -674,33 +674,33 @@ public static Uri RepositoryHookPing(string owner, string repositoryName, int ho /// /// Returns the that lists the organization hooks for the specified reference. /// - /// The name of the organization + /// The name of the organization /// - public static Uri OrganizationHooks(string organizationName) + public static Uri OrganizationHooks(string org) { - return "orgs/{0}/hooks".FormatUri(organizationName); + return "orgs/{0}/hooks".FormatUri(org); } /// /// Returns the that gets the organization hook for the specified reference. /// - /// The name of the organization + /// The name of the organization /// The identifier of the organization hook /// - public static Uri OrganizationHookById(string organizationName, int hookId) + public static Uri OrganizationHookById(string org, int hookId) { - return "orgs/{0}/hooks/{1}".FormatUri(organizationName, hookId); + return "orgs/{0}/hooks/{1}".FormatUri(org, hookId); } /// /// Returns the that can ping a specified organization hook /// - /// The name of the organization + /// The name of the organization /// The identifier of the organization hook /// - public static Uri OrganizationHookPing(string organizationName, int hookId) + public static Uri OrganizationHookPing(string org, int hookId) { - return "orgs/{0}/hooks/{1}/pings".FormatUri(organizationName, hookId); + return "orgs/{0}/hooks/{1}/pings".FormatUri(org, hookId); } /// diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index f6004fb9c3..293648a732 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -90,6 +90,7 @@ + @@ -112,6 +113,7 @@ + @@ -371,6 +373,11 @@ + + + + + From 2cbc808f06a50ece672a1dfad894761e68af2fa2 Mon Sep 17 00:00:00 2001 From: Anubhav10 Date: Tue, 22 Mar 2016 16:49:23 +0530 Subject: [PATCH 3/8] Removed extra parameter in description of delete function in ObservableOrganizationHooksClient.cs --- Octokit.Reactive/Clients/ObservableOrganizationHooksClient.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Octokit.Reactive/Clients/ObservableOrganizationHooksClient.cs b/Octokit.Reactive/Clients/ObservableOrganizationHooksClient.cs index 6bcc98dd52..3536866e91 100644 --- a/Octokit.Reactive/Clients/ObservableOrganizationHooksClient.cs +++ b/Octokit.Reactive/Clients/ObservableOrganizationHooksClient.cs @@ -84,7 +84,6 @@ public IObservable Ping(string org, int hookId) /// /// Deletes a hook for a organization /// - /// /// /// /// See API documentation for more information. From 948c3cd5a9529965d13882be5bfe9c2af783eab1 Mon Sep 17 00:00:00 2001 From: Anubhav10 Date: Wed, 23 Mar 2016 13:46:34 +0530 Subject: [PATCH 4/8] Making it more consistent Hooks -> Hook fixtures-> Fixtures variable name changes in OrganizationsHooksFixture.cs --- .../Clients/IObservableOrganizationsClient.cs | 2 +- .../ObservableOrganizationHooksClient.cs | 2 +- .../Clients/ObservableOrganizationsClient.cs | 4 +- .../Clients/OrganizationHooksClientTests.cs | 18 ++++---- .../Clients/RepositoryHooksClientTests.cs | 2 +- Octokit.Tests.Integration/Helper.cs | 2 +- .../Octokit.Tests.Integration.csproj | 12 ++--- .../fixtures/OrganizationsHooksCollection.cs | 2 +- .../fixtures/OrganizationsHooksFixture.cs | 16 +++---- .../fixtures/RepositoriesHooksCollection.cs | 2 +- .../fixtures/RepositoriesHooksFixture.cs | 2 +- .../Clients/OrganizationHooksClientTest.cs | 44 +++++++++---------- Octokit/Clients/IOrganizationsClient.cs | 2 +- Octokit/Clients/OrganizationsClient.cs | 4 +- 14 files changed, 57 insertions(+), 57 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableOrganizationsClient.cs b/Octokit.Reactive/Clients/IObservableOrganizationsClient.cs index 6d3355937e..ac487a6908 100644 --- a/Octokit.Reactive/Clients/IObservableOrganizationsClient.cs +++ b/Octokit.Reactive/Clients/IObservableOrganizationsClient.cs @@ -19,7 +19,7 @@ public interface IObservableOrganizationsClient /// A client for GitHub's Organization Hooks API. /// /// See Hooks API documentation for more information. - IObservableOrganizationHooksClient Hooks { get; } + IObservableOrganizationHooksClient Hook { get; } /// /// Returns the specified organization. diff --git a/Octokit.Reactive/Clients/ObservableOrganizationHooksClient.cs b/Octokit.Reactive/Clients/ObservableOrganizationHooksClient.cs index 3536866e91..792a0860d3 100644 --- a/Octokit.Reactive/Clients/ObservableOrganizationHooksClient.cs +++ b/Octokit.Reactive/Clients/ObservableOrganizationHooksClient.cs @@ -14,7 +14,7 @@ public ObservableOrganizationHooksClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, "client"); - _client = client.Organization.Hooks; + _client = client.Organization.Hook; _connection = client.Connection; } diff --git a/Octokit.Reactive/Clients/ObservableOrganizationsClient.cs b/Octokit.Reactive/Clients/ObservableOrganizationsClient.cs index 9ed7661901..551f2fcdcf 100644 --- a/Octokit.Reactive/Clients/ObservableOrganizationsClient.cs +++ b/Octokit.Reactive/Clients/ObservableOrganizationsClient.cs @@ -19,7 +19,7 @@ public ObservableOrganizationsClient(IGitHubClient client) Member = new ObservableOrganizationMembersClient(client); Team = new ObservableTeamsClient(client); - Hooks = new ObservableOrganizationHooksClient(client); + Hook = new ObservableOrganizationHooksClient(client); _client = client.Organization; _connection = client.Connection; @@ -39,7 +39,7 @@ public ObservableOrganizationsClient(IGitHubClient client) /// A client for GitHub's Organization Hooks API. /// /// See Hooks API documentation for more information. - public IObservableOrganizationHooksClient Hooks { get; private set; } + public IObservableOrganizationHooksClient Hook { get; private set; } /// /// Returns the specified organization. diff --git a/Octokit.Tests.Integration/Clients/OrganizationHooksClientTests.cs b/Octokit.Tests.Integration/Clients/OrganizationHooksClientTests.cs index d26615f8a9..fd8aa25f24 100644 --- a/Octokit.Tests.Integration/Clients/OrganizationHooksClientTests.cs +++ b/Octokit.Tests.Integration/Clients/OrganizationHooksClientTests.cs @@ -1,4 +1,4 @@ -using Octokit.Tests.Integration.fixtures; +using Octokit.Tests.Integration.Fixtures; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -24,7 +24,7 @@ public async Task ReturnsAllHooksFromOrganization() { var github = Helper.GetAuthenticatedClient(); - var hooks = await github.Organization.Hooks.GetAll( _fixture.org); + var hooks = await github.Organization.Hook.GetAll( _fixture.org); Assert.Single(hooks); var actualHook = hooks[0]; @@ -48,7 +48,7 @@ public async Task GetHookByCreatedId() { var github = Helper.GetAuthenticatedClient(); - var actualHook = await github.Organization.Hooks.Get(_fixture.org, _fixture.ExpectedHook.Id); + var actualHook = await github.Organization.Hook.Get(_fixture.org, _fixture.ExpectedHook.Id); AssertHook(_fixture.ExpectedHook, actualHook); } @@ -69,7 +69,7 @@ public async Task CreateAWebHookForTestOrganization() var github = Helper.GetAuthenticatedClient(); var url = "http://test.com/example"; var contentType = OrgWebHookContentType.Json; - var secret = "53cr37"; + //var secret = "53cr37"; var config = new Dictionary { { "url", "http://hostname.url" }, @@ -81,7 +81,7 @@ public async Task CreateAWebHookForTestOrganization() Active = false }; - var hook = await github.Organization.Hooks.Create(_fixture.org, parameters.ToRequest()); + var hook = await github.Organization.Hook.Create(_fixture.org, parameters.ToRequest()); var baseHookUrl = CreateExpectedBaseHookUrl(_fixture.org, hook.Id); var webHookConfig = CreateExpectedConfigDictionary(config, url, contentType); @@ -131,7 +131,7 @@ public async Task EditHookTest() Events = new[] { "pull_request" } }; - var actualHook = await github.Organization.Hooks.Edit( _fixture.org, _fixture.ExpectedHook.Id, editOrganizationHook); + var actualHook = await github.Organization.Hook.Edit( _fixture.org, _fixture.ExpectedHook.Id, editOrganizationHook); var expectedConfig = new Dictionary { { "content_type", "json" }, { "url", "http://test.com/example" } }; Assert.Equal(new[] { "commit_comment", "pull_request" }.ToList(), actualHook.Events.ToList()); @@ -155,7 +155,7 @@ public async Task PingACreatedHook() { var github = Helper.GetAuthenticatedClient(); - await github.Organization.Hooks.Ping( _fixture.org, _fixture.ExpectedHook.Id); + await github.Organization.Hook.Ping( _fixture.org, _fixture.ExpectedHook.Id); } } @@ -174,8 +174,8 @@ public async Task DeleteCreatedWebHook() { var github = Helper.GetAuthenticatedClient(); - await github.Organization.Hooks.Delete(_fixture.org, _fixture.ExpectedHook.Id); - var hooks = await github.Organization.Hooks.GetAll( _fixture.org); + await github.Organization.Hook.Delete(_fixture.org, _fixture.ExpectedHook.Id); + var hooks = await github.Organization.Hook.GetAll( _fixture.org); Assert.Empty(hooks); } diff --git a/Octokit.Tests.Integration/Clients/RepositoryHooksClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryHooksClientTests.cs index d0fd6c6e4a..ad6ccbc7f1 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryHooksClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryHooksClientTests.cs @@ -1,4 +1,4 @@ -using Octokit.Tests.Integration.fixtures; +using Octokit.Tests.Integration.Fixtures; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/Octokit.Tests.Integration/Helper.cs b/Octokit.Tests.Integration/Helper.cs index 52eaeb8cb6..1f9a017aa2 100644 --- a/Octokit.Tests.Integration/Helper.cs +++ b/Octokit.Tests.Integration/Helper.cs @@ -149,7 +149,7 @@ public static string MakeNameWithTimestamp(string name) public static Stream LoadFixture(string fileName) { - var key = "Octokit.Tests.Integration.fixtures." + fileName; + var key = "Octokit.Tests.Integration.Fixtures." + fileName; var stream = typeof(Helper).Assembly.GetManifestResourceStream(key); if (stream == null) { diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 8d06ff20e1..f75ddae89b 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -110,10 +110,10 @@ - - - - + + + + @@ -176,7 +176,7 @@ - + Designer @@ -185,7 +185,7 @@ - + diff --git a/Octokit.Tests.Integration/fixtures/OrganizationsHooksCollection.cs b/Octokit.Tests.Integration/fixtures/OrganizationsHooksCollection.cs index 55b22e0885..a247d7ffbe 100644 --- a/Octokit.Tests.Integration/fixtures/OrganizationsHooksCollection.cs +++ b/Octokit.Tests.Integration/fixtures/OrganizationsHooksCollection.cs @@ -1,6 +1,6 @@ using Xunit; -namespace Octokit.Tests.Integration.fixtures +namespace Octokit.Tests.Integration.Fixtures { [CollectionDefinition(Name)] public class OrganizationsHooksCollection : ICollectionFixture diff --git a/Octokit.Tests.Integration/fixtures/OrganizationsHooksFixture.cs b/Octokit.Tests.Integration/fixtures/OrganizationsHooksFixture.cs index c78265ce4f..a3074077dc 100644 --- a/Octokit.Tests.Integration/fixtures/OrganizationsHooksFixture.cs +++ b/Octokit.Tests.Integration/fixtures/OrganizationsHooksFixture.cs @@ -1,32 +1,32 @@ using System; using System.Collections.Generic; -namespace Octokit.Tests.Integration.fixtures +namespace Octokit.Tests.Integration.Fixtures { public class OrganizationsHooksFixture : IDisposable { readonly IGitHubClient _github; readonly OrganizationHook _hook; - private string organizationFixture; + readonly private string _organizationFixture; public OrganizationsHooksFixture() { _github = Helper.GetAuthenticatedClient(); - organizationFixture = Helper.Organization; - _hook = CreateHook(_github, organizationFixture); + _organizationFixture = Helper.Organization; + _hook = CreateHook(_github, _organizationFixture); } - public string org { get { return organizationFixture; } } + public string org { get { return _organizationFixture; } } public OrganizationHook ExpectedHook { get { return _hook; } } public void Dispose() { - _github.Organization.Hooks.Delete(organizationFixture,_hook.Id); + _github.Organization.Hook.Delete(_organizationFixture,_hook.Id); } - static OrganizationHook CreateHook(IGitHubClient github, string _organizationFixture) + static OrganizationHook CreateHook(IGitHubClient github, string orgFixture) { var config = new Dictionary { { "content_type", "json" }, { "url", "http://test.com/example" } }; var parameters = new NewOrganizationHook("web", config) @@ -34,7 +34,7 @@ static OrganizationHook CreateHook(IGitHubClient github, string _organizationFix Events = new[] { "commit_comment" }, Active = false }; - var createdHook = github.Organization.Hooks.Create(_organizationFixture, parameters); + var createdHook = github.Organization.Hook.Create(orgFixture, parameters); return createdHook.Result; } diff --git a/Octokit.Tests.Integration/fixtures/RepositoriesHooksCollection.cs b/Octokit.Tests.Integration/fixtures/RepositoriesHooksCollection.cs index 0d4006f5e7..cff098334b 100644 --- a/Octokit.Tests.Integration/fixtures/RepositoriesHooksCollection.cs +++ b/Octokit.Tests.Integration/fixtures/RepositoriesHooksCollection.cs @@ -1,6 +1,6 @@ using Xunit; -namespace Octokit.Tests.Integration.fixtures +namespace Octokit.Tests.Integration.Fixtures { [CollectionDefinition(Name)] public class RepositoriesHooksCollection : ICollectionFixture diff --git a/Octokit.Tests.Integration/fixtures/RepositoriesHooksFixture.cs b/Octokit.Tests.Integration/fixtures/RepositoriesHooksFixture.cs index cda77a8a87..8a830341e5 100644 --- a/Octokit.Tests.Integration/fixtures/RepositoriesHooksFixture.cs +++ b/Octokit.Tests.Integration/fixtures/RepositoriesHooksFixture.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace Octokit.Tests.Integration.fixtures +namespace Octokit.Tests.Integration.Fixtures { public class RepositoriesHooksFixture : IDisposable { diff --git a/Octokit.Tests/Clients/OrganizationHooksClientTest.cs b/Octokit.Tests/Clients/OrganizationHooksClientTest.cs index 2529d5655d..56c7362583 100644 --- a/Octokit.Tests/Clients/OrganizationHooksClientTest.cs +++ b/Octokit.Tests/Clients/OrganizationHooksClientTest.cs @@ -16,7 +16,7 @@ public void RequestsCorrectUrl() var connection = Substitute.For(); var client = new OrganizationsClient(connection); - client.Hooks.GetAll("org"); + client.Hook.GetAll("org"); connection.Received().GetAll(Arg.Is(u => u.ToString() == "orgs/org/hooks")); } @@ -26,14 +26,14 @@ public async Task EnsuresNonNullArguments() { var client = new OrganizationsClient(Substitute.For()); - await Assert.ThrowsAsync(() => client.Hooks.GetAll(null)); + await Assert.ThrowsAsync(() => client.Hook.GetAll(null)); } [Fact] public void EnsuresNonEmptyArguments() { var client = new OrganizationsClient(Substitute.For()); - Assert.ThrowsAsync(() => client.Hooks.GetAll("")); + Assert.ThrowsAsync(() => client.Hook.GetAll("")); } } @@ -45,7 +45,7 @@ public void RequestsCorrectUrl() var connection = Substitute.For(); var client = new OrganizationsClient(connection); - client.Hooks.Get("org", 12345678); + client.Hook.Get("org", 12345678); connection.Received().Get(Arg.Is(u => u.ToString() == "orgs/org/hooks/12345678")); } @@ -55,14 +55,14 @@ public async Task EnsuresNonNullArguments() { var client = new OrganizationsClient(Substitute.For()); - await Assert.ThrowsAsync(() => client.Hooks.Get(null, 123)); + await Assert.ThrowsAsync(() => client.Hook.Get(null, 123)); } [Fact] public void EnsuresNonEmptyArguments() { var client = new OrganizationsClient(Substitute.For()); - Assert.ThrowsAsync(() => client.Hooks.Get("",123)); + Assert.ThrowsAsync(() => client.Hook.Get("",123)); } } @@ -75,7 +75,7 @@ public void RequestsCorrectUrl() var client = new OrganizationsClient(connection); var hook = new NewOrganizationHook("name", new Dictionary { { "config", "" } }); - client.Hooks.Create("org", hook); + client.Hook.Create("org", hook); connection.Received().Post(Arg.Is(u => u.ToString() == "orgs/org/hooks"), hook); } @@ -86,8 +86,8 @@ public async Task EnsuresNonNullArguments() var client = new OrganizationsClient(Substitute.For()); var config = new Dictionary { { "config", "" } }; - await Assert.ThrowsAsync(() => client.Hooks.Create(null, new NewOrganizationHook("name", config))); - await Assert.ThrowsAsync(() => client.Hooks.Create("name", null)); + await Assert.ThrowsAsync(() => client.Hook.Create(null, new NewOrganizationHook("name", config))); + await Assert.ThrowsAsync(() => client.Hook.Create("name", null)); } [Fact] @@ -95,7 +95,7 @@ public void EnsuresNonEmptyArguments() { var client = new OrganizationsClient(Substitute.For()); var config = new Dictionary { { "url", "" } }; - Assert.ThrowsAsync(() => client.Hooks.Create("", new NewOrganizationHook("name", config))); + Assert.ThrowsAsync(() => client.Hook.Create("", new NewOrganizationHook("name", config))); } [Fact] @@ -105,7 +105,7 @@ public void UsesTheSuppliedHook() var client = new OrganizationsClient(connection); var newOrganizationHook = new NewOrganizationHook("name", new Dictionary { { "config", "" } }); - client.Hooks.Create("org", newOrganizationHook); + client.Hook.Create("org", newOrganizationHook); connection.Received().Post(Arg.Any(), newOrganizationHook); } @@ -120,7 +120,7 @@ public void RequestsCorrectUrl() var client = new OrganizationsClient(connection); var hook = new EditOrganizationHook(); - client.Hooks.Edit("org", 12345678, hook); + client.Hook.Edit("org", 12345678, hook); connection.Received().Patch(Arg.Is(u => u.ToString() == "orgs/org/hooks/12345678"), hook); } @@ -130,15 +130,15 @@ public async Task EnsuresNonNullArguments() { var client = new OrganizationsClient(Substitute.For()); - await Assert.ThrowsAsync(() => client.Hooks.Edit( null, 12345678, new EditOrganizationHook())); - await Assert.ThrowsAsync(() => client.Hooks.Edit( "name", 12345678, null)); + await Assert.ThrowsAsync(() => client.Hook.Edit( null, 12345678, new EditOrganizationHook())); + await Assert.ThrowsAsync(() => client.Hook.Edit( "name", 12345678, null)); } [Fact] public void EnsuresNonEmptyArguments() { var client = new OrganizationsClient(Substitute.For()); - Assert.ThrowsAsync(() => client.Hooks.Edit("", 123, new EditOrganizationHook())); + Assert.ThrowsAsync(() => client.Hook.Edit("", 123, new EditOrganizationHook())); } [Fact] @@ -148,7 +148,7 @@ public void UsesTheSuppliedHook() var client = new OrganizationsClient(connection); var editOrganizationHook = new EditOrganizationHook() { Active = false }; - client.Hooks.Edit("org", 12345678, editOrganizationHook); + client.Hook.Edit("org", 12345678, editOrganizationHook); connection.Received().Patch(Arg.Any(), editOrganizationHook); } @@ -161,14 +161,14 @@ public async Task EnsuresNonNullArguments() { var client = new OrganizationsClient(Substitute.For()); - await Assert.ThrowsAsync(() => client.Hooks.Ping(null, 12345678)); + await Assert.ThrowsAsync(() => client.Hook.Ping(null, 12345678)); } [Fact] public void EnsuresNonEmptyArguments() { var client = new OrganizationsClient(Substitute.For()); - Assert.ThrowsAsync(() => client.Hooks.Ping("", 123)); + Assert.ThrowsAsync(() => client.Hook.Ping("", 123)); } [Fact] @@ -177,7 +177,7 @@ public void RequestsCorrectUrl() var connection = Substitute.For(); var client = new OrganizationsClient(connection); - client.Hooks.Ping("org", 12345678); + client.Hook.Ping("org", 12345678); connection.Received().Post(Arg.Is(u => u.ToString() == "orgs/org/hooks/12345678/pings")); } @@ -191,7 +191,7 @@ public void RequestsCorrectUrl() var connection = Substitute.For(); var client = new OrganizationsClient(connection); - client.Hooks.Delete("org", 12345678); + client.Hook.Delete("org", 12345678); connection.Received().Delete(Arg.Is(u => u.ToString() == "orgs/org/hooks/12345678")); } @@ -201,14 +201,14 @@ public async Task EnsuresNonNullArguments() { var client = new OrganizationsClient(Substitute.For()); - await Assert.ThrowsAsync(() => client.Hooks.Delete(null, 12345678)); + await Assert.ThrowsAsync(() => client.Hook.Delete(null, 12345678)); } [Fact] public void EnsuresNonEmptyArguments() { var client = new OrganizationsClient(Substitute.For()); - Assert.ThrowsAsync(() => client.Hooks.Delete("", 123)); + Assert.ThrowsAsync(() => client.Hook.Delete("", 123)); } } diff --git a/Octokit/Clients/IOrganizationsClient.cs b/Octokit/Clients/IOrganizationsClient.cs index cdb1a82e6e..368bed22b0 100644 --- a/Octokit/Clients/IOrganizationsClient.cs +++ b/Octokit/Clients/IOrganizationsClient.cs @@ -28,7 +28,7 @@ public interface IOrganizationsClient /// A client for GitHub's Organization Hooks API. /// /// See Hooks API documentation for more information. - IOrganizationHooksClient Hooks { get; } + IOrganizationHooksClient Hook { get; } /// /// Returns the specified . diff --git a/Octokit/Clients/OrganizationsClient.cs b/Octokit/Clients/OrganizationsClient.cs index 5c7edec952..a74573d587 100644 --- a/Octokit/Clients/OrganizationsClient.cs +++ b/Octokit/Clients/OrganizationsClient.cs @@ -22,7 +22,7 @@ public OrganizationsClient(IApiConnection apiConnection) : base(apiConnection) { Member = new OrganizationMembersClient(apiConnection); Team = new TeamsClient(apiConnection); - Hooks = new OrganizationHooksClient(apiConnection); + Hook = new OrganizationHooksClient(apiConnection); } /// @@ -53,7 +53,7 @@ public Task Get(string org) /// A client for GitHub's Organization Hooks API. /// /// See Hooks API documentation for more information. - public IOrganizationHooksClient Hooks { get; private set; } + public IOrganizationHooksClient Hook { get; private set; } /// /// Returns all s for the current user. From 26fc1ce2ffde9a0742207258b0694c4dbf0b77c5 Mon Sep 17 00:00:00 2001 From: Martin Dawson Date: Sun, 7 Oct 2018 18:03:57 +0200 Subject: [PATCH 5/8] fixed merge --- .../Clients/IObservableOrganizationsClient.cs | 4 +- .../IObservableRepositoryHooksClient.cs | 12 - .../Clients/ObservableOrganizationsClient.cs | 15 +- .../ObservableRepositoryHooksClient.cs | 12 - Octokit.Reactive/Octokit.Reactive-Mono.csproj | 189 ------- .../Octokit.Reactive-MonoAndroid.csproj | 197 ------- .../Octokit.Reactive-Monotouch.csproj | 193 ------- Octokit.Reactive/Octokit.Reactive.csproj | 161 ------ Octokit.Tests.Integration/Helper.cs | 7 +- .../Octokit.Tests.Integration.csproj | 102 ---- Octokit.Tests/Octokit.Tests.csproj | 213 -------- Octokit.Tests/packages.Octokit.Tests.config | 16 - Octokit/Clients/IOrganizationsClient.cs | 5 +- Octokit/Clients/IRepositoryHooksClient.cs | 12 - Octokit/Clients/OrganizationsClient.cs | 10 +- Octokit/Clients/RepositoryHooksClient.cs | 12 - Octokit/Octokit-Mono.csproj | 470 ---------------- Octokit/Octokit-MonoAndroid.csproj | 479 ----------------- Octokit/Octokit-Monotouch.csproj | 476 ----------------- Octokit/Octokit-Portable.csproj | 501 ------------------ Octokit/Octokit-netcore45.csproj | 486 ----------------- Octokit/Octokit.csproj | 440 --------------- 22 files changed, 8 insertions(+), 4004 deletions(-) delete mode 100644 Octokit.Reactive/Octokit.Reactive-Mono.csproj delete mode 100644 Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj delete mode 100644 Octokit.Reactive/Octokit.Reactive-Monotouch.csproj delete mode 100644 Octokit.Tests/packages.Octokit.Tests.config delete mode 100644 Octokit/Octokit-Mono.csproj delete mode 100644 Octokit/Octokit-MonoAndroid.csproj delete mode 100644 Octokit/Octokit-Monotouch.csproj delete mode 100644 Octokit/Octokit-Portable.csproj delete mode 100644 Octokit/Octokit-netcore45.csproj diff --git a/Octokit.Reactive/Clients/IObservableOrganizationsClient.cs b/Octokit.Reactive/Clients/IObservableOrganizationsClient.cs index 4e28d7e8bf..05743fe06a 100644 --- a/Octokit.Reactive/Clients/IObservableOrganizationsClient.cs +++ b/Octokit.Reactive/Clients/IObservableOrganizationsClient.cs @@ -16,16 +16,14 @@ public interface IObservableOrganizationsClient IObservableTeamsClient Team { get; } /// -<<<<<<< HEAD /// A client for GitHub's Organization Hooks API. /// /// See Hooks API documentation for more information. IObservableOrganizationHooksClient Hook { get; } -======= + /// Returns a client to manage outside collaborators of an organization. /// IObservableOrganizationOutsideCollaboratorsClient OutsideCollaborator { get; } ->>>>>>> master /// /// Returns the specified organization. diff --git a/Octokit.Reactive/Clients/IObservableRepositoryHooksClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryHooksClient.cs index 9da6b835ed..e6daa3d909 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryHooksClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryHooksClient.cs @@ -15,16 +15,10 @@ public interface IObservableRepositoryHooksClient /// /// Gets the list of hooks defined for a repository /// -<<<<<<< HEAD - /// See API documentation for more information. - /// - IObservable GetAll(string owner, string repositoryName); -======= /// The repository's owner /// The repository's name /// See API documentation for more information. IObservable GetAll(string owner, string name); ->>>>>>> master /// /// Gets the list of hooks defined for a repository @@ -138,11 +132,6 @@ public interface IObservableRepositoryHooksClient /// /// This will trigger a ping event to be sent to the hook. /// -<<<<<<< HEAD - /// See API documentation for more information. - /// - IObservable Ping(string owner, string repositoryName, int hookId); -======= /// The Id of the repository /// The repository's hook id /// See API documentation for more information. @@ -156,7 +145,6 @@ public interface IObservableRepositoryHooksClient /// The repository's hook id /// See API documentation for more information. IObservable Delete(string owner, string name, int hookId); ->>>>>>> master /// /// Deletes a hook for a repository diff --git a/Octokit.Reactive/Clients/ObservableOrganizationsClient.cs b/Octokit.Reactive/Clients/ObservableOrganizationsClient.cs index c9d9e0e927..aaefb0ce7d 100644 --- a/Octokit.Reactive/Clients/ObservableOrganizationsClient.cs +++ b/Octokit.Reactive/Clients/ObservableOrganizationsClient.cs @@ -19,11 +19,8 @@ public ObservableOrganizationsClient(IGitHubClient client) Member = new ObservableOrganizationMembersClient(client); Team = new ObservableTeamsClient(client); -<<<<<<< HEAD Hook = new ObservableOrganizationHooksClient(client); -======= OutsideCollaborator = new ObservableOrganizationOutsideCollaboratorsClient(client); ->>>>>>> master _client = client.Organization; _connection = client.Connection; @@ -40,16 +37,14 @@ public ObservableOrganizationsClient(IGitHubClient client) public IObservableTeamsClient Team { get; private set; } /// -<<<<<<< HEAD /// A client for GitHub's Organization Hooks API. /// /// See Hooks API documentation for more information. public IObservableOrganizationHooksClient Hook { get; private set; } -======= + /// Returns a client to manage outside collaborators of an organization. /// public IObservableOrganizationOutsideCollaboratorsClient OutsideCollaborator { get; private set; } ->>>>>>> master /// /// Returns the specified organization. @@ -142,14 +137,10 @@ public IObservable GetAll(OrganizationRequest request) /// A public IObservable Update(string org, OrganizationUpdate updateRequest) { -<<<<<<< HEAD - return _client.Update(org, updateRequest).ToObservable(); -======= - Ensure.ArgumentNotNullOrEmptyString(organizationName, nameof(organizationName)); + Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); Ensure.ArgumentNotNull(updateRequest, nameof(updateRequest)); - return _client.Update(organizationName, updateRequest).ToObservable(); ->>>>>>> master + return _client.Update(org, updateRequest).ToObservable(); } } diff --git a/Octokit.Reactive/Clients/ObservableRepositoryHooksClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryHooksClient.cs index 46ea498d0f..5e7ee9c893 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryHooksClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryHooksClient.cs @@ -27,16 +27,10 @@ public ObservableRepositoryHooksClient(IGitHubClient client) /// /// Gets the list of hooks defined for a repository /// -<<<<<<< HEAD - /// See API documentation for more information. - /// - public IObservable GetAll(string owner, string repositoryName) -======= /// The repository's owner /// The repository's name /// See API documentation for more information. public IObservable GetAll(string owner, string name) ->>>>>>> master { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); @@ -202,17 +196,11 @@ public IObservable Test(long repositoryId, int hookId) /// /// This will trigger a ping event to be sent to the hook. /// -<<<<<<< HEAD - /// See API documentation for more information. - /// - public IObservable Ping(string owner, string repositoryName, int hookId) -======= /// The repository's owner /// The repository's name /// The repository's hook id /// See API documentation for more information. public IObservable Ping(string owner, string name, int hookId) ->>>>>>> master { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); diff --git a/Octokit.Reactive/Octokit.Reactive-Mono.csproj b/Octokit.Reactive/Octokit.Reactive-Mono.csproj deleted file mode 100644 index ab9496e777..0000000000 --- a/Octokit.Reactive/Octokit.Reactive-Mono.csproj +++ /dev/null @@ -1,189 +0,0 @@ - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {59AB16A2-5ED1-480F-80A1-D1D05D6C1BE4} - Library - Octokit.Reactive - Octokit.Reactive - v4.5 - 5 - - - true - full - false - obj\Debug\Mono - bin\Debug\Mono - DEBUG; - prompt - 4 - false - - - full - true - obj\Release\Mono - bin\Release\Mono - prompt - 4 - false - - - - - - ..\packages\Rx-Core.2.1.30214.0\lib\Net40\System.Reactive.Core.dll - - - ..\packages\Rx-Interfaces.2.1.30214.0\lib\Net40\System.Reactive.Interfaces.dll - - - ..\packages\Rx-Linq.2.1.30214.0\lib\Net40\System.Reactive.Linq.dll - - - ..\packages\Rx-PlatformServices.2.1.30214.0\lib\Net40\System.Reactive.PlatformServices.dll - - - - - Helpers\Ensure.cs - - - Helpers\Pagination.cs - - - Properties\SolutionInfo.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {49EF16A2-5ED1-480F-80A1-D1D05D6C1BE4} - Octokit-Mono - - - diff --git a/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj b/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj deleted file mode 100644 index e1382a00c4..0000000000 --- a/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj +++ /dev/null @@ -1,197 +0,0 @@ - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {B24FC6FF-0801-4FC7-8AFF-05DE2C923869} - {EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Library - Octokit.Reactive - Resources - Assets - False - Octokit.Reactive - 5 - - - true - full - false - obj\Debug\MonoAndroid - bin\Debug\MonoAndroid - DEBUG; - prompt - 4 - None - false - - - full - true - obj\Release\MonoAndroid - bin\Release\MonoAndroid - prompt - 4 - false - false - - - - - - - - - ..\ext\Monoandroid\System.Reactive.Core.dll - - - ..\ext\Monoandroid\System.Reactive.Interfaces.dll - - - ..\ext\Monoandroid\System.Reactive.Linq.dll - - - ..\ext\Monoandroid\System.Reactive.PlatformServices.dll - - - - - Helpers\Ensure.cs - - - Helpers\Pagination.cs - - - Properties\SolutionInfo.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {B24FC6FA-B80C-4EC7-8AFF-05DE2C923869} - Octokit-MonoAndroid - - - diff --git a/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj b/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj deleted file mode 100644 index 094bd86b42..0000000000 --- a/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj +++ /dev/null @@ -1,193 +0,0 @@ - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {F4ADA431-8344-4B36-9A0B-C4D96AF53908} - {6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Library - Octokit.Reactive - Resources - Octokit.Reactive - 5 - - - true - full - false - obj\Debug\Monotouch - bin\Debug\Monotouch - DEBUG; - prompt - 4 - false - - - full - true - obj\Release\Monotouch - bin\Release\Monotouch - prompt - 4 - false - - - - - - - - - ..\ext\Monotouch\System.Reactive.Core.dll - - - ..\ext\Monotouch\System.Reactive.Interfaces.dll - - - ..\ext\Monotouch\System.Reactive.Linq.dll - - - ..\ext\Monotouch\System.Reactive.PlatformServices.dll - - - - - Helpers\Ensure.cs - - - Helpers\Pagination.cs - - - Properties\SolutionInfo.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {E4AD1421-8844-4236-9A0B-C4D96AF53908} - Octokit-Monotouch - - - diff --git a/Octokit.Reactive/Octokit.Reactive.csproj b/Octokit.Reactive/Octokit.Reactive.csproj index ae62ad4d94..33b4f859b7 100644 --- a/Octokit.Reactive/Octokit.Reactive.csproj +++ b/Octokit.Reactive/Octokit.Reactive.csproj @@ -23,168 +23,7 @@ -<<<<<<< HEAD - - - - - - False - ..\packages\Rx-Core.2.2.5\lib\net45\System.Reactive.Core.dll - - - False - ..\packages\Rx-Interfaces.2.2.5\lib\net45\System.Reactive.Interfaces.dll - - - False - ..\packages\Rx-Linq.2.2.5\lib\net45\System.Reactive.Linq.dll - - - False - ..\packages\Rx-PlatformServices.2.2.5\lib\net45\System.Reactive.PlatformServices.dll - - - - - - - - - - Helpers\Ensure.cs - - - Helpers\Pagination.cs - - - Properties\SolutionInfo.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -======= ->>>>>>> master diff --git a/Octokit.Tests.Integration/Helper.cs b/Octokit.Tests.Integration/Helper.cs index 1f229c97bf..397926fdc8 100644 --- a/Octokit.Tests.Integration/Helper.cs +++ b/Octokit.Tests.Integration/Helper.cs @@ -244,13 +244,8 @@ public static string MakeNameWithTimestamp(string name) public static Stream LoadFixture(string fileName) { -<<<<<<< HEAD - var key = "Octokit.Tests.Integration.Fixtures." + fileName; - var stream = typeof(Helper).Assembly.GetManifestResourceStream(key); -======= var key = "Octokit.Tests.Integration.fixtures." + fileName; var stream = typeof(Helper).GetTypeInfo().Assembly.GetManifestResourceStream(key); ->>>>>>> master if (stream == null) { throw new InvalidOperationException( @@ -259,7 +254,7 @@ public static Stream LoadFixture(string fileName) return stream; } - public static IGitHubClient GetAuthenticatedClient(bool useSecondUser = false) + public static IGitHubClient GetAuthenticatedClient(bool useSecondUser = false)# { return new GitHubClient(new ProductHeaderValue("OctokitTests"), TargetUrl) { diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 9bc85d1d11..c38f326981 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -24,98 +24,9 @@ -<<<<<<< HEAD - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -======= ->>>>>>> master @@ -125,32 +36,19 @@ -<<<<<<< HEAD - - - - Designer - -======= ->>>>>>> master -<<<<<<< HEAD - - -======= 0.0.2 ->>>>>>> master diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index e1f3956dc1..d53e8befbe 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -20,212 +20,16 @@ -<<<<<<< HEAD - - ..\packages\NSubstitute.1.9.2.0\lib\net45\NSubstitute.dll - True - - - - - - - ..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Extensions.dll - True - - - ..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Primitives.dll - True - - - - ..\packages\Rx-Core.2.2.5\lib\net45\System.Reactive.Core.dll - True - - - ..\packages\Rx-Interfaces.2.2.5\lib\net45\System.Reactive.Interfaces.dll - True - - - ..\packages\Rx-Linq.2.2.5\lib\net45\System.Reactive.Linq.dll - True - - - - - ..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll - - - ..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll - True - - - ..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll - True - - - ..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll - True - -======= PreserveNewest ->>>>>>> master -<<<<<<< HEAD - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Code - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -======= ->>>>>>> master @@ -237,27 +41,10 @@ -<<<<<<< HEAD - - - - - - - - - - - - - Designer - -======= ->>>>>>> master diff --git a/Octokit.Tests/packages.Octokit.Tests.config b/Octokit.Tests/packages.Octokit.Tests.config deleted file mode 100644 index 89dd0f6d08..0000000000 --- a/Octokit.Tests/packages.Octokit.Tests.config +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Octokit/Clients/IOrganizationsClient.cs b/Octokit/Clients/IOrganizationsClient.cs index 2ed8fb7690..faaf082f3d 100644 --- a/Octokit/Clients/IOrganizationsClient.cs +++ b/Octokit/Clients/IOrganizationsClient.cs @@ -25,16 +25,15 @@ public interface IOrganizationsClient ITeamsClient Team { get; } /// -<<<<<<< HEAD /// A client for GitHub's Organization Hooks API. /// /// See Hooks API documentation for more information. IOrganizationHooksClient Hook { get; } -======= + + /// /// Returns a client to manage outside collaborators of an organization. /// IOrganizationOutsideCollaboratorsClient OutsideCollaborator { get; } ->>>>>>> master /// /// Returns the specified . diff --git a/Octokit/Clients/IRepositoryHooksClient.cs b/Octokit/Clients/IRepositoryHooksClient.cs index 3558a13847..c7899ff563 100644 --- a/Octokit/Clients/IRepositoryHooksClient.cs +++ b/Octokit/Clients/IRepositoryHooksClient.cs @@ -15,11 +15,6 @@ public interface IRepositoryHooksClient /// /// Gets the list of hooks defined for a repository /// -<<<<<<< HEAD - /// See API documentation for more information. - /// - Task> GetAll(string owner, string repositoryName); -======= /// The repository's owner /// The repository's name /// See API documentation for more information. @@ -58,7 +53,6 @@ public interface IRepositoryHooksClient /// See API documentation for more information. [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "This is ok; we're matching HTTP verbs not keywords")] Task Get(string owner, string name, int hookId); ->>>>>>> master /// /// Gets a single hook by Id @@ -138,11 +132,6 @@ public interface IRepositoryHooksClient /// /// This will trigger a ping event to be sent to the hook. /// -<<<<<<< HEAD - /// See API documentation for more information. - /// - Task Ping(string owner, string repositoryName, int hookId); -======= /// The Id of the repository /// The repository's hook id /// See API documentation for more information. @@ -156,7 +145,6 @@ public interface IRepositoryHooksClient /// The repository's hook id /// See API documentation for more information. Task Delete(string owner, string name, int hookId); ->>>>>>> master /// /// Deletes a hook for a repository diff --git a/Octokit/Clients/OrganizationsClient.cs b/Octokit/Clients/OrganizationsClient.cs index 7ba1167447..661d463989 100644 --- a/Octokit/Clients/OrganizationsClient.cs +++ b/Octokit/Clients/OrganizationsClient.cs @@ -20,11 +20,8 @@ public OrganizationsClient(IApiConnection apiConnection) : base(apiConnection) { Member = new OrganizationMembersClient(apiConnection); Team = new TeamsClient(apiConnection); -<<<<<<< HEAD Hook = new OrganizationHooksClient(apiConnection); -======= OutsideCollaborator = new OrganizationOutsideCollaboratorsClient(apiConnection); ->>>>>>> master } /// @@ -147,13 +144,8 @@ public Task> GetAll(OrganizationRequest request) /// A public Task Update(string org, OrganizationUpdate updateRequest) { -<<<<<<< HEAD - Ensure.ArgumentNotNullOrEmptyString(org, "org"); - Ensure.ArgumentNotNull(updateRequest, "updateRequest"); -======= - Ensure.ArgumentNotNullOrEmptyString(organizationName, nameof(organizationName)); + Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); Ensure.ArgumentNotNull(updateRequest, nameof(updateRequest)); ->>>>>>> master var updateUri = new Uri("orgs/" + org, UriKind.Relative); diff --git a/Octokit/Clients/RepositoryHooksClient.cs b/Octokit/Clients/RepositoryHooksClient.cs index 7ef8b8aec5..81f4c9c7db 100644 --- a/Octokit/Clients/RepositoryHooksClient.cs +++ b/Octokit/Clients/RepositoryHooksClient.cs @@ -23,16 +23,10 @@ public RepositoryHooksClient(IApiConnection apiConnection) /// /// Gets the list of hooks defined for a repository /// -<<<<<<< HEAD - /// See API documentation for more information. - /// - public Task> GetAll(string owner, string repositoryName) -======= /// The repository's owner /// The repository's name /// See API documentation for more information. public Task> GetAll(string owner, string name) ->>>>>>> master { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); @@ -198,17 +192,11 @@ public Task Test(long repositoryId, int hookId) /// /// This will trigger a ping event to be sent to the hook. /// -<<<<<<< HEAD - /// See API documentation for more information. - /// - public Task Ping(string owner, string repositoryName, int hookId) -======= /// The repository's owner /// The repository's name /// The repository's hook id /// See API documentation for more information. public Task Ping(string owner, string name, int hookId) ->>>>>>> master { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj deleted file mode 100644 index 741d01223a..0000000000 --- a/Octokit/Octokit-Mono.csproj +++ /dev/null @@ -1,470 +0,0 @@ - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {49EF16A2-5ED1-480F-80A1-D1D05D6C1BE4} - Library - Octokit - Octokit - v4.5 - 5 - - - true - full - false - obj\Debug\Mono - bin\Debug\Mono - TRACE;DEBUG;CODE_ANALYSIS;SIMPLE_JSON_OBJARRAYINTERNAL;SIMPLE_JSON_INTERNAL;NET_45;SIMPLE_JSON_READONLY_COLLECTIONS - prompt - 4 - false - - - full - true - obj\Release\Mono - TRACE;CODE_ANALYSIS;SIMPLE_JSON_OBJARRAYINTERNAL;SIMPLE_JSON_INTERNAL;NET_45;SIMPLE_JSON_READONLY_COLLECTIONS - bin\Release\Mono - prompt - 4 - false - bin\Release\Mono\Octokit.XML - 1591 - - - - - - - - Properties\SolutionInfo.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Code - - - - Code - - - - - - - Code - - - - - - Code - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj deleted file mode 100644 index c2688cb750..0000000000 --- a/Octokit/Octokit-MonoAndroid.csproj +++ /dev/null @@ -1,479 +0,0 @@ - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {B24FC6FA-B80C-4EC7-8AFF-05DE2C923869} - {EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Library - Octokit - Resources - Assets - False - Octokit - 5 - - - true - full - false - obj\Debug\MonoAndroid - bin\Debug\MonoAndroid - DEBUG; - prompt - 4 - TRACE;DEBUG;CODE_ANALYSIS;CODE_ANALYSIS;SIMPLE_JSON_OBJARRAYINTERNAL;SIMPLE_JSON_INTERNAL;NET_45 - None - false - - - full - true - obj\Release\MonoAndroid - bin\Release\MonoAndroid - TRACE;CODE_ANALYSIS;CODE_ANALYSIS;SIMPLE_JSON_OBJARRAYINTERNAL;SIMPLE_JSON_INTERNAL;NET_45 - prompt - 4 - false - false - - - - - - - - - - - Properties\SolutionInfo.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Code - - - - Code - - - - - - - Code - - - - - - Code - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj deleted file mode 100644 index c08b17229c..0000000000 --- a/Octokit/Octokit-Monotouch.csproj +++ /dev/null @@ -1,476 +0,0 @@ - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {E4AD1421-8844-4236-9A0B-C4D96AF53908} - {6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Library - Octokit - Resources - Octokit - 5 - - - true - full - false - obj\Debug\Monotouch - TRACE;DEBUG;CODE_ANALYSIS;CODE_ANALYSIS;SIMPLE_JSON_OBJARRAYINTERNAL;SIMPLE_JSON_INTERNAL;NET_45 - bin\Debug\Monotouch - TRACE;DEBUG;CODE_ANALYSIS;CODE_ANALYSIS;SIMPLE_JSON_OBJARRAYINTERNAL;SIMPLE_JSON_INTERNAL;NET_45 - prompt - 4 - false - - - full - true - TRACE;CODE_ANALYSIS;CODE_ANALYSIS;SIMPLE_JSON_OBJARRAYINTERNAL;SIMPLE_JSON_INTERNAL;NET_45 - obj\Release\Monotouch - bin\Release\Monotouch - prompt - 4 - false - - - - - - - - - - - Properties\SolutionInfo.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Code - - - - Code - - - - - - - Code - - - - - - Code - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Octokit/Octokit-Portable.csproj b/Octokit/Octokit-Portable.csproj deleted file mode 100644 index ba482813c2..0000000000 --- a/Octokit/Octokit-Portable.csproj +++ /dev/null @@ -1,501 +0,0 @@ - - - - - 11.0 - Debug - AnyCPU - {DDB20481-E17D-4E0A-B2C0-FFFF78D4ED71} - Library - Properties - Octokit - Octokit - v4.5 - Profile259 - 512 - en-US - {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 5 - - - true - full - false - bin\Debug\Portable\ - TRACE;DEBUG;CODE_ANALYSIS;NETFX_CORE;CODE_ANALYSIS;SIMPLE_JSON_OBJARRAYINTERNAL;SIMPLE_JSON_INTERNAL;NET_45;PORTABLE;SIMPLE_JSON_READONLY_COLLECTIONS - prompt - 4 - ..\Octokit.ruleset - false - - - pdbonly - true - bin\Release\Portable\ - TRACE;NETFX_CORE;CODE_ANALYSIS;SIMPLE_JSON_OBJARRAYINTERNAL;SIMPLE_JSON_INTERNAL;NET_45;PORTABLE;SIMPLE_JSON_READONLY_COLLECTIONS - prompt - 4 - false - ..\Octokit.ruleset - bin\Release\Portable\Octokit.XML - 1591 - - - - Properties\SolutionInfo.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Code - - - - - - - - Code - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CustomDictionary.xml - - - - - ..\packages\Microsoft.Net.Http.2.2.29\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.dll - True - - - ..\packages\Microsoft.Net.Http.2.2.29\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.Extensions.dll - True - - - ..\packages\Microsoft.Net.Http.2.2.29\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.Primitives.dll - True - - - - - - - - - - - - - \ No newline at end of file diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj deleted file mode 100644 index 851fe01b52..0000000000 --- a/Octokit/Octokit-netcore45.csproj +++ /dev/null @@ -1,486 +0,0 @@ - - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {C8BC13B6-3FA3-4716-827D-E7706F976FE1} - Library - Properties - Octokit - Octokit - - - 512 - en-US - {BC8A1FFA-BEE3-4634-8014-F334798102B3};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - en-US - 5 - 8.1 - 12 - - - true - full - false - obj\Debug\NetCore45 - bin\Debug\NetCore45 - TRACE;DEBUG;CODE_ANALYSIS;NETFX_CORE;CODE_ANALYSIS;SIMPLE_JSON_OBJARRAYINTERNAL;SIMPLE_JSON_INTERNAL;NET_45;SIMPLE_JSON_READONLY_COLLECTIONS - prompt - 4 - true - true - ..\Octokit.ruleset - - - pdbonly - true - obj\Release\NetCore45 - bin\Release\NetCore45\ - TRACE;NETFX_CORE;CODE_ANALYSIS;SIMPLE_JSON_OBJARRAYINTERNAL;SIMPLE_JSON_INTERNAL;NET_45;SIMPLE_JSON_READONLY_COLLECTIONS - prompt - 4 - true - ..\Octokit.ruleset - bin\Release\NetCore45\Octokit.XML - 1591 - - - - Properties\SolutionInfo.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Code - - - - - - - - Code - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CustomDictionary.xml - - - - - \ No newline at end of file diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 894f8ea343..a8e824d5fe 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -34,446 +34,6 @@ -<<<<<<< HEAD - - - - - - - Properties\SolutionInfo.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Code - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Code - - - - Code - - - - - - - Code - - - - - - Code - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CustomDictionary.xml - -======= ->>>>>>> master From 97b67d52aeabed11eba027f3f63eb75f318bdd2d Mon Sep 17 00:00:00 2001 From: Martin Dawson Date: Sun, 7 Oct 2018 18:15:01 +0200 Subject: [PATCH 6/8] fixed trailing error --- Octokit.Tests.Integration/Helper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit.Tests.Integration/Helper.cs b/Octokit.Tests.Integration/Helper.cs index 397926fdc8..f005e0ffb9 100644 --- a/Octokit.Tests.Integration/Helper.cs +++ b/Octokit.Tests.Integration/Helper.cs @@ -254,7 +254,7 @@ public static Stream LoadFixture(string fileName) return stream; } - public static IGitHubClient GetAuthenticatedClient(bool useSecondUser = false)# + public static IGitHubClient GetAuthenticatedClient(bool useSecondUser = false) { return new GitHubClient(new ProductHeaderValue("OctokitTests"), TargetUrl) { From 4b74a52180f46492cbc74f19eb4161b86dbfefb0 Mon Sep 17 00:00:00 2001 From: Martin Dawson Date: Sun, 7 Oct 2018 20:06:17 +0200 Subject: [PATCH 7/8] fixed tests --- .../IObservableOrganizationHooksClient.cs | 27 ++- .../Clients/IObservableOrganizationsClient.cs | 3 +- .../ObservableOrganizationHooksClient.cs | 52 +++-- .../Clients/ObservableOrganizationsClient.cs | 1 + .../Clients/OrganizationHooksClientTests.cs | 66 ++++++- .../ObservableRepositoryHooksClientTests.cs | 2 +- .../fixtures/OrganizationsHooksFixture.cs | 19 +- .../Clients/OrganizationHooksClientTest.cs | 48 ++++- .../Models/NewOrganizationWebHookTests.cs | 77 ++++++-- .../ObservableOrganizationHooksClientTests.cs | 187 ++++++++++++++++++ Octokit/Clients/IOrganizationHooksClient.cs | 34 +++- Octokit/Clients/OrganizationHooksClient.cs | 38 ++-- .../OrganizationWebHookConfigException.cs | 60 ------ Octokit/Models/Request/NewOrganizationHook.cs | 2 +- .../Models/Request/NewOrganizationWebHook.cs | 11 +- 15 files changed, 480 insertions(+), 147 deletions(-) create mode 100644 Octokit.Tests/Reactive/ObservableOrganizationHooksClientTests.cs delete mode 100644 Octokit/Exceptions/OrganizationWebHookConfigException.cs diff --git a/Octokit.Reactive/Clients/IObservableOrganizationHooksClient.cs b/Octokit.Reactive/Clients/IObservableOrganizationHooksClient.cs index 19ab40a844..533a0b4e9d 100644 --- a/Octokit.Reactive/Clients/IObservableOrganizationHooksClient.cs +++ b/Octokit.Reactive/Clients/IObservableOrganizationHooksClient.cs @@ -9,15 +9,24 @@ public interface IObservableOrganizationHooksClient /// /// Gets the list of hooks defined for a organization /// - /// See API documentation for more information. - /// + /// The organizations name + /// See API documentation for more information. IObservable GetAll(string org); + /// + /// Gets the list of hooks defined for a organization + /// + /// The organizations name + /// Options for changing the API response + /// See API documentation for more information. + IObservable GetAll(string org, ApiOptions options); + /// /// Gets a single hook defined for a organization by id /// + /// The organizations name + /// The organizations hook id /// See API documentation for more information. - /// [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "This is ok; we're matching HTTP verbs not keyworks")] IObservable Get(string org, int hookId); @@ -31,24 +40,26 @@ public interface IObservableOrganizationHooksClient /// /// Edits a hook for a organization /// + /// The organizations name + /// The organizations hook id + /// The hook's parameters /// See API documentation for more information. - /// IObservable Edit(string org, int hookId, EditOrganizationHook hook); /// /// This will trigger a ping event to be sent to the hook. /// + /// The organizations name + /// The organizations hook id /// See API documentation for more information. - /// IObservable Ping(string org, int hookId); /// /// Deletes a hook for a organization /// - /// - /// + /// The organizations name + /// The organizations hook id /// See API documentation for more information. - /// IObservable Delete(string org, int hookId); } } \ No newline at end of file diff --git a/Octokit.Reactive/Clients/IObservableOrganizationsClient.cs b/Octokit.Reactive/Clients/IObservableOrganizationsClient.cs index 05743fe06a..793b17846e 100644 --- a/Octokit.Reactive/Clients/IObservableOrganizationsClient.cs +++ b/Octokit.Reactive/Clients/IObservableOrganizationsClient.cs @@ -20,7 +20,8 @@ public interface IObservableOrganizationsClient /// /// See Hooks API documentation for more information. IObservableOrganizationHooksClient Hook { get; } - + + /// /// Returns a client to manage outside collaborators of an organization. /// IObservableOrganizationOutsideCollaboratorsClient OutsideCollaborator { get; } diff --git a/Octokit.Reactive/Clients/ObservableOrganizationHooksClient.cs b/Octokit.Reactive/Clients/ObservableOrganizationHooksClient.cs index 792a0860d3..b8e78925b6 100644 --- a/Octokit.Reactive/Clients/ObservableOrganizationHooksClient.cs +++ b/Octokit.Reactive/Clients/ObservableOrganizationHooksClient.cs @@ -12,7 +12,7 @@ public class ObservableOrganizationHooksClient : IObservableOrganizationHooksCli public ObservableOrganizationHooksClient(IGitHubClient client) { - Ensure.ArgumentNotNull(client, "client"); + Ensure.ArgumentNotNull(client, nameof(client)); _client = client.Organization.Hook; _connection = client.Connection; @@ -21,24 +21,38 @@ public ObservableOrganizationHooksClient(IGitHubClient client) /// /// Gets the list of hooks defined for a organization /// + /// The organizations name /// See API documentation for more information. - /// public IObservable GetAll(string org) { - Ensure.ArgumentNotNullOrEmptyString(org, "org"); - + Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); return _connection.GetAndFlattenAllPages(ApiUrls.OrganizationHooks(org)); } + /// + /// Gets the list of hooks defined for a organization + /// + /// The organizations name + /// Options for changing the API response + /// See API documentation for more information. + public IObservable GetAll(string org, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); + Ensure.ArgumentNotNull(options, nameof(options)); + + return _connection.GetAndFlattenAllPages(ApiUrls.OrganizationHooks(org), options); + } + /// /// Gets a single hook defined for a organization by id /// + /// The organizations name + /// The organizations hook id /// See API documentation for more information. - /// public IObservable Get(string org, int hookId) { - Ensure.ArgumentNotNullOrEmptyString(org, "org"); + Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); return _client.Get(org, hookId).ToObservable(); } @@ -46,12 +60,13 @@ public IObservable Get(string org, int hookId) /// /// Creates a hook for a organization /// + /// The organizations name + /// The hook's parameters /// See API documentation for more information. - /// public IObservable Create(string org, NewOrganizationHook hook) { - Ensure.ArgumentNotNullOrEmptyString(org, "org"); - Ensure.ArgumentNotNull(hook, "hook"); + Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); + Ensure.ArgumentNotNull(hook, nameof(hook)); return _client.Create(org, hook).ToObservable(); } @@ -59,12 +74,15 @@ public IObservable Create(string org, NewOrganizationHook hook /// /// Edits a hook for a organization /// + /// The organizations name + /// The organizations hook id + /// The hook's parameters /// See API documentation for more information. /// public IObservable Edit(string org, int hookId, EditOrganizationHook hook) { - Ensure.ArgumentNotNullOrEmptyString(org, "org"); - Ensure.ArgumentNotNull(hook, "hook"); + Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); + Ensure.ArgumentNotNull(hook, nameof(hook)); return _client.Edit(org, hookId, hook).ToObservable(); } @@ -72,11 +90,12 @@ public IObservable Edit(string org, int hookId, EditOrganizati /// /// This will trigger a ping event to be sent to the hook. /// + /// The organizations name + /// The organizations hook id /// See API documentation for more information. - /// public IObservable Ping(string org, int hookId) { - Ensure.ArgumentNotNullOrEmptyString(org, "org"); + Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); return _client.Ping(org, hookId).ToObservable(); } @@ -84,13 +103,12 @@ public IObservable Ping(string org, int hookId) /// /// Deletes a hook for a organization /// - /// - /// + /// The organizations name + /// The organizations hook id /// See API documentation for more information. - /// public IObservable Delete(string org, int hookId) { - Ensure.ArgumentNotNullOrEmptyString(org, "org"); + Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); return _client.Delete(org, hookId).ToObservable(); } diff --git a/Octokit.Reactive/Clients/ObservableOrganizationsClient.cs b/Octokit.Reactive/Clients/ObservableOrganizationsClient.cs index aaefb0ce7d..ec7e43f40f 100644 --- a/Octokit.Reactive/Clients/ObservableOrganizationsClient.cs +++ b/Octokit.Reactive/Clients/ObservableOrganizationsClient.cs @@ -42,6 +42,7 @@ public ObservableOrganizationsClient(IGitHubClient client) /// See Hooks API documentation for more information. public IObservableOrganizationHooksClient Hook { get; private set; } + /// /// Returns a client to manage outside collaborators of an organization. /// public IObservableOrganizationOutsideCollaboratorsClient OutsideCollaborator { get; private set; } diff --git a/Octokit.Tests.Integration/Clients/OrganizationHooksClientTests.cs b/Octokit.Tests.Integration/Clients/OrganizationHooksClientTests.cs index fd8aa25f24..a70b089934 100644 --- a/Octokit.Tests.Integration/Clients/OrganizationHooksClientTests.cs +++ b/Octokit.Tests.Integration/Clients/OrganizationHooksClientTests.cs @@ -10,9 +10,8 @@ public class OrganizationHooksClientTests { [Collection(OrganizationsHooksCollection.Name)] public class TheGetAllMethod - { - OrganizationsHooksFixture _fixture; + readonly OrganizationsHooksFixture _fixture; public TheGetAllMethod(OrganizationsHooksFixture fixture) { @@ -26,11 +25,70 @@ public async Task ReturnsAllHooksFromOrganization() var hooks = await github.Organization.Hook.GetAll( _fixture.org); - Assert.Single(hooks); - var actualHook = hooks[0]; + Assert.Equal(_fixture.ExpectedHooks.Count, hooks.Count); + var actualHook = hooks[0]; AssertHook(_fixture.ExpectedHook, actualHook); } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfHooksWithoutStart() + { + var github = Helper.GetAuthenticatedClient(); + + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var hooks = await github.Organization.Hook.GetAll(_fixture.org, options); + + Assert.Equal(_fixture.ExpectedHooks.Count, hooks.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfHooksWithStart() + { + var github = Helper.GetAuthenticatedClient(); + + var options = new ApiOptions + { + PageSize = 3, + PageCount = 1, + StartPage = 2 + }; + + var hooks = await github.Organization.Hook.GetAll(_fixture.org, options); + + Assert.Equal(1, hooks.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStartPage() + { + var github = Helper.GetAuthenticatedClient(); + + var startOptions = new ApiOptions + { + PageSize = 2, + PageCount = 1 + }; + + var firstPage = await github.Organization.Hook.GetAll(_fixture.org, startOptions); + + var skipStartOptions = new ApiOptions + { + PageSize = 2, + PageCount = 1, + StartPage = 2 + }; + + var secondPage = await github.Organization.Hook.GetAll(_fixture.org, skipStartOptions); + + Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); + Assert.NotEqual(firstPage[1].Id, secondPage[1].Id); + } } [Collection(OrganizationsHooksCollection.Name)] diff --git a/Octokit.Tests.Integration/Reactive/ObservableRepositoryHooksClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableRepositoryHooksClientTests.cs index 4998af8c58..e863226e22 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableRepositoryHooksClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableRepositoryHooksClientTests.cs @@ -1,8 +1,8 @@ using System.Reactive.Linq; using System.Threading.Tasks; using Octokit.Reactive; -using Octokit.Tests.Integration.fixtures; using Xunit; +using Octokit.Tests.Integration.Fixtures; namespace Octokit.Tests.Integration.Reactive { diff --git a/Octokit.Tests.Integration/fixtures/OrganizationsHooksFixture.cs b/Octokit.Tests.Integration/fixtures/OrganizationsHooksFixture.cs index a3074077dc..d708b508f7 100644 --- a/Octokit.Tests.Integration/fixtures/OrganizationsHooksFixture.cs +++ b/Octokit.Tests.Integration/fixtures/OrganizationsHooksFixture.cs @@ -8,30 +8,39 @@ public class OrganizationsHooksFixture : IDisposable readonly IGitHubClient _github; readonly OrganizationHook _hook; readonly private string _organizationFixture; + readonly IList _hooks; public OrganizationsHooksFixture() { _github = Helper.GetAuthenticatedClient(); _organizationFixture = Helper.Organization; - _hook = CreateHook(_github, _organizationFixture); + _hooks = new List(5) + { + CreateHook(_github, _organizationFixture, "awscodedeploy", "deployment"), + CreateHook(_github, _organizationFixture, "awsopsworks", "push"), + CreateHook(_github, _organizationFixture, "activecollab", "push"), + CreateHook(_github, _organizationFixture, "acunote", "push") + }; + _hook = _hooks[0]; } - public string org { get { return _organizationFixture; } } public OrganizationHook ExpectedHook { get { return _hook; } } + public IList ExpectedHooks { get { return _hooks; } } + public void Dispose() { _github.Organization.Hook.Delete(_organizationFixture,_hook.Id); } - static OrganizationHook CreateHook(IGitHubClient github, string orgFixture) + static OrganizationHook CreateHook(IGitHubClient github, string orgFixture, string hookName, string eventName) { var config = new Dictionary { { "content_type", "json" }, { "url", "http://test.com/example" } }; - var parameters = new NewOrganizationHook("web", config) + var parameters = new NewOrganizationHook(hookName, config) { - Events = new[] { "commit_comment" }, + Events = new[] { eventName }, Active = false }; var createdHook = github.Organization.Hook.Create(orgFixture, parameters); diff --git a/Octokit.Tests/Clients/OrganizationHooksClientTest.cs b/Octokit.Tests/Clients/OrganizationHooksClientTest.cs index 56c7362583..7a06b95d9b 100644 --- a/Octokit.Tests/Clients/OrganizationHooksClientTest.cs +++ b/Octokit.Tests/Clients/OrganizationHooksClientTest.cs @@ -8,19 +8,49 @@ namespace Octokit.Tests.Clients { public class OrganizationHooksClientTests { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new OrganizationHooksClient(null)); + } + } + public class TheGetAllMethod { [Fact] - public void RequestsCorrectUrl() + public async Task RequestsCorrectUrl() { var connection = Substitute.For(); var client = new OrganizationsClient(connection); - client.Hook.GetAll("org"); + await client.Hook.GetAll("org"); connection.Received().GetAll(Arg.Is(u => u.ToString() == "orgs/org/hooks")); } + [Fact] + public async Task RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new OrganizationsClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + + await client.Hook.GetAll("org", options); + + connection.Received(1) + .GetAll(Arg.Is(u => u.ToString() == "orgs/org/hooks"), + options); + } + [Fact] public async Task EnsuresNonNullArguments() { @@ -30,22 +60,23 @@ public async Task EnsuresNonNullArguments() } [Fact] - public void EnsuresNonEmptyArguments() + public async Task EnsuresNonEmptyArguments() { var client = new OrganizationsClient(Substitute.For()); - Assert.ThrowsAsync(() => client.Hook.GetAll("")); + + await Assert.ThrowsAsync(() => client.Hook.GetAll("")); } } public class TheGetMethod { [Fact] - public void RequestsCorrectUrl() + public async Task RequestsCorrectUrl() { var connection = Substitute.For(); var client = new OrganizationsClient(connection); - client.Hook.Get("org", 12345678); + await client.Hook.Get("org", 12345678); connection.Received().Get(Arg.Is(u => u.ToString() == "orgs/org/hooks/12345678")); } @@ -59,10 +90,11 @@ public async Task EnsuresNonNullArguments() } [Fact] - public void EnsuresNonEmptyArguments() + public async Task EnsuresNonEmptyArguments() { var client = new OrganizationsClient(Substitute.For()); - Assert.ThrowsAsync(() => client.Hook.Get("",123)); + + await Assert.ThrowsAsync(() => client.Hook.Get("",123)); } } diff --git a/Octokit.Tests/Models/NewOrganizationWebHookTests.cs b/Octokit.Tests/Models/NewOrganizationWebHookTests.cs index 1ea1cb167f..ae38c6709b 100644 --- a/Octokit.Tests/Models/NewOrganizationWebHookTests.cs +++ b/Octokit.Tests/Models/NewOrganizationWebHookTests.cs @@ -7,9 +7,6 @@ public class NewOrganizationWebHookTests { public class TheCtor { - string ExpectedOrganizationWebHookConfigExceptionMessage = - "Duplicate webhook config values found - these values: Url should not be passed in as part of the config values. Use the properties on the NewOrganizationWebHook class instead."; - [Fact] public void UsesDefaultValuesForDefaultConfig() { @@ -78,7 +75,47 @@ public void CombinesUserSpecifiedContentTypeWithConfig() } [Fact] - public void ShouldThrowOrganizationWebHookConfigExceptionWhenDuplicateKeysExists() + public void CanSetHookEvents() + { + var create = new NewOrganizationWebHook("web", new Dictionary(), "http://test.com/example") + { + Events = new List { "*" } + }; + + var request = create.ToRequest(); + + Assert.Contains("*", request.Events); + } + + [Fact] + public void EnsureCanCallToRequestMultipleTimes() + { + var create = new NewOrganizationWebHook("web", new Dictionary(), "http://test.com/example") + { + Events = new List { "*" } + }; + + var request = create.ToRequest(); + var requestRepeated = create.ToRequest(); + + Assert.Contains("*", request.Events); + Assert.Contains("*", requestRepeated.Events); + } + + [Fact] + public void ShouldNotContainDuplicateConfigEntriesOnSubsequentRequests() + { + var create = new NewOrganizationWebHook("web", new Dictionary(), "http://test.com/example"); + + var request = create.ToRequest(); + var requestRepeated = create.ToRequest(); + + Assert.Equal(request.Config.Count, 4); + Assert.Equal(requestRepeated.Config.Count, 4); + } + + [Fact] + public void ShouldNotContainDuplicateConfigEntriesOnSubsequentRequestsWithCustomisedConfig() { var config = new Dictionary { @@ -88,20 +125,32 @@ public void ShouldThrowOrganizationWebHookConfigExceptionWhenDuplicateKeysExists {"password", "password"} }; - var create = new NewOrganizationWebHook("windowsazure", config, "http://test.com/example") + var create = new NewOrganizationWebHook("web", config, "http://test.com/example"); + + var request = create.ToRequest(); + var requestRepeated = create.ToRequest(); + + //This is not 8, because `url` used in config, is already part of the base config + Assert.Equal(request.Config.Count, 7); + Assert.Equal(requestRepeated.Config.Count, 7); + } + + [Fact] + public void PropertiesShouldTakePrecedenceOverConfigPassedIn() + { + var config = new Dictionary { - ContentType = OrgWebHookContentType.Json, - Secret = string.Empty, - InsecureSsl = true + {"url", "http://originalurl.com/test"}, }; - Assert.Equal(create.Url, "http://test.com/example"); - Assert.Equal(create.ContentType, OrgWebHookContentType.Json); - Assert.Empty(create.Secret); - Assert.True(create.InsecureSsl); + var create = new NewOrganizationWebHook("web", config, "http://test.com/example"); + + var request = create.ToRequest(); + + Assert.Equal(request.Config["url"], "http://test.com/example"); - var ex = Assert.Throws(() => create.ToRequest()); - Assert.Equal(ExpectedOrganizationWebHookConfigExceptionMessage, ex.Message); + var subsequentRequest = create.ToRequest(); + Assert.Equal(subsequentRequest.Config["url"], "http://test.com/example"); } } } diff --git a/Octokit.Tests/Reactive/ObservableOrganizationHooksClientTests.cs b/Octokit.Tests/Reactive/ObservableOrganizationHooksClientTests.cs new file mode 100644 index 0000000000..ed8fe73107 --- /dev/null +++ b/Octokit.Tests/Reactive/ObservableOrganizationHooksClientTests.cs @@ -0,0 +1,187 @@ +using System; +using System.Collections.Generic; +using NSubstitute; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Reactive +{ + public class ObservableOrganizationHooksClientTests + { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new ObservableOrganizationHooksClient(null)); + } + } + + public class TheGetAllMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableOrganizationHooksClient(gitHubClient); + + client.GetAll("org"); + + gitHubClient.Received().Organization.Hook.GetAll("org"); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableOrganizationHooksClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + + client.GetAll("org", options); + + gitHubClient.Received(1).Organization.Hook.GetAll("org", options); + } + + [Fact] + public void EnsuresNonNullArguments() + { + var client = new ObservableOrganizationHooksClient(Substitute.For()); + + Assert.Throws(() => client.GetAll(null, ApiOptions.None)); + Assert.Throws(() => client.GetAll("org", null)); + Assert.Throws(() => client.GetAll("")); + Assert.Throws(() => client.GetAll("", null)); + } + } + + public class TheGetMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableOrganizationHooksClient(gitHubClient); + + client.Get("org", 12345678); + + gitHubClient.Received().Organization.Hook.Get("org", 12345678); + } + + [Fact] + public void EnsuresNonNullArguments() + { + var client = new ObservableOrganizationHooksClient(Substitute.For()); + + Assert.Throws(() => client.Get(null, 123)); + Assert.Throws(() => client.Get("", 123)); + } + } + + public class TheCreateMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableOrganizationHooksClient(gitHubClient); + + var hook = new NewOrganizationHook("name", new Dictionary { { "config", "" } }); + + client.Create("org", hook); + + gitHubClient.Received().Organization.Hook.Create("org", hook); + } + + [Fact] + public void EnsuresNonNullArguments() + { + var client = new ObservableOrganizationHooksClient(Substitute.For()); + + var config = new Dictionary { { "config", "" } }; + + Assert.Throws(() => client.Create(null, new NewOrganizationHook("name", config))); + Assert.Throws(() => client.Create("org", null)); + Assert.Throws(() => client.Create("", new NewOrganizationHook("name", config))); + } + } + + public class TheEditMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableOrganizationHooksClient(gitHubClient); + + var hook = new EditOrganizationHook(); + + client.Edit("org", 12345678, hook); + + gitHubClient.Received().Organization.Hook.Edit("org", 12345678, hook); + } + + [Fact] + public void EnsuresNonNullArguments() + { + var client = new ObservableOrganizationHooksClient(Substitute.For()); + + Assert.Throws(() => client.Edit(null, 12345678, new EditOrganizationHook())); + Assert.Throws(() => client.Edit("org", 12345678, null)); + Assert.Throws(() => client.Edit("", 12345678, new EditOrganizationHook())); + } + } + + public class ThePingMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableOrganizationHooksClient(gitHubClient); + + client.Ping("org", 12345678); + + gitHubClient.Received().Organization.Hook.Ping("org", 12345678); + } + + [Fact] + public void EnsuresNonNullArguments() + { + var client = new ObservableOrganizationHooksClient(Substitute.For()); + + Assert.Throws(() => client.Ping(null, 12345678)); + Assert.Throws(() => client.Ping("", 12345678)); + } + } + + public class TheDeleteMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableOrganizationHooksClient(gitHubClient); + + client.Delete("org", 12345678); + + gitHubClient.Received().Organization.Hook.Delete("org", 12345678); + } + + [Fact] + public void EnsuresNonNullArguments() + { + var client = new ObservableOrganizationHooksClient(Substitute.For()); + + Assert.Throws(() => client.Delete(null, 12345678)); + Assert.Throws(() => client.Delete("", 12345678)); + } + } + } +} diff --git a/Octokit/Clients/IOrganizationHooksClient.cs b/Octokit/Clients/IOrganizationHooksClient.cs index 6377e60f14..3d8820a0fc 100644 --- a/Octokit/Clients/IOrganizationHooksClient.cs +++ b/Octokit/Clients/IOrganizationHooksClient.cs @@ -4,21 +4,34 @@ namespace Octokit { + /// + /// A client for GitHub's Organization Webhooks API. + /// + /// + /// See the Webhooks API documentation for more information. + /// public interface IOrganizationHooksClient { /// /// Gets the list of hooks defined for a organization /// + /// The organizations name /// See API documentation for more information. - /// Task> GetAll(string org); + /// + /// Gets the list of hooks defined for a organization + /// + /// The organizations name + /// Options for changing the API response + /// See API documentation for more information. + Task> GetAll(string org, ApiOptions options); + /// /// Gets a single hook by Id /// - /// - /// - /// + /// The organizations name + /// The repository's hook id /// See API documentation for more information. [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "This is ok; we're matching HTTP verbs not keywords")] Task Get(string org, int hookId); @@ -26,29 +39,34 @@ public interface IOrganizationHooksClient /// /// Creates a hook for a organization /// + /// The organizations name + /// The hook's parameters /// See API documentation for more information. - /// Task Create(string org, NewOrganizationHook hook); /// /// Edits a hook for a organization /// + /// The organizations name + /// The organizations hook id + /// The hook's parameters /// See API documentation for more information. - /// Task Edit(string org, int hookId, EditOrganizationHook hook); /// /// This will trigger a ping event to be sent to the hook. /// + /// The organizations name + /// The organizations hook id /// See API documentation for more information. - /// Task Ping(string org, int hookId); /// /// Deletes a hook for a organization /// + /// The organizations name + /// The organizations hook id /// See API documentation for more information. - /// Task Delete(string org, int hookId); } } diff --git a/Octokit/Clients/OrganizationHooksClient.cs b/Octokit/Clients/OrganizationHooksClient.cs index 4dfb17c454..20a926fb65 100644 --- a/Octokit/Clients/OrganizationHooksClient.cs +++ b/Octokit/Clients/OrganizationHooksClient.cs @@ -17,15 +17,31 @@ public OrganizationHooksClient(IApiConnection apiConnection) /// /// Gets the list of hooks defined for a organization /// + /// The organization's name /// See API documentation for more information. /// public Task> GetAll(string org) { - Ensure.ArgumentNotNullOrEmptyString(org, "org"); + Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); return ApiConnection.GetAll(ApiUrls.OrganizationHooks(org)); } + /// + /// Gets the list of hooks defined for a organization + /// + /// The organization's name + /// Options for changing the API response + /// See API documentation for more information. + /// + public Task> GetAll(string org, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); + Ensure.ArgumentNotNull(options, nameof(options)); + + return ApiConnection.GetAll(ApiUrls.OrganizationHooks(org), options); + } + /// /// Gets a single hook by Id /// @@ -35,8 +51,8 @@ public Task> GetAll(string org) /// See API documentation for more information. public Task Get(string org, int hookId) { - Ensure.ArgumentNotNullOrEmptyString(org, "org"); - Ensure.ArgumentNotNull(hookId, "HookId"); + Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); + Ensure.ArgumentNotNull(hookId, nameof(hookId)); return ApiConnection.Get(ApiUrls.OrganizationHookById(org, hookId)); } @@ -48,8 +64,8 @@ public Task Get(string org, int hookId) /// public Task Create(string org, NewOrganizationHook hook) { - Ensure.ArgumentNotNullOrEmptyString(org, "org"); - Ensure.ArgumentNotNull(hook, "hook"); + Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); + Ensure.ArgumentNotNull(hook, nameof(hook)); return ApiConnection.Post(ApiUrls.OrganizationHooks(org), hook.ToRequest()); } @@ -61,8 +77,8 @@ public Task Create(string org, NewOrganizationHook hook) /// public Task Edit(string org, int hookId, EditOrganizationHook hook) { - Ensure.ArgumentNotNullOrEmptyString(org, "org"); - Ensure.ArgumentNotNull(hook, "hook"); + Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); + Ensure.ArgumentNotNull(hook, nameof(hook)); return ApiConnection.Patch(ApiUrls.OrganizationHookById(org, hookId), hook); } @@ -74,8 +90,8 @@ public Task Edit(string org, int hookId, EditOrganizationHook /// public Task Ping(string org, int hookId) { - Ensure.ArgumentNotNullOrEmptyString(org, "org"); - Ensure.ArgumentNotNull(hookId, "hookId"); + Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); + Ensure.ArgumentNotNull(hookId, nameof(hookId)); return ApiConnection.Post(ApiUrls.OrganizationHookPing(org, hookId)); } @@ -86,8 +102,8 @@ public Task Ping(string org, int hookId) /// public Task Delete(string org, int hookId) { - Ensure.ArgumentNotNullOrEmptyString(org, "org"); - Ensure.ArgumentNotNull(hookId, "hookId"); + Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); + Ensure.ArgumentNotNull(hookId, nameof(hookId)); return ApiConnection.Delete(ApiUrls.OrganizationHookById(org, hookId)); } diff --git a/Octokit/Exceptions/OrganizationWebHookConfigException.cs b/Octokit/Exceptions/OrganizationWebHookConfigException.cs deleted file mode 100644 index 4ffa4a3f57..0000000000 --- a/Octokit/Exceptions/OrganizationWebHookConfigException.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Globalization; -using System.Linq; -using System.Runtime.Serialization; -using System.Text; -using System.Threading.Tasks; - -namespace Octokit -{ -#if !NETFX_CORE - [Serializable] -#endif - [SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors", - Justification = "These exceptions are specific to the GitHub API and not general purpose exceptions")] - public class OrganizationWebHookConfigException : Exception - { - readonly string message; - - public OrganizationWebHookConfigException(IEnumerable invalidConfig) - { - var parameterList = string.Join(", ", invalidConfig.Select(ic => ic.FromRubyCase())); - message = string.Format(CultureInfo.InvariantCulture, - "Duplicate webhook config values found - these values: {0} should not be passed in as part of the config values. Use the properties on the NewOrganizationWebHook class instead.", - parameterList); - } - - public override string Message - { - get { return message; } - } - -#if !NETFX_CORE - /// - /// Constructs an instance of OrganizationWebHookConfigException - /// - /// - /// The that holds the - /// serialized object data about the exception being thrown. - /// - /// - /// The that contains - /// contextual information about the source or destination. - /// - protected OrganizationWebHookConfigException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - if (info == null) return; - message = info.GetString("Message"); - } - - public override void GetObjectData(SerializationInfo info, StreamingContext context) - { - base.GetObjectData(info, context); - info.AddValue("Message", Message); - } -#endif - } -} diff --git a/Octokit/Models/Request/NewOrganizationHook.cs b/Octokit/Models/Request/NewOrganizationHook.cs index 8573e93944..ec2819bb22 100644 --- a/Octokit/Models/Request/NewOrganizationHook.cs +++ b/Octokit/Models/Request/NewOrganizationHook.cs @@ -82,7 +82,7 @@ public NewOrganizationHook(string name, IReadOnlyDictionary conf /// /// The configuration. /// - public IReadOnlyDictionary Config { get; private set; } + public IReadOnlyDictionary Config { get; protected set; } /// /// Determines what events the hook is triggered for. Default: ["push"] diff --git a/Octokit/Models/Request/NewOrganizationWebHook.cs b/Octokit/Models/Request/NewOrganizationWebHook.cs index e294ec2bad..8d1dfa1cb5 100644 --- a/Octokit/Models/Request/NewOrganizationWebHook.cs +++ b/Octokit/Models/Request/NewOrganizationWebHook.cs @@ -109,18 +109,11 @@ public NewOrganizationWebHook(string name, IReadOnlyDictionary c public override NewOrganizationHook ToRequest() { - var webHookConfig = GetWebHookConfig(); - if (Config.Any(c => webHookConfig.ContainsKey(c.Key))) - { - var invalidConfigs = Config.Where(c => webHookConfig.ContainsKey(c.Key)).Select(c => c.Key); - throw new OrganizationWebHookConfigException(invalidConfigs); - } - - var config = webHookConfig + Config = GetWebHookConfig() .Union(Config, new WebHookConfigComparer()) .ToDictionary(k => k.Key, v => v.Value); - return new NewOrganizationHook(Name, config); + return this; } Dictionary GetWebHookConfig() From 9c8310bcd3d5ee1f28424e3bb18d0ab2751266dd Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Sun, 7 Jun 2020 16:41:40 -0300 Subject: [PATCH 8/8] add missing attributes --- Octokit/Clients/OrganizationHooksClient.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Octokit/Clients/OrganizationHooksClient.cs b/Octokit/Clients/OrganizationHooksClient.cs index 20a926fb65..a7bc46ffc1 100644 --- a/Octokit/Clients/OrganizationHooksClient.cs +++ b/Octokit/Clients/OrganizationHooksClient.cs @@ -20,6 +20,7 @@ public OrganizationHooksClient(IApiConnection apiConnection) /// The organization's name /// See API documentation for more information. /// + [ManualRoute("GET", "orgs/{org}/hooks")] public Task> GetAll(string org) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); @@ -34,6 +35,7 @@ public Task> GetAll(string org) /// Options for changing the API response /// See API documentation for more information. /// + [ManualRoute("GET", "orgs/{org}/hooks")] public Task> GetAll(string org, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); @@ -49,6 +51,7 @@ public Task> GetAll(string org, ApiOptions optio /// /// /// See API documentation for more information. + [ManualRoute("GET", "orgs/{org}/hooks/{hook_id}")] public Task Get(string org, int hookId) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); @@ -62,8 +65,9 @@ public Task Get(string org, int hookId) /// /// See API documentation for more information. /// + [ManualRoute("POST", "orgs/{org}/hooks")] public Task Create(string org, NewOrganizationHook hook) - { + { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); Ensure.ArgumentNotNull(hook, nameof(hook)); @@ -75,6 +79,7 @@ public Task Create(string org, NewOrganizationHook hook) /// /// See API documentation for more information. /// + [ManualRoute("PATCH", "orgs/{org}/hooks/{hook_id}")] public Task Edit(string org, int hookId, EditOrganizationHook hook) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); @@ -88,6 +93,7 @@ public Task Edit(string org, int hookId, EditOrganizationHook /// /// See API documentation for more information. /// + [ManualRoute("POST", "orgs/{org}/hooks/{hook_id}/pings")] public Task Ping(string org, int hookId) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); @@ -100,6 +106,7 @@ public Task Ping(string org, int hookId) /// /// See API documentation for more information. /// + [ManualRoute("DELETE", "orgs/{org}/hooks/{hook_id}")] public Task Delete(string org, int hookId) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); @@ -108,4 +115,4 @@ public Task Delete(string org, int hookId) return ApiConnection.Delete(ApiUrls.OrganizationHookById(org, hookId)); } } -} \ No newline at end of file +}