diff --git a/build.cake b/build.cake index 3836fdc..d7b0fc1 100644 --- a/build.cake +++ b/build.cake @@ -1,7 +1,7 @@ #addin "nuget:?package=Cake.MinVer&version=3.0.0" #addin "nuget:?package=Cake.Args&version=3.0.0" -var target = ArgumentOrDefault("Target") ?? "Default"; +var target = ArgumentOrDefault("Target") ?? "Default"; var buildVersion = MinVer(s => s.WithTagPrefix("v").WithDefaultPreReleasePhase("preview")); Task("Clean") @@ -53,7 +53,7 @@ Task("Pack") MSBuildSettings = new DotNetMSBuildSettings { Version = buildVersion.Version, - PackageReleaseNotes = $"https://github.com/cake-contrib/Cake.GitHub.Endpoints/releases/tag/v{buildVersion.Version}" + PackageReleaseNotes = $"https://github.com/cake-contrib/Cake.GitHub.Endpoints/releases/tag/v{buildVersion.Version}" } }); }); @@ -91,11 +91,11 @@ Task("Publish") .IsDependentOn("Push") .WithCriteria(() => GetFiles("./artifact/nuget/**/*")?.Count > 0) .WithCriteria(() => GitHubActions.IsRunningOnGitHubActions) - .WithCriteria(() => string.Equals("refs/heads/main", GitHubActions.Environment.Workflow.Ref, StringComparison.OrdinalIgnoreCase) || GitHubActions.Environment.Workflow.Ref.StartsWith("refs/tags/", StringComparison.OrdinalIgnoreCase)) + .WithCriteria(() => string.Equals("refs/heads/main", GitHubActions.Environment.Workflow.Ref, StringComparison.OrdinalIgnoreCase)) .Does(async () => await GitHubActions.Commands.UploadArtifact(Directory("./artifact/nuget"), $"Cake.GitHub.Endpoints.{buildVersion.Version}")); Task("Default") .IsDependentOn("Publish"); -RunTarget(target); \ No newline at end of file +RunTarget(target); diff --git a/src/Cake.GitHub.Endpoints/Cake.GitHub.Endpoints.csproj b/src/Cake.GitHub.Endpoints/Cake.GitHub.Endpoints.csproj index 55ce586..59300d3 100644 --- a/src/Cake.GitHub.Endpoints/Cake.GitHub.Endpoints.csproj +++ b/src/Cake.GitHub.Endpoints/Cake.GitHub.Endpoints.csproj @@ -1,7 +1,7 @@  - net6.0;net7.0;net8.0 + net6.0;net8.0 Cake.GitHub.Endpoints 0.0.1.0 true @@ -57,7 +57,7 @@ - + @@ -73,6 +73,7 @@ + True diff --git a/src/Cake.GitHub.Endpoints/Constants.cs b/src/Cake.GitHub.Endpoints/Constants.cs index dbfb639..616975e 100644 --- a/src/Cake.GitHub.Endpoints/Constants.cs +++ b/src/Cake.GitHub.Endpoints/Constants.cs @@ -10,6 +10,11 @@ public static class Values } } + public static class Options + { + public static readonly ApiOptions DefaultApiOptions = new ApiOptions { PageSize = 100 }; + } + public static class Repos { public static class Contents diff --git a/src/Cake.GitHub.Endpoints/GitHubEndpointsRepositoryActionsSecretsAliases.cs b/src/Cake.GitHub.Endpoints/GitHubEndpointsRepositoryActionsSecretsAliases.cs new file mode 100644 index 0000000..b6b0c52 --- /dev/null +++ b/src/Cake.GitHub.Endpoints/GitHubEndpointsRepositoryActionsSecretsAliases.cs @@ -0,0 +1,62 @@ +namespace Cake.GitHub.Endpoints; + +/// +/// Contains functionality for working with GitHub Repository Actions Repository Secrets API +/// +[CakeAliasCategory("GitHub")] +[CakeNamespaceImport("Cake.GitHub.Endpoints")] +public static class GitHubEndpointsRepositoryActionsSecretsAliases +{ + /// + /// List the secrets for a repository. + /// + /// + /// See the API documentation for more information. + /// + /// The GitHubEndpointContext context + /// Thrown when a general API error occurs. + /// A instance for the list of repository secrets. + public static Task GitHubRepositoryActionsSecretsGetAll(this IGitHubEndpointContext context) => + context.GitHubClient().Repository.Actions.Secrets.GetAll(context.Owner, context.RepoName); + + /// + /// Get a secret from a repository. + /// + /// + /// See the API documentation for more information. + /// + /// The GitHubEndpointContext context + /// The name of the secret + /// Thrown when a general API error occurs. + /// A instance for the repository secret. + public static Task GitHubRepositoryActionsSecretsGet(this IGitHubEndpointContext context, string name) => + context.GitHubClient().Repository.Actions.Secrets.Get(context.Owner, context.RepoName, name); + + /// + /// Create or update a secret in a repository. + /// + /// + /// See the API documentation for more information. + /// + /// The GitHubEndpointContext context + /// The name of the variable to create or update + /// The id of the encryption key used to encrypt the secret. + /// Get key and id from and use the API documentation for more information on how to encrypt the secret + /// The encrypted value and id of the encryption key + /// Thrown when a general API error occurs. + /// A instance for the repository secret that was created or updated. + public static Task GitHubRepositoryActionsSecretsCreate(this IGitHubEndpointContext context, string name, string keyId, string encryptedValue) => + context.GitHubClient().Repository.Actions.Secrets.CreateOrUpdate(context.Owner, context.RepoName, name, new UpsertRepositorySecret { EncryptedValue = encryptedValue, KeyId = keyId }); + + /// + /// Delete a secret in a repository. + /// + /// + /// See the API documentation for more information. + /// + /// The GitHubEndpointContext context + /// The name of the secret + /// Thrown when a general API error occurs. + public static Task GitHubRepositoryActionsSecretsDelete(this IGitHubEndpointContext context, string name) => + context.GitHubClient().Repository.Actions.Secrets.Delete(context.Owner, context.RepoName, name); +} diff --git a/src/Cake.GitHub.Endpoints/GitHubEndpointsRepositoryActionsVariablesAliases.cs b/src/Cake.GitHub.Endpoints/GitHubEndpointsRepositoryActionsVariablesAliases.cs new file mode 100644 index 0000000..2d7f5d3 --- /dev/null +++ b/src/Cake.GitHub.Endpoints/GitHubEndpointsRepositoryActionsVariablesAliases.cs @@ -0,0 +1,83 @@ +namespace Cake.GitHub.Endpoints; + +/// +/// Contains functionality for working with GitHub Repository Actions Repository Variables API +/// +[CakeAliasCategory("GitHub")] +[CakeNamespaceImport("Cake.GitHub.Endpoints")] +public static class GitHubEndpointsRepositoryActionsVariablesAliases +{ + /// + /// List the variables for a repository. + /// + /// + /// See the API documentation for more information. + /// + /// The GitHubEndpointContext context + public static Task GitHubRepositoryActionsVariablesGetAll(this IGitHubEndpointContext context) => + context.GitHubClient().Repository.Actions.Variables.GetAll(context.Owner, context.RepoName); + + /// + /// Get a variable from a repository. + /// + /// + /// See the API documentation for more information. + /// + /// The GitHubEndpointContext context + /// The name of the variable + /// Thrown when a general API error occurs. + /// A instance for the repository secret. + public static Task GitHubRepositoryActionsVariablesGet(this IGitHubEndpointContext context, string name) => + context.GitHubClient().Repository.Actions.Variables.Get(context.Owner, context.RepoName, name); + + /// + /// List the organization variables for a repository. + /// + /// + /// See the API documentation for more information. + /// + /// The GitHubEndpointContext context + /// Thrown when a general API error occurs. + /// A instance for the list of repository variables. + public static Task GitHubRepositoryActionsVariablesGetAllOrganization(this IGitHubEndpointContext context) => + context.GitHubClient().Repository.Actions.Variables.GetAllOrganization(context.Owner, context.RepoName); + + /// + /// Create a variable in a repository. + /// + /// + /// See the API documentation for more information. + /// + /// The GitHubEndpointContext context + /// The name of the variable to create + /// The value of the variable to create + /// Thrown when a general API error occurs. + /// A instance for the repository variable that was created. + public static Task GitHubRepositoryActionsVariablesCreate(this IGitHubEndpointContext context, string name, string value) => + context.GitHubClient().Repository.Actions.Variables.Create(context.Owner, context.RepoName, new Variable(name, value)); + + /// + /// Update a variable in a repository. + /// + /// + /// See the API documentation for more information. + /// + /// The GitHubEndpointContext context + /// The name of the variable to create + /// The value of the variable to create + /// Thrown when a general API error occurs. + public static Task GitHubRepositoryActionsVariablesUpdate(this IGitHubEndpointContext context, string name, string value) => + context.GitHubClient().Repository.Actions.Variables.Update(context.Owner, context.RepoName, new Variable(name, value)); + + /// + /// Delete a variable in a repository. + /// + /// + /// See the API documentation for more information. + /// + /// The GitHubEndpointContext context + /// The name of the variable + /// Thrown when a general API error occurs. + public static Task GitHubRepositoryActionsVariablesDelete(this IGitHubEndpointContext context, string name) => + context.GitHubClient().Repository.Actions.Variables.Delete(context.Owner, context.RepoName, name); +} diff --git a/src/Cake.GitHub.Endpoints/GitHubEndpointsRepositoryBranchAliases.cs b/src/Cake.GitHub.Endpoints/GitHubEndpointsRepositoryBranchAliases.cs new file mode 100644 index 0000000..9766825 --- /dev/null +++ b/src/Cake.GitHub.Endpoints/GitHubEndpointsRepositoryBranchAliases.cs @@ -0,0 +1,75 @@ +namespace Cake.GitHub.Endpoints; + +/// +/// Contains functionality for working with GitHub Repository Branches API +/// +[CakeAliasCategory("GitHub")] +[CakeNamespaceImport("Cake.GitHub.Endpoints")] +public static class GitHubEndpointsRepositoryBranchAliases +{ + /// + /// Gets all the branches for the specified repository. + /// + /// The GitHubEndpointContext context + /// + /// See the API documentation for more details + /// + public static Task> GitHubRepositoryBranch(this IGitHubEndpointContext context) => + context.GitHubClient().Repository.Branch.GetAll(context.Owner, context.RepoName); + + /// + /// Gets the specified branch. + /// + /// + /// See the API documentation for more details + /// + /// The GitHubEndpointContext context + /// The name of the branch + public static Task GitHubRepositoryBranchGet(this IGitHubEndpointContext context, string branch) => + context.GitHubClient().Repository.Branch.Get(context.Owner, context.RepoName, branch); + + /// + /// Get the branch protection settings for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The GitHubEndpointContext context + /// The name of the branch + public static Task GitHubRepositoryBranchProtectionGet(this IGitHubEndpointContext context, string branch) => + context.GitHubClient().Repository.Branch.GetBranchProtection(context.Owner, context.RepoName, branch); + + /// + /// Renames a branch in a repository + /// + /// + /// See the API documentation for more details + /// + /// The GitHubEndpointContext context + /// The name of the branch to rename + /// The new name of the branch + public static Task GitHubRepositoryBranchRename(this IGitHubEndpointContext context, string branch, string newName) => + context.GitHubClient().Repository.Branch.RenameBranch(context.Owner, context.RepoName, branch, newName); + + /// + /// Get the required status checks for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The GitHubEndpointContext context + /// The name of the branch + public static Task GitHubRepositoryBranchRequiredStatusChecks(this IGitHubEndpointContext context, string branch) => + context.GitHubClient().Repository.Branch.GetRequiredStatusChecks(context.Owner, context.RepoName, branch); + + /// + /// Get restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The GitHubEndpointContext context + /// The name of the branch + public static Task GitHubRepositoryBranchProtectedRestrictions(this IGitHubEndpointContext context, string branch) => + context.GitHubClient().Repository.Branch.GetProtectedBranchRestrictions(context.Owner, context.RepoName, branch); +} diff --git a/src/Cake.GitHub.Endpoints/GitHubEndpointsRepositoryDeploymentsAliases.cs b/src/Cake.GitHub.Endpoints/GitHubEndpointsRepositoryDeploymentsAliases.cs new file mode 100644 index 0000000..a820273 --- /dev/null +++ b/src/Cake.GitHub.Endpoints/GitHubEndpointsRepositoryDeploymentsAliases.cs @@ -0,0 +1,56 @@ +namespace Cake.GitHub.Endpoints; + +/// +/// Contains functionality for working with GitHub Repository Releases API +/// +[CakeAliasCategory("GitHub")] +[CakeNamespaceImport("Cake.GitHub.Endpoints")] +public static class GitHubEndpointsRepositoryDeploymentsAliases +{ + /// + /// Gets all the deployments for the specified repository. Any user with pull access + /// to a repository can view deployments. + /// + /// + /// http://developer.github.com/v3/repos/deployments/#list-deployments + /// + public static Task> GitHubRepositoryDeploymentGetAll(this IGitHubEndpointContext context) => + context.GitHubClient().Repository.Deployment.GetAll(context.Owner, context.RepoName, Options.DefaultApiOptions); + + /// + /// Creates a new deployment for the specified repository. + /// Users with push access can create a deployment for a given ref. + /// + /// + /// http://developer.github.com/v3/repos/deployments/#create-a-deployment + /// + /// The GitHubEndpointContext context + /// A instance describing the new deployment to create + public static Task GitHubRepositoryDeploymentCreate(this IGitHubEndpointContext context, NewDeployment deployment) => + context.GitHubClient().Repository.Deployment.Create(context.Owner, context.RepoName, deployment); + + /// + /// Gets all the statuses for the given deployment. Any user with pull access to a repository can + /// view deployments. + /// + /// + /// http://developer.github.com/v3/repos/deployments/#list-deployment-statuses + /// + /// The GitHubEndpointContext context + /// The id of the deployment. + public static Task> GitHubRepositoryDeploymentGetAll(this IGitHubEndpointContext context, int deploymentId) => + context.GitHubClient().Repository.Deployment.Status.GetAll(context.Owner, context.RepoName, deploymentId); + + /// + /// Creates a new status for the given deployment. Users with push access can create deployment + /// statuses for a given deployment. + /// + /// + /// http://developer.github.com/v3/repos/deployments/#create-a-deployment-status + /// + /// The GitHubEndpointContext context + /// The id of the deployment. + /// The new deployment status to create. + public static Task GitHubRepositoryDeploymentCreate(this IGitHubEndpointContext context, int deploymentId, NewDeploymentStatus deploymentStatus) => + context.GitHubClient().Repository.Deployment.Status.Create(context.Owner, context.RepoName, deploymentId, deploymentStatus); +} diff --git a/src/Cake.GitHub.Endpoints/GitHubEndpointsRepositoryEnvironmentAliases.cs b/src/Cake.GitHub.Endpoints/GitHubEndpointsRepositoryEnvironmentAliases.cs new file mode 100644 index 0000000..8939e6b --- /dev/null +++ b/src/Cake.GitHub.Endpoints/GitHubEndpointsRepositoryEnvironmentAliases.cs @@ -0,0 +1,18 @@ +namespace Cake.GitHub.Endpoints; + +/// +/// +/// +public static class GitHubEndpointsRepositoryEnvironmentAliases +{ + /// + /// Gets all the environments for the specified repository. Any user with pull access + /// to a repository can view deployments. + /// + /// + /// https://docs.github.com/en/rest/deployments/environments#list-environments + /// + /// The GitHubEndpointContext context + public static Task GitHubRepositoryEnvironmentGetAll(this IGitHubEndpointContext context) => + context.GitHubClient().Repository.Environment.GetAll(context.Owner, context.RepoName, Options.DefaultApiOptions); +} diff --git a/src/Cake.GitHub.Endpoints/GitHubEndpointsRepositoryReleaseAliases.cs b/src/Cake.GitHub.Endpoints/GitHubEndpointsRepositoryReleaseAliases.cs new file mode 100644 index 0000000..7f84b78 --- /dev/null +++ b/src/Cake.GitHub.Endpoints/GitHubEndpointsRepositoryReleaseAliases.cs @@ -0,0 +1,157 @@ +namespace Cake.GitHub.Endpoints; + +/// +/// Contains functionality for working with GitHub Repository Releases API +/// +[CakeAliasCategory("GitHub")] +[CakeNamespaceImport("Cake.GitHub.Endpoints")] +public static class GitHubRepositoryReleaseAliases +{ + /// + /// Gets all s for the specified repository. + /// + /// + /// See the API documentation for more information. + /// + public static Task> GitHubRepositoryReleaseGetAll(this IGitHubEndpointContext context) => + context.GitHubClient().Repository.Release.GetAll(context.Owner, context.RepoName, Options.DefaultApiOptions); + + /// + /// Gets a single for the specified repository. + /// + /// + /// See the API documentation for more information. + /// + /// The GitHubEndpointContext context + /// The tag of the release + /// Thrown when a general API error occurs. + public static Task GitHubRepositoryReleaseGet(this IGitHubEndpointContext context, string tag) => + context.GitHubClient().Repository.Release.Get(context.Owner, context.RepoName, tag); + + /// + /// Gets the latest for the specified repository. + /// + /// + /// See the API documentation for more information. + /// + /// The GitHubEndpointContext context + /// Thrown when a general API error occurs. + public static Task GitHubRepositoryReleaseGetLatest(this IGitHubEndpointContext context) => + context.GitHubClient().Repository.Release.GetLatest(context.Owner, context.RepoName); + + /// + /// Creates a new for the specified repository. + /// + /// + /// See the API documentation for more information. + /// + /// The GitHubEndpointContext context + /// A description of the release to create + /// Thrown when a general API error occurs. + public static Task GitHubRepositoryReleaseCreate(this IGitHubEndpointContext context, NewRelease data) => + context.GitHubClient().Repository.Release.Create(context.Owner, context.RepoName, data); + + /// + /// Edits an existing for the specified repository. + /// + /// + /// See the API documentation for more information. + /// + /// The GitHubEndpointContext context + /// The id of the release + /// A description of the release to edit + /// Thrown when a general API error occurs. + public static Task GitHubRepositoryReleaseEdit(this IGitHubEndpointContext context, int id, ReleaseUpdate data) => + context.GitHubClient().Repository.Release.Edit(context.Owner, context.RepoName, id, data); + + /// + /// Deletes an existing for the specified repository. + /// + /// + /// See the API documentation for more information. + /// + /// The GitHubEndpointContext context + /// The id of the release to delete + /// Thrown when a general API error occurs. + public static Task GitHubRepositoryReleaseDelete(this IGitHubEndpointContext context, int id) => + context.GitHubClient().Repository.Release.Delete(context.Owner, context.RepoName, id); + + /// + /// Gets the specified for the specified release of the specified repository. + /// + /// + /// See the API documentation for more information. + /// + /// The GitHubEndpointContext context + /// The id of the + public static Task GitHubRepositoryReleaseGetAsset(this IGitHubEndpointContext context, int assetId) => + context.GitHubClient().Repository.Release.GetAsset(context.Owner, context.RepoName, assetId); + + /// + /// Gets all for the specified release of the specified repository. + /// + /// + /// See the API documentation for more information. + /// + /// The GitHubEndpointContext context + /// The id of the . + /// Thrown when a general API error occurs. + public static Task> GitHubRepositoryReleaseGetAssetsAll(this IGitHubEndpointContext context, int assetId) => + context.GitHubClient().Repository.Release.GetAllAssets(context.Owner, context.RepoName, assetId); + + /// + /// Edits the for the specified release of the specified repository. + /// + /// + /// See the API documentation for more information. + /// + /// The GitHubEndpointContext context + /// The id of the + /// Description of the asset with its amended data + public static Task GitHubRepositoryReleaseEditAsset(this IGitHubEndpointContext context, int assetId, ReleaseAssetUpdate data) => + context.GitHubClient().Repository.Release.EditAsset(context.Owner, context.RepoName, assetId, data); + + /// + /// Deletes the specified from the specified repository + /// + /// + /// See the API documentation for more information. + /// + /// The GitHubEndpointContext context + /// The id of the . + public static Task GitHubRepositoryReleaseDeleteAsset(this IGitHubEndpointContext context, int assetId) => + context.GitHubClient().Repository.Release.DeleteAsset(context.Owner, context.RepoName, assetId); + + /// + /// Uploads a for the specified release. + /// + /// + /// See the API documentation for more information. + /// + /// The GitHubEndpointContext context + /// The tag of the release to upload the asset to + /// Description of the asset with its data + /// An optional token to monitor for cancellation requests + /// Thrown when a general API error occurs. + /// Thrown when a release with the tag is not found + public static async Task GitHubRepositoryReleaseUploadAsset(this IGitHubEndpointContext context, string tag, ReleaseAssetUpload data, CancellationToken cancellationToken = default) + { + var release = await context.GitHubClient().Repository.Release.Get(context.Owner, context.RepoName, tag); + if (release is null) + throw new CakeException($"Release with tag '{tag}' not found."); + + return await context.GitHubClient().Repository.Release.UploadAsset(release, data, cancellationToken); + } + + /// + /// Generates a s for the specified repository with auto generated notes. + /// + /// + /// See the API documentation for more information. + /// + /// The GitHubEndpointContext context + /// The request for generating release notes + /// Thrown when a general API error occurs. + public static Task GitHubRepositoryReleaseDeleteAsset(this IGitHubEndpointContext context, GenerateReleaseNotesRequest data) => + context.GitHubClient().Repository.Release.GenerateReleaseNotes(context.Owner, context.RepoName, data); +}