@backstage/plugin-scaffolder-backend-module-github 0.7.2-next.0 → 0.8.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +64 -0
- package/dist/actions/github.cjs.js +45 -52
- package/dist/actions/github.cjs.js.map +1 -1
- package/dist/actions/githubActionsDispatch.cjs.js +15 -29
- package/dist/actions/githubActionsDispatch.cjs.js.map +1 -1
- package/dist/actions/githubAutolinks.cjs.js +15 -30
- package/dist/actions/githubAutolinks.cjs.js.map +1 -1
- package/dist/actions/githubBranchProtection.cjs.js +15 -23
- package/dist/actions/githubBranchProtection.cjs.js.map +1 -1
- package/dist/actions/githubDeployKey.cjs.js +21 -41
- package/dist/actions/githubDeployKey.cjs.js.map +1 -1
- package/dist/actions/githubEnvironment.cjs.js +47 -89
- package/dist/actions/githubEnvironment.cjs.js.map +1 -1
- package/dist/actions/githubIssuesLabel.cjs.js +12 -27
- package/dist/actions/githubIssuesLabel.cjs.js.map +1 -1
- package/dist/actions/githubPagesEnable.cjs.js +15 -34
- package/dist/actions/githubPagesEnable.cjs.js.map +1 -1
- package/dist/actions/githubPullRequest.cjs.js +66 -126
- package/dist/actions/githubPullRequest.cjs.js.map +1 -1
- package/dist/actions/githubRepoCreate.cjs.js +35 -42
- package/dist/actions/githubRepoCreate.cjs.js.map +1 -1
- package/dist/actions/githubRepoPush.cjs.js +23 -30
- package/dist/actions/githubRepoPush.cjs.js.map +1 -1
- package/dist/actions/githubWebhook.cjs.js +29 -63
- package/dist/actions/githubWebhook.cjs.js.map +1 -1
- package/dist/actions/inputProperties.cjs.js +145 -281
- package/dist/actions/inputProperties.cjs.js.map +1 -1
- package/dist/actions/outputProperties.cjs.js +9 -12
- package/dist/actions/outputProperties.cjs.js.map +1 -1
- package/dist/index.d.ts +210 -211
- package/dist/module.cjs.js +4 -9
- package/dist/module.cjs.js.map +1 -1
- package/package.json +9 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"githubDeployKey.cjs.js","sources":["../../src/actions/githubDeployKey.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport {\n createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { getOctokitOptions } from '../util';\nimport { Octokit } from 'octokit';\nimport Sodium from 'libsodium-wrappers';\nimport { examples } from './githubDeployKey.examples';\n\n/**\n * Creates an `github:deployKey:create` Scaffolder action that creates a Deploy Key\n *\n * @public\n */\nexport function createGithubDeployKeyAction(options: {\n integrations: ScmIntegrationRegistry;\n}) {\n const { integrations } = options;\n // For more information on how to define custom actions, see\n // https://backstage.io/docs/features/software-templates/writing-custom-actions\n return createTemplateAction
|
|
1
|
+
{"version":3,"file":"githubDeployKey.cjs.js","sources":["../../src/actions/githubDeployKey.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport {\n createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { getOctokitOptions } from '../util';\nimport { Octokit } from 'octokit';\nimport Sodium from 'libsodium-wrappers';\nimport { examples } from './githubDeployKey.examples';\n\n/**\n * Creates an `github:deployKey:create` Scaffolder action that creates a Deploy Key\n *\n * @public\n */\nexport function createGithubDeployKeyAction(options: {\n integrations: ScmIntegrationRegistry;\n}) {\n const { integrations } = options;\n // For more information on how to define custom actions, see\n // https://backstage.io/docs/features/software-templates/writing-custom-actions\n return createTemplateAction({\n id: 'github:deployKey:create',\n description: 'Creates and stores Deploy Keys',\n examples,\n schema: {\n input: {\n repoUrl: z =>\n z.string({\n description:\n 'Accepts the format `github.com?repo=reponame&owner=owner` where `reponame` is the new repository name and `owner` is an organization or username',\n }),\n publicKey: z =>\n z.string({\n description:\n 'Generated from `ssh-keygen`. Begins with `ssh-rsa`, `ecdsa-sha2-nistp256`, `ecdsa-sha2-nistp384`, `ecdsa-sha2-nistp521`, `ssh-ed25519`, `sk-ecdsa-sha2-nistp256@openssh.com`, or `sk-ssh-ed25519@openssh.com`.',\n }),\n privateKey: z =>\n z.string({\n description: 'SSH Private Key generated from `ssh-keygen`',\n }),\n deployKeyName: z =>\n z.string({\n description: `Name of the Deploy Key`,\n }),\n privateKeySecretName: z =>\n z\n .string({\n description:\n 'Name of the GitHub Secret to store the private key related to the Deploy Key. Defaults to: `KEY_NAME_PRIVATE_KEY` where `KEY_NAME` is the name of the Deploy Key',\n })\n .optional(),\n token: z =>\n z\n .string({\n description: 'The token to use for authorization to GitHub',\n })\n .optional(),\n },\n output: {\n privateKeySecretName: z =>\n z.string({\n description:\n 'The GitHub Action Repo Secret Name for the Private Key',\n }),\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n publicKey,\n privateKey,\n deployKeyName,\n privateKeySecretName = `${deployKeyName\n .split(' ')\n .join('_')\n .toLocaleUpperCase('en-US')}_PRIVATE_KEY`,\n token: providedToken,\n } = ctx.input;\n\n const { host, owner, repo } = parseRepoUrl(repoUrl, integrations);\n\n if (!owner) {\n throw new InputError(`No owner provided for repo ${repoUrl}`);\n }\n\n const octokitOptions = await getOctokitOptions({\n integrations,\n token: providedToken,\n host,\n owner,\n repo,\n });\n\n const client = new Octokit({\n ...octokitOptions,\n log: ctx.logger,\n });\n\n await ctx.checkpoint({\n key: `create.deploy.key.${owner}.${repo}.${publicKey}`,\n fn: async () => {\n await client.rest.repos.createDeployKey({\n owner: owner,\n repo: repo,\n title: deployKeyName,\n key: publicKey,\n });\n },\n });\n\n const { key, keyId } = await ctx.checkpoint({\n key: `get.repo.public.key.${owner}.${repo}`,\n fn: async () => {\n const publicKeyResponse = await client.rest.actions.getRepoPublicKey({\n owner: owner,\n repo: repo,\n });\n return {\n key: publicKeyResponse.data.key,\n keyId: publicKeyResponse.data.key_id,\n };\n },\n });\n\n await Sodium.ready;\n const binaryKey = Sodium.from_base64(\n key,\n Sodium.base64_variants.ORIGINAL,\n );\n const binarySecret = Sodium.from_string(privateKey);\n const encryptedBinarySecret = Sodium.crypto_box_seal(\n binarySecret,\n binaryKey,\n );\n const encryptedBase64Secret = Sodium.to_base64(\n encryptedBinarySecret,\n Sodium.base64_variants.ORIGINAL,\n );\n\n await ctx.checkpoint({\n key: `create.or.update.repo.secret.${owner}.${repo}.${keyId}`,\n fn: async () => {\n await client.rest.actions.createOrUpdateRepoSecret({\n owner: owner,\n repo: repo,\n secret_name: privateKeySecretName,\n encrypted_value: encryptedBase64Secret,\n key_id: keyId,\n });\n },\n });\n\n ctx.output('privateKeySecretName', privateKeySecretName);\n },\n });\n}\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","getOctokitOptions","Octokit","Sodium"],"mappings":";;;;;;;;;;;;;AAgCO,SAAS,4BAA4B,OAEzC,EAAA;AACD,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AAGzB,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,yBAAA;AAAA,IACJ,WAAa,EAAA,gCAAA;AAAA,cACbC,iCAAA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;AACF,OACD,CAAA;AAED,MAAA,MAAMC,uBAAO,CAAA,KAAA;AACb,MAAA,MAAM,YAAYA,uBAAO,CAAA,WAAA;AAAA,QACvB,GAAA;AAAA,QACAA,wBAAO,eAAgB,CAAA;AAAA,OACzB;AACA,MAAM,MAAA,YAAA,GAAeA,uBAAO,CAAA,WAAA,CAAY,UAAU,CAAA;AAClD,MAAA,MAAM,wBAAwBA,uBAAO,CAAA,eAAA;AAAA,QACnC,YAAA;AAAA,QACA;AAAA,OACF;AACA,MAAA,MAAM,wBAAwBA,uBAAO,CAAA,SAAA;AAAA,QACnC,qBAAA;AAAA,QACAA,wBAAO,eAAgB,CAAA;AAAA,OACzB;AAEA,MAAA,MAAM,IAAI,UAAW,CAAA;AAAA,QACnB,KAAK,CAAgC,6BAAA,EAAA,KAAK,CAAI,CAAA,EAAA,IAAI,IAAI,KAAK,CAAA,CAAA;AAAA,QAC3D,IAAI,YAAY;AACd,UAAM,MAAA,MAAA,CAAO,IAAK,CAAA,OAAA,CAAQ,wBAAyB,CAAA;AAAA,YACjD,KAAA;AAAA,YACA,IAAA;AAAA,YACA,WAAa,EAAA,oBAAA;AAAA,YACb,eAAiB,EAAA,qBAAA;AAAA,YACjB,MAAQ,EAAA;AAAA,WACT,CAAA;AAAA;AACH,OACD,CAAA;AAED,MAAI,GAAA,CAAA,MAAA,CAAO,wBAAwB,oBAAoB,CAAA;AAAA;AACzD,GACD,CAAA;AACH;;;;"}
|
|
@@ -12,98 +12,60 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
12
12
|
var Sodium__default = /*#__PURE__*/_interopDefaultCompat(Sodium);
|
|
13
13
|
|
|
14
14
|
function createGithubEnvironmentAction(options) {
|
|
15
|
-
const { integrations,
|
|
15
|
+
const { integrations, catalog } = options;
|
|
16
16
|
return pluginScaffolderNode.createTemplateAction({
|
|
17
17
|
id: "github:environment:create",
|
|
18
18
|
description: "Creates Deployment Environments",
|
|
19
19
|
examples: gitHubEnvironment_examples.examples,
|
|
20
20
|
schema: {
|
|
21
21
|
input: {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
title: "Deployment Branch Policy",
|
|
37
|
-
description: "The type of deployment branch policy for this environment. To allow all branches to deploy, set to `null`.",
|
|
38
|
-
type: "object",
|
|
39
|
-
required: ["protected_branches", "custom_branch_policies"],
|
|
40
|
-
properties: {
|
|
41
|
-
protected_branches: {
|
|
42
|
-
title: "Protected Branches",
|
|
43
|
-
description: "Whether only branches with branch protection rules can deploy to this environment. If `protected_branches` is `true`, `custom_branch_policies` must be `false`; if `protected_branches` is `false`, `custom_branch_policies` must be `true`.",
|
|
44
|
-
type: "boolean"
|
|
45
|
-
},
|
|
46
|
-
custom_branch_policies: {
|
|
47
|
-
title: "Custom Branch Policies",
|
|
48
|
-
description: "Whether only branches that match the specified name patterns can deploy to this environment. If `custom_branch_policies` is `true`, `protected_branches` must be `false`; if `custom_branch_policies` is `false`, `protected_branches` must be `true`.",
|
|
49
|
-
type: "boolean"
|
|
50
|
-
}
|
|
51
|
-
}
|
|
22
|
+
repoUrl: (z) => z.string({
|
|
23
|
+
description: "Accepts the format `github.com?repo=reponame&owner=owner` where `reponame` is the new repository name and `owner` is an organization or username"
|
|
24
|
+
}),
|
|
25
|
+
name: (z) => z.string({
|
|
26
|
+
description: `Name of the deployment environment to create`
|
|
27
|
+
}),
|
|
28
|
+
deploymentBranchPolicy: (z) => z.object(
|
|
29
|
+
{
|
|
30
|
+
protected_branches: z.boolean({
|
|
31
|
+
description: "Whether only branches with branch protection rules can deploy to this environment. If `protected_branches` is `true`, `custom_branch_policies` must be `false`; if `protected_branches` is `false`, `custom_branch_policies` must be `true`."
|
|
32
|
+
}),
|
|
33
|
+
custom_branch_policies: z.boolean({
|
|
34
|
+
description: "Whether only branches that match the specified name patterns can deploy to this environment. If `custom_branch_policies` is `true`, `protected_branches` must be `false`; if `custom_branch_policies` is `false`, `protected_branches` must be `true`."
|
|
35
|
+
})
|
|
52
36
|
},
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
37
|
+
{
|
|
38
|
+
description: "The type of deployment branch policy for this environment. To allow all branches to deploy, set to `null`."
|
|
39
|
+
}
|
|
40
|
+
).optional(),
|
|
41
|
+
customBranchPolicyNames: (z) => z.array(z.string(), {
|
|
42
|
+
description: `The name pattern that branches must match in order to deploy to the environment.
|
|
56
43
|
|
|
57
|
-
Wildcard characters will not match \`/\`. For example, to match branches 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
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
customTagPolicyNames: {
|
|
64
|
-
title: "Custom Tag Policy Name",
|
|
65
|
-
description: `The name pattern that tags must match in order to deploy to the environment.
|
|
44
|
+
Wildcard characters will not match \`/\`. For example, to match branches 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.`
|
|
45
|
+
}).optional(),
|
|
46
|
+
customTagPolicyNames: (z) => z.array(z.string(), {
|
|
47
|
+
description: `The name pattern that tags must match in order to deploy to the environment.
|
|
66
48
|
|
|
67
|
-
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
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
},
|
|
88
|
-
waitTimer: {
|
|
89
|
-
title: "Wait Timer",
|
|
90
|
-
type: "integer",
|
|
91
|
-
description: "The time to wait before creating or updating the environment (in milliseconds)"
|
|
92
|
-
},
|
|
93
|
-
preventSelfReview: {
|
|
94
|
-
title: "Prevent Self Review",
|
|
95
|
-
type: "boolean",
|
|
96
|
-
description: "Whether to prevent self-review for this environment"
|
|
97
|
-
},
|
|
98
|
-
reviewers: {
|
|
99
|
-
title: "Reviewers",
|
|
100
|
-
type: "array",
|
|
101
|
-
description: "Reviewers for this environment. Must be a list of Backstage entity references.",
|
|
102
|
-
items: {
|
|
103
|
-
type: "string"
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
49
|
+
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.`
|
|
50
|
+
}).optional(),
|
|
51
|
+
environmentVariables: (z) => z.record(z.string(), {
|
|
52
|
+
description: `Environment variables attached to the deployment environment`
|
|
53
|
+
}).optional(),
|
|
54
|
+
secrets: (z) => z.record(z.string(), {
|
|
55
|
+
description: `Secrets attached to the deployment environment`
|
|
56
|
+
}).optional(),
|
|
57
|
+
token: (z) => z.string({
|
|
58
|
+
description: "The token to use for authorization to GitHub"
|
|
59
|
+
}).optional(),
|
|
60
|
+
waitTimer: (z) => z.number({
|
|
61
|
+
description: "The time to wait before creating or updating the environment (in milliseconds)"
|
|
62
|
+
}).optional(),
|
|
63
|
+
preventSelfReview: (z) => z.boolean({
|
|
64
|
+
description: "Whether to prevent self-review for this environment"
|
|
65
|
+
}).optional(),
|
|
66
|
+
reviewers: (z) => z.array(z.string(), {
|
|
67
|
+
description: "Reviewers for this environment. Must be a list of Backstage entity references."
|
|
68
|
+
}).optional()
|
|
107
69
|
}
|
|
108
70
|
},
|
|
109
71
|
async handler(ctx) {
|
|
@@ -120,10 +82,6 @@ Wildcard characters will not match \`/\`. For example, to match tags that begin
|
|
|
120
82
|
preventSelfReview,
|
|
121
83
|
reviewers
|
|
122
84
|
} = ctx.input;
|
|
123
|
-
const { token } = await auth?.getPluginRequestToken({
|
|
124
|
-
onBehalfOf: await ctx.getInitiatorCredentials(),
|
|
125
|
-
targetPluginId: "catalog"
|
|
126
|
-
}) ?? { token: ctx.secrets?.backstageToken };
|
|
127
85
|
await new Promise((resolve) => setTimeout(resolve, 2e3));
|
|
128
86
|
const { host, owner, repo } = pluginScaffolderNode.parseRepoUrl(repoUrl, integrations);
|
|
129
87
|
if (!owner) {
|
|
@@ -153,12 +111,12 @@ Wildcard characters will not match \`/\`. For example, to match tags that begin
|
|
|
153
111
|
const githubReviewers = [];
|
|
154
112
|
if (reviewers) {
|
|
155
113
|
let reviewersEntityRefs = [];
|
|
156
|
-
const catalogResponse = await
|
|
114
|
+
const catalogResponse = await catalog.getEntitiesByRefs(
|
|
157
115
|
{
|
|
158
116
|
entityRefs: reviewers
|
|
159
117
|
},
|
|
160
118
|
{
|
|
161
|
-
|
|
119
|
+
credentials: await ctx.getInitiatorCredentials()
|
|
162
120
|
}
|
|
163
121
|
);
|
|
164
122
|
if (catalogResponse?.items?.length) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"githubEnvironment.cjs.js","sources":["../../src/actions/githubEnvironment.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport {\n createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { getOctokitOptions } from '../util';\nimport { Octokit } from 'octokit';\nimport Sodium from 'libsodium-wrappers';\nimport { examples } from './gitHubEnvironment.examples';\nimport { CatalogApi } from '@backstage/catalog-client';\nimport { Entity } from '@backstage/catalog-model';\nimport { AuthService } from '@backstage/backend-plugin-api';\n\n/**\n * Creates an `github:environment:create` Scaffolder action that creates a Github Environment.\n *\n * @public\n */\nexport function createGithubEnvironmentAction(options: {\n integrations: ScmIntegrationRegistry;\n catalogClient?: CatalogApi;\n auth?: AuthService;\n}) {\n const { integrations, catalogClient, auth } = options;\n // For more information on how to define custom actions, see\n // https://backstage.io/docs/features/software-templates/writing-custom-actions\n return createTemplateAction<{\n repoUrl: string;\n name: string;\n deploymentBranchPolicy?: {\n protected_branches: boolean;\n custom_branch_policies: boolean;\n };\n customBranchPolicyNames?: string[];\n customTagPolicyNames?: string[];\n environmentVariables?: { [key: string]: string };\n secrets?: { [key: string]: string };\n token?: string;\n waitTimer?: number;\n preventSelfReview?: boolean;\n reviewers?: string[];\n }>({\n id: 'github:environment:create',\n description: 'Creates Deployment Environments',\n examples,\n schema: {\n input: {\n type: 'object',\n required: ['repoUrl', 'name'],\n properties: {\n repoUrl: {\n title: 'Repository Location',\n description:\n 'Accepts the format `github.com?repo=reponame&owner=owner` where `reponame` is the new repository name and `owner` is an organization or username',\n type: 'string',\n },\n name: {\n title: 'Environment Name',\n description: `Name of the deployment environment to create`,\n type: 'string',\n },\n deploymentBranchPolicy: {\n title: 'Deployment Branch Policy',\n description:\n 'The type of deployment branch policy for this environment. To allow all branches to deploy, set to `null`.',\n type: 'object',\n required: ['protected_branches', 'custom_branch_policies'],\n properties: {\n protected_branches: {\n title: 'Protected Branches',\n description:\n 'Whether only branches with branch protection rules can deploy to this environment. If `protected_branches` is `true`, `custom_branch_policies` must be `false`; if `protected_branches` is `false`, `custom_branch_policies` must be `true`.',\n type: 'boolean',\n },\n custom_branch_policies: {\n title: 'Custom Branch Policies',\n description:\n 'Whether only branches that match the specified name patterns can deploy to this environment. If `custom_branch_policies` is `true`, `protected_branches` must be `false`; if `custom_branch_policies` is `false`, `protected_branches` must be `true`.',\n type: 'boolean',\n },\n },\n },\n customBranchPolicyNames: {\n title: 'Custom Branch Policy Name',\n description: `The name pattern that branches must match in order to deploy to the environment.\n\nWildcard characters will not match \\`/\\`. For example, to match branches 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.`,\n type: 'array',\n items: {\n type: 'string',\n },\n },\n customTagPolicyNames: {\n title: 'Custom Tag Policy Name',\n description: `The name pattern that tags must match in order to deploy to the environment.\n\nWildcard 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.`,\n type: 'array',\n items: {\n type: 'string',\n },\n },\n environmentVariables: {\n title: 'Environment Variables',\n description: `Environment variables attached to the deployment environment`,\n type: 'object',\n },\n secrets: {\n title: 'Deployment Secrets',\n description: `Secrets attached to the deployment environment`,\n type: 'object',\n },\n token: {\n title: 'Authentication Token',\n type: 'string',\n description: 'The token to use for authorization to GitHub',\n },\n waitTimer: {\n title: 'Wait Timer',\n type: 'integer',\n description:\n 'The time to wait before creating or updating the environment (in milliseconds)',\n },\n preventSelfReview: {\n title: 'Prevent Self Review',\n type: 'boolean',\n description: 'Whether to prevent self-review for this environment',\n },\n reviewers: {\n title: 'Reviewers',\n type: 'array',\n description:\n 'Reviewers for this environment. Must be a list of Backstage entity references.',\n items: {\n type: 'string',\n },\n },\n },\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n name,\n deploymentBranchPolicy,\n customBranchPolicyNames,\n customTagPolicyNames,\n environmentVariables,\n secrets,\n token: providedToken,\n waitTimer,\n preventSelfReview,\n reviewers,\n } = ctx.input;\n\n const { token } = (await auth?.getPluginRequestToken({\n onBehalfOf: await ctx.getInitiatorCredentials(),\n targetPluginId: 'catalog',\n })) ?? { token: ctx.secrets?.backstageToken };\n\n // When environment creation step is executed right after a repo publish step, the repository might not be available immediately.\n // Add a 2-second delay before initiating the steps in this action.\n await new Promise(resolve => setTimeout(resolve, 2000));\n\n const { host, owner, repo } = parseRepoUrl(repoUrl, integrations);\n\n if (!owner) {\n throw new InputError(`No owner provided for repo ${repoUrl}`);\n }\n\n const octokitOptions = await getOctokitOptions({\n integrations,\n token: providedToken,\n host,\n owner,\n repo,\n });\n const client = new Octokit({\n ...octokitOptions,\n log: ctx.logger,\n });\n\n const repositoryId = await ctx.checkpoint({\n key: `get.repo.${owner}.${repo}`,\n fn: async () => {\n const repository = await client.rest.repos.get({\n owner: owner,\n repo: repo,\n });\n return repository.data.id;\n },\n });\n\n // convert reviewers from catalog entity to Github user or team\n const githubReviewers: { type: 'User' | 'Team'; id: number }[] = [];\n if (reviewers) {\n let reviewersEntityRefs: Array<Entity | undefined> = [];\n // Fetch reviewers from Catalog\n const catalogResponse = await catalogClient?.getEntitiesByRefs(\n {\n entityRefs: reviewers,\n },\n {\n token,\n },\n );\n if (catalogResponse?.items?.length) {\n reviewersEntityRefs = catalogResponse.items;\n }\n\n for (const reviewerEntityRef of reviewersEntityRefs) {\n if (reviewerEntityRef?.kind === 'User') {\n try {\n const userId = await ctx.checkpoint({\n key: `get.user.${reviewerEntityRef.metadata.name}`,\n fn: async () => {\n const user = await client.rest.users.getByUsername({\n username: reviewerEntityRef.metadata.name,\n });\n return user.data.id;\n },\n });\n\n githubReviewers.push({\n type: 'User',\n id: userId,\n });\n } catch (error) {\n ctx.logger.error('User not found:', error);\n }\n } else if (reviewerEntityRef?.kind === 'Group') {\n try {\n const teamId = await ctx.checkpoint({\n key: `get.team.${reviewerEntityRef.metadata.name}`,\n fn: async () => {\n const team = await client.rest.teams.getByName({\n org: owner,\n team_slug: reviewerEntityRef.metadata.name,\n });\n return team.data.id;\n },\n });\n\n githubReviewers.push({\n type: 'Team',\n id: teamId,\n });\n } catch (error) {\n ctx.logger.error('Team not found:', error);\n }\n }\n }\n }\n\n await ctx.checkpoint({\n key: `create.or.update.environment.${owner}.${repo}.${name}`,\n fn: async () => {\n await client.rest.repos.createOrUpdateEnvironment({\n owner: owner,\n repo: repo,\n environment_name: name,\n deployment_branch_policy: deploymentBranchPolicy ?? undefined,\n wait_timer: waitTimer ?? undefined,\n prevent_self_review: preventSelfReview ?? undefined,\n reviewers: githubReviewers.length ? githubReviewers : undefined,\n });\n },\n });\n\n if (customBranchPolicyNames) {\n for (const item of customBranchPolicyNames) {\n await ctx.checkpoint({\n key: `create.deployment.branch.policy.branch.${owner}.${repo}.${name}.${item}`,\n fn: async () => {\n await client.rest.repos.createDeploymentBranchPolicy({\n owner: owner,\n repo: repo,\n type: 'branch',\n environment_name: name,\n name: item,\n });\n },\n });\n }\n }\n\n if (customTagPolicyNames) {\n for (const item of customTagPolicyNames) {\n await ctx.checkpoint({\n key: `create.deployment.branch.policy.tag.${owner}.${repo}.${name}.${item}`,\n fn: async () => {\n await client.rest.repos.createDeploymentBranchPolicy({\n owner: owner,\n repo: repo,\n type: 'tag',\n environment_name: name,\n name: item,\n });\n },\n });\n }\n }\n\n for (const [key, value] of Object.entries(environmentVariables ?? {})) {\n await ctx.checkpoint({\n key: `create.env.variable.${owner}.${repo}.${name}.${key}`,\n fn: async () => {\n await client.rest.actions.createEnvironmentVariable({\n repository_id: repositoryId,\n owner: owner,\n repo: repo,\n environment_name: name,\n name: key,\n value,\n });\n },\n });\n }\n\n if (secrets) {\n const { publicKey, publicKeyId } = await ctx.checkpoint({\n key: `get.env.public.key.${owner}.${repo}.${name}`,\n fn: async () => {\n const publicKeyResponse =\n await client.rest.actions.getEnvironmentPublicKey({\n repository_id: repositoryId,\n owner: owner,\n repo: repo,\n environment_name: name,\n });\n return {\n publicKey: publicKeyResponse.data.key,\n publicKeyId: publicKeyResponse.data.key_id,\n };\n },\n });\n\n await Sodium.ready;\n const binaryKey = Sodium.from_base64(\n publicKey,\n Sodium.base64_variants.ORIGINAL,\n );\n for (const [key, value] of Object.entries(secrets)) {\n const binarySecret = Sodium.from_string(value);\n const encryptedBinarySecret = Sodium.crypto_box_seal(\n binarySecret,\n binaryKey,\n );\n const encryptedBase64Secret = Sodium.to_base64(\n encryptedBinarySecret,\n Sodium.base64_variants.ORIGINAL,\n );\n\n await ctx.checkpoint({\n key: `create.or.update.env.secret.${owner}.${repo}.${name}.${key}`,\n fn: async () => {\n await client.rest.actions.createOrUpdateEnvironmentSecret({\n repository_id: repositoryId,\n owner: owner,\n repo: repo,\n environment_name: name,\n secret_name: key,\n encrypted_value: encryptedBase64Secret,\n key_id: publicKeyId,\n });\n },\n });\n }\n }\n },\n });\n}\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","getOctokitOptions","Octokit","Sodium"],"mappings":";;;;;;;;;;;;;AAmCO,SAAS,8BAA8B,OAI3C,EAAA;AACD,EAAA,MAAM,EAAE,YAAA,EAAc,aAAe,EAAA,IAAA,EAAS,GAAA,OAAA;AAG9C,EAAA,OAAOA,yCAeJ,CAAA;AAAA,IACD,EAAI,EAAA,2BAAA;AAAA,IACJ,WAAa,EAAA,iCAAA;AAAA,cACbC,mCAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,IAAM,EAAA,QAAA;AAAA,QACN,QAAA,EAAU,CAAC,SAAA,EAAW,MAAM,CAAA;AAAA,QAC5B,UAAY,EAAA;AAAA,UACV,OAAS,EAAA;AAAA,YACP,KAAO,EAAA,qBAAA;AAAA,YACP,WACE,EAAA,kJAAA;AAAA,YACF,IAAM,EAAA;AAAA,WACR;AAAA,UACA,IAAM,EAAA;AAAA,YACJ,KAAO,EAAA,kBAAA;AAAA,YACP,WAAa,EAAA,CAAA,4CAAA,CAAA;AAAA,YACb,IAAM,EAAA;AAAA,WACR;AAAA,UACA,sBAAwB,EAAA;AAAA,YACtB,KAAO,EAAA,0BAAA;AAAA,YACP,WACE,EAAA,4GAAA;AAAA,YACF,IAAM,EAAA,QAAA;AAA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ACb,QAAA,MAAM,YAAYA,uBAAO,CAAA,WAAA;AAAA,UACvB,SAAA;AAAA,UACAA,wBAAO,eAAgB,CAAA;AAAA,SACzB;AACA,QAAA,KAAA,MAAW,CAAC,GAAK,EAAA,KAAK,KAAK,MAAO,CAAA,OAAA,CAAQ,OAAO,CAAG,EAAA;AAClD,UAAM,MAAA,YAAA,GAAeA,uBAAO,CAAA,WAAA,CAAY,KAAK,CAAA;AAC7C,UAAA,MAAM,wBAAwBA,uBAAO,CAAA,eAAA;AAAA,YACnC,YAAA;AAAA,YACA;AAAA,WACF;AACA,UAAA,MAAM,wBAAwBA,uBAAO,CAAA,SAAA;AAAA,YACnC,qBAAA;AAAA,YACAA,wBAAO,eAAgB,CAAA;AAAA,WACzB;AAEA,UAAA,MAAM,IAAI,UAAW,CAAA;AAAA,YACnB,GAAA,EAAK,+BAA+B,KAAK,CAAA,CAAA,EAAI,IAAI,CAAI,CAAA,EAAA,IAAI,IAAI,GAAG,CAAA,CAAA;AAAA,YAChE,IAAI,YAAY;AACd,cAAM,MAAA,MAAA,CAAO,IAAK,CAAA,OAAA,CAAQ,+BAAgC,CAAA;AAAA,gBACxD,aAAe,EAAA,YAAA;AAAA,gBACf,KAAA;AAAA,gBACA,IAAA;AAAA,gBACA,gBAAkB,EAAA,IAAA;AAAA,gBAClB,WAAa,EAAA,GAAA;AAAA,gBACb,eAAiB,EAAA,qBAAA;AAAA,gBACjB,MAAQ,EAAA;AAAA,eACT,CAAA;AAAA;AACH,WACD,CAAA;AAAA;AACH;AACF;AACF,GACD,CAAA;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"githubEnvironment.cjs.js","sources":["../../src/actions/githubEnvironment.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport {\n createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { getOctokitOptions } from '../util';\nimport { Octokit } from 'octokit';\nimport Sodium from 'libsodium-wrappers';\nimport { examples } from './gitHubEnvironment.examples';\nimport { Entity } from '@backstage/catalog-model';\nimport { CatalogService } from '@backstage/plugin-catalog-node';\n\n/**\n * Creates an `github:environment:create` Scaffolder action that creates a Github Environment.\n *\n * @public\n */\nexport function createGithubEnvironmentAction(options: {\n integrations: ScmIntegrationRegistry;\n catalog: CatalogService;\n}) {\n const { integrations, catalog } = options;\n // For more information on how to define custom actions, see\n // https://backstage.io/docs/features/software-templates/writing-custom-actions\n return createTemplateAction({\n id: 'github:environment:create',\n description: 'Creates Deployment Environments',\n examples,\n schema: {\n input: {\n repoUrl: z =>\n z.string({\n description:\n 'Accepts the format `github.com?repo=reponame&owner=owner` where `reponame` is the new repository name and `owner` is an organization or username',\n }),\n name: z =>\n z.string({\n description: `Name of the deployment environment to create`,\n }),\n deploymentBranchPolicy: z =>\n z\n .object(\n {\n protected_branches: z.boolean({\n description:\n 'Whether only branches with branch protection rules can deploy to this environment. If `protected_branches` is `true`, `custom_branch_policies` must be `false`; if `protected_branches` is `false`, `custom_branch_policies` must be `true`.',\n }),\n custom_branch_policies: z.boolean({\n description:\n 'Whether only branches that match the specified name patterns can deploy to this environment. If `custom_branch_policies` is `true`, `protected_branches` must be `false`; if `custom_branch_policies` is `false`, `protected_branches` must be `true`.',\n }),\n },\n {\n description:\n 'The type of deployment branch policy for this environment. To allow all branches to deploy, set to `null`.',\n },\n )\n .optional(),\n customBranchPolicyNames: z =>\n z\n .array(z.string(), {\n description: `The name pattern that branches must match in order to deploy to the environment.\n\nWildcard characters will not match \\`/\\`. For example, to match branches 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.`,\n })\n .optional(),\n customTagPolicyNames: z =>\n z\n .array(z.string(), {\n description: `The name pattern that tags must match in order to deploy to the environment.\n\nWildcard 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.`,\n })\n .optional(),\n environmentVariables: z =>\n z\n .record(z.string(), {\n description: `Environment variables attached to the deployment environment`,\n })\n .optional(),\n secrets: z =>\n z\n .record(z.string(), {\n description: `Secrets attached to the deployment environment`,\n })\n .optional(),\n token: z =>\n z\n .string({\n description: 'The token to use for authorization to GitHub',\n })\n .optional(),\n waitTimer: z =>\n z\n .number({\n description:\n 'The time to wait before creating or updating the environment (in milliseconds)',\n })\n .optional(),\n preventSelfReview: z =>\n z\n .boolean({\n description:\n 'Whether to prevent self-review for this environment',\n })\n .optional(),\n reviewers: z =>\n z\n .array(z.string(), {\n description:\n 'Reviewers for this environment. Must be a list of Backstage entity references.',\n })\n .optional(),\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n name,\n deploymentBranchPolicy,\n customBranchPolicyNames,\n customTagPolicyNames,\n environmentVariables,\n secrets,\n token: providedToken,\n waitTimer,\n preventSelfReview,\n reviewers,\n } = ctx.input;\n\n // When environment creation step is executed right after a repo publish step, the repository might not be available immediately.\n // Add a 2-second delay before initiating the steps in this action.\n await new Promise(resolve => setTimeout(resolve, 2000));\n\n const { host, owner, repo } = parseRepoUrl(repoUrl, integrations);\n\n if (!owner) {\n throw new InputError(`No owner provided for repo ${repoUrl}`);\n }\n\n const octokitOptions = await getOctokitOptions({\n integrations,\n token: providedToken,\n host,\n owner,\n repo,\n });\n const client = new Octokit({\n ...octokitOptions,\n log: ctx.logger,\n });\n\n const repositoryId = await ctx.checkpoint({\n key: `get.repo.${owner}.${repo}`,\n fn: async () => {\n const repository = await client.rest.repos.get({\n owner: owner,\n repo: repo,\n });\n return repository.data.id;\n },\n });\n\n // convert reviewers from catalog entity to Github user or team\n const githubReviewers: { type: 'User' | 'Team'; id: number }[] = [];\n if (reviewers) {\n let reviewersEntityRefs: Array<Entity | undefined> = [];\n // Fetch reviewers from Catalog\n const catalogResponse = await catalog.getEntitiesByRefs(\n {\n entityRefs: reviewers,\n },\n {\n credentials: await ctx.getInitiatorCredentials(),\n },\n );\n if (catalogResponse?.items?.length) {\n reviewersEntityRefs = catalogResponse.items;\n }\n\n for (const reviewerEntityRef of reviewersEntityRefs) {\n if (reviewerEntityRef?.kind === 'User') {\n try {\n const userId = await ctx.checkpoint({\n key: `get.user.${reviewerEntityRef.metadata.name}`,\n fn: async () => {\n const user = await client.rest.users.getByUsername({\n username: reviewerEntityRef.metadata.name,\n });\n return user.data.id;\n },\n });\n\n githubReviewers.push({\n type: 'User',\n id: userId,\n });\n } catch (error) {\n ctx.logger.error('User not found:', error);\n }\n } else if (reviewerEntityRef?.kind === 'Group') {\n try {\n const teamId = await ctx.checkpoint({\n key: `get.team.${reviewerEntityRef.metadata.name}`,\n fn: async () => {\n const team = await client.rest.teams.getByName({\n org: owner,\n team_slug: reviewerEntityRef.metadata.name,\n });\n return team.data.id;\n },\n });\n\n githubReviewers.push({\n type: 'Team',\n id: teamId,\n });\n } catch (error) {\n ctx.logger.error('Team not found:', error);\n }\n }\n }\n }\n\n await ctx.checkpoint({\n key: `create.or.update.environment.${owner}.${repo}.${name}`,\n fn: async () => {\n await client.rest.repos.createOrUpdateEnvironment({\n owner: owner,\n repo: repo,\n environment_name: name,\n deployment_branch_policy: deploymentBranchPolicy ?? undefined,\n wait_timer: waitTimer ?? undefined,\n prevent_self_review: preventSelfReview ?? undefined,\n reviewers: githubReviewers.length ? githubReviewers : undefined,\n });\n },\n });\n\n if (customBranchPolicyNames) {\n for (const item of customBranchPolicyNames) {\n await ctx.checkpoint({\n key: `create.deployment.branch.policy.branch.${owner}.${repo}.${name}.${item}`,\n fn: async () => {\n await client.rest.repos.createDeploymentBranchPolicy({\n owner: owner,\n repo: repo,\n type: 'branch',\n environment_name: name,\n name: item,\n });\n },\n });\n }\n }\n\n if (customTagPolicyNames) {\n for (const item of customTagPolicyNames) {\n await ctx.checkpoint({\n key: `create.deployment.branch.policy.tag.${owner}.${repo}.${name}.${item}`,\n fn: async () => {\n await client.rest.repos.createDeploymentBranchPolicy({\n owner: owner,\n repo: repo,\n type: 'tag',\n environment_name: name,\n name: item,\n });\n },\n });\n }\n }\n\n for (const [key, value] of Object.entries(environmentVariables ?? {})) {\n await ctx.checkpoint({\n key: `create.env.variable.${owner}.${repo}.${name}.${key}`,\n fn: async () => {\n await client.rest.actions.createEnvironmentVariable({\n repository_id: repositoryId,\n owner: owner,\n repo: repo,\n environment_name: name,\n name: key,\n value,\n });\n },\n });\n }\n\n if (secrets) {\n const { publicKey, publicKeyId } = await ctx.checkpoint({\n key: `get.env.public.key.${owner}.${repo}.${name}`,\n fn: async () => {\n const publicKeyResponse =\n await client.rest.actions.getEnvironmentPublicKey({\n repository_id: repositoryId,\n owner: owner,\n repo: repo,\n environment_name: name,\n });\n return {\n publicKey: publicKeyResponse.data.key,\n publicKeyId: publicKeyResponse.data.key_id,\n };\n },\n });\n\n await Sodium.ready;\n const binaryKey = Sodium.from_base64(\n publicKey,\n Sodium.base64_variants.ORIGINAL,\n );\n for (const [key, value] of Object.entries(secrets)) {\n const binarySecret = Sodium.from_string(value);\n const encryptedBinarySecret = Sodium.crypto_box_seal(\n binarySecret,\n binaryKey,\n );\n const encryptedBase64Secret = Sodium.to_base64(\n encryptedBinarySecret,\n Sodium.base64_variants.ORIGINAL,\n );\n\n await ctx.checkpoint({\n key: `create.or.update.env.secret.${owner}.${repo}.${name}.${key}`,\n fn: async () => {\n await client.rest.actions.createOrUpdateEnvironmentSecret({\n repository_id: repositoryId,\n owner: owner,\n repo: repo,\n environment_name: name,\n secret_name: key,\n encrypted_value: encryptedBase64Secret,\n key_id: publicKeyId,\n });\n },\n });\n }\n }\n },\n });\n}\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","getOctokitOptions","Octokit","Sodium"],"mappings":";;;;;;;;;;;;;AAkCO,SAAS,8BAA8B,OAG3C,EAAA;AACD,EAAM,MAAA,EAAE,YAAc,EAAA,OAAA,EAAY,GAAA,OAAA;AAGlC,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,2BAAA;AAAA,IACJ,WAAa,EAAA,iCAAA;AAAA,cACbC,mCAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,OAAA,EAAS,CACP,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,UACP,WACE,EAAA;AAAA,SACH,CAAA;AAAA,QACH,IAAA,EAAM,CACJ,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,UACP,WAAa,EAAA,CAAA,4CAAA;AAAA,SACd,CAAA;AAAA,QACH,sBAAA,EAAwB,OACtB,CACG,CAAA,MAAA;AAAA,UACC;AAAA,YACE,kBAAA,EAAoB,EAAE,OAAQ,CAAA;AAAA,cAC5B,WACE,EAAA;AAAA,aACH,CAAA;AAAA,YACD,sBAAA,EAAwB,EAAE,OAAQ,CAAA;AAAA,cAChC,WACE,EAAA;AAAA,aACH;AAAA,WACH;AAAA,UACA;AAAA,YACE,WACE,EAAA;AAAA;AACJ,UAED,QAAS,EAAA;AAAA,QACd,yBAAyB,CACvB,CAAA,KAAA,CAAA,CACG,KAAM,CAAA,CAAA,CAAE,QAAU,EAAA;AAAA,UACjB,WAAa,EAAA,CAAA;;AAAA,+PAAA;AAAA,SAGd,EACA,QAAS,EAAA;AAAA,QACd,sBAAsB,CACpB,CAAA,KAAA,CAAA,CACG,KAAM,CAAA,CAAA,CAAE,QAAU,EAAA;AAAA,UACjB,WAAa,EAAA,CAAA;;AAAA,2PAAA;AAAA,SAGd,EACA,QAAS,EAAA;AAAA,QACd,sB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ACH;AACF;AACF,GACD,CAAA;AACH;;;;"}
|
|
@@ -14,33 +14,18 @@ function createGithubIssuesLabelAction(options) {
|
|
|
14
14
|
examples: githubIssuesLabel_examples.examples,
|
|
15
15
|
schema: {
|
|
16
16
|
input: {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
},
|
|
30
|
-
labels: {
|
|
31
|
-
title: "Labels",
|
|
32
|
-
description: "The labels to add to the pull request or issue",
|
|
33
|
-
type: "array",
|
|
34
|
-
items: {
|
|
35
|
-
type: "string"
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
token: {
|
|
39
|
-
title: "Authentication Token",
|
|
40
|
-
type: "string",
|
|
41
|
-
description: "The `GITHUB_TOKEN` to use for authorization to GitHub"
|
|
42
|
-
}
|
|
43
|
-
}
|
|
17
|
+
repoUrl: (z) => z.string({
|
|
18
|
+
description: "Accepts the format `github.com?repo=reponame&owner=owner` where `reponame` is the repository name and `owner` is an organization or username"
|
|
19
|
+
}),
|
|
20
|
+
number: (z) => z.number({
|
|
21
|
+
description: "The pull request or issue number to add labels to"
|
|
22
|
+
}),
|
|
23
|
+
labels: (z) => z.array(z.string(), {
|
|
24
|
+
description: "The labels to add to the pull request or issue"
|
|
25
|
+
}),
|
|
26
|
+
token: (z) => z.string({
|
|
27
|
+
description: "The `GITHUB_TOKEN` to use for authorization to GitHub"
|
|
28
|
+
}).optional()
|
|
44
29
|
}
|
|
45
30
|
},
|
|
46
31
|
async handler(ctx) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"githubIssuesLabel.cjs.js","sources":["../../src/actions/githubIssuesLabel.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n GithubCredentialsProvider,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\nimport {\n createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { assertError, InputError } from '@backstage/errors';\nimport { Octokit } from 'octokit';\nimport { getOctokitOptions } from '../util';\nimport { examples } from './githubIssuesLabel.examples';\n\n/**\n * Adds labels to a pull request or issue on GitHub\n * @public\n */\nexport function createGithubIssuesLabelAction(options: {\n integrations: ScmIntegrationRegistry;\n githubCredentialsProvider?: GithubCredentialsProvider;\n}) {\n const { integrations, githubCredentialsProvider } = options;\n\n return createTemplateAction
|
|
1
|
+
{"version":3,"file":"githubIssuesLabel.cjs.js","sources":["../../src/actions/githubIssuesLabel.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n GithubCredentialsProvider,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\nimport {\n createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { assertError, InputError } from '@backstage/errors';\nimport { Octokit } from 'octokit';\nimport { getOctokitOptions } from '../util';\nimport { examples } from './githubIssuesLabel.examples';\n\n/**\n * Adds labels to a pull request or issue on GitHub\n * @public\n */\nexport function createGithubIssuesLabelAction(options: {\n integrations: ScmIntegrationRegistry;\n githubCredentialsProvider?: GithubCredentialsProvider;\n}) {\n const { integrations, githubCredentialsProvider } = options;\n\n return createTemplateAction({\n id: 'github:issues:label',\n description: 'Adds labels to a pull request or issue on GitHub.',\n examples,\n schema: {\n input: {\n repoUrl: z =>\n z.string({\n description:\n 'Accepts the format `github.com?repo=reponame&owner=owner` where `reponame` is the repository name and `owner` is an organization or username',\n }),\n number: z =>\n z.number({\n description: 'The pull request or issue number to add labels to',\n }),\n labels: z =>\n z.array(z.string(), {\n description: 'The labels to add to the pull request or issue',\n }),\n token: z =>\n z\n .string({\n description:\n 'The `GITHUB_TOKEN` to use for authorization to GitHub',\n })\n .optional(),\n },\n },\n async handler(ctx) {\n const { repoUrl, number, labels, token: providedToken } = ctx.input;\n\n const { host, owner, repo } = parseRepoUrl(repoUrl, integrations);\n ctx.logger.info(`Adding labels to ${number} issue on repo ${repo}`);\n\n if (!owner) {\n throw new InputError('Invalid repository owner provided in repoUrl');\n }\n\n const octokitOptions = await getOctokitOptions({\n integrations,\n credentialsProvider: githubCredentialsProvider,\n host,\n owner,\n repo,\n token: providedToken,\n });\n const client = new Octokit({\n ...octokitOptions,\n log: ctx.logger,\n });\n\n try {\n await ctx.checkpoint({\n key: `github.issues.add.label.${owner}.${repo}.${number}`,\n fn: async () => {\n await client.rest.issues.addLabels({\n owner,\n repo,\n issue_number: number,\n labels,\n });\n },\n });\n } catch (e) {\n assertError(e);\n ctx.logger.warn(\n `Failed: adding labels to issue: '${number}' on repo: '${repo}', ${e.message}`,\n );\n }\n },\n });\n}\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","getOctokitOptions","Octokit","assertError"],"mappings":";;;;;;;;AAiCO,SAAS,8BAA8B,OAG3C,EAAA;AACD,EAAM,MAAA,EAAE,YAAc,EAAA,yBAAA,EAA8B,GAAA,OAAA;AAEpD,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,qBAAA;AAAA,IACJ,WAAa,EA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AAA,QACH,KAAK,GAAI,CAAA;AAAA,OACV,CAAA;AAED,MAAI,IAAA;AACF,QAAA,MAAM,IAAI,UAAW,CAAA;AAAA,UACnB,KAAK,CAA2B,wBAAA,EAAA,KAAK,CAAI,CAAA,EAAA,IAAI,IAAI,MAAM,CAAA,CAAA;AAAA,UACvD,IAAI,YAAY;AACd,YAAM,MAAA,MAAA,CAAO,IAAK,CAAA,MAAA,CAAO,SAAU,CAAA;AAAA,cACjC,KAAA;AAAA,cACA,IAAA;AAAA,cACA,YAAc,EAAA,MAAA;AAAA,cACd;AAAA,aACD,CAAA;AAAA;AACH,SACD,CAAA;AAAA,eACM,CAAG,EAAA;AACV,QAAAC,kBAAA,CAAY,CAAC,CAAA;AACb,QAAA,GAAA,CAAI,MAAO,CAAA,IAAA;AAAA,UACT,oCAAoC,MAAM,CAAA,YAAA,EAAe,IAAI,CAAA,GAAA,EAAM,EAAE,OAAO,CAAA;AAAA,SAC9E;AAAA;AACF;AACF,GACD,CAAA;AACH;;;;"}
|
|
@@ -14,40 +14,21 @@ function createGithubPagesEnableAction(options) {
|
|
|
14
14
|
description: "Enables GitHub Pages for a repository.",
|
|
15
15
|
schema: {
|
|
16
16
|
input: {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
sourceBranch: {
|
|
33
|
-
title: "Source Branch",
|
|
34
|
-
type: "string",
|
|
35
|
-
default: "main",
|
|
36
|
-
description: 'The GitHub Pages source branch. Default is "main"'
|
|
37
|
-
},
|
|
38
|
-
sourcePath: {
|
|
39
|
-
title: "Source Path",
|
|
40
|
-
type: "string",
|
|
41
|
-
default: "/",
|
|
42
|
-
description: 'The GitHub Pages source path - "/" or "/docs". Default is "/"',
|
|
43
|
-
enum: ["/", "/docs"]
|
|
44
|
-
},
|
|
45
|
-
token: {
|
|
46
|
-
title: "Authorization Token",
|
|
47
|
-
type: "string",
|
|
48
|
-
description: "The token to use for authorization to GitHub"
|
|
49
|
-
}
|
|
50
|
-
}
|
|
17
|
+
repoUrl: (z) => z.string({
|
|
18
|
+
description: "Accepts the format `github.com?repo=reponame&owner=owner` where `reponame` is the new repository name and `owner` is an organization or username"
|
|
19
|
+
}),
|
|
20
|
+
buildType: (z) => z.enum(["legacy", "workflow"], {
|
|
21
|
+
description: "The GitHub Pages build type - `legacy` or `workflow`. Default is `workflow`"
|
|
22
|
+
}).default("workflow").optional(),
|
|
23
|
+
sourceBranch: (z) => z.string({
|
|
24
|
+
description: 'The GitHub Pages source branch. Default is "main"'
|
|
25
|
+
}).default("main").optional(),
|
|
26
|
+
sourcePath: (z) => z.enum(["/", "/docs"], {
|
|
27
|
+
description: 'The GitHub Pages source path - "/" or "/docs". Default is "/"'
|
|
28
|
+
}).default("/").optional(),
|
|
29
|
+
token: (z) => z.string({
|
|
30
|
+
description: "The token to use for authorization to GitHub"
|
|
31
|
+
}).optional()
|
|
51
32
|
}
|
|
52
33
|
},
|
|
53
34
|
async handler(ctx) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"githubPagesEnable.cjs.js","sources":["../../src/actions/githubPagesEnable.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport {\n GithubCredentialsProvider,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\nimport { Octokit } from 'octokit';\nimport {\n createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { examples } from './githubPagesEnable.examples';\nimport { getOctokitOptions } from '../util';\n\n/**\n * Creates a new action that enables GitHub Pages for a repository.\n *\n * @public\n */\nexport function createGithubPagesEnableAction(options: {\n integrations: ScmIntegrationRegistry;\n githubCredentialsProvider?: GithubCredentialsProvider;\n}) {\n const { integrations, githubCredentialsProvider } = options;\n\n return createTemplateAction
|
|
1
|
+
{"version":3,"file":"githubPagesEnable.cjs.js","sources":["../../src/actions/githubPagesEnable.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport {\n GithubCredentialsProvider,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\nimport { Octokit } from 'octokit';\nimport {\n createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { examples } from './githubPagesEnable.examples';\nimport { getOctokitOptions } from '../util';\n\n/**\n * Creates a new action that enables GitHub Pages for a repository.\n *\n * @public\n */\nexport function createGithubPagesEnableAction(options: {\n integrations: ScmIntegrationRegistry;\n githubCredentialsProvider?: GithubCredentialsProvider;\n}) {\n const { integrations, githubCredentialsProvider } = options;\n\n return createTemplateAction({\n id: 'github:pages:enable',\n examples,\n description: 'Enables GitHub Pages for a repository.',\n schema: {\n input: {\n repoUrl: z =>\n z.string({\n description:\n 'Accepts the format `github.com?repo=reponame&owner=owner` where `reponame` is the new repository name and `owner` is an organization or username',\n }),\n buildType: z =>\n z\n .enum(['legacy', 'workflow'], {\n description:\n 'The GitHub Pages build type - `legacy` or `workflow`. Default is `workflow`',\n })\n .default('workflow')\n .optional(),\n sourceBranch: z =>\n z\n .string({\n description: 'The GitHub Pages source branch. Default is \"main\"',\n })\n .default('main')\n .optional(),\n sourcePath: z =>\n z\n .enum(['/', '/docs'], {\n description:\n 'The GitHub Pages source path - \"/\" or \"/docs\". Default is \"/\"',\n })\n .default('/')\n .optional(),\n token: z =>\n z\n .string({\n description: 'The token to use for authorization to GitHub',\n })\n .optional(),\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n buildType = 'workflow',\n sourceBranch = 'main',\n sourcePath = '/',\n token: providedToken,\n } = ctx.input;\n\n const { host, owner, repo } = parseRepoUrl(repoUrl, integrations);\n\n if (!owner) {\n throw new InputError('Invalid repository owner provided in repoUrl');\n }\n\n const octokitOptions = await getOctokitOptions({\n integrations,\n credentialsProvider: githubCredentialsProvider,\n token: providedToken,\n host,\n owner,\n repo,\n });\n const client = new Octokit({\n ...octokitOptions,\n log: ctx.logger,\n });\n\n ctx.logger.info(\n `Attempting to enable GitHub Pages for ${owner}/${repo} with \"${buildType}\" build type, on source branch \"${sourceBranch}\" and source path \"${sourcePath}\"`,\n );\n\n await ctx.checkpoint({\n key: `enabled.github.pages.${owner}.${repo}`,\n fn: async () => {\n await client.request('POST /repos/{owner}/{repo}/pages', {\n owner: owner,\n repo: repo,\n build_type: buildType,\n source: {\n branch: sourceBranch,\n path: sourcePath,\n },\n headers: {\n 'X-GitHub-Api-Version': '2022-11-28',\n },\n });\n },\n });\n\n ctx.logger.info('Completed enabling GitHub Pages');\n },\n });\n}\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","getOctokitOptions","Octokit"],"mappings":";;;;;;;;AAkCO,SAAS,8BAA8B,OAG3C,EAAA;AACD,EAAM,MAAA,EAAE,YAAc,EAAA,yBAAA,EAA8B,GAAA,OAAA;AAEpD,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,qBAAA;AAAA,cACJC,mCAA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