feat: Adds Packages and Package versions APIs (#2551)

This commit is contained in:
Chris Simpson
2022-09-08 15:59:46 +01:00
committed by GitHub
parent b3d2096766
commit cf9db5fc46
27 changed files with 3460 additions and 0 deletions

View File

@@ -0,0 +1,152 @@
using System;
using System.Reactive;
namespace Octokit.Reactive
{
public interface IObservablePackageVersionsClient
{
/// <summary>
/// List all versions of a package.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-all-package-versions-for-a-package-owned-by-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="state">Optional: Return packages with a state. Defaults to Active</param>
/// <param name="options">Optional: Paging options</param>
IObservable<PackageVersion> GetAllForOrg(string org, PackageType packageType, string packageName, PackageVersionState state = PackageVersionState.Active, ApiOptions options = null);
/// <summary>
/// Get a specific version of a package.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-a-package-version-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
IObservable<PackageVersion> GetForOrg(string org, PackageType packageType, string packageName, int packageVersionId);
/// <summary>
/// Deletes a specific package version in an organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#delete-package-version-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
IObservable<Unit> DeleteForOrg(string org, PackageType packageType, string packageName, int packageVersionId);
/// <summary>
/// Restores a specific package version in an organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#restore-package-version-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
IObservable<Unit> RestoreForOrg(string org, PackageType packageType, string packageName, int packageVersionId);
/// <summary>
/// Returns all package versions for a package owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-all-package-versions-for-a-package-owned-by-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="state">Optional: Return packages with a state. Defaults to Active</param>
/// <param name="options">Optional: Paging options</param>
IObservable<PackageVersion> GetAllForActiveUser(PackageType packageType, string packageName, PackageVersionState state = PackageVersionState.Active, ApiOptions options = null);
/// <summary>
/// Gets a specific package version for a package owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-a-package-version-for-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
IObservable<PackageVersion> GetForActiveUser(PackageType packageType, string packageName, int packageVersionId);
/// <summary>
/// Deletes a specific package version for a package owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#delete-a-package-version-for-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
IObservable<Unit> DeleteForActiveUser(PackageType packageType, string packageName, int packageVersionId);
/// <summary>
/// Restores a package version owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#restore-a-package-version-for-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
IObservable<Unit> RestoreForActiveUser(PackageType packageType, string packageName, int packageVersionId);
/// <summary>
/// Returns all package versions for a public package owned by a specified user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-all-package-versions-for-a-package-owned-by-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="state">Optional: Return packages with a state. Defaults to Active</param>
/// <param name="options">Optional: Paging options</param>
IObservable<PackageVersion> GetAllForUser(string username, PackageType packageType, string packageName, PackageVersionState state = PackageVersionState.Active, ApiOptions options = null);
/// <summary>
/// Gets a specific package version for a public package owned by a specified user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-a-package-version-for-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
IObservable<PackageVersion> GetForUser(string username, PackageType packageType, string packageName, int packageVersionId);
/// <summary>
/// Deletes a specific package version for a user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#delete-package-version-for-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
IObservable<Unit> DeleteForUser(string username, PackageType packageType, string packageName, int packageVersionId);
/// <summary>
/// Restores a specific package version for a user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#restore-package-version-for-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
IObservable<Unit> RestoreForUser(string username, PackageType packageType, string packageName, int packageVersionId);
}
}

View File

@@ -0,0 +1,138 @@
using System;
using System.Reactive;
namespace Octokit.Reactive
{
public interface IObservablePackagesClient
{
IObservablePackageVersionsClient PackageVersions { get; }
/// <summary>
/// List all packages for an organisations, readable by the current user
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#list-packages-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageVisibility">Optional: The visibility of the package</param>
IObservable<Package> GetAllForOrg(string org, PackageType packageType, PackageVisibility? packageVisibility = null);
/// <summary>
/// Get a specific package for an Organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-a-package-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
IObservable<Package> GetForOrg(string org, PackageType packageType, string packageName);
/// <summary>
/// Delete a specific package for an Organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#delete-a-package-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
IObservable<Unit> DeleteForOrg(string org, PackageType packageType, string packageName);
/// <summary>
/// Restore a specific package for an Organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#restore-a-package-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
IObservable<Unit> RestoreForOrg(string org, PackageType packageType, string packageName);
/// <summary>
/// Lists packages owned by the authenticated user within the user's namespace
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#list-packages-for-the-authenticated-users-namespace">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageVisibility">Optional: The visibility of the package</param>
IObservable<Package> GetAllForActiveUser(PackageType packageType, PackageVisibility? packageVisibility = null);
/// <summary>
/// Gets a specific package for a package owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-a-package-for-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
IObservable<Package> GetForActiveUser(PackageType packageType, string packageName);
/// <summary>
/// Deletes a package owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#delete-a-package-for-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
IObservable<Unit> DeleteForActiveUser(PackageType packageType, string packageName);
/// <summary>
/// Restores a package owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#restore-a-package-for-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
IObservable<Unit> RestoreForActiveUser(PackageType packageType, string packageName);
/// <summary>
/// Lists packages owned by the authenticated user within the user's namespace
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#list-packages-for-the-authenticated-users-namespace">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageVisibility">Optional: The visibility of the package</param>
IObservable<Package> GetAllForUser(string username, PackageType packageType, PackageVisibility? packageVisibility = null);
/// <summary>
/// Gets a specific package metadata for a public package owned by a user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-a-package-for-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
IObservable<Package> GetForUser(string username, PackageType packageType, string packageName);
/// <summary>
/// Deletes an entire package for a user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#delete-a-package-for-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
IObservable<Unit> DeleteForUser(string username, PackageType packageType, string packageName);
/// <summary>
/// Restores an entire package for a user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#restore-a-package-for-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
IObservable<Unit> RestoreForUser(string username, PackageType packageType, string packageName);
}
}

View File

@@ -0,0 +1,253 @@
using Octokit.Reactive.Internal;
using System;
using System.Reactive;
using System.Reactive.Threading.Tasks;
namespace Octokit.Reactive
{
public class ObservablePackageVersionsClient : IObservablePackageVersionsClient
{
readonly IPackageVersionsClient _client;
readonly IConnection _connection;
public ObservablePackageVersionsClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, nameof(client));
_client = client.Packages.PackageVersions;
_connection = client.Connection;
}
/// <summary>
/// List all versions of a package.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-all-package-versions-for-a-package-owned-by-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="state">Optional: Return packages with a state. Defaults to Active</param>
/// <param name="options">Optional: Paging options</param>
public IObservable<PackageVersion> GetAllForOrg(string org, PackageType packageType, string packageName, PackageVersionState state = PackageVersionState.Active, ApiOptions options = null)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
Ensure.ApiOptionsNotNull(ref options);
var route = ApiUrls.PackageVersionsOrg(org, packageType, packageName);
var parameters = ParameterBuilder.AddParameter("state", state);
return _connection.GetAndFlattenAllPages<PackageVersion>(route, parameters);
}
/// <summary>
/// Get a specific version of a package.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-a-package-version-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
public IObservable<PackageVersion> GetForOrg(string org, PackageType packageType, string packageName, int packageVersionId)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
Ensure.GreaterThanZero(packageVersionId, nameof(packageVersionId));
return _client.GetForOrg(org, packageType, packageName, packageVersionId).ToObservable();
}
/// <summary>
/// Deletes a specific package version in an organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#delete-package-version-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
public IObservable<Unit> DeleteForOrg(string org, PackageType packageType, string packageName, int packageVersionId)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
Ensure.GreaterThanZero(packageVersionId, nameof(packageVersionId));
return _client.DeleteForOrg(org, packageType, packageName, packageVersionId).ToObservable();
}
/// <summary>
/// Restores a specific package version in an organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#restore-package-version-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
public IObservable<Unit> RestoreForOrg(string org, PackageType packageType, string packageName, int packageVersionId)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
Ensure.GreaterThanZero(packageVersionId, nameof(packageVersionId));
return _client.RestoreForOrg(org, packageType, packageName, packageVersionId).ToObservable();
}
/// <summary>
/// Returns all package versions for a package owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-all-package-versions-for-a-package-owned-by-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="state">Optional: Return packages with a state. Defaults to Active</param>
/// <param name="options">Optional: Paging options</param>
public IObservable<PackageVersion> GetAllForActiveUser(PackageType packageType, string packageName, PackageVersionState state = PackageVersionState.Active, ApiOptions options = null)
{
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
Ensure.ApiOptionsNotNull(ref options);
var route = ApiUrls.PackageVersionsActiveUser(packageType, packageName);
var parameters = ParameterBuilder.AddParameter("state", state);
return _connection.GetAndFlattenAllPages<PackageVersion>(route, parameters);
}
/// <summary>
/// Gets a specific package version for a package owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-a-package-version-for-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
public IObservable<PackageVersion> GetForActiveUser(PackageType packageType, string packageName, int packageVersionId)
{
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
Ensure.GreaterThanZero(packageVersionId, nameof(packageVersionId));
return _client.GetForActiveUser(packageType, packageName, packageVersionId).ToObservable();
}
/// <summary>
/// Deletes a specific package version for a package owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#delete-a-package-version-for-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
public IObservable<Unit> DeleteForActiveUser(PackageType packageType, string packageName, int packageVersionId)
{
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
Ensure.GreaterThanZero(packageVersionId, nameof(packageVersionId));
return _client.DeleteForActiveUser(packageType, packageName, packageVersionId).ToObservable();
}
/// <summary>
/// Restores a package version owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#restore-a-package-version-for-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
public IObservable<Unit> RestoreForActiveUser(PackageType packageType, string packageName, int packageVersionId)
{
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
Ensure.GreaterThanZero(packageVersionId, nameof(packageVersionId));
return _client.RestoreForActiveUser(packageType, packageName, packageVersionId).ToObservable();
}
/// <summary>
/// Returns all package versions for a public package owned by a specified user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-all-package-versions-for-a-package-owned-by-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="state">Optional: Return packages with a state. Defaults to Active</param>
/// <param name="options">Optional: Paging options</param>
public IObservable<PackageVersion> GetAllForUser(string username, PackageType packageType, string packageName, PackageVersionState state = PackageVersionState.Active, ApiOptions options = null)
{
Ensure.ArgumentNotNullOrEmptyString(username, nameof(username));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
Ensure.ApiOptionsNotNull(ref options);
var route = ApiUrls.PackageVersionsUser(username, packageType, packageName);
var parameters = ParameterBuilder.AddParameter("state", state);
return _connection.GetAndFlattenAllPages<PackageVersion>(route, parameters);
}
/// <summary>
/// Gets a specific package version for a public package owned by a specified user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-a-package-version-for-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
public IObservable<PackageVersion> GetForUser(string username, PackageType packageType, string packageName, int packageVersionId)
{
Ensure.ArgumentNotNullOrEmptyString(username, nameof(username));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
Ensure.GreaterThanZero(packageVersionId, nameof(packageVersionId));
return _client.GetForUser(username, packageType, packageName, packageVersionId).ToObservable();
}
/// <summary>
/// Deletes a specific package version for a user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#delete-package-version-for-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
public IObservable<Unit> DeleteForUser(string username, PackageType packageType, string packageName, int packageVersionId)
{
Ensure.ArgumentNotNullOrEmptyString(username, nameof(username));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
Ensure.GreaterThanZero(packageVersionId, nameof(packageVersionId));
return _client.DeleteForUser(username, packageType, packageName, packageVersionId).ToObservable();
}
/// <summary>
/// Restores a specific package version for a user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#restore-package-version-for-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
public IObservable<Unit> RestoreForUser(string username, PackageType packageType, string packageName, int packageVersionId)
{
Ensure.ArgumentNotNullOrEmptyString(username, nameof(username));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
Ensure.GreaterThanZero(packageVersionId, nameof(packageVersionId));
return _client.RestoreForUser(username, packageType, packageName, packageVersionId).ToObservable();
}
}
}

