Skip to content

Commit

Permalink
GitHub Endpoint Releases (#7)
Browse files Browse the repository at this point in the history
* Github Repository Release and Release Assets

* Repository Deployment Endpoints Added

* Repository Environments Added

* Additional Repository added
build.cake update
  • Loading branch information
louisfischer committed Apr 15, 2024
1 parent 7d90f30 commit 631a177
Show file tree
Hide file tree
Showing 9 changed files with 463 additions and 6 deletions.
8 changes: 4 additions & 4 deletions build.cake
Original file line number Diff line number Diff line change
@@ -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<string>("Target") ?? "Default";
var target = ArgumentOrDefault<string>("Target") ?? "Default";
var buildVersion = MinVer(s => s.WithTagPrefix("v").WithDefaultPreReleasePhase("preview"));

Task("Clean")
Expand Down Expand Up @@ -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}"
}
});
});
Expand Down Expand Up @@ -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);
RunTarget(target);
5 changes: 3 additions & 2 deletions src/Cake.GitHub.Endpoints/Cake.GitHub.Endpoints.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<AssemblyName>Cake.GitHub.Endpoints</AssemblyName>
<AssemblyVersion>0.0.1.0</AssemblyVersion>
<GenerateAssemblyVersionAttribute>true</GenerateAssemblyVersionAttribute>
Expand Down Expand Up @@ -57,7 +57,7 @@
<PackageReference Include="Costura.Fody" Version="5.8.0-alpha0098" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="JWT" Version="10.1.1" />
<PackageReference Include="Octokit" Version="9.0.0" />
<PackageReference Include="Octokit" Version="11.0.0" />
</ItemGroup>

<ItemGroup>
Expand All @@ -73,6 +73,7 @@
<Using Include="Cake.Core.Annotations" />
<Using Include="Cake.Core.Diagnostics" />
<Using Include="Cake.Core.IO" />
<Using Include="Octokit.Models.Response"/>
<Using Include="Cake.Core.Tooling" />
<Using Include="Cake.GitHub.Endpoints.Constants">
<Static>True</Static>
Expand Down
5 changes: 5 additions & 0 deletions src/Cake.GitHub.Endpoints/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
namespace Cake.GitHub.Endpoints;

/// <summary>
/// Contains functionality for working with GitHub Repository Actions Repository Secrets API
/// </summary>
[CakeAliasCategory("GitHub")]
[CakeNamespaceImport("Cake.GitHub.Endpoints")]
public static class GitHubEndpointsRepositoryActionsSecretsAliases
{
/// <summary>
/// List the secrets for a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/actions/secrets/#list-repository-secrets">API documentation</a> for more information.
/// </remarks>
/// <param name="context">The GitHubEndpointContext context</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A <see cref="RepositorySecretsCollection"/> instance for the list of repository secrets.</returns>
public static Task<RepositorySecretsCollection> GitHubRepositoryActionsSecretsGetAll(this IGitHubEndpointContext context) =>
context.GitHubClient().Repository.Actions.Secrets.GetAll(context.Owner, context.RepoName);

/// <summary>
/// Get a secret from a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/actions/secrets/#get-a-repository-secret">API documentation</a> for more information.
/// </remarks>
/// <param name="context">The GitHubEndpointContext context</param>
/// <param name="name">The name of the secret</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A <see cref="RepositorySecret"/> instance for the repository secret.</returns>
public static Task<RepositorySecret> GitHubRepositoryActionsSecretsGet(this IGitHubEndpointContext context, string name) =>
context.GitHubClient().Repository.Actions.Secrets.Get(context.Owner, context.RepoName, name);

/// <summary>
/// Create or update a secret in a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/actions/secrets/#create-or-update-a-repository-secret">API documentation</a> for more information.
/// </remarks>
/// <param name="context">The GitHubEndpointContext context</param>
/// <param name="name">The name of the variable to create or update</param>
/// <param name="keyId">The id of the encryption key used to encrypt the secret.</param>
/// <remarks>Get key and id from <see cref="RepositorySecretsClient.GetPublicKey(string, string)"/> and use the <a href="https://developer.github.com/v3/actions/secrets/#create-or-update-a-repository-secret">API documentation</a> for more information on how to encrypt the secret</remarks>
/// <param name="encryptedValue">The encrypted value and id of the encryption key</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A <see cref="RepositorySecret"/> instance for the repository secret that was created or updated.</returns>
public static Task<RepositorySecret> 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 });

/// <summary>
/// Delete a secret in a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/actions/secrets/#delete-a-repository-secret">API documentation</a> for more information.
/// </remarks>
/// <param name="context">The GitHubEndpointContext context</param>
/// <param name="name">The name of the secret</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public static Task GitHubRepositoryActionsSecretsDelete(this IGitHubEndpointContext context, string name) =>
context.GitHubClient().Repository.Actions.Secrets.Delete(context.Owner, context.RepoName, name);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
namespace Cake.GitHub.Endpoints;

