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

Added enterprise pre-receive hooks client #2375

Merged
merged 1 commit into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,13 @@ public interface IObservableEnterpriseClient
/// See the <a href="https://developer.github.com/v3/enterprise-admin/pre_receive_environments/">Enterprise Pre-receive Environments API documentation</a> for more information.
///</remarks>
IObservableEnterprisePreReceiveEnvironmentsClient PreReceiveEnvironment { get; }

/// <summary>
/// A client for GitHub's Enterprise Pre-receive Hooks API
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/enterprise-server/rest/reference/enterprise-admin#pre-receive-hooks">Enterprise Pre-receive Hooks API documentation</a> for more information.
///</remarks>
IObservableEnterprisePreReceiveHooksClient PreReceiveHook { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System;
using System.Reactive;

namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's Enterprise Pre-receive Hooks API
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/enterprise-server/rest/reference/enterprise-admin#pre-receive-hooks">Enterprise Pre-receive Hooks API documentation</a> for more information.
///</remarks>
public interface IObservableEnterprisePreReceiveHooksClient
{
/// <summary>
/// Gets all <see cref="PreReceiveHook"/>s.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/enterprise-server/rest/reference/enterprise-admin#list-pre-receive-hooks">API documentation</a> for more information.
/// </remarks>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
IObservable<PreReceiveHook> GetAll();

/// <summary>
/// Gets all <see cref="PreReceiveHook"/>s.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/enterprise-server/rest/reference/enterprise-admin#list-pre-receive-hooks">API documentation</a> for more information.
/// </remarks>
/// <param name="options">Options for changing the API response</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
IObservable<PreReceiveHook> GetAll(ApiOptions options);

/// <summary>
/// Gets a single <see cref="PreReceiveHook"/>.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/enterprise-server/rest/reference/enterprise-admin#get-a-pre-receive-hook">API documentation</a> for more information.
/// </remarks>
/// <param name="hookId">The id of the pre-receive hook</param>
/// <exception cref="NotFoundException">Thrown when the specified <paramref name="hookId"/> does not exist.</exception>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
IObservable<PreReceiveHook> Get(long hookId);

/// <summary>
/// Creates a new <see cref="PreReceiveHook"/>.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/enterprise-server/rest/reference/enterprise-admin#create-a-pre-receive-hook">API documentation</a> for more information.
/// </remarks>
/// <param name="newPreReceiveHook">A description of the pre-receive hook to create</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
IObservable<PreReceiveHook> Create(NewPreReceiveHook newPreReceiveHook);

/// <summary>
/// Edits an existing <see cref="PreReceiveHook"/>.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/enterprise-server/rest/reference/enterprise-admin#update-a-pre-receive-hook">API documentation</a> for more information.
/// </remarks>
/// <param name="hookId">The id of the pre-receive hook</param>
/// <param name="updatePreReceiveHook">A description of the pre-receive hook to edit</param>
/// <exception cref="NotFoundException">Thrown when the specified <paramref name="hookId"/> does not exist.</exception>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
IObservable<PreReceiveHook> Edit(long hookId, UpdatePreReceiveHook updatePreReceiveHook);

/// <summary>
/// Deletes an existing <see cref="PreReceiveHook"/>.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/enterprise-server/rest/reference/enterprise-admin#delete-a-pre-receive-hook">API documentation</a> for more information.
/// </remarks>
/// <param name="hookId">The id of the pre-receive hook</param>
/// <exception cref="NotFoundException">Thrown when the specified <paramref name="hookId"/> does not exist.</exception>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
IObservable<Unit> Delete(long hookId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public ObservableEnterpriseClient(IGitHubClient client)
Organization = new ObservableEnterpriseOrganizationClient(client);
SearchIndexing = new ObservableEnterpriseSearchIndexingClient(client);
PreReceiveEnvironment = new ObservableEnterprisePreReceiveEnvironmentsClient(client);
PreReceiveHook = new ObservableEnterprisePreReceiveHooksClient(client);
}

/// <summary>
Expand Down Expand Up @@ -76,5 +77,13 @@ public ObservableEnterpriseClient(IGitHubClient client)
/// See the <a href="https://developer.github.com/v3/enterprise-admin/pre_receive_environments/">Enterprise Pre-receive Environments API documentation</a> for more information.
///</remarks>
public IObservableEnterprisePreReceiveEnvironmentsClient PreReceiveEnvironment { get; private set; }

/// <summary>
/// A client for GitHub's Enterprise Pre-receive Hooks API
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/enterprise-server/rest/reference/enterprise-admin#pre-receive-hooks">Enterprise Pre-receive Hooks API documentation</a> for more information.
///</remarks>
public IObservableEnterprisePreReceiveHooksClient PreReceiveHook { get; private set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using System;
using System.Reactive;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;

namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's Enterprise Pre-receive Hooks API
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/enterprise-server/rest/reference/enterprise-admin#pre-receive-hooks">Enterprise Pre-receive Hooks API documentation</a> for more information.
///</remarks>
public class ObservableEnterprisePreReceiveHooksClient : IObservableEnterprisePreReceiveHooksClient
{
readonly IEnterprisePreReceiveHooksClient _client;
readonly IConnection _connection;

public ObservableEnterprisePreReceiveHooksClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, nameof(client));

_client = client.Enterprise.PreReceiveHook;
_connection = client.Connection;
}

/// <summary>
/// Gets all <see cref="PreReceiveHook"/>s.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/enterprise-server/rest/reference/enterprise-admin#list-pre-receive-hooks">API documentation</a> for more information.
/// </remarks>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<PreReceiveHook> GetAll()
{
return GetAll(ApiOptions.None);
}

/// <summary>
/// Gets all <see cref="PreReceiveHook"/>s.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/enterprise-server/rest/reference/enterprise-admin#list-pre-receive-hooks">API documentation</a> for more information.
/// </remarks>
/// <param name="options">Options for changing the API response</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<PreReceiveHook> GetAll(ApiOptions options)
{
Ensure.ArgumentNotNull(options, nameof(options));

return _connection.GetAndFlattenAllPages<PreReceiveHook>(ApiUrls.AdminPreReceiveHooks(), null, AcceptHeaders.StableVersionJson, options);
}

/// <summary>
/// Gets a single <see cref="PreReceiveHook"/>.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/enterprise-server/rest/reference/enterprise-admin#get-a-pre-receive-hook">API documentation</a> for more information.
/// </remarks>
/// <param name="hookId">The id of the pre-receive hook</param>
/// <exception cref="NotFoundException">Thrown when the specified <paramref name="hookId"/> does not exist.</exception>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<PreReceiveHook> Get(long hookId)
{
return _client.Get(hookId).ToObservable();
}

/// <summary>
/// Creates a new <see cref="PreReceiveHook"/>.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/enterprise-server/rest/reference/enterprise-admin#create-a-pre-receive-hook">API documentation</a> for more information.
/// </remarks>
/// <param name="newPreReceiveHook">A description of the pre-receive hook to create</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<PreReceiveHook> Create(NewPreReceiveHook newPreReceiveHook)
{
Ensure.ArgumentNotNull(newPreReceiveHook, nameof(newPreReceiveHook));

return _client.Create(newPreReceiveHook).ToObservable();
}

/// <summary>
/// Edits an existing <see cref="PreReceiveHook"/>.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/enterprise-server/rest/reference/enterprise-admin#update-a-pre-receive-hook">API documentation</a> for more information.
/// </remarks>
/// <param name="hookId">The id of the pre-receive hook</param>
/// <param name="updatePreReceiveHook">A description of the pre-receive hook to edit</param>
/// <exception cref="NotFoundException">Thrown when the specified <paramref name="hookId"/> does not exist.</exception>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<PreReceiveHook> Edit(long hookId, UpdatePreReceiveHook updatePreReceiveHook)
{
Ensure.ArgumentNotNull(updatePreReceiveHook, nameof(updatePreReceiveHook));

return _client.Edit(hookId, updatePreReceiveHook).ToObservable();
}

/// <summary>
/// Deletes an existing <see cref="PreReceiveHook"/>.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/enterprise-server/rest/reference/enterprise-admin#delete-a-pre-receive-hook">API documentation</a> for more information.
/// </remarks>
/// <param name="hookId">The id of the pre-receive hook</param>
/// <exception cref="NotFoundException">Thrown when the specified <paramref name="hookId"/> does not exist.</exception>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<Unit> Delete(long hookId)
{
return _client.Delete(hookId).ToObservable();
}
}
}
Loading