View File

@@ -0,0 +1,235 @@
using Octokit.Reactive.Internal;
using System;
using System.Reactive;
using System.Reactive.Threading.Tasks;
namespace Octokit.Reactive
{
public class ObservablePackagesClient : IObservablePackagesClient
{
readonly IPackagesClient _client;
readonly IConnection _connection;
public ObservablePackagesClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, nameof(client));
_client = client.Packages;
_connection = client.Connection;
}
public IObservablePackageVersionsClient PackageVersions { get; private set; }
/// <summary>
/// List all packages for an organisations, readable by the current user
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#list-packages-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageVisibility">Optional: The visibility of the package</param>
public IObservable<Package> GetAllForOrg(string org, PackageType packageType, PackageVisibility? packageVisibility = null)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNull(packageType, nameof(packageType));
var route = ApiUrls.PackagesOrg(org);
var parameters = ParameterBuilder.AddParameter("package_type", packageType).AddOptionalParameter("visibility", packageVisibility);
return _connection.GetAndFlattenAllPages<Package>(route, parameters);
}
/// <summary>
/// Get a specific package for an Organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-a-package-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
public IObservable<Package> GetForOrg(string org, PackageType packageType, string packageName)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNull(packageType, nameof(packageType));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
return _client.GetForOrg(org, packageType, packageName).ToObservable();
}
/// <summary>
/// Delete a specific package for an Organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#delete-a-package-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
public IObservable<Unit> DeleteForOrg(string org, PackageType packageType, string packageName)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNull(packageType, nameof(packageType));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
return _client.DeleteForOrg(org, packageType, packageName).ToObservable();
}
/// <summary>
/// Restore a specific package for an Organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#restore-a-package-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
public IObservable<Unit> RestoreForOrg(string org, PackageType packageType, string packageName)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNull(packageType, nameof(packageType));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
return _client.RestoreForOrg(org, packageType, packageName).ToObservable();
}
/// <summary>
/// Lists packages owned by the authenticated user within the user's namespace
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#list-packages-for-the-authenticated-users-namespace">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageVisibility">Optional: The visibility of the package</param>
public IObservable<Package> GetAllForActiveUser(PackageType packageType, PackageVisibility? packageVisibility = null)
{
var route = ApiUrls.PackagesActiveUser();
var parameters = ParameterBuilder.AddParameter("package_type", packageType).AddOptionalParameter("visibility", packageVisibility);
return _connection.GetAndFlattenAllPages<Package>(route, parameters);
}
/// <summary>
/// Gets a specific package for a package owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-a-package-for-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
public IObservable<Package> GetForActiveUser(PackageType packageType, string packageName)
{
Ensure.ArgumentNotNull(packageType, nameof(packageType));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
return _client.GetForActiveUser(packageType, packageName).ToObservable();
}
/// <summary>
/// Deletes a package owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#delete-a-package-for-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
public IObservable<Unit> DeleteForActiveUser(PackageType packageType, string packageName)
{
Ensure.ArgumentNotNull(packageType, nameof(packageType));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
return _client.DeleteForActiveUser(packageType, packageName).ToObservable();
}
/// <summary>
/// Restores a package owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#restore-a-package-for-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
public IObservable<Unit> RestoreForActiveUser(PackageType packageType, string packageName)
{
Ensure.ArgumentNotNull(packageType, nameof(packageType));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
return _client.RestoreForActiveUser(packageType, packageName).ToObservable();
}
/// <summary>
/// Lists packages owned by the authenticated user within the user's namespace
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#list-packages-for-the-authenticated-users-namespace">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageVisibility">Optional: The visibility of the package</param>
public IObservable<Package> GetAllForUser(string username, PackageType packageType, PackageVisibility? packageVisibility = null)
{
Ensure.ArgumentNotNullOrEmptyString(username, nameof(username));
Ensure.ArgumentNotNull(packageType, nameof(packageType));
var route = ApiUrls.PackagesUser(username);
var parameters = ParameterBuilder.AddParameter("package_type", packageType).AddOptionalParameter("visibility", packageVisibility);
return _connection.GetAndFlattenAllPages<Package>(route, parameters);
}
/// <summary>
/// Gets a specific package metadata for a public package owned by a user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-a-package-for-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
public IObservable<Package> GetForUser(string username, PackageType packageType, string packageName)
{
Ensure.ArgumentNotNullOrEmptyString(username, nameof(username));
Ensure.ArgumentNotNull(packageType, nameof(packageType));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
return _client.GetForUser(username, packageType, packageName).ToObservable();
}
/// <summary>
/// Deletes an entire package for a user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#delete-a-package-for-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
public IObservable<Unit> DeleteForUser(string username, PackageType packageType, string packageName)
{
Ensure.ArgumentNotNullOrEmptyString(username, nameof(username));
Ensure.ArgumentNotNull(packageType, nameof(packageType));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
return _client.DeleteForUser(username, packageType, packageName).ToObservable();
}
/// <summary>
/// Restores an entire package for a user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#restore-a-package-for-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
public IObservable<Unit> RestoreForUser(string username, PackageType packageType, string packageName)
{
Ensure.ArgumentNotNullOrEmptyString(username, nameof(username));
Ensure.ArgumentNotNull(packageType, nameof(packageType));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
return _client.RestoreForUser(username, packageType, packageName).ToObservable();
}
}
}

View File

@@ -34,5 +34,6 @@ namespace Octokit.Reactive
IObservableMigrationClient Migration { get; }
IObservableReactionsClient Reaction { get; }
IObservableChecksClient Check { get; }
IObservablePackagesClient Packages{ get; }
}
}

View File

@@ -49,6 +49,7 @@ namespace Octokit.Reactive
Migration = new ObservableMigrationClient(gitHubClient);
Reaction = new ObservableReactionsClient(gitHubClient);
Check = new ObservableChecksClient(gitHubClient);
Packages = new ObservablePackagesClient(gitHubClient);
}
public IConnection Connection
@@ -88,6 +89,7 @@ namespace Octokit.Reactive
public IObservableMigrationClient Migration { get; private set; }
public IObservableReactionsClient Reaction { get; private set; }
public IObservableChecksClient Check { get; private set; }
public IObservablePackagesClient Packages { get; private set; }
/// <summary>
/// Gets the latest API Info - this will be null if no API calls have been made

View File

@@ -0,0 +1,34 @@
using System.Threading.Tasks;
using Xunit;
namespace Octokit.Tests.Integration.Clients
{
public class PackageVersionsClientTests
{
public class TheGetAllMethod
{
[IntegrationTest(Skip = "Cannot create packages as part of this test, so can never succeed")]
public async Task ReturnsAllPackageVersions()
{
var github = Helper.GetAuthenticatedClient();
var result = await github.Packages.PackageVersions.GetAllForOrg(Helper.Organization, PackageType.Container, "asd");
Assert.NotEmpty(result);
}
}
public class TheGetMethod
{
[IntegrationTest(Skip = "Cannot create packages as part of this test, so can never succeed")]
public async Task ReturnsAPackages()
{
var github = Helper.GetAuthenticatedClient();
var result = await github.Packages.PackageVersions.GetForOrg(Helper.Organization, PackageType.Container, "asd", 1);
Assert.NotNull(result);
}
}
}
}

View File

@@ -0,0 +1,34 @@
using System.Threading.Tasks;
using Xunit;
namespace Octokit.Tests.Integration.Clients
{
public class PackagesClientTests
{
public class TheGetAllMethod
{
[IntegrationTest(Skip = "Cannot create packages as part of this test, so can never succeed")]
public async Task ReturnsAllPackages()
{
var github = Helper.GetAuthenticatedClient();
var result = await github.Packages.GetAllForOrg(Helper.Organization, PackageType.Container);
Assert.NotEmpty(result);
}
}
public class TheGetMethod
{
[IntegrationTest(Skip = "Cannot create packages as part of this test, so can never succeed")]
public async Task ReturnsAPackages()
{
var github = Helper.GetAuthenticatedClient();
var result = await github.Packages.GetForOrg(Helper.Organization, PackageType.Container, "asd");
Assert.NotNull(result);
}
}
}
}

View File

