Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

organization web hooks #1884

Merged
merged 14 commits into from
Jun 7, 2020
65 changes: 65 additions & 0 deletions Octokit.Reactive/Clients/IObservableOrganizationHooksClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reactive;

namespace Octokit.Reactive
{
public interface IObservableOrganizationHooksClient
{
/// <summary>
/// Gets the list of hooks defined for a organization
/// </summary>
/// <param name="org">The organizations name</param>
/// <remarks>See <a href="http://developer.github.com/v3/orgs/hooks/#list-hooks">API documentation</a> for more information.</remarks>
IObservable<OrganizationHook> GetAll(string org);

/// <summary>
/// Gets the list of hooks defined for a organization
/// </summary>
/// <param name="org">The organizations name</param>
/// <param name="options">Options for changing the API response</param>
/// <remarks>See <a href="http://developer.github.com/v3/orgs/hooks/#list-hooks">API documentation</a> for more information.</remarks>
IObservable<OrganizationHook> GetAll(string org, ApiOptions options);

/// <summary>
/// Gets a single hook defined for a organization by id
/// </summary>
/// <param name="org">The organizations name</param>
/// <param name="hookId">The organizations hook id</param>
/// <remarks>See <a href="https://developer.github.com/v3/orgs/hooks/#get-single-hook">API documentation</a> for more information.</remarks>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "This is ok; we're matching HTTP verbs not keyworks")]
IObservable<OrganizationHook> Get(string org, int hookId);

/// <summary>
/// Creates a hook for a organization
/// </summary>
/// <remarks>See <a href="https://developer.github.com/v3/orgs/hooks/#create-a-hook">API documentation</a> for more information.</remarks>
/// <returns></returns>
IObservable<OrganizationHook> Create(string org, NewOrganizationHook hook);

/// <summary>
/// Edits a hook for a organization
/// </summary>
/// <param name="org">The organizations name</param>
/// <param name="hookId">The organizations hook id</param>
/// <param name="hook">The hook's parameters</param>
/// <remarks>See <a href="https://developer.github.com/v3/orgs/hooks/#edit-a-hook">API documentation</a> for more information.</remarks>
IObservable<OrganizationHook> Edit(string org, int hookId, EditOrganizationHook hook);

/// <summary>
/// This will trigger a ping event to be sent to the hook.
/// </summary>
/// <param name="org">The organizations name</param>
/// <param name="hookId">The organizations hook id</param>
/// <remarks>See <a href="https://developer.github.com/v3/orgs/hooks/#ping-a-hook">API documentation</a> for more information.</remarks>
IObservable<Unit> Ping(string org, int hookId);

/// <summary>
/// Deletes a hook for a organization
/// </summary>
/// <param name="org">The organizations name</param>
/// <param name="hookId">The organizations hook id</param>
/// <remarks>See <a href="https://developer.github.com/v3/orgs/hooks/#delete-a-hook">API documentation</a> for more information.</remarks>
IObservable<Unit> Delete(string org, int hookId);
}
}
10 changes: 8 additions & 2 deletions Octokit.Reactive/Clients/IObservableOrganizationsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public interface IObservableOrganizationsClient
/// </summary>
IObservableTeamsClient Team { get; }

/// <summary>
/// A client for GitHub's Organization Hooks API.
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/orgs/hooks/">Hooks API documentation</a> for more information.</remarks>
IObservableOrganizationHooksClient Hook { get; }

/// <summary>
/// Returns a client to manage outside collaborators of an organization.
/// </summary>
Expand Down Expand Up @@ -77,10 +83,10 @@ public interface IObservableOrganizationsClient
/// <summary>
/// Update the specified organization with data from <see cref="OrganizationUpdate"/>.
/// </summary>
/// <param name="organizationName">The name of the organization to update.</param>
/// <param name="org">The name of the organization to update.</param>
/// <param name="updateRequest"></param>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>A <see cref="Organization"/></returns>
IObservable<Organization> Update(string organizationName, OrganizationUpdate updateRequest);
IObservable<Organization> Update(string org, OrganizationUpdate updateRequest);
}
}
116 changes: 116 additions & 0 deletions Octokit.Reactive/Clients/ObservableOrganizationHooksClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
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, nameof(client));

_client = client.Organization.Hook;
_connection = client.Connection;
}

/// <summary>
/// Gets the list of hooks defined for a organization
/// </summary>
/// <param name="org">The organizations name</param>
/// <remarks>See <a href="http://developer.github.com/v3/orgs/hooks/#list-hooks">API documentation</a> for more information.</remarks>
public IObservable<OrganizationHook> GetAll(string org)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));

return _connection.GetAndFlattenAllPages<OrganizationHook>(ApiUrls.OrganizationHooks(org));
}

