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
+162
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);
}
}
}
+19
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)]
+16
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;
}
}
}
+91
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;
}
}
}