@@ -0,0 +1,395 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using NSubstitute;
using Xunit;
namespace Octokit.Tests.Clients
{
public class PackageVersionsClientTests
{
public class TheCtor
{
[Fact]
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new PackageVersionsClient(null));
}
}
public class TheGetAllForOrgMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackageVersionsClient(connection);
await client.GetAllForOrg("fake", PackageType.RubyGems, "name");
connection.Received().GetAll<PackageVersion>(Arg.Is<Uri>(u =>
u.ToString() == "/orgs/fake/packages/rubygems/name/versions"),
Arg.Is<Dictionary<string, string>>(d => d.ContainsKey("state")),
Args.ApiOptions);
}
[Fact]
public async Task RequestsCorrectUrlWithOptionalParameter()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackageVersionsClient(connection);
await client.GetAllForOrg("fake", PackageType.RubyGems, "name", PackageVersionState.Deleted);
var calls = connection.ReceivedCalls();
connection.Received().GetAll<PackageVersion>(Arg.Is<Uri>(u =>
u.ToString() == "/orgs/fake/packages/rubygems/name/versions"),
Arg.Is<Dictionary<string, string>>(d => d.ContainsKey("state") && d["state"] == "deleted"),
Args.ApiOptions);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackageVersionsClient(connection);
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForOrg(null, PackageType.Npm, "asd"));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForOrg("", PackageType.Npm, "asd"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForOrg("owner", PackageType.Npm, null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForOrg("owner", PackageType.Npm, ""));
}
}
public class TheGetForOrgMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackageVersionsClient(connection);
await client.GetForOrg("fake", PackageType.Npm, "name", 5);
connection.Received().Get<PackageVersion>(Arg.Is<Uri>(u => u.ToString() == "/orgs/fake/packages/npm/name/versions/5"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new PackageVersionsClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetForOrg(null, PackageType.Npm, "asd", 5));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetForOrg("", PackageType.Npm, "asd", 5));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetForOrg("owner", PackageType.Npm, null, 5));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetForOrg("owner", PackageType.Npm, "", 5));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetForOrg("owner", PackageType.Npm, "", 0));
}
}
public class TheDeleteForOrgMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackageVersionsClient(connection);
await client.DeleteForOrg("fake", PackageType.Npm, "name", 5);
connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "/orgs/fake/packages/npm/name/versions/5"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new PackageVersionsClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.DeleteForOrg(null, PackageType.Npm, "asd", 5));
await Assert.ThrowsAsync<ArgumentException>(() => client.DeleteForOrg("", PackageType.Npm, "asd", 5));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.DeleteForOrg("owner", PackageType.Npm, null, 5));
await Assert.ThrowsAsync<ArgumentException>(() => client.DeleteForOrg("owner", PackageType.Npm, "", 5));
await Assert.ThrowsAsync<ArgumentException>(() => client.DeleteForOrg("owner", PackageType.Npm, "", 0));
}
}
public class TheRestoreForOrgMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackageVersionsClient(connection);
await client.RestoreForOrg("fake", PackageType.Npm, "name", 5);
connection.Received().Post(Arg.Is<Uri>(u => u.ToString() == "/orgs/fake/packages/npm/name/versions/5/restore"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new PackageVersionsClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.RestoreForOrg(null, PackageType.Npm, "asd", 5));
await Assert.ThrowsAsync<ArgumentException>(() => client.RestoreForOrg("", PackageType.Npm, "asd", 5));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.RestoreForOrg("owner", PackageType.Npm, null, 5));
await Assert.ThrowsAsync<ArgumentException>(() => client.RestoreForOrg("owner", PackageType.Npm, "", 5));
await Assert.ThrowsAsync<ArgumentException>(() => client.RestoreForOrg("owner", PackageType.Npm, "", 0));
}
}
public class TheGetAllForActiveUserMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackageVersionsClient(connection);
await client.GetAllForActiveUser(PackageType.RubyGems, "name");
connection.Received().GetAll<PackageVersion>(Arg.Is<Uri>(u =>
u.ToString() == "/user/packages/rubygems/name/versions"),
Arg.Is<Dictionary<string, string>>(d => d.ContainsKey("state")),
Args.ApiOptions);
}
[Fact]
public async Task RequestsCorrectUrlWithOptionalParameter()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackageVersionsClient(connection);
await client.GetAllForActiveUser(PackageType.RubyGems, "name", PackageVersionState.Deleted);
var calls = connection.ReceivedCalls();
connection.Received().GetAll<PackageVersion>(Arg.Is<Uri>(u =>
u.ToString() == "/user/packages/rubygems/name/versions"),
Arg.Is<Dictionary<string, string>>(d => d.ContainsKey("state") && d["state"] == "deleted"),
Args.ApiOptions);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackageVersionsClient(connection);
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForActiveUser(PackageType.Npm, null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForActiveUser(PackageType.Npm, ""));
}
}
public class TheGetForActiveUserMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackageVersionsClient(connection);
await client.GetForActiveUser(PackageType.Npm, "name", 5);
connection.Received().Get<PackageVersion>(Arg.Is<Uri>(u => u.ToString() == "/user/packages/npm/name/versions/5"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new PackageVersionsClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetForActiveUser(PackageType.Npm, null, 5));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetForActiveUser(PackageType.Npm, "", 5));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetForActiveUser(PackageType.Npm, "", 0));
}
}
public class TheDeleteForActiveUserMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackageVersionsClient(connection);
await client.DeleteForActiveUser(PackageType.Npm, "name", 5);
connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "/user/packages/npm/name/versions/5"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new PackageVersionsClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.DeleteForActiveUser(PackageType.Npm, null, 5));
await Assert.ThrowsAsync<ArgumentException>(() => client.DeleteForActiveUser(PackageType.Npm, "", 5));
await Assert.ThrowsAsync<ArgumentException>(() => client.DeleteForActiveUser(PackageType.Npm, "", 0));
}
}
public class TheRestoreForActiveUserMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackageVersionsClient(connection);
await client.RestoreForActiveUser(PackageType.Npm, "name", 5);
connection.Received().Post(Arg.Is<Uri>(u => u.ToString() == "/user/packages/npm/name/versions/5/restore"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new PackageVersionsClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.RestoreForActiveUser(PackageType.Npm, null, 5));
await Assert.ThrowsAsync<ArgumentException>(() => client.RestoreForActiveUser(PackageType.Npm, "", 5));
await Assert.ThrowsAsync<ArgumentException>(() => client.RestoreForActiveUser(PackageType.Npm, "", 0));
}
}
public class TheGetAllForUserMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackageVersionsClient(connection);
await client.GetAllForUser("fake", PackageType.RubyGems, "name");
connection.Received().GetAll<PackageVersion>(Arg.Is<Uri>(u =>
u.ToString() == "/users/fake/packages/rubygems/name/versions"),
Arg.Is<Dictionary<string, string>>(d => d.ContainsKey("state")),
Args.ApiOptions);
}
[Fact]
public async Task RequestsCorrectUrlWithOptionalParameter()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackageVersionsClient(connection);
await client.GetAllForUser("fake", PackageType.RubyGems, "name", PackageVersionState.Deleted);
var calls = connection.ReceivedCalls();
connection.Received().GetAll<PackageVersion>(Arg.Is<Uri>(u =>
u.ToString() == "/users/fake/packages/rubygems/name/versions"),
Arg.Is<Dictionary<string, string>>(d => d.ContainsKey("state") && d["state"] == "deleted"),
Args.ApiOptions);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackageVersionsClient(connection);
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUser(null, PackageType.Npm, "asd"));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForUser("", PackageType.Npm, "asd"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUser("owner", PackageType.Npm, null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForUser("owner", PackageType.Npm, ""));
}
}
public class TheGetForUserMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackageVersionsClient(connection);
await client.GetForUser("fake", PackageType.Npm, "name", 5);
connection.Received().Get<PackageVersion>(Arg.Is<Uri>(u => u.ToString() == "/users/fake/packages/npm/name/versions/5"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new PackageVersionsClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetForUser(null, PackageType.Npm, "asd", 5));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetForUser("", PackageType.Npm, "asd", 5));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetForUser("owner", PackageType.Npm, null, 5));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetForUser("owner", PackageType.Npm, "", 5));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetForUser("owner", PackageType.Npm, "", 0));
}
}
public class TheDeleteForUserMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackageVersionsClient(connection);
await client.DeleteForUser("fake", PackageType.Npm, "name", 5);
connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "/users/fake/packages/npm/name/versions/5"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new PackageVersionsClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.DeleteForUser(null, PackageType.Npm, "asd", 5));
await Assert.ThrowsAsync<ArgumentException>(() => client.DeleteForUser("", PackageType.Npm, "asd", 5));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.DeleteForUser("owner", PackageType.Npm, null, 5));
await Assert.ThrowsAsync<ArgumentException>(() => client.DeleteForUser("owner", PackageType.Npm, "", 5));
await Assert.ThrowsAsync<ArgumentException>(() => client.DeleteForUser("owner", PackageType.Npm, "", 0));
}
}
public class TheRestoreForUserMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackageVersionsClient(connection);
await client.RestoreForUser("fake", PackageType.Npm, "name", 5);
connection.Received().Post(Arg.Is<Uri>(u => u.ToString() == "/users/fake/packages/npm/name/versions/5/restore"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new PackageVersionsClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.RestoreForUser(null, PackageType.Npm, "asd", 5));
await Assert.ThrowsAsync<ArgumentException>(() => client.RestoreForUser("", PackageType.Npm, "asd", 5));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.RestoreForUser("owner", PackageType.Npm, null, 5));
await Assert.ThrowsAsync<ArgumentException>(() => client.RestoreForUser("owner", PackageType.Npm, "", 5));
await Assert.ThrowsAsync<ArgumentException>(() => client.RestoreForUser("owner", PackageType.Npm, "", 0));
}
}
}
}

View File