/// <summary>
/// Gets the list of hooks defined for a organization
/// </summary>
/// <param name="org">The organizations name</param>
/// <param name="options">Options for changing the API response</param>
/// <remarks>See <a href="http://developer.github.com/v3/orgs/hooks/#list-hooks">API documentation</a> for more information.</remarks>
public IObservable<OrganizationHook> GetAll(string org, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNull(options, nameof(options));

return _connection.GetAndFlattenAllPages<OrganizationHook>(ApiUrls.OrganizationHooks(org), options);
}

/// <summary>
/// Gets a single hook defined for a organization by id
/// </summary>
/// <param name="org">The organizations name</param>
/// <param name="hookId">The organizations hook id</param>
/// <remarks>See <a href="http://developer.github.com/v3/orgs/hooks/#get-single-hook">API documentation</a> for more information.</remarks>
public IObservable<OrganizationHook> Get(string org, int hookId)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));

return _client.Get(org, hookId).ToObservable();
}

/// <summary>
/// Creates a hook for a organization
/// </summary>
/// <param name="org">The organizations name</param>
/// <param name="hook">The hook's parameters</param>
/// <remarks>See <a href="http://developer.github.com/v3/orgs/hooks/#create-a-hook">API documentation</a> for more information.</remarks>
public IObservable<OrganizationHook> Create(string org, NewOrganizationHook hook)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNull(hook, nameof(hook));

return _client.Create(org, hook).ToObservable();
}

/// <summary>
/// Edits a hook for a organization
/// </summary>
/// <param name="org">The organizations name</param>
/// <param name="hookId">The organizations hook id</param>
/// <param name="hook">The hook's parameters</param>
/// <remarks>See <a href="http://developer.github.com/v3/orgs/hooks/#edit-a-hook">API documentation</a> for more information.</remarks>
/// <returns></returns>
public IObservable<OrganizationHook> Edit(string org, int hookId, EditOrganizationHook hook)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNull(hook, nameof(hook));

return _client.Edit(org, hookId, hook).ToObservable();
}

/// <summary>
/// This will trigger a ping event to be sent to the hook.
/// </summary>
/// <param name="org">The organizations name</param>
/// <param name="hookId">The organizations hook id</param>
/// <remarks>See <a href="http://developer.github.com/v3/orgs/hooks/#ping-a-hook">API documentation</a> for more information.</remarks>
public IObservable<Unit> Ping(string org, int hookId)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));

return _client.Ping(org, hookId).ToObservable();
}

/// <summary>
/// Deletes a hook for a organization
/// </summary>
/// <param name="org">The organizations name</param>
/// <param name="hookId">The organizations hook id</param>
/// <remarks>See <a href="http://developer.github.com/v3/orgs/hooks/#delete-a-hook">API documentation</a> for more information.</remarks>
public IObservable<Unit> Delete(string org, int hookId)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));

return _client.Delete(org, hookId).ToObservable();
}
}
}
16 changes: 12 additions & 4 deletions Octokit.Reactive/Clients/ObservableOrganizationsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public ObservableOrganizationsClient(IGitHubClient client)

Member = new ObservableOrganizationMembersClient(client);
Team = new ObservableTeamsClient(client);
Hook = new ObservableOrganizationHooksClient(client);
OutsideCollaborator = new ObservableOrganizationOutsideCollaboratorsClient(client);

_client = client.Organization;
Expand All @@ -35,6 +36,12 @@ public ObservableOrganizationsClient(IGitHubClient client)
/// </summary>
public IObservableTeamsClient Team { get; private set; }

/// <summary>
/// A client for GitHub's Organization Hooks API.
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/orgs/hooks/">Hooks API documentation</a> for more information.</remarks>
public IObservableOrganizationHooksClient Hook { get; private set; }

/// <summary>
/// Returns a client to manage outside collaborators of an organization.
/// </summary>
Expand Down Expand Up @@ -125,16 +132,17 @@ public IObservable<Organization> GetAll(OrganizationRequest request)
/// <summary>
/// Update the specified organization with data from <see cref="OrganizationUpdate"/>.
/// </summary>
/// <param name="organizationName">The name of the organization to update.</param>
/// <param name="org">The name of the organization to update.</param>
/// <param name="updateRequest"></param>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>A <see cref="Organization"/></returns>
public IObservable<Organization> Update(string organizationName, OrganizationUpdate updateRequest)
public IObservable<Organization> Update(string org, OrganizationUpdate updateRequest)
{
Ensure.ArgumentNotNullOrEmptyString(organizationName, nameof(organizationName));
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNull(updateRequest, nameof(updateRequest));

return _client.Update(organizationName, updateRequest).ToObservable();
return _client.Update(org, updateRequest).ToObservable();
}

}
}
Loading