/// <summary>
/// Contains functionality for working with GitHub Repository Actions Repository Variables API
/// </summary>
[CakeAliasCategory("GitHub")]
[CakeNamespaceImport("Cake.GitHub.Endpoints")]
public static class GitHubEndpointsRepositoryActionsVariablesAliases
{
/// <summary>
/// List the variables for a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#list-repository-variables">API documentation</a> for more information.
/// </remarks>
/// <param name="context">The GitHubEndpointContext context</param>
public static Task<RepositoryVariablesCollection> GitHubRepositoryActionsVariablesGetAll(this IGitHubEndpointContext context) =>
context.GitHubClient().Repository.Actions.Variables.GetAll(context.Owner, context.RepoName);

/// <summary>
/// Get a variable from a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#get-a-repository-variable">API documentation</a> for more information.
/// </remarks>
/// <param name="context">The GitHubEndpointContext context</param>
/// <param name="name">The name of the variable</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A <see cref="RepositoryVariable"/> instance for the repository secret.</returns>
public static Task<RepositoryVariable> GitHubRepositoryActionsVariablesGet(this IGitHubEndpointContext context, string name) =>
context.GitHubClient().Repository.Actions.Variables.Get(context.Owner, context.RepoName, name);

/// <summary>
/// List the organization variables for a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#list-repository-organization-variables">API documentation</a> for more information.
/// </remarks>
/// <param name="context">The GitHubEndpointContext context</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A <see cref="RepositoryVariablesCollection"/> instance for the list of repository variables.</returns>
public static Task<RepositoryVariablesCollection> GitHubRepositoryActionsVariablesGetAllOrganization(this IGitHubEndpointContext context) =>
context.GitHubClient().Repository.Actions.Variables.GetAllOrganization(context.Owner, context.RepoName);

/// <summary>
/// Create a variable in a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-a-repository-variable">API documentation</a> for more information.
/// </remarks>
/// <param name="context">The GitHubEndpointContext context</param>
/// <param name="name">The name of the variable to create</param>
/// <param name="value">The value of the variable to create</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A <see cref="RepositoryVariable"/> instance for the repository variable that was created.</returns>
public static Task<RepositoryVariable> GitHubRepositoryActionsVariablesCreate(this IGitHubEndpointContext context, string name, string value) =>
context.GitHubClient().Repository.Actions.Variables.Create(context.Owner, context.RepoName, new Variable(name, value));

/// <summary>
/// Update a variable in a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-a-repository-variable">API documentation</a> for more information.
/// </remarks>
/// <param name="context">The GitHubEndpointContext context</param>
/// <param name="name">The name of the variable to create</param>
/// <param name="value">The value of the variable to create</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public static Task<RepositoryVariable> GitHubRepositoryActionsVariablesUpdate(this IGitHubEndpointContext context, string name, string value) =>
context.GitHubClient().Repository.Actions.Variables.Update(context.Owner, context.RepoName, new Variable(name, value));

/// <summary>
/// Delete a variable in a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-a-repository-variable">API documentation</a> for more information.
/// </remarks>
/// <param name="context">The GitHubEndpointContext context</param>
/// <param name="name">The name of the variable</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public static Task GitHubRepositoryActionsVariablesDelete(this IGitHubEndpointContext context, string name) =>
context.GitHubClient().Repository.Actions.Variables.Delete(context.Owner, context.RepoName, name);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
namespace Cake.GitHub.Endpoints;

/// <summary>
/// Contains functionality for working with GitHub Repository Branches API
/// </summary>
[CakeAliasCategory("GitHub")]
[CakeNamespaceImport("Cake.GitHub.Endpoints")]
public static class GitHubEndpointsRepositoryBranchAliases
{
/// <summary>
/// Gets all the branches for the specified repository.
/// </summary>
/// <param name="context">The GitHubEndpointContext context</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/branches/#list-branches">API documentation</a> for more details
/// </remarks>
public static Task<IReadOnlyList<Branch>> GitHubRepositoryBranch(this IGitHubEndpointContext context) =>
context.GitHubClient().Repository.Branch.GetAll(context.Owner, context.RepoName);

/// <summary>
/// Gets the specified branch.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/branches/#get-branch">API documentation</a> for more details
/// </remarks>
/// <param name="context">The GitHubEndpointContext context</param>
/// <param name="branch">The name of the branch</param>
public static Task<Branch> GitHubRepositoryBranchGet(this IGitHubEndpointContext context, string branch) =>
context.GitHubClient().Repository.Branch.Get(context.Owner, context.RepoName, branch);

/// <summary>
/// Get the branch protection settings for the specified branch
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/branches/#get-branch-protection">API documentation</a> for more details
/// </remarks>
/// <param name="context">The GitHubEndpointContext context</param>
/// <param name="branch">The name of the branch</param>
public static Task<BranchProtectionSettings> GitHubRepositoryBranchProtectionGet(this IGitHubEndpointContext context, string branch) =>
context.GitHubClient().Repository.Branch.GetBranchProtection(context.Owner, context.RepoName, branch);

/// <summary>
/// Renames a branch in a repository
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/branches/branches?apiVersion=2022-11-28#rename-a-branch">API documentation</a> for more details
/// </remarks>
/// <param name="context">The GitHubEndpointContext context</param>
/// <param name="branch">The name of the branch to rename</param>
/// <param name="newName">The new name of the branch</param>
public static Task<Branch> GitHubRepositoryBranchRename(this IGitHubEndpointContext context, string branch, string newName) =>
context.GitHubClient().Repository.Branch.RenameBranch(context.Owner, context.RepoName, branch, newName);

/// <summary>
/// Get the required status checks for the specified branch
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/branches/#get-required-status-checks-of-protected-branch">API documentation</a> for more details
/// </remarks>
/// <param name="context">The GitHubEndpointContext context</param>
/// <param name="branch">The name of the branch</param>
public static Task<BranchProtectionRequiredStatusChecks> GitHubRepositoryBranchRequiredStatusChecks(this IGitHubEndpointContext context, string branch) =>
context.GitHubClient().Repository.Branch.GetRequiredStatusChecks(context.Owner, context.RepoName, branch);

/// <summary>
/// Get restrictions for the specified branch (applies only to Organization owned repositories)
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/branches/#get-restrictions-of-protected-branch">API documentation</a> for more details
/// </remarks>
/// <param name="context">The GitHubEndpointContext context</param>
/// <param name="branch">The name of the branch</param>
public static Task<BranchProtectionPushRestrictions> GitHubRepositoryBranchProtectedRestrictions(this IGitHubEndpointContext context, string branch) =>
context.GitHubClient().Repository.Branch.GetProtectedBranchRestrictions(context.Owner, context.RepoName, branch);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
namespace Cake.GitHub.Endpoints;

/// <summary>
/// Contains functionality for working with GitHub Repository Releases API
/// </summary>
[CakeAliasCategory("GitHub")]
[CakeNamespaceImport("Cake.GitHub.Endpoints")]
public static class GitHubEndpointsRepositoryDeploymentsAliases
{
/// <summary>
/// Gets all the deployments for the specified repository. Any user with pull access
/// to a repository can view deployments.
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/repos/deployments/#list-deployments
/// </remarks>
public static Task<IReadOnlyList<Deployment>> GitHubRepositoryDeploymentGetAll(this IGitHubEndpointContext context) =>
context.GitHubClient().Repository.Deployment.GetAll(context.Owner, context.RepoName, Options.DefaultApiOptions);

/// <summary>
/// Creates a new deployment for the specified repository.
/// Users with push access can create a deployment for a given ref.
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/repos/deployments/#create-a-deployment
/// </remarks>
/// <param name="context">The GitHubEndpointContext context</param>
/// <param name="deployment">A <see cref="NewDeployment"/> instance describing the new deployment to create</param>
public static Task<Deployment> GitHubRepositoryDeploymentCreate(this IGitHubEndpointContext context, NewDeployment deployment) =>
context.GitHubClient().Repository.Deployment.Create(context.Owner, context.RepoName, deployment);

/// <summary>
/// Gets all the statuses for the given deployment. Any user with pull access to a repository can
/// view deployments.
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/repos/deployments/#list-deployment-statuses
/// </remarks>
/// <param name="context">The GitHubEndpointContext context</param>
/// <param name="deploymentId">The id of the deployment.</param>
public static Task<IReadOnlyList<DeploymentStatus>> GitHubRepositoryDeploymentGetAll(this IGitHubEndpointContext context, int deploymentId) =>
context.GitHubClient().Repository.Deployment.Status.GetAll(context.Owner, context.RepoName, deploymentId);

/// <summary>
/// Creates a new status for the given deployment. Users with push access can create deployment
/// statuses for a given deployment.
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/repos/deployments/#create-a-deployment-status
/// </remarks>
/// <param name="context">The GitHubEndpointContext context</param>
/// <param name="deploymentId">The id of the deployment.</param>
/// <param name="deploymentStatus">The new deployment status to create.</param>
public static Task<DeploymentStatus> GitHubRepositoryDeploymentCreate(this IGitHubEndpointContext context, int deploymentId, NewDeploymentStatus deploymentStatus) =>
context.GitHubClient().Repository.Deployment.Status.Create(context.Owner, context.RepoName, deploymentId, deploymentStatus);
}
Loading

0 comments on commit 631a177

Please sign in to comment.