@@ -0,0 +1,344 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using NSubstitute;
using Xunit;
namespace Octokit.Tests.Clients
{
public class PackagesClientTests
{
public class TheCtor
{
[Fact]
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new PackagesClient(null));
}
}
public class TheGetAllForOrgMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackagesClient(connection);
await client.GetAllForOrg("fake", PackageType.RubyGems);
connection.Received().GetAll<Package>(Arg.Is<Uri>(u => u.ToString() == "/orgs/fake/packages"), Arg.Is<Dictionary<string, string>>(d => d.ContainsKey("package_type")));
}
[Fact]
public async Task RequestsCorrectUrlWithOptionalParameter()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackagesClient(connection);
await client.GetAllForOrg("fake", PackageType.RubyGems, PackageVisibility.Public);
var calls = connection.ReceivedCalls();
connection.Received().GetAll<Package>(Arg.Is<Uri>(u => u.ToString() == "/orgs/fake/packages"), Arg.Is<Dictionary<string, string>>(d => d.ContainsKey("package_type") && d.ContainsKey("visibility")));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackagesClient(connection);
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForOrg(null, PackageType.Nuget));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForOrg("", PackageType.Nuget));
}
}
public class TheGetForOrgMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackagesClient(connection);
await client.GetForOrg("fake", PackageType.Npm, "name");
connection.Received().Get<Package>(Arg.Is<Uri>(u => u.ToString() == "/orgs/fake/packages/npm/name"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new PackagesClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetForOrg(null, PackageType.Npm, "asd"));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetForOrg("", PackageType.Npm, "asd"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetForOrg("owner", PackageType.Npm, null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetForOrg("owner", PackageType.Npm, ""));
}
}
public class TheDeleteForOrgMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackagesClient(connection);
await client.DeleteForOrg("fake", PackageType.Npm, "name");
connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "/orgs/fake/packages/npm/name"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new PackagesClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.DeleteForOrg(null, PackageType.Npm, "asd"));
await Assert.ThrowsAsync<ArgumentException>(() => client.DeleteForOrg("", PackageType.Npm, "asd"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.DeleteForOrg("owner", PackageType.Npm, null));
await Assert.ThrowsAsync<ArgumentException>(() => client.DeleteForOrg("owner", PackageType.Npm, ""));
}
}
public class TheRestoreForOrgMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackagesClient(connection);
await client.RestoreForOrg("fake", PackageType.Npm, "name");
connection.Received().Post(Arg.Is<Uri>(u => u.ToString() == "/orgs/fake/packages/npm/name/restore"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new PackagesClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.RestoreForOrg(null, PackageType.Npm, "asd"));
await Assert.ThrowsAsync<ArgumentException>(() => client.RestoreForOrg("", PackageType.Npm, "asd"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.RestoreForOrg("owner", PackageType.Npm, null));
await Assert.ThrowsAsync<ArgumentException>(() => client.RestoreForOrg("owner", PackageType.Npm, ""));
}
}
public class TheGetAllForActiveUserMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackagesClient(connection);
await client.GetAllForActiveUser(PackageType.RubyGems);
connection.Received().GetAll<Package>(Arg.Is<Uri>(u => u.ToString() == "/user/packages"), Arg.Is<Dictionary<string, string>>(d => d.ContainsKey("package_type")));
}
[Fact]
public async Task RequestsCorrectUrlWithOptionalParameter()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackagesClient(connection);
await client.GetAllForActiveUser(PackageType.RubyGems, PackageVisibility.Public);
var calls = connection.ReceivedCalls();
connection.Received().GetAll<Package>(Arg.Is<Uri>(u => u.ToString() == "/user/packages"), Arg.Is<Dictionary<string, string>>(d => d.ContainsKey("package_type") && d.ContainsKey("visibility")));
}
}
public class TheGetForActiveUserMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackagesClient(connection);
await client.GetForActiveUser(PackageType.Npm, "name");
connection.Received().Get<Package>(Arg.Is<Uri>(u => u.ToString() == "/user/packages/npm/name"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new PackagesClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetForActiveUser(PackageType.Npm, null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetForActiveUser(PackageType.Npm, ""));
}
}
public class TheDeleteForActiveUserMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackagesClient(connection);
await client.DeleteForActiveUser(PackageType.Npm, "name");
connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "/user/packages/npm/name"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new PackagesClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.DeleteForActiveUser(PackageType.Npm, null));
await Assert.ThrowsAsync<ArgumentException>(() => client.DeleteForActiveUser(PackageType.Npm, ""));
}
}
public class TheRestoreForActiveUserMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackagesClient(connection);
await client.RestoreForActiveUser(PackageType.Npm, "name");
connection.Received().Post(Arg.Is<Uri>(u => u.ToString() == "/user/packages/npm/name/restore"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new PackagesClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.RestoreForActiveUser(PackageType.Npm, null));
await Assert.ThrowsAsync<ArgumentException>(() => client.RestoreForActiveUser(PackageType.Npm, ""));
}
}
public class TheGetAllForUserMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackagesClient(connection);
await client.GetAllForUser("fake", PackageType.RubyGems);
connection.Received().GetAll<Package>(Arg.Is<Uri>(u => u.ToString() == "/users/fake/packages"), Arg.Is<Dictionary<string, string>>(d => d.ContainsKey("package_type")));
}
[Fact]
public async Task RequestsCorrectUrlWithOptionalParameter()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackagesClient(connection);
await client.GetAllForUser("fake", PackageType.RubyGems, PackageVisibility.Public);
var calls = connection.ReceivedCalls();
connection.Received().GetAll<Package>(Arg.Is<Uri>(u => u.ToString() == "/users/fake/packages"), Arg.Is<Dictionary<string, string>>(d => d.ContainsKey("package_type") && d.ContainsKey("visibility")));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackagesClient(connection);
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUser(null, PackageType.Nuget));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForUser("", PackageType.Nuget));
}
}
public class TheGetForUserMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackagesClient(connection);
await client.GetForUser("fake", PackageType.Npm, "name");
connection.Received().Get<Package>(Arg.Is<Uri>(u => u.ToString() == "/users/fake/packages/npm/name"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new PackagesClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetForUser(null, PackageType.Npm, "asd"));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetForUser("", PackageType.Npm, "asd"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetForUser("owner", PackageType.Npm, null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetForUser("owner", PackageType.Npm, ""));
}
}
public class TheDeleteForUserMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackagesClient(connection);
await client.DeleteForUser("fake", PackageType.Npm, "name");
connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "/users/fake/packages/npm/name"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new PackagesClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.DeleteForUser(null, PackageType.Npm, "asd"));
await Assert.ThrowsAsync<ArgumentException>(() => client.DeleteForUser("", PackageType.Npm, "asd"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.DeleteForUser("owner", PackageType.Npm, null));
await Assert.ThrowsAsync<ArgumentException>(() => client.DeleteForUser("owner", PackageType.Npm, ""));
}
}
public class TheRestoreForUserMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new PackagesClient(connection);
await client.RestoreForUser("fake", PackageType.Npm, "name");
connection.Received().Post(Arg.Is<Uri>(u => u.ToString() == "/users/fake/packages/npm/name/restore"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new PackagesClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.RestoreForUser(null, PackageType.Npm, "asd"));
await Assert.ThrowsAsync<ArgumentException>(() => client.RestoreForUser("", PackageType.Npm, "asd"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.RestoreForUser("owner", PackageType.Npm, null));
await Assert.ThrowsAsync<ArgumentException>(() => client.RestoreForUser("owner", PackageType.Npm, ""));
}
}
}
}

View File

@@ -0,0 +1,146 @@
using System;
using System.Collections.Generic;
using NSubstitute;
using Octokit.Reactive;
using Xunit;
namespace Octokit.Tests.Reactive
{
public class ObservablePackageVersionsTests
{
public class TheCtor
{
[Fact]
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new ObservablePackageVersionsClient(null));
}
}
public class TheGetAllMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePackageVersionsClient(gitHubClient);
client.GetAllForOrg("fake", PackageType.RubyGems, "name");
gitHubClient.Connection.Received().Get<List<PackageVersion>>(
new Uri("/orgs/fake/packages/rubygems/name/versions", UriKind.Relative),
Arg.Is<Dictionary<string, string>>(d => d.ContainsKey("state")));
}
[Fact]
public void RequestsCorrectUrlWithOptionalParameter()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePackageVersionsClient(gitHubClient);
client.GetAllForOrg("fake", PackageType.RubyGems, "name", PackageVersionState.Deleted);
gitHubClient.Connection.Received().Get<List<PackageVersion>>(
Arg.Is<Uri>(u => u.ToString() == "/orgs/fake/packages/rubygems/name/versions"),
Arg.Is<Dictionary<string, string>>(d => d.ContainsKey("state") && d["state"] == "deleted"));
}
[Fact]
public void EnsuresNonNullArguments()
{
var client = new ObservablePackageVersionsClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.GetAllForOrg(null, PackageType.Nuget, "name"));
Assert.Throws<ArgumentException>(() => client.GetAllForOrg("", PackageType.Nuget, "name"));
Assert.Throws<ArgumentNullException>(() => client.GetAllForOrg("fake", PackageType.Nuget, null));
Assert.Throws<ArgumentException>(() => client.GetAllForOrg("fake", PackageType.Nuget, ""));
}
}
public class TheGetMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePackageVersionsClient(gitHubClient);
client.GetForOrg("fake", PackageType.Npm, "name", 5);
gitHubClient.Packages.PackageVersions.Received().GetForOrg("fake", PackageType.Npm, "name", 5);
}
[Fact]
public void EnsuresNonNullArguments()
{
var client = new ObservablePackageVersionsClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.GetForOrg(null, PackageType.Npm, "asd", 5));
Assert.Throws<ArgumentException>(() => client.GetForOrg("", PackageType.Npm, "asd", 5));
Assert.Throws<ArgumentNullException>(() => client.GetForOrg("owner", PackageType.Npm, null, 5));
Assert.Throws<ArgumentException>(() => client.GetForOrg("owner", PackageType.Npm, "", 5));
Assert.Throws<ArgumentException>(() => client.GetForOrg("owner", PackageType.Npm, "asd", 0));
}
}
public class TheDeleteMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePackageVersionsClient(gitHubClient);
client.DeleteForOrg("fake", PackageType.Npm, "name", 5);
gitHubClient.Packages.PackageVersions.Received(1).DeleteForOrg("fake", PackageType.Npm, "name", 5);
}
[Fact]
public void EnsuresNonNullArguments()
{
var client = new ObservablePackageVersionsClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.DeleteForOrg(null, PackageType.Npm, "asd", 5));
Assert.Throws<ArgumentException>(() => client.DeleteForOrg("", PackageType.Npm, "asd", 5));
Assert.Throws<ArgumentNullException>(() => client.DeleteForOrg("owner", PackageType.Npm, null, 5));
Assert.Throws<ArgumentException>(() => client.DeleteForOrg("owner", PackageType.Npm, "", 5));
Assert.Throws<ArgumentException>(() => client.DeleteForOrg("owner", PackageType.Npm, "asd", 0));
}
}
public class TheRestoreMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePackageVersionsClient(gitHubClient);
client.RestoreForOrg("fake", PackageType.Npm, "name", 5);
gitHubClient.Packages.PackageVersions.Received(1).RestoreForOrg("fake", PackageType.Npm, "name", 5);
}
[Fact]
public void EnsuresNonNullArguments()
{
var client = new ObservablePackageVersionsClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.RestoreForOrg(null, PackageType.Npm, "asd", 5));
Assert.Throws<ArgumentException>(() => client.RestoreForOrg("", PackageType.Npm, "asd", 5));
Assert.Throws<ArgumentNullException>(() => client.RestoreForOrg("owner", PackageType.Npm, null, 5));
Assert.Throws<ArgumentException>(() => client.RestoreForOrg("owner", PackageType.Npm, "", 5));
Assert.Throws<ArgumentException>(() => client.RestoreForOrg("owner", PackageType.Npm, "asd", 0));
}
}
}
}

View File

