Skip to content

Commit

Permalink
[FEAT]: Custom Properties (#2933)
Browse files Browse the repository at this point in the history
* add custom properties model and clients

* observable

* observable tests

* add search

* error CS8370: 'target-typed object creation'

* Error CS8370: 'target-typed object creation'

* add patch with body that return status code

* fixes for failed ConventionTests

* working UnitTests

* (de)serialization and model tests

* Update Repository.cs
  • Loading branch information
colbylwilliams authored Jun 17, 2024
1 parent 7d54cb0 commit 9a3177e
Show file tree
Hide file tree
Showing 53 changed files with 3,121 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Reactive;

namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's Organization Custom Properties API.
/// </summary>
/// <remarks>
/// See <a href="https://docs.github.com/rest/orgs/custom-properties">Custom Properties API documentation</a> for more information.
/// </remarks>
public interface IObservableOrganizationCustomPropertiesClient
{
/// <summary>
/// Get all custom properties for an organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/orgs/custom-properties#get-all-custom-properties-for-an-organization">API documentation</a> for more information.
/// </remarks>
/// <param name="org">The name of the organization</param>
IObservable<OrganizationCustomProperty> GetAll(string org);

/// <summary>
/// Get a single custom property by name.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/orgs/custom-properties#get-a-custom-property-for-an-organization">API documentation</a> for more information.
/// </remarks>
/// <param name="org">The name of the organization</param>
/// <param name="propertyName">The name of the custom property</param>
IObservable<OrganizationCustomProperty> Get(string org, string propertyName);

/// <summary>
/// Create new or update existing custom properties for an organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/orgs/custom-properties#create-or-update-custom-properties-for-an-organization">API documentation</a> for more information.
/// </remarks>
/// <param name="org">The name of the organization</param>
/// <param name="properties">The custom properties to create or update</param>
IObservable<OrganizationCustomProperty> CreateOrUpdate(string org, UpsertOrganizationCustomProperties properties);

/// <summary>
/// Create new or update existing custom property for an organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/orgs/custom-properties#create-or-update-a-custom-property-for-an-organization">API documentation</a> for more information.
/// </remarks>
/// <param name="org">The name of the organization</param>
/// <param name="propertyName">The name of the custom property</param>
/// <param name="property">The custom property to create or update</param>
IObservable<OrganizationCustomProperty> CreateOrUpdate(string org, string propertyName, UpsertOrganizationCustomProperty property);

/// <summary>
/// Removes a custom property that is defined for an organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/orgs/custom-properties#remove-a-custom-property-for-an-organization">API documentation</a> for more information.
/// </remarks>
/// <param name="org">The name of the organization</param>
/// <param name="propertyName">The name of the custom property</param>
IObservable<Unit> Delete(string org, string propertyName);

/// <summary>
/// A client for GitHub's Organization Custom Property Values API.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/orgs/custom-properties">Custom Properties API documentation</a> for more information.
/// </remarks>
IObservableOrganizationCustomPropertyValuesClient Values { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Reactive;

namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's Organization Custom Property Values API.
/// </summary>
/// <remarks>
/// See <a href="https://docs.github.com/rest/orgs/custom-properties">Custom Properties API documentation</a> for more information.
/// </remarks>
public interface IObservableOrganizationCustomPropertyValuesClient
{
/// <summary>
/// Get all custom property values for repositories an organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/orgs/custom-properties#list-custom-property-values-for-organization-repositories">API documentation</a> for more information.
/// </remarks>
/// <param name="org">The name of the organization</param>
IObservable<OrganizationCustomPropertyValues> GetAll(string org);

/// <summary>
/// Get all custom property values for repositories an organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/orgs/custom-properties#list-custom-property-values-for-organization-repositories">API documentation</a> for more information.
/// </remarks>
/// <param name="org">The name of the organization</param>
/// <param name="options">Options for changing the API response</param>
IObservable<OrganizationCustomPropertyValues> GetAll(string org, ApiOptions options);

/// <summary>
/// Get all custom property values for repositories an organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/orgs/custom-properties#list-custom-property-values-for-organization-repositories">API documentation</a> for more information.
/// </remarks>
/// <param name="org">The name of the organization</param>
/// <param name="repositoryQuery">Finds repositories in the organization with a query containing one or more search keywords and qualifiers.</param>
IObservable<OrganizationCustomPropertyValues> GetAll(string org, OrganizationCustomPropertyValuesRequest repositoryQuery);

/// <summary>
/// Create new or update existing custom property values for repositories an organization.
/// Using a value of null for a custom property will remove or 'unset' the property value from the repository.
/// A maximum of 30 repositories can be updated in a single request.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/orgs/custom-properties#create-or-update-custom-property-values-for-organization-repositories">API documentation</a> for more information.
/// </remarks>
/// <param name="org">The name of the organization</param>
/// <param name="propertyValues">The custom property values to create or update</param>
IObservable<Unit> CreateOrUpdate(string org, UpsertOrganizationCustomPropertyValues propertyValues);
}
}
5 changes: 5 additions & 0 deletions Octokit.Reactive/Clients/IObservableOrganizationsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public interface IObservableOrganizationsClient
/// </summary>
IObservableOrganizationActionsClient Actions { get; }

/// <summary>
/// Returns a client to manage organization custom properties.
/// </summary>
IObservableOrganizationCustomPropertiesClient CustomProperty { get; }

/// <summary>
/// Returns the specified organization.
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions Octokit.Reactive/Clients/IObservableRepositoriesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,14 @@ public interface IObservableRepositoriesClient
/// </remarks>
IObservableRepositoryCommentsClient Comment { get; }

/// <summary>
/// Client for GitHub's Repository Custom Property Values API.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/custom-properties/">Repository Custom Property API documentation</a> for more information.
/// </remarks>
IObservableRepositoryCustomPropertiesClient CustomProperty { get; }

/// <summary>
/// A client for GitHub's Repository Hooks API.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Reactive;

namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's Repository Custom Property Values API.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/repos/custom-properties">Custom Properties API documentation</a> for more information.
/// </remarks>
public interface IObservableRepositoryCustomPropertiesClient
{
/// <summary>
/// Get all custom property values for a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/repos/custom-properties#get-all-custom-property-values-for-a-repository">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The owner of the repository.</param>
/// <param name="repoName">The name of the repository.</param>
IObservable<CustomPropertyValue> GetAll(string owner, string repoName);

/// <summary>
/// Create new or update existing custom property values for a repository. Using a value of null for a custom property will remove or 'unset' the property value from the repository.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/repos/custom-properties#create-or-update-custom-property-values-for-a-repository">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="repoName">The name of the repository</param>
/// <param name="propertyValues">The custom property values to create or update</param>
IObservable<Unit> CreateOrUpdate(string owner, string repoName, UpsertRepositoryCustomPropertyValues propertyValues);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using System;
using System.Reactive;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;

namespace Octokit.Reactive
{
public class ObservableOrganizationCustomPropertiesClient : IObservableOrganizationCustomPropertiesClient
{
readonly IOrganizationCustomPropertiesClient _client;
readonly IConnection _connection;

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

Values = new ObservableOrganizationCustomPropertyValuesClient(client);

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

/// <summary>
/// Get all custom properties for an organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/orgs/custom-properties#get-all-custom-properties-for-an-organization">API documentation</a> for more information.
/// </remarks>
/// <param name="org">The name of the organization</param>
public IObservable<OrganizationCustomProperty> GetAll(string org)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));

return _client.GetAll(org).ToObservable().SelectMany(p => p);
}

/// <summary>
/// Get a single custom property by name.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/orgs/custom-properties#get-a-custom-property-for-an-organization">API documentation</a> for more information.
/// </remarks>
/// <param name="org">The name of the organization</param>
/// <param name="propertyName">The name of the custom property</param>
public IObservable<OrganizationCustomProperty> Get(string org, string propertyName)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNullOrEmptyString(propertyName, nameof(propertyName));

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

/// <summary>
/// Create new or update existing custom properties for an organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/orgs/custom-properties#create-or-update-custom-properties-for-an-organization">API documentation</a> for more information.
/// </remarks>
/// <param name="org">The name of the organization</param>
/// <param name="properties">The custom properties to create or update</param>
public IObservable<OrganizationCustomProperty> CreateOrUpdate(string org, UpsertOrganizationCustomProperties properties)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNull(properties, nameof(properties));
Ensure.ArgumentNotNullOrEmptyEnumerable(properties.Properties, nameof(properties.Properties));

return _client.CreateOrUpdate(org, properties).ToObservable().SelectMany(p => p);
}

/// <summary>
/// Create new or update existing custom property for an organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/orgs/custom-properties#create-or-update-a-custom-property-for-an-organization">API documentation</a> for more information.
/// </remarks>
/// <param name="org">The name of the organization</param>
/// <param name="propertyName">The name of the custom property</param>
/// <param name="property">The custom property to create or update</param>
public IObservable<OrganizationCustomProperty> CreateOrUpdate(string org, string propertyName, UpsertOrganizationCustomProperty property)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNullOrEmptyString(propertyName, nameof(propertyName));
Ensure.ArgumentNotNull(property, nameof(property));
Ensure.ArgumentNotNullOrDefault(property.ValueType, nameof(property.ValueType));

return _client.CreateOrUpdate(org, propertyName, property).ToObservable();
}

/// <summary>
/// Removes a custom property that is defined for an organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/orgs/custom-properties#remove-a-custom-property-for-an-organization">API documentation</a> for more information.
/// </remarks>
/// <param name="org">The name of the organization</param>
/// <param name="propertyName">The name of the custom property</param>
public IObservable<Unit> Delete(string org, string propertyName)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNullOrEmptyString(propertyName, nameof(propertyName));

return _client.Delete(org, propertyName).ToObservable();
}

/// <summary>
/// A client for GitHub's Organization Custom Property Values API.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/orgs/custom-properties">Custom Properties API documentation</a> for more information.
/// </remarks>
public IObservableOrganizationCustomPropertyValuesClient Values { get; private set; }
}
}
Loading

0 comments on commit 9a3177e

Please sign in to comment.