From bdcb2990b321d2fc1e9379f637e3e6ab97f20126 Mon Sep 17 00:00:00 2001 From: Christopher Diaz Date: Wed, 19 Jun 2024 15:28:07 -0400 Subject: [PATCH] feat: support tag based policies Signed-off-by: Christopher Diaz --- .../src/actions/githubEnvironment.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/plugins/scaffolder-backend-module-github/src/actions/githubEnvironment.ts b/plugins/scaffolder-backend-module-github/src/actions/githubEnvironment.ts index 7f6f9f7fa3..e821ff0cd6 100644 --- a/plugins/scaffolder-backend-module-github/src/actions/githubEnvironment.ts +++ b/plugins/scaffolder-backend-module-github/src/actions/githubEnvironment.ts @@ -44,6 +44,7 @@ export function createGithubEnvironmentAction(options: { custom_branch_policies: boolean; }; customBranchPolicyNames?: string[]; + customTagPolicyNames?: string[]; environmentVariables?: { [key: string]: string }; secrets?: { [key: string]: string }; token?: string; @@ -94,6 +95,16 @@ export function createGithubEnvironmentAction(options: { type: 'string', }, }, + customTagPolicyNames: { + title: 'Custom Tag Policy Name', + description: `The name pattern that tags must match in order to deploy to the environment. + + Wildcard characters will not match /. For example, to match tags that begin with release/ and contain an additional single slash, use release/*/*. For more information about pattern matching syntax, see the Ruby File.fnmatch documentation.`, + type: 'array', + items: { + type: 'string', + }, + }, environmentVariables: { title: 'Environment Variables', description: `Environment variables attached to the deployment environment`, @@ -118,6 +129,7 @@ export function createGithubEnvironmentAction(options: { name, deploymentBranchPolicy, customBranchPolicyNames, + customTagPolicyNames, environmentVariables, secrets, token: providedToken, @@ -153,6 +165,19 @@ export function createGithubEnvironmentAction(options: { await client.rest.repos.createDeploymentBranchPolicy({ owner: owner, repo: repo, + type: 'branch', + environment_name: name, + name: item, + }); + } + } + + if (customTagPolicyNames) { + for (const item of customTagPolicyNames) { + await client.rest.repos.createDeploymentBranchPolicy({ + owner: owner, + repo: repo, + type: 'tag', environment_name: name, name: item, });