@@ -0,0 +1,350 @@
using System;
using System.Collections.Generic;
using NSubstitute;
using Octokit.Reactive;
using Xunit;
namespace Octokit.Tests.Reactive
{
public class ObservablePackagesTests
{
public class TheCtor
{
[Fact]
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new ObservablePackagesClient(null));
}
}
public class TheGetAllForOrgMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePackagesClient(gitHubClient);
client.GetAllForOrg("fake", PackageType.RubyGems);
gitHubClient.Connection.Received(1).Get<List<Package>>(
new Uri("/orgs/fake/packages", UriKind.Relative),
Arg.Is<Dictionary<string, string>>(d => d.ContainsKey("package_type")));
}
[Fact]
public void RequestsCorrectUrlWithOptionalParameter()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePackagesClient(gitHubClient);
client.GetAllForOrg("fake", PackageType.RubyGems, PackageVisibility.Public);
gitHubClient.Connection.Received().Get<List<Package>>(
Arg.Is<Uri>(u => u.ToString() == "/orgs/fake/packages"),
Arg.Is<Dictionary<string, string>>(d => d.ContainsKey("package_type") && d.ContainsKey("visibility")));
}
[Fact]
public void EnsuresNonNullArguments()
{
var client = new ObservablePackagesClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.GetAllForOrg(null, PackageType.Nuget));
Assert.Throws<ArgumentException>(() => client.GetAllForOrg("", PackageType.Nuget));
}
}
public class TheGetForOrgMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePackagesClient(gitHubClient);
client.GetForOrg("fake", PackageType.Npm, "name");
gitHubClient.Packages.Received().GetForOrg("fake", PackageType.Npm, "name");
}
[Fact]
public void EnsuresNonNullArguments()
{
var client = new ObservablePackagesClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.GetForOrg(null, PackageType.Npm, "asd"));
Assert.Throws<ArgumentException>(() => client.GetForOrg("", PackageType.Npm, "asd"));
Assert.Throws<ArgumentNullException>(() => client.GetForOrg("owner", PackageType.Npm, null));
Assert.Throws<ArgumentException>(() => client.GetForOrg("owner", PackageType.Npm, ""));
}
}
public class TheDeleteForOrgMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePackagesClient(gitHubClient);
client.DeleteForOrg("fake", PackageType.Npm, "name");
gitHubClient.Packages.Received(1).DeleteForOrg("fake", PackageType.Npm, "name");
}
[Fact]
public void EnsuresNonNullArguments()
{
var client = new ObservablePackagesClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.DeleteForOrg(null, PackageType.Npm, "asd"));
Assert.Throws<ArgumentException>(() => client.DeleteForOrg("", PackageType.Npm, "asd"));
Assert.Throws<ArgumentNullException>(() => client.DeleteForOrg("owner", PackageType.Npm, null));
Assert.Throws<ArgumentException>(() => client.DeleteForOrg("owner", PackageType.Npm, ""));
}
}
public class TheRestoreForOrgMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePackagesClient(gitHubClient);
client.RestoreForOrg("fake", PackageType.Npm, "name");
gitHubClient.Packages.Received(1).RestoreForOrg("fake", PackageType.Npm, "name");
}
[Fact]
public void EnsuresNonNullArguments()
{
var client = new ObservablePackagesClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.RestoreForOrg(null, PackageType.Npm, "asd"));
Assert.Throws<ArgumentException>(() => client.RestoreForOrg("", PackageType.Npm, "asd"));
Assert.Throws<ArgumentNullException>(() => client.RestoreForOrg("owner", PackageType.Npm, null));
Assert.Throws<ArgumentException>(() => client.RestoreForOrg("owner", PackageType.Npm, ""));
}
public class TheGetAllForActiveUserMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePackagesClient(gitHubClient);
client.GetAllForActiveUser(PackageType.RubyGems);
gitHubClient.Connection.Received(1).Get<List<Package>>(
new Uri("/user/packages", UriKind.Relative),
Arg.Is<Dictionary<string, string>>(d => d.ContainsKey("package_type")));
}
[Fact]
public void RequestsCorrectUrlWithOptionalParameter()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePackagesClient(gitHubClient);
client.GetAllForActiveUser(PackageType.RubyGems, PackageVisibility.Public);
gitHubClient.Connection.Received().Get<List<Package>>(
Arg.Is<Uri>(u => u.ToString() == "/user/packages"),
Arg.Is<Dictionary<string, string>>(d => d.ContainsKey("package_type") && d.ContainsKey("visibility")));
}
}
public class TheGetForActiveUserMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePackagesClient(gitHubClient);
client.GetForActiveUser(PackageType.Npm, "name");
gitHubClient.Packages.Received().GetForActiveUser(PackageType.Npm, "name");
}
[Fact]
public void EnsuresNonNullArguments()
{
var client = new ObservablePackagesClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.GetForActiveUser(PackageType.Npm, null));
Assert.Throws<ArgumentException>(() => client.GetForActiveUser(PackageType.Npm, ""));
}
}
public class TheDeleteForActiveUserMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePackagesClient(gitHubClient);
client.DeleteForActiveUser(PackageType.Npm, "name");
gitHubClient.Packages.Received(1).DeleteForActiveUser(PackageType.Npm, "name");
}
[Fact]
public void EnsuresNonNullArguments()
{
var client = new ObservablePackagesClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.DeleteForActiveUser(PackageType.Npm, null));
Assert.Throws<ArgumentException>(() => client.DeleteForActiveUser(PackageType.Npm, ""));
}
}
public class TheRestoreForActiveUserMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePackagesClient(gitHubClient);
client.RestoreForActiveUser(PackageType.Npm, "name");
gitHubClient.Packages.Received(1).RestoreForActiveUser(PackageType.Npm, "name");
}
[Fact]
public void EnsuresNonNullArguments()
{
var client = new ObservablePackagesClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.RestoreForActiveUser(PackageType.Npm, null));
Assert.Throws<ArgumentException>(() => client.RestoreForActiveUser(PackageType.Npm, ""));
}
}
public class TheGetAllForUserMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePackagesClient(gitHubClient);
client.GetAllForUser("fake", PackageType.RubyGems);
gitHubClient.Connection.Received(1).Get<List<Package>>(
new Uri("/users/fake/packages", UriKind.Relative),
Arg.Is<Dictionary<string, string>>(d => d.ContainsKey("package_type")));
}
[Fact]
public void RequestsCorrectUrlWithOptionalParameter()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePackagesClient(gitHubClient);
client.GetAllForUser("fake", PackageType.RubyGems, PackageVisibility.Public);
gitHubClient.Connection.Received().Get<List<Package>>(
Arg.Is<Uri>(u => u.ToString() == "/users/fake/packages"),
Arg.Is<Dictionary<string, string>>(d => d.ContainsKey("package_type") && d.ContainsKey("visibility")));
}
[Fact]
public void EnsuresNonNullArguments()
{
var client = new ObservablePackagesClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.GetAllForUser(null, PackageType.Nuget));
Assert.Throws<ArgumentException>(() => client.GetAllForUser("", PackageType.Nuget));
}
}
public class TheGetForUserMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePackagesClient(gitHubClient);
client.GetForUser("fake", PackageType.Npm, "name");
gitHubClient.Packages.Received().GetForUser("fake", PackageType.Npm, "name");
}
[Fact]
public void EnsuresNonNullArguments()
{
var client = new ObservablePackagesClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.GetForUser(null, PackageType.Npm, "asd"));
Assert.Throws<ArgumentException>(() => client.GetForUser("", PackageType.Npm, "asd"));
Assert.Throws<ArgumentNullException>(() => client.GetForUser("owner", PackageType.Npm, null));
Assert.Throws<ArgumentException>(() => client.GetForUser("owner", PackageType.Npm, ""));
}
}
public class TheDeleteForUserMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePackagesClient(gitHubClient);
client.DeleteForUser("fake", PackageType.Npm, "name");
gitHubClient.Packages.Received(1).DeleteForUser("fake", PackageType.Npm, "name");
}
[Fact]
public void EnsuresNonNullArguments()
{
var client = new ObservablePackagesClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.DeleteForUser(null, PackageType.Npm, "asd"));
Assert.Throws<ArgumentException>(() => client.DeleteForUser("", PackageType.Npm, "asd"));
Assert.Throws<ArgumentNullException>(() => client.DeleteForUser("owner", PackageType.Npm, null));
Assert.Throws<ArgumentException>(() => client.DeleteForUser("owner", PackageType.Npm, ""));
}
}
public class TheRestoreForUserMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePackagesClient(gitHubClient);
client.RestoreForUser("fake", PackageType.Npm, "name");
gitHubClient.Packages.Received(1).RestoreForUser("fake", PackageType.Npm, "name");
}
[Fact]
public void EnsuresNonNullArguments()
{
var client = new ObservablePackagesClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.RestoreForUser(null, PackageType.Npm, "asd"));
Assert.Throws<ArgumentException>(() => client.RestoreForUser("", PackageType.Npm, "asd"));
Assert.Throws<ArgumentNullException>(() => client.RestoreForUser("owner", PackageType.Npm, null));
Assert.Throws<ArgumentException>(() => client.RestoreForUser("owner", PackageType.Npm, ""));
}
}
}
}
}

View File

@@ -0,0 +1,151 @@
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Octokit
{
public interface IPackageVersionsClient
{
/// <summary>
/// List all versions of a package.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-all-package-versions-for-a-package-owned-by-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="state">Optional: Return packages with a state. Defaults to Active</param>
/// <param name="options">Optional: Paging options</param>
Task<IReadOnlyList<PackageVersion>> GetAllForOrg(string org, PackageType packageType, string packageName, PackageVersionState state = PackageVersionState.Active, ApiOptions options = null);
/// <summary>
/// Get a specific version of a package.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-a-package-version-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
Task<PackageVersion> GetForOrg(string org, PackageType packageType, string packageName, int packageVersionId);
/// <summary>
/// Deletes a specific package version in an organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#delete-package-version-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
Task DeleteForOrg(string org, PackageType packageType, string packageName, int packageVersionId);
/// <summary>
/// Restores a specific package version in an organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#restore-package-version-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
Task RestoreForOrg(string org, PackageType packageType, string packageName, int packageVersionId);
/// <summary>
/// Returns all package versions for a package owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-all-package-versions-for-a-package-owned-by-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="state">Optional: Return packages with a state. Defaults to Active</param>
/// <param name="options">Optional: Paging options</param>
Task<IReadOnlyList<PackageVersion>> GetAllForActiveUser(PackageType packageType, string packageName, PackageVersionState state = PackageVersionState.Active, ApiOptions options = null);
/// <summary>
/// Gets a specific package version for a package owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-a-package-version-for-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
Task<PackageVersion> GetForActiveUser(PackageType packageType, string packageName, int packageVersionId);
/// <summary>
/// Deletes a specific package version for a package owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#delete-a-package-version-for-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
Task DeleteForActiveUser(PackageType packageType, string packageName, int packageVersionId);
/// <summary>
/// Restores a package version owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#restore-a-package-version-for-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
Task RestoreForActiveUser(PackageType packageType, string packageName, int packageVersionId);
/// <summary>
/// Returns all package versions for a public package owned by a specified user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-all-package-versions-for-a-package-owned-by-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="state">Optional: Return packages with a state. Defaults to Active</param>
/// <param name="options">Optional: Paging options</param>
Task<IReadOnlyList<PackageVersion>> GetAllForUser(string username, PackageType packageType, string packageName, PackageVersionState state = PackageVersionState.Active, ApiOptions options = null);
/// <summary>
/// Gets a specific package version for a public package owned by a specified user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-a-package-version-for-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
Task<PackageVersion> GetForUser(string username, PackageType packageType, string packageName, int packageVersionId);
/// <summary>
/// Deletes a specific package version for a user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#delete-package-version-for-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
Task DeleteForUser(string username, PackageType packageType, string packageName, int packageVersionId);
/// <summary>
/// Restores a specific package version for a user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#restore-package-version-for-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
Task RestoreForUser(string username, PackageType packageType, string packageName, int packageVersionId);
}
}

View File

@@ -0,0 +1,141 @@
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Octokit
{
public interface IPackagesClient
{
IPackageVersionsClient PackageVersions { get; }
/// <summary>
/// List all packages for an organisations, readable by the current user
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#list-packages-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageVisibility">Optional: The visibility of the package</param>
[ExcludeFromPaginationApiOptionsConventionTest("No api options available according to the documentation")]
Task<IReadOnlyList<Package>> GetAllForOrg(string org, PackageType packageType, PackageVisibility? packageVisibility = null);
/// <summary>
/// Get a specific package for an Organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-a-package-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
Task<Package> GetForOrg(string org, PackageType packageType, string packageName);
/// <summary>
/// Delete a specific package for an Organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#delete-a-package-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
Task DeleteForOrg(string org, PackageType packageType, string packageName);
/// <summary>
/// Restore a specific package for an Organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#restore-a-package-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
Task RestoreForOrg(string org, PackageType packageType, string packageName);
/// <summary>
/// Lists packages owned by the authenticated user within the user's namespace
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#list-packages-for-the-authenticated-users-namespace">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageVisibility">Optional: The visibility of the package</param>
[ExcludeFromPaginationApiOptionsConventionTest("No api options available according to the documentation")]
Task<IReadOnlyList<Package>> GetAllForActiveUser(PackageType packageType, PackageVisibility? packageVisibility = null);
/// <summary>
/// Gets a specific package for a package owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-a-package-for-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
Task<Package> GetForActiveUser(PackageType packageType, string packageName);
/// <summary>
/// Deletes a package owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#delete-a-package-for-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
Task DeleteForActiveUser(PackageType packageType, string packageName);
/// <summary>
/// Restores a package owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#restore-a-package-for-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
Task RestoreForActiveUser(PackageType packageType, string packageName);
/// <summary>
/// Lists packages owned by the authenticated user within the user's namespace
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#list-packages-for-the-authenticated-users-namespace">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageVisibility">Optional: The visibility of the package</param>
[ExcludeFromPaginationApiOptionsConventionTest("No api options available according to the documentation")]
Task<IReadOnlyList<Package>> GetAllForUser(string username, PackageType packageType, PackageVisibility? packageVisibility = null);
/// <summary>
/// Gets a specific package metadata for a public package owned by a user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-a-package-for-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
Task<Package> GetForUser(string username, PackageType packageType, string packageName);
/// <summary>
/// Deletes an entire package for a user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#delete-a-package-for-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
Task DeleteForUser(string username, PackageType packageType, string packageName);
/// <summary>
/// Restores an entire package for a user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#restore-a-package-for-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
Task RestoreForUser(string username, PackageType packageType, string packageName);
}
}

View File

@@ -0,0 +1,283 @@
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Octokit
{
public class PackageVersionsClient : ApiClient, IPackageVersionsClient
{
public PackageVersionsClient(IApiConnection apiConnection) : base(apiConnection)
{
}
#region Organization
/// <summary>
/// List all versions of a package.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-all-package-versions-for-a-package-owned-by-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="state">Optional: Return packages with a state. Defaults to Active</param>
/// <param name="options">Optional: Paging options</param>
[ManualRoute("GET", "/orgs/{org}/packages/{package_type}/{package_name}/versions")]
public Task<IReadOnlyList<PackageVersion>> GetAllForOrg(string org, PackageType packageType, string packageName, PackageVersionState state = PackageVersionState.Active, ApiOptions options = null)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
Ensure.ApiOptionsNotNull(ref options);
var route = ApiUrls.PackageVersionsOrg(org, packageType, packageName);
var parameters = ParameterBuilder.AddParameter("state", state);
return ApiConnection.GetAll<PackageVersion>(route, parameters, options);
}
/// <summary>
/// Get a specific version of a package.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-a-package-version-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
[ManualRoute("GET", "/orgs/{org}/packages/{package_type}/{package_name}/versions/{package_version_id}")]
public Task<PackageVersion> GetForOrg(string org, PackageType packageType, string packageName, int packageVersionId)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNull(packageType, nameof(packageType));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
Ensure.GreaterThanZero(packageVersionId, nameof(packageVersionId));
var route = ApiUrls.PackageVersionOrg(org, packageType, packageName, packageVersionId);
return ApiConnection.Get<PackageVersion>(route);
}
/// <summary>
/// Deletes a specific package version in an organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#delete-package-version-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
[ManualRoute("DELETE", "/orgs/{org}/packages/{package_type}/{package_name}/versions/{package_version_id}")]
public Task DeleteForOrg(string org, PackageType packageType, string packageName, int packageVersionId)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNull(packageType, nameof(packageType));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
Ensure.GreaterThanZero(packageVersionId, nameof(packageVersionId));
var route = ApiUrls.PackageVersionOrg(org, packageType, packageName, packageVersionId);
return ApiConnection.Delete(route);
}
/// <summary>
/// Restores a specific package version in an organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#restore-package-version-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
[ManualRoute("POST", "/orgs/{org}/packages/{package_type}/{package_name}/versions/{package_version_id}/restore")]
public Task RestoreForOrg(string org, PackageType packageType, string packageName, int packageVersionId)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
Ensure.GreaterThanZero(packageVersionId, nameof(packageVersionId));
var route = ApiUrls.PackageVersionRestoreOrg(org, packageType, packageName, packageVersionId);
return ApiConnection.Post(route);
}
#endregion
#region Active User
/// <summary>
/// Returns all package versions for a package owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-all-package-versions-for-a-package-owned-by-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="state">Optional: Return packages with a state. Defaults to Active</param>
/// <param name="options">Optional: Paging options</param>
[ManualRoute("GET", "/user/packages/{package_type}/{package_name}/versions")]
public Task<IReadOnlyList<PackageVersion>> GetAllForActiveUser(PackageType packageType, string packageName, PackageVersionState state = PackageVersionState.Active, ApiOptions options = null)
{
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
Ensure.ApiOptionsNotNull(ref options);
var route = ApiUrls.PackageVersionsActiveUser(packageType, packageName);
var parameters = ParameterBuilder.AddParameter("state", state);
return ApiConnection.GetAll<PackageVersion>(route, parameters, options);
}
/// <summary>
/// Gets a specific package version for a package owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-a-package-version-for-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
[ManualRoute("GET", "/user/packages/{package_type}/{package_name}/versions/{package_version_id}")]
public Task<PackageVersion> GetForActiveUser(PackageType packageType, string packageName, int packageVersionId)
{
Ensure.ArgumentNotNull(packageType, nameof(packageType));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
Ensure.GreaterThanZero(packageVersionId, nameof(packageVersionId));
var route = ApiUrls.PackageVersionActiveUser( packageType, packageName, packageVersionId);
return ApiConnection.Get<PackageVersion>(route);
}
/// <summary>
/// Deletes a specific package version for a package owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#delete-a-package-version-for-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
[ManualRoute("DELETE", "/user/packages/{package_type}/{package_name}/versions/{package_version_id}")]
public Task DeleteForActiveUser(PackageType packageType, string packageName, int packageVersionId)
{
Ensure.ArgumentNotNull(packageType, nameof(packageType));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
Ensure.GreaterThanZero(packageVersionId, nameof(packageVersionId));
var route = ApiUrls.PackageVersionActiveUser(packageType, packageName, packageVersionId);
return ApiConnection.Delete(route);
}
/// <summary>
/// Restores a package version owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#restore-a-package-version-for-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
[ManualRoute("POST", "/user/packages/{package_type}/{package_name}/versions/{package_version_id}/restore")]
public Task RestoreForActiveUser(PackageType packageType, string packageName, int packageVersionId)
{
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
Ensure.GreaterThanZero(packageVersionId, nameof(packageVersionId));
var route = ApiUrls.PackageVersionRestoreActiveUser(packageType, packageName, packageVersionId);
return ApiConnection.Post(route);
}
#endregion
#region Specific User
/// <summary>
/// Returns all package versions for a public package owned by a specified user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-all-package-versions-for-a-package-owned-by-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="state">Optional: Return packages with a state. Defaults to Active</param>
/// <param name="options">Optional: Paging options</param>
[ManualRoute("GET", "/users/{username}/packages/{package_type}/{package_name}/versions")]
public Task<IReadOnlyList<PackageVersion>> GetAllForUser(string username, PackageType packageType, string packageName, PackageVersionState state = PackageVersionState.Active, ApiOptions options = null)
{
Ensure.ArgumentNotNullOrEmptyString(username, nameof(username));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
Ensure.ApiOptionsNotNull(ref options);
var route = ApiUrls.PackageVersionsUser(username, packageType, packageName);
var parameters = ParameterBuilder.AddParameter("state", state);
return ApiConnection.GetAll<PackageVersion>(route, parameters, options);
}
/// <summary>
/// Gets a specific package version for a public package owned by a specified user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-a-package-version-for-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
[ManualRoute("GET", "/users/{username}/packages/{package_type}/{package_name}/versions/{package_version_id}")]
public Task<PackageVersion> GetForUser(string username, PackageType packageType, string packageName, int packageVersionId)
{
Ensure.ArgumentNotNullOrEmptyString(username, nameof(username));
Ensure.ArgumentNotNull(packageType, nameof(packageType));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
Ensure.GreaterThanZero(packageVersionId, nameof(packageVersionId));
var route = ApiUrls.PackageVersionUser(username, packageType, packageName, packageVersionId);
return ApiConnection.Get<PackageVersion>(route);
}
/// <summary>
/// Deletes a specific package version for a user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#delete-package-version-for-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
[ManualRoute("DELETE", "/users/{username}/packages/{package_type}/{package_name}/versions/{package_version_id}")]
public Task DeleteForUser(string username, PackageType packageType, string packageName, int packageVersionId)
{
Ensure.ArgumentNotNullOrEmptyString(username, nameof(username));
Ensure.ArgumentNotNull(packageType, nameof(packageType));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
Ensure.GreaterThanZero(packageVersionId, nameof(packageVersionId));
var route = ApiUrls.PackageVersionUser(username, packageType, packageName, packageVersionId);
return ApiConnection.Delete(route);
}
/// <summary>
/// Restores a specific package version for a user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#restore-package-version-for-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
/// <param name="packageVersionId">Required: The id of the package version</param>
[ManualRoute("POST", "/users/{username}/packages/{package_type}/{package_name}/versions/{package_version_id}/restore")]
public Task RestoreForUser(string username, PackageType packageType, string packageName, int packageVersionId)
{
Ensure.ArgumentNotNullOrEmptyString(username, nameof(username));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
Ensure.GreaterThanZero(packageVersionId, nameof(packageVersionId));
var route = ApiUrls.PackageVersionRestoreUser(username, packageType, packageName, packageVersionId);
return ApiConnection.Post(route);
}
#endregion
}
}

View File

@@ -0,0 +1,258 @@
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Octokit
{
/// <summary>
/// A client for GitHub's Packages API.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/packages">Packages API documentation</a> for more details.
/// </remarks>
public class PackagesClient : ApiClient, IPackagesClient
{
public PackagesClient(IApiConnection apiConnection) : base(apiConnection)
{
PackageVersions = new PackageVersionsClient(apiConnection);
}
public IPackageVersionsClient PackageVersions { get; private set; }
#region Organization
/// <summary>
/// List all packages for an organisations, readable by the current user
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#list-packages-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageVisibility">Optional: The visibility of the package</param>
[ManualRoute("GET", "/orgs/{org}/packages")]
public Task<IReadOnlyList<Package>> GetAllForOrg(string org, PackageType packageType, PackageVisibility? packageVisibility = null)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
var route = ApiUrls.PackagesOrg(org);
var parameters = ParameterBuilder.AddParameter("package_type", packageType).AddOptionalParameter("visibility", packageVisibility);
return ApiConnection.GetAll<Package>(route, parameters);
}
/// <summary>
/// Get a specific package for an Organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-a-package-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
[ManualRoute("GET", "/orgs/{org}/packages/{package_type}/{package_name}")]
public Task<Package> GetForOrg(string org, PackageType packageType, string packageName)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
var route = ApiUrls.PackageOrg(org, packageType, packageName);
return ApiConnection.Get<Package>(route);
}
/// <summary>
/// Delete a specific package for an Organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#delete-a-package-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
[ManualRoute("DELETE", "/orgs/{org}/packages/{package_type}/{package_name}")]
public Task DeleteForOrg(string org, PackageType packageType, string packageName)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
var route = ApiUrls.PackageOrg(org, packageType, packageName);
return ApiConnection.Delete(route);
}
/// <summary>
/// Restore a specific package for an Organization.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#restore-a-package-for-an-organization">API documentation</a> for more details
/// </remarks>
/// <param name="org">Required: Organisation Name</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
[ManualRoute("POST", "/orgs/{org}/packages/{package_type}/{package_name}/restore")]
public Task RestoreForOrg(string org, PackageType packageType, string packageName)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
var route = ApiUrls.PackageRestoreOrg(org, packageType, packageName);
return ApiConnection.Post(route);
}
#endregion
#region Active User
/// <summary>
/// Lists packages owned by the authenticated user within the user's namespace
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#list-packages-for-the-authenticated-users-namespace">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageVisibility">Optional: The visibility of the package</param>
[ManualRoute("GET", "/user/packages")]
public Task<IReadOnlyList<Package>> GetAllForActiveUser(PackageType packageType, PackageVisibility? packageVisibility = null)
{
var route = ApiUrls.PackagesActiveUser();
var parameters = ParameterBuilder.AddParameter("package_type", packageType).AddOptionalParameter("visibility", packageVisibility);
return ApiConnection.GetAll<Package>(route, parameters);
}
/// <summary>
/// Gets a specific package for a package owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-a-package-for-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
[ManualRoute("GET", "/user/packages/{package_type}/{package_name}")]
public Task<Package> GetForActiveUser(PackageType packageType, string packageName)
{
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
var route = ApiUrls.PackageActiveUser(packageType, packageName);
return ApiConnection.Get<Package>(route);
}
/// <summary>
/// Deletes a package owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#delete-a-package-for-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
[ManualRoute("DELETE", "/user/packages/{package_type}/{package_name}")]
public Task DeleteForActiveUser(PackageType packageType, string packageName)
{
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
var route = ApiUrls.PackageActiveUser(packageType, packageName);
return ApiConnection.Delete(route);
}
/// <summary>
/// Restores a package owned by the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#restore-a-package-for-the-authenticated-user">API documentation</a> for more details
/// </remarks>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
[ManualRoute("POST", "/user/packages/{package_type}/{package_name}/restore")]
public Task RestoreForActiveUser(PackageType packageType, string packageName)
{
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
var route = ApiUrls.PackageRestoreActiveUser(packageType, packageName);
return ApiConnection.Post(route);
}
#endregion
#region Specific User
/// <summary>
/// Lists packages owned by the authenticated user within the user's namespace
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#list-packages-for-the-authenticated-users-namespace">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageVisibility">Optional: The visibility of the package</param>
[ManualRoute("GET", "/users/{username}/packages")]
public Task<IReadOnlyList<Package>> GetAllForUser(string username, PackageType packageType, PackageVisibility? packageVisibility = null)
{
Ensure.ArgumentNotNullOrEmptyString(username, nameof(username));
var route = ApiUrls.PackagesUser(username);
var parameters = ParameterBuilder.AddParameter("package_type", packageType).AddOptionalParameter("visibility", packageVisibility);
return ApiConnection.GetAll<Package>(route, parameters);
}
/// <summary>
/// Gets a specific package metadata for a public package owned by a user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#get-a-package-for-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
[ManualRoute("GET", "/users/{username}/packages/{package_type}/{package_name}")]
public Task<Package> GetForUser(string username, PackageType packageType, string packageName)
{
Ensure.ArgumentNotNullOrEmptyString(username, nameof(username));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
var route = ApiUrls.PackageUser(username, packageType, packageName);
return ApiConnection.Get<Package>(route);
}
/// <summary>
/// Deletes an entire package for a user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#delete-a-package-for-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
[ManualRoute("DELETE", "/users/{username}/packages/{package_type}/{package_name}")]
public Task DeleteForUser(string username, PackageType packageType, string packageName)
{
Ensure.ArgumentNotNullOrEmptyString(username, nameof(username));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
var route = ApiUrls.PackageUser(username, packageType, packageName);
return ApiConnection.Delete(route);
}
/// <summary>
/// Restores an entire package for a user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/packages#restore-a-package-for-a-user">API documentation</a> for more details
/// </remarks>
/// <param name="username">Required: Username</param>
/// <param name="packageType">Required: The type of package</param>
/// <param name="packageName">Required: The name of the package</param>
[ManualRoute("POST", "/users/{username}/packages/{package_type}/{package_name}/restore")]
public Task RestoreForUser(string username, PackageType packageType, string packageName)
{
Ensure.ArgumentNotNullOrEmptyString(username, nameof(username));
Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName));
var route = ApiUrls.PackageRestoreUser(username, packageType, packageName);
return ApiConnection.Post(route);
}
#endregion
}
}

View File

@@ -111,6 +111,7 @@ namespace Octokit
User = new UsersClient(apiConnection);
Reaction = new ReactionsClient(apiConnection);
Check = new ChecksClient(apiConnection);
Packages = new PackagesClient(apiConnection);
}
/// <summary>
@@ -225,6 +226,14 @@ namespace Octokit
/// </remarks>
public IOrganizationsClient Organization { get; private set; }
/// <summary>
/// Access GitHub's Pacakges API.
/// </summary>
/// <remarks>
/// Refer to the API documentation for more information: https://docs.github.com/en/rest/packages
/// </remarks>
public IPackagesClient Packages { get; private set; }
/// <summary>
/// Access GitHub's Pull Requests API.
/// </summary>

View File

@@ -4457,5 +4457,167 @@ namespace Octokit
{
return "meta".FormatUri();
}
/// <summary>
/// Returns the <see cref="Uri"/> for the Packages request
/// </summary>
/// <returns>The <see cref="Uri"/> Packages endpoint.</returns>
public static Uri PackagesOrg(string org)
{
return "/orgs/{0}/packages".FormatUri(org);
}
/// <summary>
/// Returns the <see cref="Uri"/> for the Package request
/// </summary>
/// <returns>The <see cref="Uri"/> Package endpoint.</returns>
public static Uri PackageOrg(string org, PackageType packageType, string packageName)
{
return "/orgs/{0}/packages/{1}/{2}".FormatUri(org, packageType.ToParameter(), packageName);
}
/// <summary>
/// Returns the <see cref="Uri"/> for the Package Restore request
/// </summary>
/// <returns>The <see cref="Uri"/> Package Restore endpoint.</returns>
public static Uri PackageRestoreOrg(string org, PackageType packageType, string packageName)
{
return "/orgs/{0}/packages/{1}/{2}/restore".FormatUri(org, packageType.ToParameter(), packageName);
}
/// <summary>
/// Returns the <see cref="Uri"/> for the Package Versions request
/// </summary>
/// <returns>The <see cref="Uri"/> Package endpoint.</returns>
public static Uri PackageVersionsOrg(string org, PackageType packageType, string packageName)
{
return "/orgs/{0}/packages/{1}/{2}/versions".FormatUri(org, packageType.ToParameter(), packageName);
}
/// <summary>
/// Returns the <see cref="Uri"/> for the Package Version request
/// </summary>
/// <returns>The <see cref="Uri"/> Package endpoint.</returns>
public static Uri PackageVersionOrg(string org, PackageType packageType, string packageName, int packageVersionId)
{
return "/orgs/{0}/packages/{1}/{2}/versions/{3}".FormatUri(org, packageType.ToParameter(), packageName, packageVersionId);
}
/// <summary>
/// Returns the <see cref="Uri"/> for the Package Version request
/// </summary>
/// <returns>The <see cref="Uri"/> Package endpoint.</returns>
public static Uri PackageVersionRestoreOrg(string org, PackageType packageType, string packageName, int packageVersionId)
{
return "/orgs/{0}/packages/{1}/{2}/versions/{3}/restore".FormatUri(org, packageType.ToParameter(), packageName, packageVersionId);
}
/// <summary>
/// Returns the <see cref="Uri"/> for the Packages request
/// </summary>
/// <returns>The <see cref="Uri"/> Packages endpoint.</returns>
public static Uri PackagesActiveUser()
{
return "/user/packages".FormatUri();
}
/// <summary>
/// Returns the <see cref="Uri"/> for the Package request
/// </summary>
/// <returns>The <see cref="Uri"/> Package endpoint.</returns>
public static Uri PackageActiveUser(PackageType packageType, string packageName)
{
return "/user/packages/{0}/{1}".FormatUri(packageType.ToParameter(), packageName);
}
/// <summary>
/// Returns the <see cref="Uri"/> for the Package Restore request
/// </summary>
/// <returns>The <see cref="Uri"/> Package Restore endpoint.</returns>
public static Uri PackageRestoreActiveUser(PackageType packageType, string packageName)
{
return "/user/packages/{0}/{1}/restore".FormatUri(packageType.ToParameter(), packageName);
}
/// <summary>
/// Returns the <see cref="Uri"/> for the Package Versions request
/// </summary>
/// <returns>The <see cref="Uri"/> Package endpoint.</returns>
public static Uri PackageVersionsActiveUser(PackageType packageType, string packageName)
{
return "/user/packages/{0}/{1}/versions".FormatUri(packageType.ToParameter(), packageName);
}
/// <summary>
/// Returns the <see cref="Uri"/> for the Package Version request
/// </summary>
/// <returns>The <see cref="Uri"/> Package endpoint.</returns>
public static Uri PackageVersionActiveUser(PackageType packageType, string packageName, int packageVersionId)
{
return "/user/packages/{0}/{1}/versions/{2}".FormatUri(packageType.ToParameter(), packageName, packageVersionId);
}
/// <summary>
/// Returns the <see cref="Uri"/> for the Package Version request
/// </summary>
/// <returns>The <see cref="Uri"/> Package endpoint.</returns>
public static Uri PackageVersionRestoreActiveUser(PackageType packageType, string packageName, int packageVersionId)
{
return "/user/packages/{0}/{1}/versions/{2}/restore".FormatUri(packageType.ToParameter(), packageName, packageVersionId);
}
/// <summary>
/// Returns the <see cref="Uri"/> for the Packages request
/// </summary>
/// <returns>The <see cref="Uri"/> Packages endpoint.</returns>
public static Uri PackagesUser(string username)
{
return "/users/{0}/packages".FormatUri(username);
}
/// <summary>
/// Returns the <see cref="Uri"/> for the Package request
/// </summary>
/// <returns>The <see cref="Uri"/> Package endpoint.</returns>
public static Uri PackageUser(string username, PackageType packageType, string packageName)
{
return "/users/{0}/packages/{1}/{2}".FormatUri(username, packageType.ToParameter(), packageName);
}
/// <summary>
/// Returns the <see cref="Uri"/> for the Package Restore request
/// </summary>
/// <returns>The <see cref="Uri"/> Package Restore endpoint.</returns>
public static Uri PackageRestoreUser(string username, PackageType packageType, string packageName)
{
return "/users/{0}/packages/{1}/{2}/restore".FormatUri(username, packageType.ToParameter(), packageName);
}
/// <summary>
/// Returns the <see cref="Uri"/> for the Package Versions request
/// </summary>
/// <returns>The <see cref="Uri"/> Package endpoint.</returns>
public static Uri PackageVersionsUser(string username, PackageType packageType, string packageName)
{
return "/users/{0}/packages/{1}/{2}/versions".FormatUri(username, packageType.ToParameter(), packageName);
}
/// <summary>
/// Returns the <see cref="Uri"/> for the Package Version request
/// </summary>
/// <returns>The <see cref="Uri"/> Package endpoint.</returns>
public static Uri PackageVersionUser(string username, PackageType packageType, string packageName, int packageVersionId)
{
return "/users/{0}/packages/{1}/{2}/versions/{3}".FormatUri(username, packageType.ToParameter(), packageName, packageVersionId);
}
/// <summary>
/// Returns the <see cref="Uri"/> for the Package Version request
/// </summary>
/// <returns>The <see cref="Uri"/> Package endpoint.</returns>
public static Uri PackageVersionRestoreUser(string username, PackageType packageType, string packageName, int packageVersionId)
{
return "/users/{0}/packages/{1}/{2}/versions/{3}/restore".FormatUri(username, packageType.ToParameter(), packageName, packageVersionId);
}
}
}

View File

@@ -50,6 +50,20 @@ namespace Octokit
throw new ArgumentException("Timespan must be greater than zero", name);
}
/// <summary>
/// Checks an integer argument to ensure it is a positive value.
/// </summary>
/// <param name = "value">The argument value to check</param>
/// <param name = "name">The name of the argument</param>
public static void GreaterThanZero([ValidatedNotNull] int value, string name)
{
ArgumentNotNull(value, name);
if (value > 0) return;
throw new ArgumentException("Value must be greater than zero", name);
}
/// <summary>
/// Checks an enumerable argument to ensure it isn't null or empty.
/// </summary>
@@ -62,6 +76,11 @@ namespace Octokit
throw new ArgumentException("List cannot be empty", name);
}
public static void ApiOptionsNotNull(ref ApiOptions options)
{
options = options ?? ApiOptions.None;
}
}
[AttributeUsage(AttributeTargets.Parameter)]

View File

@@ -24,5 +24,21 @@ namespace Octokit
return attribute != null ? attribute.Value : propString.ToLowerInvariant();
}
internal static bool HasParameter(this Enum prop)
{
if (prop == null) return false;
var propString = prop.ToString();
var member = prop.GetType().GetMember(propString).FirstOrDefault();
if (member == null) return false;
var attribute = member.GetCustomAttributes(typeof(ParameterAttribute), false)
.Cast<ParameterAttribute>()
.FirstOrDefault();
return attribute != null;
}
}
}

View File

@@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
namespace Octokit
{
public static class ParameterBuilder
{
public static Dictionary<string, string> AddParameter(string key, string value)
{
Ensure.ArgumentNotNullOrEmptyString(key, nameof(key));
Ensure.ArgumentNotNullOrEmptyString(value, nameof(value));
return new Dictionary<string, string> { { key, value } };
}
public static Dictionary<string, string> AddParameter(string key, Enum value)
{
Ensure.ArgumentNotNullOrEmptyString(key, nameof(key));
Ensure.ArgumentNotNull(value, nameof(value));
if (value.HasParameter())
{
return new Dictionary<string, string> { { key, value.ToParameter() } };
}
return new Dictionary<string, string> { { key, value.ToString() } };
}
public static Dictionary<string, string> AddParameter(this Dictionary<string, string> data, string key, string value)
{
Ensure.ArgumentNotNull(data, nameof(data));
Ensure.ArgumentNotNullOrEmptyString(key, nameof(key));
Ensure.ArgumentNotNullOrEmptyString(value, nameof(value));
data.Add(key, value);
return data;
}
public static Dictionary<string, string> AddParameter(this Dictionary<string, string> data, string key, Enum value)
{
Ensure.ArgumentNotNull(data, nameof(data));
Ensure.ArgumentNotNullOrEmptyString(key, nameof(key));
Ensure.ArgumentNotNull(value, nameof(value));
if (value.HasParameter())
{
data.Add(key, value.ToParameter());
}
else
{
data.Add(key, value.ToString());
}
return data;
}
public static Dictionary<string, string> AddOptionalParameter(this Dictionary<string, string> data, string key, string value)
{
Ensure.ArgumentNotNull(data, nameof(data));
Ensure.ArgumentNotNullOrEmptyString(key, nameof(key));
if (value != null)
{
data.Add(key, value);
}
return data;
}
public static Dictionary<string, string> AddOptionalParameter(this Dictionary<string, string> data, string key, Enum value)
{
Ensure.ArgumentNotNull(data, nameof(data));
Ensure.ArgumentNotNullOrEmptyString(key, nameof(key));
if (value != null)
{
if (value.HasParameter())
{
data.Add(key, value.ToParameter());
}
else
{
data.Add(key, value.ToString());
}
}
return data;
}
}
}

View File

@@ -87,6 +87,14 @@ namespace Octokit
/// </remarks>
IOrganizationsClient Organization { get; }
/// <summary>
/// Access GitHub's Pacakges API.
/// </summary>
/// <remarks>
/// Refer to the API documentation for more information: https://docs.github.com/en/rest/packages
/// </remarks>
IPackagesClient Packages { get; }
/// <summary>
/// Access GitHub's Pull Requests API.
/// </summary>

View File

@@ -0,0 +1,43 @@
using Octokit.Internal;
namespace Octokit
{
public enum PackageType
{
/// <summary>
/// Npm repository packages
/// </summary>
[Parameter(Value = "npm")]
Npm,
/// <summary>
/// Gradle registry packages
/// </summary>
[Parameter(Value = "maven")]
Maven,
/// <summary>
/// RubyGems packages
/// </summary>
[Parameter(Value = "rubygems")]
RubyGems,
/// <summary>
/// Docker container registry packages
/// </summary>
[Parameter(Value = "docker")]
Docker,
/// <summary>
/// Nuget registry packages
/// </summary>
[Parameter(Value = "nuget")]
Nuget,
/// <summary>
/// Container registry packages
/// </summary>
[Parameter(Value = "container")]
Container,
}
}

View File

@@ -0,0 +1,19 @@
using Octokit.Internal;
namespace Octokit
{
public enum PackageVersionState
{
/// <summary>
/// Package version which is active
/// </summary>
[Parameter(Value = "active")]
Active,
/// <summary>
/// Package version whic is deleted
/// </summary>
[Parameter(Value = "deleted")]
Deleted
}
}

View File

@@ -0,0 +1,25 @@
using Octokit.Internal;
namespace Octokit
{
public enum PackageVisibility
{
/// <summary>
/// Only public packages
/// </summary>
[Parameter(Value = "public")]
Public,
/// <summary>
/// Only private packages
/// </summary>
[Parameter(Value = "private")]
Private,
/// <summary>
/// Only supported by container package types, otherwise the same as private
/// </summary>
[Parameter(Value = "internal")]
Internal
}
}

View File

@@ -0,0 +1,78 @@
using Octokit.Internal;
using System;
using System.Diagnostics;
namespace Octokit
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class Package
{
public Package() { }
public Package(long id, string name, PackageType packageType, Author owner, int versionCount, PackageVisibility visibility, string url, DateTime createdAt, DateTime updatedAt, string htmlUrl)
{
Id = id;
Name = name;
PackageType = packageType;
Owner = owner;
VersionCount = versionCount;
Visibility = visibility;
Url = url;
CreatedAt = createdAt;
UpdatedAt = updatedAt;
HtmlUrl = htmlUrl;
}
/// <summary>
/// The Id of the package
/// </summary>
public long Id { get; private set; }
/// <summary>
/// The Name of the package
/// </summary>
public string Name { get; private set; }
/// <summary>
/// The Type of the package
/// </summary>
public StringEnum<PackageType> PackageType { get; private set; }
/// <summary>
/// The Owner of the package
/// </summary>
public Author Owner { get; private set; }
/// <summary>
/// The Version Count of the package
/// </summary>
public int VersionCount { get; private set; }
/// <summary>
/// The Visibility of the package
/// </summary>
public StringEnum<PackageVisibility> Visibility { get; private set; }
/// <summary>
/// The Url of the package
/// </summary>
public string Url { get; private set; }
/// <summary>
/// The Date the package was first created
/// </summary>
public DateTime CreatedAt { get; private set; }
/// <summary>
/// The Date the package was last updated
/// </summary>
public DateTime UpdatedAt { get; private set; }
/// <summary>
/// The Url of the package
/// </summary>
public string HtmlUrl { get; private set; }
internal string DebuggerDisplay => new SimpleJsonSerializer().Serialize(this);
}
}

View File

@@ -0,0 +1,73 @@
using Octokit.Internal;
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace Octokit
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class PackageVersion
{
public PackageVersion() { }
public PackageVersion(long id, string name, string url, string packageHtmlUrl, DateTime createdAt, DateTime updatedAt, string htmlUrl, PackageVersionMetadata metadata)
{
Id = id;
Name = name;
Url = url;
PackageHtmlUrl = packageHtmlUrl;
CreatedAt = createdAt;
UpdatedAt = updatedAt;
HtmlUrl = htmlUrl;
Metadata = metadata;
}
public long Id { get; private set; }
public string Name { get; private set; }
public string Url { get; private set; }
public string PackageHtmlUrl { get; private set; }
public DateTime CreatedAt { get; private set; }
public DateTime UpdatedAt { get; private set; }
public string HtmlUrl { get; private set; }
public PackageVersionMetadata Metadata { get; private set; }
internal string DebuggerDisplay => new SimpleJsonSerializer().Serialize(this);
}
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class PackageVersionMetadata
{
public PackageVersionMetadata() { }
public PackageVersionMetadata(string packageType)
{
PackageType = packageType;
}
public string PackageType { get; private set; }
internal string DebuggerDisplay => new SimpleJsonSerializer().Serialize(this);
}
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class PackageVersionMetadataContainer
{
public PackageVersionMetadataContainer() { }
public PackageVersionMetadataContainer(IReadOnlyList<string> tags)
{
Tags = tags;
}
public IReadOnlyList<string> Tags { get; private set; }
internal string DebuggerDisplay => new SimpleJsonSerializer().Serialize(this);
}
}