@backstage/plugin-scaffolder-backend-module-github 0.9.13-next.0 → 0.9.14-next.1
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 +11 -0
- package/dist/actions/github.cjs.js +7 -1
- package/dist/actions/github.cjs.js.map +1 -1
- package/dist/actions/githubActionsDispatch.cjs.js +2 -1
- package/dist/actions/githubActionsDispatch.cjs.js.map +1 -1
- package/dist/actions/githubAutolinks.cjs.js +2 -1
- package/dist/actions/githubAutolinks.cjs.js.map +1 -1
- package/dist/actions/githubBranchProtection.cjs.js +2 -1
- package/dist/actions/githubBranchProtection.cjs.js.map +1 -1
- package/dist/actions/githubDeployKey.cjs.js +2 -1
- package/dist/actions/githubDeployKey.cjs.js.map +1 -1
- package/dist/actions/githubEnvironment.cjs.js +2 -1
- package/dist/actions/githubEnvironment.cjs.js.map +1 -1
- package/dist/actions/githubIssuesCreate.cjs.js +2 -1
- package/dist/actions/githubIssuesCreate.cjs.js.map +1 -1
- package/dist/actions/githubIssuesLabel.cjs.js +2 -1
- package/dist/actions/githubIssuesLabel.cjs.js.map +1 -1
- package/dist/actions/githubPagesEnable.cjs.js +2 -1
- package/dist/actions/githubPagesEnable.cjs.js.map +1 -1
- package/dist/actions/githubPullRequest.cjs.js +7 -1
- package/dist/actions/githubPullRequest.cjs.js.map +1 -1
- package/dist/actions/githubRepoCreate.cjs.js +2 -1
- package/dist/actions/githubRepoCreate.cjs.js.map +1 -1
- package/dist/actions/githubRepoPush.cjs.js +7 -1
- package/dist/actions/githubRepoPush.cjs.js.map +1 -1
- package/dist/actions/githubWebhook.cjs.js +7 -1
- package/dist/actions/githubWebhook.cjs.js.map +1 -1
- package/dist/index.d.ts +18 -0
- package/dist/module.cjs.js +30 -13
- package/dist/module.cjs.js.map +1 -1
- package/dist/util.cjs.js +12 -1
- package/dist/util.cjs.js.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @backstage/plugin-scaffolder-backend-module-github
|
|
2
2
|
|
|
3
|
+
## 0.9.14-next.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- bbba6b5: Added support for requiring user-provided credentials for GitHub mutation actions when `scaffolder.requireScmUserCredentials` is enabled.
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @backstage/integration@2.1.2-next.0
|
|
10
|
+
- @backstage/plugin-scaffolder-node@0.13.7-next.1
|
|
11
|
+
- @backstage/backend-plugin-api@1.10.1-next.0
|
|
12
|
+
- @backstage/plugin-catalog-node@2.2.5-next.0
|
|
13
|
+
|
|
3
14
|
## 0.9.13-next.0
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
|
@@ -10,7 +10,12 @@ var outputProperties = require('./outputProperties.cjs.js');
|
|
|
10
10
|
var github_examples = require('./github.examples.cjs.js');
|
|
11
11
|
|
|
12
12
|
function createPublishGithubAction(options) {
|
|
13
|
-
const {
|
|
13
|
+
const {
|
|
14
|
+
integrations,
|
|
15
|
+
config,
|
|
16
|
+
githubCredentialsProvider,
|
|
17
|
+
requireScmUserCredentials
|
|
18
|
+
} = options;
|
|
14
19
|
return pluginScaffolderNode.createTemplateAction({
|
|
15
20
|
id: "publish:github",
|
|
16
21
|
description: "Initializes a git repository of contents in workspace and publishes it to GitHub.",
|
|
@@ -116,6 +121,7 @@ function createPublishGithubAction(options) {
|
|
|
116
121
|
}
|
|
117
122
|
const octokitOptions = await util.getOctokitOptions({
|
|
118
123
|
integrations,
|
|
124
|
+
requireScmUserCredentials,
|
|
119
125
|
credentialsProvider: githubCredentialsProvider,
|
|
120
126
|
token: providedToken,
|
|
121
127
|
host,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"github.cjs.js","sources":["../../src/actions/github.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 { Config } from '@backstage/config';\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 {\n createGithubRepoWithCollaboratorsAndTopics,\n initRepoPushAndProtect,\n} from './helpers';\nimport { getOctokitOptions } from '../util';\nimport * as inputProps from './inputProperties';\nimport * as outputProps from './outputProperties';\nimport { examples } from './github.examples';\n\n/**\n * Creates a new action that initializes a git repository of the content in the workspace\n * and publishes it to GitHub.\n *\n * @public\n */\nexport function createPublishGithubAction(options: {\n integrations: ScmIntegrationRegistry;\n config: Config;\n githubCredentialsProvider?: GithubCredentialsProvider;\n}) {\n const { integrations, config, githubCredentialsProvider } = options;\n\n return createTemplateAction({\n id: 'publish:github',\n description:\n 'Initializes a git repository of contents in workspace and publishes it to GitHub.',\n examples,\n schema: {\n input: {\n repoUrl: inputProps.repoUrl,\n description: inputProps.description,\n homepage: inputProps.homepage,\n access: inputProps.access,\n bypassPullRequestAllowances: inputProps.bypassPullRequestAllowances,\n requiredApprovingReviewCount: inputProps.requiredApprovingReviewCount,\n restrictions: inputProps.restrictions,\n requireCodeOwnerReviews: inputProps.requireCodeOwnerReviews,\n dismissStaleReviews: inputProps.dismissStaleReviews,\n requiredStatusCheckContexts: inputProps.requiredStatusCheckContexts,\n requireBranchesToBeUpToDate: inputProps.requireBranchesToBeUpToDate,\n requiredConversationResolution:\n inputProps.requiredConversationResolution,\n requireLastPushApproval: inputProps.requireLastPushApproval,\n repoVisibility: inputProps.repoVisibility,\n defaultBranch: inputProps.defaultBranch,\n protectDefaultBranch: inputProps.protectDefaultBranch,\n protectEnforceAdmins: inputProps.protectEnforceAdmins,\n deleteBranchOnMerge: inputProps.deleteBranchOnMerge,\n gitCommitMessage: inputProps.gitCommitMessage,\n gitAuthorName: inputProps.gitAuthorName,\n gitAuthorEmail: inputProps.gitAuthorEmail,\n allowMergeCommit: inputProps.allowMergeCommit,\n allowSquashMerge: inputProps.allowSquashMerge,\n squashMergeCommitTitle: inputProps.squashMergeCommitTitle,\n squashMergeCommitMessage: inputProps.squashMergeCommitMessage,\n allowRebaseMerge: inputProps.allowRebaseMerge,\n allowAutoMerge: inputProps.allowAutoMerge,\n allowUpdateBranch: inputProps.allowUpdateBranch,\n sourcePath: inputProps.sourcePath,\n collaborators: inputProps.collaborators,\n hasProjects: inputProps.hasProjects,\n hasWiki: inputProps.hasWiki,\n hasIssues: inputProps.hasIssues,\n token: inputProps.token,\n topics: inputProps.topics,\n repoVariables: inputProps.repoVariables,\n secrets: inputProps.secrets,\n oidcCustomization: inputProps.oidcCustomization,\n requiredCommitSigning: inputProps.requiredCommitSigning,\n requiredLinearHistory: inputProps.requiredLinearHistory,\n customProperties: inputProps.customProperties,\n subscribe: inputProps.subscribe,\n },\n output: {\n remoteUrl: outputProps.remoteUrl,\n repoContentsUrl: outputProps.repoContentsUrl,\n commitHash: outputProps.commitHash,\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n description,\n homepage,\n access,\n requireCodeOwnerReviews = false,\n dismissStaleReviews = false,\n bypassPullRequestAllowances,\n requiredApprovingReviewCount = 1,\n restrictions,\n requiredStatusCheckContexts = [],\n requireBranchesToBeUpToDate = true,\n requiredConversationResolution = false,\n requireLastPushApproval = false,\n repoVisibility = 'private',\n defaultBranch = 'main',\n protectDefaultBranch = true,\n protectEnforceAdmins = true,\n deleteBranchOnMerge = false,\n gitCommitMessage,\n gitAuthorName,\n gitAuthorEmail,\n allowMergeCommit = true,\n allowSquashMerge = true,\n squashMergeCommitTitle = 'COMMIT_OR_PR_TITLE',\n squashMergeCommitMessage = 'COMMIT_MESSAGES',\n allowRebaseMerge = true,\n allowAutoMerge = false,\n allowUpdateBranch = false,\n collaborators,\n hasProjects = undefined,\n hasWiki = undefined,\n hasIssues = undefined,\n topics,\n repoVariables,\n secrets,\n oidcCustomization,\n token: providedToken,\n customProperties,\n subscribe = false,\n requiredCommitSigning = false,\n requiredLinearHistory = false,\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 const { remoteUrl, repoContentsUrl } = await ctx.checkpoint({\n key: `create.github.repo.${owner}.${repo}`,\n fn: async () => {\n const newRepo = await createGithubRepoWithCollaboratorsAndTopics(\n client,\n repo,\n owner,\n repoVisibility,\n description,\n homepage,\n deleteBranchOnMerge,\n allowMergeCommit,\n allowSquashMerge,\n squashMergeCommitTitle,\n squashMergeCommitMessage,\n allowRebaseMerge,\n allowAutoMerge,\n allowUpdateBranch,\n access,\n collaborators,\n hasProjects,\n hasWiki,\n hasIssues,\n topics,\n repoVariables,\n secrets,\n oidcCustomization,\n customProperties,\n subscribe,\n ctx.logger,\n );\n\n return {\n remoteUrl: newRepo.clone_url,\n repoContentsUrl: `${newRepo.html_url}/blob/${defaultBranch}`,\n };\n },\n });\n\n const commitResult = await initRepoPushAndProtect(\n remoteUrl,\n octokitOptions.auth,\n ctx.workspacePath,\n ctx.input.sourcePath,\n defaultBranch,\n protectDefaultBranch,\n protectEnforceAdmins,\n owner,\n client,\n repo,\n requireCodeOwnerReviews,\n bypassPullRequestAllowances,\n requiredApprovingReviewCount,\n restrictions,\n requiredStatusCheckContexts,\n requireBranchesToBeUpToDate,\n requiredConversationResolution,\n requireLastPushApproval,\n config,\n ctx.logger,\n gitCommitMessage,\n gitAuthorName,\n gitAuthorEmail,\n dismissStaleReviews,\n requiredCommitSigning,\n requiredLinearHistory,\n );\n\n ctx.output('commitHash', commitResult?.commitHash);\n ctx.output('remoteUrl', remoteUrl);\n ctx.output('repoContentsUrl', repoContentsUrl);\n },\n });\n}\n"],"names":["createTemplateAction","examples","inputProps.repoUrl","inputProps.description","inputProps.homepage","inputProps.access","inputProps.bypassPullRequestAllowances","inputProps.requiredApprovingReviewCount","inputProps.restrictions","inputProps.requireCodeOwnerReviews","inputProps.dismissStaleReviews","inputProps.requiredStatusCheckContexts","inputProps.requireBranchesToBeUpToDate","inputProps.requiredConversationResolution","inputProps.requireLastPushApproval","inputProps.repoVisibility","inputProps.defaultBranch","inputProps.protectDefaultBranch","inputProps.protectEnforceAdmins","inputProps.deleteBranchOnMerge","inputProps.gitCommitMessage","inputProps.gitAuthorName","inputProps.gitAuthorEmail","inputProps.allowMergeCommit","inputProps.allowSquashMerge","inputProps.squashMergeCommitTitle","inputProps.squashMergeCommitMessage","inputProps.allowRebaseMerge","inputProps.allowAutoMerge","inputProps.allowUpdateBranch","inputProps.sourcePath","inputProps.collaborators","inputProps.hasProjects","inputProps.hasWiki","inputProps.hasIssues","inputProps.token","inputProps.topics","inputProps.repoVariables","inputProps.secrets","inputProps.oidcCustomization","inputProps.requiredCommitSigning","inputProps.requiredLinearHistory","inputProps.customProperties","inputProps.subscribe","outputProps.remoteUrl","outputProps.repoContentsUrl","outputProps.commitHash","parseRepoUrl","InputError","getOctokitOptions","Octokit","createGithubRepoWithCollaboratorsAndTopics","initRepoPushAndProtect"],"mappings":";;;;;;;;;;;AA0CO,SAAS,0BAA0B,OAAA,EAIvC;AACD,EAAA,MAAM,EAAE,YAAA,EAAc,MAAA,EAAQ,yBAAA,EAA0B,GAAI,OAAA;AAE5D,EAAA,OAAOA,yCAAA,CAAqB;AAAA,IAC1B,EAAA,EAAI,gBAAA;AAAA,IACJ,WAAA,EACE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,SAAA;AAAA,YACA,GAAA,CAAI;AAAA,WACN;AAEA,UAAA,OAAO;AAAA,YACL,WAAW,OAAA,CAAQ,SAAA;AAAA,YACnB,eAAA,EAAiB,CAAA,EAAG,OAAA,CAAQ,QAAQ,SAAS,aAAa,CAAA;AAAA,WAC5D;AAAA,QACF;AAAA,OACD,CAAA;AAED,MAAA,MAAM,eAAe,MAAMC,8BAAA;AAAA,QACzB,SAAA;AAAA,QACA,cAAA,CAAe,IAAA;AAAA,QACf,GAAA,CAAI,aAAA;AAAA,QACJ,IAAI,KAAA,CAAM,UAAA;AAAA,QACV,aAAA;AAAA,QACA,oBAAA;AAAA,QACA,oBAAA;AAAA,QACA,KAAA;AAAA,QACA,MAAA;AAAA,QACA,IAAA;AAAA,QACA,uBAAA;AAAA,QACA,2BAAA;AAAA,QACA,4BAAA;AAAA,QACA,YAAA;AAAA,QACA,2BAAA;AAAA,QACA,2BAAA;AAAA,QACA,8BAAA;AAAA,QACA,uBAAA;AAAA,QACA,MAAA;AAAA,QACA,GAAA,CAAI,MAAA;AAAA,QACJ,gBAAA;AAAA,QACA,aAAA;AAAA,QACA,cAAA;AAAA,QACA,mBAAA;AAAA,QACA,qBAAA;AAAA,QACA;AAAA,OACF;AAEA,MAAA,GAAA,CAAI,MAAA,CAAO,YAAA,EAAc,YAAA,EAAc,UAAU,CAAA;AACjD,MAAA,GAAA,CAAI,MAAA,CAAO,aAAa,SAAS,CAAA;AACjC,MAAA,GAAA,CAAI,MAAA,CAAO,mBAAmB,eAAe,CAAA;AAAA,IAC/C;AAAA,GACD,CAAA;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"github.cjs.js","sources":["../../src/actions/github.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 { Config } from '@backstage/config';\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 {\n createGithubRepoWithCollaboratorsAndTopics,\n initRepoPushAndProtect,\n} from './helpers';\nimport { getOctokitOptions } from '../util';\nimport * as inputProps from './inputProperties';\nimport * as outputProps from './outputProperties';\nimport { examples } from './github.examples';\n\n/**\n * Creates a new action that initializes a git repository of the content in the workspace\n * and publishes it to GitHub.\n *\n * @public\n */\nexport function createPublishGithubAction(options: {\n integrations: ScmIntegrationRegistry;\n config: Config;\n githubCredentialsProvider?: GithubCredentialsProvider;\n requireScmUserCredentials?: boolean;\n}) {\n const {\n integrations,\n config,\n githubCredentialsProvider,\n requireScmUserCredentials,\n } = options;\n\n return createTemplateAction({\n id: 'publish:github',\n description:\n 'Initializes a git repository of contents in workspace and publishes it to GitHub.',\n examples,\n schema: {\n input: {\n repoUrl: inputProps.repoUrl,\n description: inputProps.description,\n homepage: inputProps.homepage,\n access: inputProps.access,\n bypassPullRequestAllowances: inputProps.bypassPullRequestAllowances,\n requiredApprovingReviewCount: inputProps.requiredApprovingReviewCount,\n restrictions: inputProps.restrictions,\n requireCodeOwnerReviews: inputProps.requireCodeOwnerReviews,\n dismissStaleReviews: inputProps.dismissStaleReviews,\n requiredStatusCheckContexts: inputProps.requiredStatusCheckContexts,\n requireBranchesToBeUpToDate: inputProps.requireBranchesToBeUpToDate,\n requiredConversationResolution:\n inputProps.requiredConversationResolution,\n requireLastPushApproval: inputProps.requireLastPushApproval,\n repoVisibility: inputProps.repoVisibility,\n defaultBranch: inputProps.defaultBranch,\n protectDefaultBranch: inputProps.protectDefaultBranch,\n protectEnforceAdmins: inputProps.protectEnforceAdmins,\n deleteBranchOnMerge: inputProps.deleteBranchOnMerge,\n gitCommitMessage: inputProps.gitCommitMessage,\n gitAuthorName: inputProps.gitAuthorName,\n gitAuthorEmail: inputProps.gitAuthorEmail,\n allowMergeCommit: inputProps.allowMergeCommit,\n allowSquashMerge: inputProps.allowSquashMerge,\n squashMergeCommitTitle: inputProps.squashMergeCommitTitle,\n squashMergeCommitMessage: inputProps.squashMergeCommitMessage,\n allowRebaseMerge: inputProps.allowRebaseMerge,\n allowAutoMerge: inputProps.allowAutoMerge,\n allowUpdateBranch: inputProps.allowUpdateBranch,\n sourcePath: inputProps.sourcePath,\n collaborators: inputProps.collaborators,\n hasProjects: inputProps.hasProjects,\n hasWiki: inputProps.hasWiki,\n hasIssues: inputProps.hasIssues,\n token: inputProps.token,\n topics: inputProps.topics,\n repoVariables: inputProps.repoVariables,\n secrets: inputProps.secrets,\n oidcCustomization: inputProps.oidcCustomization,\n requiredCommitSigning: inputProps.requiredCommitSigning,\n requiredLinearHistory: inputProps.requiredLinearHistory,\n customProperties: inputProps.customProperties,\n subscribe: inputProps.subscribe,\n },\n output: {\n remoteUrl: outputProps.remoteUrl,\n repoContentsUrl: outputProps.repoContentsUrl,\n commitHash: outputProps.commitHash,\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n description,\n homepage,\n access,\n requireCodeOwnerReviews = false,\n dismissStaleReviews = false,\n bypassPullRequestAllowances,\n requiredApprovingReviewCount = 1,\n restrictions,\n requiredStatusCheckContexts = [],\n requireBranchesToBeUpToDate = true,\n requiredConversationResolution = false,\n requireLastPushApproval = false,\n repoVisibility = 'private',\n defaultBranch = 'main',\n protectDefaultBranch = true,\n protectEnforceAdmins = true,\n deleteBranchOnMerge = false,\n gitCommitMessage,\n gitAuthorName,\n gitAuthorEmail,\n allowMergeCommit = true,\n allowSquashMerge = true,\n squashMergeCommitTitle = 'COMMIT_OR_PR_TITLE',\n squashMergeCommitMessage = 'COMMIT_MESSAGES',\n allowRebaseMerge = true,\n allowAutoMerge = false,\n allowUpdateBranch = false,\n collaborators,\n hasProjects = undefined,\n hasWiki = undefined,\n hasIssues = undefined,\n topics,\n repoVariables,\n secrets,\n oidcCustomization,\n token: providedToken,\n customProperties,\n subscribe = false,\n requiredCommitSigning = false,\n requiredLinearHistory = false,\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 requireScmUserCredentials,\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 const { remoteUrl, repoContentsUrl } = await ctx.checkpoint({\n key: `create.github.repo.${owner}.${repo}`,\n fn: async () => {\n const newRepo = await createGithubRepoWithCollaboratorsAndTopics(\n client,\n repo,\n owner,\n repoVisibility,\n description,\n homepage,\n deleteBranchOnMerge,\n allowMergeCommit,\n allowSquashMerge,\n squashMergeCommitTitle,\n squashMergeCommitMessage,\n allowRebaseMerge,\n allowAutoMerge,\n allowUpdateBranch,\n access,\n collaborators,\n hasProjects,\n hasWiki,\n hasIssues,\n topics,\n repoVariables,\n secrets,\n oidcCustomization,\n customProperties,\n subscribe,\n ctx.logger,\n );\n\n return {\n remoteUrl: newRepo.clone_url,\n repoContentsUrl: `${newRepo.html_url}/blob/${defaultBranch}`,\n };\n },\n });\n\n const commitResult = await initRepoPushAndProtect(\n remoteUrl,\n octokitOptions.auth,\n ctx.workspacePath,\n ctx.input.sourcePath,\n defaultBranch,\n protectDefaultBranch,\n protectEnforceAdmins,\n owner,\n client,\n repo,\n requireCodeOwnerReviews,\n bypassPullRequestAllowances,\n requiredApprovingReviewCount,\n restrictions,\n requiredStatusCheckContexts,\n requireBranchesToBeUpToDate,\n requiredConversationResolution,\n requireLastPushApproval,\n config,\n ctx.logger,\n gitCommitMessage,\n gitAuthorName,\n gitAuthorEmail,\n dismissStaleReviews,\n requiredCommitSigning,\n requiredLinearHistory,\n );\n\n ctx.output('commitHash', commitResult?.commitHash);\n ctx.output('remoteUrl', remoteUrl);\n ctx.output('repoContentsUrl', repoContentsUrl);\n },\n });\n}\n"],"names":["createTemplateAction","examples","inputProps.repoUrl","inputProps.description","inputProps.homepage","inputProps.access","inputProps.bypassPullRequestAllowances","inputProps.requiredApprovingReviewCount","inputProps.restrictions","inputProps.requireCodeOwnerReviews","inputProps.dismissStaleReviews","inputProps.requiredStatusCheckContexts","inputProps.requireBranchesToBeUpToDate","inputProps.requiredConversationResolution","inputProps.requireLastPushApproval","inputProps.repoVisibility","inputProps.defaultBranch","inputProps.protectDefaultBranch","inputProps.protectEnforceAdmins","inputProps.deleteBranchOnMerge","inputProps.gitCommitMessage","inputProps.gitAuthorName","inputProps.gitAuthorEmail","inputProps.allowMergeCommit","inputProps.allowSquashMerge","inputProps.squashMergeCommitTitle","inputProps.squashMergeCommitMessage","inputProps.allowRebaseMerge","inputProps.allowAutoMerge","inputProps.allowUpdateBranch","inputProps.sourcePath","inputProps.collaborators","inputProps.hasProjects","inputProps.hasWiki","inputProps.hasIssues","inputProps.token","inputProps.topics","inputProps.repoVariables","inputProps.secrets","inputProps.oidcCustomization","inputProps.requiredCommitSigning","inputProps.requiredLinearHistory","inputProps.customProperties","inputProps.subscribe","outputProps.remoteUrl","outputProps.repoContentsUrl","outputProps.commitHash","parseRepoUrl","InputError","getOctokitOptions","Octokit","createGithubRepoWithCollaboratorsAndTopics","initRepoPushAndProtect"],"mappings":";;;;;;;;;;;AA0CO,SAAS,0BAA0B,OAAA,EAKvC;AACD,EAAA,MAAM;AAAA,IACJ,YAAA;AAAA,IACA,MAAA;AAAA,IACA,yBAAA;AAAA,IACA;AAAA,GACF,GAAI,OAAA;AAEJ,EAAA,OAAOA,yCAAA,CAAqB;AAAA,IAC1B,EAAA,EAAI,gBAAA;AAAA,IACJ,WAAA,EACE,mFAAA;AAAA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,YACA,SAAA;AAAA,YACA,GAAA,CAAI;AAAA,WACN;AAEA,UAAA,OAAO;AAAA,YACL,WAAW,OAAA,CAAQ,SAAA;AAAA,YACnB,eAAA,EAAiB,CAAA,EAAG,OAAA,CAAQ,QAAQ,SAAS,aAAa,CAAA;AAAA,WAC5D;AAAA,QACF;AAAA,OACD,CAAA;AAED,MAAA,MAAM,eAAe,MAAMC,8BAAA;AAAA,QACzB,SAAA;AAAA,QACA,cAAA,CAAe,IAAA;AAAA,QACf,GAAA,CAAI,aAAA;AAAA,QACJ,IAAI,KAAA,CAAM,UAAA;AAAA,QACV,aAAA;AAAA,QACA,oBAAA;AAAA,QACA,oBAAA;AAAA,QACA,KAAA;AAAA,QACA,MAAA;AAAA,QACA,IAAA;AAAA,QACA,uBAAA;AAAA,QACA,2BAAA;AAAA,QACA,4BAAA;AAAA,QACA,YAAA;AAAA,QACA,2BAAA;AAAA,QACA,2BAAA;AAAA,QACA,8BAAA;AAAA,QACA,uBAAA;AAAA,QACA,MAAA;AAAA,QACA,GAAA,CAAI,MAAA;AAAA,QACJ,gBAAA;AAAA,QACA,aAAA;AAAA,QACA,cAAA;AAAA,QACA,mBAAA;AAAA,QACA,qBAAA;AAAA,QACA;AAAA,OACF;AAEA,MAAA,GAAA,CAAI,MAAA,CAAO,YAAA,EAAc,YAAA,EAAc,UAAU,CAAA;AACjD,MAAA,GAAA,CAAI,MAAA,CAAO,aAAa,SAAS,CAAA;AACjC,MAAA,GAAA,CAAI,MAAA,CAAO,mBAAmB,eAAe,CAAA;AAAA,IAC/C;AAAA,GACD,CAAA;AACH;;;;"}
|
|
@@ -7,7 +7,7 @@ var util = require('../util.cjs.js');
|
|
|
7
7
|
var githubActionsDispatch_examples = require('./githubActionsDispatch.examples.cjs.js');
|
|
8
8
|
|
|
9
9
|
function createGithubActionsDispatchAction(options) {
|
|
10
|
-
const { integrations, githubCredentialsProvider } = options;
|
|
10
|
+
const { integrations, githubCredentialsProvider, requireScmUserCredentials } = options;
|
|
11
11
|
return pluginScaffolderNode.createTemplateAction({
|
|
12
12
|
id: "github:actions:dispatch",
|
|
13
13
|
description: "Dispatches a GitHub Action workflow for a given branch or tag",
|
|
@@ -57,6 +57,7 @@ function createGithubActionsDispatchAction(options) {
|
|
|
57
57
|
}
|
|
58
58
|
const octokitOptions = await util.getOctokitOptions({
|
|
59
59
|
integrations,
|
|
60
|
+
requireScmUserCredentials,
|
|
60
61
|
host,
|
|
61
62
|
owner,
|
|
62
63
|
repo,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"githubActionsDispatch.cjs.js","sources":["../../src/actions/githubActionsDispatch.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, toError } from '@backstage/errors';\nimport {\n GithubCredentialsProvider,\n ScmIntegrations,\n} from '@backstage/integration';\nimport {\n createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { Octokit } from 'octokit';\nimport { getOctokitOptions } from '../util';\nimport { examples } from './githubActionsDispatch.examples';\n\n/**\n * Creates a new action that dispatches a GitHub Action workflow for a given branch or tag.\n * @public\n */\nexport function createGithubActionsDispatchAction(options: {\n integrations: ScmIntegrations;\n githubCredentialsProvider?: GithubCredentialsProvider;\n}) {\n const { integrations, githubCredentialsProvider } = options;\n\n return createTemplateAction({\n id: 'github:actions:dispatch',\n description:\n 'Dispatches a GitHub Action workflow for a given branch or tag',\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 workflowId: z =>\n z.string({\n description: 'The GitHub Action Workflow filename',\n }),\n branchOrTagName: z =>\n z.string({\n description:\n 'The git branch or tag name used to dispatch the workflow',\n }),\n workflowInputs: z =>\n z\n .record(z.string(), {\n description:\n 'Inputs keys and values to send to GitHub Action configured on the workflow file. The maximum number of properties is 25.',\n })\n .optional(),\n returnWorkflowRunDetails: z =>\n z\n .boolean({\n description:\n 'If true, returns the workflow run ID and URLs as action outputs.',\n })\n .optional(),\n token: z =>\n z\n .string({\n description:\n 'The `GITHUB_TOKEN` to use for authorization to GitHub',\n })\n .optional(),\n },\n output: {\n workflowRunId: z =>\n z.number({ description: 'The triggered workflow run ID' }).optional(),\n workflowRunUrl: z =>\n z.string({ description: 'API URL of the workflow run' }).optional(),\n workflowRunHtmlUrl: z =>\n z.string({ description: 'HTML URL of the workflow run' }).optional(),\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n workflowId,\n branchOrTagName,\n workflowInputs,\n returnWorkflowRunDetails,\n token: providedToken,\n } = ctx.input;\n\n ctx.logger.info(\n `Dispatching workflow ${workflowId} for repo ${repoUrl} on ${branchOrTagName}`,\n );\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 host,\n owner,\n repo,\n credentialsProvider: githubCredentialsProvider,\n token: providedToken,\n });\n const client = new Octokit({\n ...octokitOptions,\n log: ctx.logger,\n });\n\n try {\n const runDetails = await ctx.checkpoint({\n key: `create.workflow.dispatch.${owner}.${repo}.${workflowId}`,\n fn: async () => {\n const dispatchParams = {\n owner,\n repo,\n workflow_id: workflowId,\n ref: branchOrTagName,\n inputs: workflowInputs,\n ...(returnWorkflowRunDetails ? { return_run_details: true } : {}),\n };\n const response = await client.rest.actions.createWorkflowDispatch(\n dispatchParams,\n );\n\n ctx.logger.info(`Workflow ${workflowId} dispatched successfully`);\n\n if (returnWorkflowRunDetails && response.data) {\n // GitHub's API returns 200 with run details when return_run_details is true.\n // @octokit/openapi-types still types this as OctokitResponse<never, 204> because\n // it hasn't picked up the updated GitHub OpenAPI spec yet.\n // See: https://github.blog/changelog/2026-02-19-workflow-dispatch-api-now-returns-run-ids/\n // This cast can be removed once @octokit/openapi-types includes the updated spec.\n // Note: only supported on GitHub.com and GitHub Enterprise Cloud, not GitHub Enterprise Server\n const data = response.data as unknown as {\n workflow_run_id: number;\n run_url: string;\n html_url: string;\n };\n\n return {\n workflowRunId: data.workflow_run_id,\n workflowRunUrl: data.run_url,\n workflowRunHtmlUrl: data.html_url,\n };\n }\n return null;\n },\n });\n\n if (runDetails) {\n ctx.output('workflowRunId', runDetails.workflowRunId);\n ctx.output('workflowRunUrl', runDetails.workflowRunUrl);\n ctx.output('workflowRunHtmlUrl', runDetails.workflowRunHtmlUrl);\n\n if (runDetails.workflowRunHtmlUrl) {\n ctx.logger.info(\n `Workflow run url: ${runDetails.workflowRunHtmlUrl}`,\n );\n }\n }\n } catch (e) {\n const error = toError(e);\n ctx.logger.warn(\n `Failed: dispatching workflow '${workflowId}' on repo: '${repo}', ${error.message}`,\n );\n throw error;\n }\n },\n });\n}\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","getOctokitOptions","Octokit","toError"],"mappings":";;;;;;;;AAiCO,SAAS,kCAAkC,OAAA,EAG/C;AACD,EAAA,MAAM,EAAE,YAAA,EAAc,yBAAA,EAA0B,GAAI,OAAA;AAEpD,EAAA,OAAOA,yCAAA,CAAqB;AAAA,IAC1B,EAAA,EAAI,yBAAA;AAAA,IACJ,WAAA,EACE,+DAAA;AAAA,cACFC,uCAAA;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,KAAA,EAAO;AAAA,QACL,OAAA,EAAS,CAAA,CAAA,KACP,CAAA,CAAE,MAAA,CAAO;AAAA,UACP,WAAA,EACE;AAAA,SACH,CAAA;AAAA,QACH,UAAA,EAAY,CAAA,CAAA,KACV,C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AO;AAAA,gBACL,eAAe,IAAA,CAAK,eAAA;AAAA,gBACpB,gBAAgB,IAAA,CAAK,OAAA;AAAA,gBACrB,oBAAoB,IAAA,CAAK;AAAA,eAC3B;AAAA,YACF;AACA,YAAA,OAAO,IAAA;AAAA,UACT;AAAA,SACD,CAAA;AAED,QAAA,IAAI,UAAA,EAAY;AACd,UAAA,GAAA,CAAI,MAAA,CAAO,eAAA,EAAiB,UAAA,CAAW,aAAa,CAAA;AACpD,UAAA,GAAA,CAAI,MAAA,CAAO,gBAAA,EAAkB,UAAA,CAAW,cAAc,CAAA;AACtD,UAAA,GAAA,CAAI,MAAA,CAAO,oBAAA,EAAsB,UAAA,CAAW,kBAAkB,CAAA;AAE9D,UAAA,IAAI,WAAW,kBAAA,EAAoB;AACjC,YAAA,GAAA,CAAI,MAAA,CAAO,IAAA;AAAA,cACT,CAAA,kBAAA,EAAqB,WAAW,kBAAkB,CAAA;AAAA,aACpD;AAAA,UACF;AAAA,QACF;AAAA,MACF,SAAS,CAAA,EAAG;AACV,QAAA,MAAM,KAAA,GAAQC,eAAQ,CAAC,CAAA;AACvB,QAAA,GAAA,CAAI,MAAA,CAAO,IAAA;AAAA,UACT,iCAAiC,UAAU,CAAA,YAAA,EAAe,IAAI,CAAA,GAAA,EAAM,MAAM,OAAO,CAAA;AAAA,SACnF;AACA,QAAA,MAAM,KAAA;AAAA,MACR;AAAA,IACF;AAAA,GACD,CAAA;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"githubActionsDispatch.cjs.js","sources":["../../src/actions/githubActionsDispatch.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, toError } from '@backstage/errors';\nimport {\n GithubCredentialsProvider,\n ScmIntegrations,\n} from '@backstage/integration';\nimport {\n createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { Octokit } from 'octokit';\nimport { getOctokitOptions } from '../util';\nimport { examples } from './githubActionsDispatch.examples';\n\n/**\n * Creates a new action that dispatches a GitHub Action workflow for a given branch or tag.\n * @public\n */\nexport function createGithubActionsDispatchAction(options: {\n integrations: ScmIntegrations;\n githubCredentialsProvider?: GithubCredentialsProvider;\n requireScmUserCredentials?: boolean;\n}) {\n const { integrations, githubCredentialsProvider, requireScmUserCredentials } =\n options;\n\n return createTemplateAction({\n id: 'github:actions:dispatch',\n description:\n 'Dispatches a GitHub Action workflow for a given branch or tag',\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 workflowId: z =>\n z.string({\n description: 'The GitHub Action Workflow filename',\n }),\n branchOrTagName: z =>\n z.string({\n description:\n 'The git branch or tag name used to dispatch the workflow',\n }),\n workflowInputs: z =>\n z\n .record(z.string(), {\n description:\n 'Inputs keys and values to send to GitHub Action configured on the workflow file. The maximum number of properties is 25.',\n })\n .optional(),\n returnWorkflowRunDetails: z =>\n z\n .boolean({\n description:\n 'If true, returns the workflow run ID and URLs as action outputs.',\n })\n .optional(),\n token: z =>\n z\n .string({\n description:\n 'The `GITHUB_TOKEN` to use for authorization to GitHub',\n })\n .optional(),\n },\n output: {\n workflowRunId: z =>\n z.number({ description: 'The triggered workflow run ID' }).optional(),\n workflowRunUrl: z =>\n z.string({ description: 'API URL of the workflow run' }).optional(),\n workflowRunHtmlUrl: z =>\n z.string({ description: 'HTML URL of the workflow run' }).optional(),\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n workflowId,\n branchOrTagName,\n workflowInputs,\n returnWorkflowRunDetails,\n token: providedToken,\n } = ctx.input;\n\n ctx.logger.info(\n `Dispatching workflow ${workflowId} for repo ${repoUrl} on ${branchOrTagName}`,\n );\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 requireScmUserCredentials,\n host,\n owner,\n repo,\n credentialsProvider: githubCredentialsProvider,\n token: providedToken,\n });\n const client = new Octokit({\n ...octokitOptions,\n log: ctx.logger,\n });\n\n try {\n const runDetails = await ctx.checkpoint({\n key: `create.workflow.dispatch.${owner}.${repo}.${workflowId}`,\n fn: async () => {\n const dispatchParams = {\n owner,\n repo,\n workflow_id: workflowId,\n ref: branchOrTagName,\n inputs: workflowInputs,\n ...(returnWorkflowRunDetails ? { return_run_details: true } : {}),\n };\n const response = await client.rest.actions.createWorkflowDispatch(\n dispatchParams,\n );\n\n ctx.logger.info(`Workflow ${workflowId} dispatched successfully`);\n\n if (returnWorkflowRunDetails && response.data) {\n // GitHub's API returns 200 with run details when return_run_details is true.\n // @octokit/openapi-types still types this as OctokitResponse<never, 204> because\n // it hasn't picked up the updated GitHub OpenAPI spec yet.\n // See: https://github.blog/changelog/2026-02-19-workflow-dispatch-api-now-returns-run-ids/\n // This cast can be removed once @octokit/openapi-types includes the updated spec.\n // Note: only supported on GitHub.com and GitHub Enterprise Cloud, not GitHub Enterprise Server\n const data = response.data as unknown as {\n workflow_run_id: number;\n run_url: string;\n html_url: string;\n };\n\n return {\n workflowRunId: data.workflow_run_id,\n workflowRunUrl: data.run_url,\n workflowRunHtmlUrl: data.html_url,\n };\n }\n return null;\n },\n });\n\n if (runDetails) {\n ctx.output('workflowRunId', runDetails.workflowRunId);\n ctx.output('workflowRunUrl', runDetails.workflowRunUrl);\n ctx.output('workflowRunHtmlUrl', runDetails.workflowRunHtmlUrl);\n\n if (runDetails.workflowRunHtmlUrl) {\n ctx.logger.info(\n `Workflow run url: ${runDetails.workflowRunHtmlUrl}`,\n );\n }\n }\n } catch (e) {\n const error = toError(e);\n ctx.logger.warn(\n `Failed: dispatching workflow '${workflowId}' on repo: '${repo}', ${error.message}`,\n );\n throw error;\n }\n },\n });\n}\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","getOctokitOptions","Octokit","toError"],"mappings":";;;;;;;;AAiCO,SAAS,kCAAkC,OAAA,EAI/C;AACD,EAAA,MAAM,EAAE,YAAA,EAAc,yBAAA,EAA2B,yBAAA,EAA0B,GACzE,OAAA;AAEF,EAAA,OAAOA,yCAAA,CAAqB;AAAA,IAC1B,EAAA,EAAI,yBAAA;AAAA,IACJ,WAAA,EACE,+DAAA;AAAA,cACFC,uCAAA;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,KAAA,EAAO;AAAA,QACL,OAAA,EAAS,CAAA,CAAA,KACP,CAAA,CAAE,MAAA,CAAO;AAAA,UACP,WAAA,EACE;AAAA,SACH,CAAA;AAAA,QACH,UAAA,EAAY,CAAA,CAAA,KACV,CAAA,CAAE,MAAA,CAAO;AAAA,UACP,WAAA,EAAa;AAAA,SACd,CAAA;AAAA,QACH,eAAA,EAAiB,CAAA,CAAA,KACf,CAAA,CAAE,MAAA,CAAO;AAAA,UACP,WAAA,EACE;AAAA,SACH,CAAA;AAAA,QACH,gBAAgB,CAAA,CAAA,KACd,CAAA,CACG,MAAA,CAAO,CAAA,CAAE,QAAO,EAAG;AAAA,UAClB,WAAA,EACE;AAAA,SACH,EACA,QAAA,EAAS;AAAA,QACd,wBAAA,EAA0B,CAAA,CAAA,KACxB,CAAA,CACG,OAAA,CAAQ;AAAA,UACP,WAAA,EACE;AAAA,SACH,EACA,QAAA,EAAS;AAAA,QACd,KAAA,EAAO,CAAA,CAAA,KACL,CAAA,CACG,MAAA,CAAO;AAAA,UACN,WAAA,EACE;AAAA,SACH,EACA,QAAA;AAAS,OAChB;AAAA,MACA,MAAA,EAAQ;AAAA,QACN,aAAA,EAAe,OACb,CAAA,C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AAA,aACpD;AAAA,UACF;AAAA,QACF;AAAA,MACF,SAAS,CAAA,EAAG;AACV,QAAA,MAAM,KAAA,GAAQC,eAAQ,CAAC,CAAA;AACvB,QAAA,GAAA,CAAI,MAAA,CAAO,IAAA;AAAA,UACT,iCAAiC,UAAU,CAAA,YAAA,EAAe,IAAI,CAAA,GAAA,EAAM,MAAM,OAAO,CAAA;AAAA,SACnF;AACA,QAAA,MAAM,KAAA;AAAA,MACR;AAAA,IACF;AAAA,GACD,CAAA;AACH;;;;"}
|
|
@@ -7,7 +7,7 @@ var githubAutolinks_examples = require('./githubAutolinks.examples.cjs.js');
|
|
|
7
7
|
var util = require('../util.cjs.js');
|
|
8
8
|
|
|
9
9
|
function createGithubAutolinksAction(options) {
|
|
10
|
-
const { integrations, githubCredentialsProvider } = options;
|
|
10
|
+
const { integrations, githubCredentialsProvider, requireScmUserCredentials } = options;
|
|
11
11
|
return pluginScaffolderNode.createTemplateAction({
|
|
12
12
|
id: "github:autolinks:create",
|
|
13
13
|
description: "Create an autolink reference for a repository",
|
|
@@ -40,6 +40,7 @@ function createGithubAutolinksAction(options) {
|
|
|
40
40
|
}
|
|
41
41
|
const octokitOptions = await util.getOctokitOptions({
|
|
42
42
|
integrations,
|
|
43
|
+
requireScmUserCredentials,
|
|
43
44
|
host,
|
|
44
45
|
owner,
|
|
45
46
|
repo,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"githubAutolinks.cjs.js","sources":["../../src/actions/githubAutolinks.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 GithubCredentialsProvider,\n ScmIntegrations,\n} from '@backstage/integration';\nimport {\n createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { Octokit } from 'octokit';\nimport { examples } from './githubAutolinks.examples';\nimport { getOctokitOptions } from '../util';\n\n/**\n * Create an autolink reference for a repository\n * @public\n */\nexport function createGithubAutolinksAction(options: {\n integrations: ScmIntegrations;\n githubCredentialsProvider?: GithubCredentialsProvider;\n}) {\n const { integrations, githubCredentialsProvider }
|
|
1
|
+
{"version":3,"file":"githubAutolinks.cjs.js","sources":["../../src/actions/githubAutolinks.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 GithubCredentialsProvider,\n ScmIntegrations,\n} from '@backstage/integration';\nimport {\n createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { Octokit } from 'octokit';\nimport { examples } from './githubAutolinks.examples';\nimport { getOctokitOptions } from '../util';\n\n/**\n * Create an autolink reference for a repository\n * @public\n */\nexport function createGithubAutolinksAction(options: {\n integrations: ScmIntegrations;\n githubCredentialsProvider?: GithubCredentialsProvider;\n requireScmUserCredentials?: boolean;\n}) {\n const { integrations, githubCredentialsProvider, requireScmUserCredentials } =\n options;\n\n return createTemplateAction({\n id: 'github:autolinks:create',\n description: 'Create an autolink reference for a repository',\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 keyPrefix: z =>\n z.string({\n description:\n 'This prefix appended by certain characters will generate a link any time it is found in an issue, pull request, or commit.',\n }),\n urlTemplate: z =>\n z.string({\n description:\n 'The URL must contain `<num>` for the reference number. `<num>` matches different characters depending on the value of isAlphanumeric.',\n }),\n isAlphanumeric: z =>\n z\n .boolean({\n description:\n 'Whether this autolink reference matches alphanumeric characters. If `true`, the `<num>` parameter of the `url_template` matches alphanumeric characters `A-Z` (case insensitive), `0-9`, and `-`. If `false`, this autolink reference only matches numeric characters. Default: `true`',\n })\n .default(true)\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 { repoUrl, keyPrefix, urlTemplate, isAlphanumeric, token } =\n ctx.input;\n\n ctx.logger.info(`Creating autolink reference for repo ${repoUrl}`);\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 requireScmUserCredentials,\n host,\n owner,\n repo,\n credentialsProvider: githubCredentialsProvider,\n token,\n });\n const client = new Octokit({\n ...octokitOptions,\n log: ctx.logger,\n });\n\n await ctx.checkpoint({\n key: `create.auto.link.${owner}.${repo}`,\n fn: async () => {\n await client.rest.repos.createAutolink({\n owner,\n repo,\n key_prefix: keyPrefix,\n url_template: urlTemplate,\n is_alphanumeric: isAlphanumeric,\n });\n\n ctx.logger.info(`Autolink reference created successfully`);\n },\n });\n },\n });\n}\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","getOctokitOptions","Octokit"],"mappings":";;;;;;;;AAiCO,SAAS,4BAA4B,OAAA,EAIzC;AACD,EAAA,MAAM,EAAE,YAAA,EAAc,yBAAA,EAA2B,yBAAA,EAA0B,GACzE,OAAA;AAEF,EAAA,OAAOA,yCAAA,CAAqB;AAAA,IAC1B,EAAA,EAAI,yBAAA;AAAA,IACJ,WAA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EAAqB,yBAAA;AAAA,QACrB;AAAA,OACD,CAAA;AACD,MAAA,MAAM,MAAA,GAAS,IAAIC,eAAA,CAAQ;AAAA,QACzB,GAAG,cAAA;AAAA,QACH,KAAK,GAAA,CAAI;AAAA,OACV,CAAA;AAED,MAAA,MAAM,IAAI,UAAA,CAAW;AAAA,QACnB,GAAA,EAAK,CAAA,iBAAA,EAAoB,KAAK,CAAA,CAAA,EAAI,IAAI,CAAA,CAAA;AAAA,QACtC,IAAI,YAAY;AACd,UAAA,MAAM,MAAA,CAAO,IAAA,CAAK,KAAA,CAAM,cAAA,CAAe;AAAA,YACrC,KAAA;AAAA,YACA,IAAA;AAAA,YACA,UAAA,EAAY,SAAA;AAAA,YACZ,YAAA,EAAc,WAAA;AAAA,YACd,eAAA,EAAiB;AAAA,WAClB,CAAA;AAED,UAAA,GAAA,CAAI,MAAA,CAAO,KAAK,CAAA,uCAAA,CAAyC,CAAA;AAAA,QAC3D;AAAA,OACD,CAAA;AAAA,IACH;AAAA,GACD,CAAA;AACH;;;;"}
|
|
@@ -9,7 +9,7 @@ var octokit = require('octokit');
|
|
|
9
9
|
var gitHelpers = require('./gitHelpers.cjs.js');
|
|
10
10
|
|
|
11
11
|
function createGithubBranchProtectionAction(options) {
|
|
12
|
-
const { integrations } = options;
|
|
12
|
+
const { integrations, requireScmUserCredentials } = options;
|
|
13
13
|
return pluginScaffolderNode.createTemplateAction({
|
|
14
14
|
id: "github:branch-protection:create",
|
|
15
15
|
description: "Configures Branch Protection",
|
|
@@ -59,6 +59,7 @@ function createGithubBranchProtectionAction(options) {
|
|
|
59
59
|
}
|
|
60
60
|
const octokitOptions = await util.getOctokitOptions({
|
|
61
61
|
integrations,
|
|
62
|
+
requireScmUserCredentials,
|
|
62
63
|
token: providedToken,
|
|
63
64
|
host,
|
|
64
65
|
owner,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"githubBranchProtection.cjs.js","sources":["../../src/actions/githubBranchProtection.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 createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { examples } from './githubBranchProtection.examples';\nimport * as inputProps from './inputProperties';\nimport { getOctokitOptions } from '../util';\nimport { Octokit } from 'octokit';\nimport { enableBranchProtectionOnDefaultRepoBranch } from './gitHelpers';\n\n/**\n * Creates an `github:branch-protection:create` Scaffolder action that configured Branch Protection in a Github Repository.\n *\n * @public\n */\nexport function createGithubBranchProtectionAction(options: {\n integrations: ScmIntegrationRegistry;\n}) {\n const { integrations } = options;\n\n return createTemplateAction({\n id: 'github:branch-protection:create',\n description: 'Configures Branch Protection',\n examples,\n schema: {\n input: {\n repoUrl: inputProps.repoUrl,\n branch: inputProps.branch,\n enforceAdmins: inputProps.protectEnforceAdmins,\n requiredApprovingReviewCount: inputProps.requiredApprovingReviewCount,\n requireCodeOwnerReviews: inputProps.requireCodeOwnerReviews,\n dismissStaleReviews: inputProps.dismissStaleReviews,\n bypassPullRequestAllowances: inputProps.bypassPullRequestAllowances,\n restrictions: inputProps.restrictions,\n requiredStatusCheckContexts: inputProps.requiredStatusCheckContexts,\n requireBranchesToBeUpToDate: inputProps.requireBranchesToBeUpToDate,\n requiredConversationResolution:\n inputProps.requiredConversationResolution,\n requireLastPushApproval: inputProps.requireLastPushApproval,\n requiredCommitSigning: inputProps.requiredCommitSigning,\n requiredLinearHistory: inputProps.requiredLinearHistory,\n blockCreations: inputProps.blockCreations,\n token: inputProps.token,\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n branch,\n enforceAdmins = true,\n requiredApprovingReviewCount = 1,\n requireCodeOwnerReviews = false,\n dismissStaleReviews = false,\n bypassPullRequestAllowances,\n restrictions,\n requiredStatusCheckContexts = [],\n requireBranchesToBeUpToDate = true,\n requiredConversationResolution = false,\n requireLastPushApproval = false,\n requiredCommitSigning = false,\n requiredLinearHistory = false,\n blockCreations,\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 const client = new Octokit({\n ...octokitOptions,\n log: ctx.logger,\n });\n\n const defaultBranch = await ctx.checkpoint({\n key: `read.default.branch.${owner}.${repo}`,\n fn: async () => {\n const repository = await client.rest.repos.get({\n owner: owner,\n repo: repo,\n });\n return repository.data.default_branch;\n },\n });\n\n await ctx.checkpoint({\n key: `enable.branch.protection.${owner}.${repo}`,\n fn: async () => {\n await enableBranchProtectionOnDefaultRepoBranch({\n repoName: repo,\n client,\n owner,\n logger: ctx.logger,\n requireCodeOwnerReviews,\n bypassPullRequestAllowances,\n requiredApprovingReviewCount,\n restrictions,\n requiredStatusCheckContexts,\n requireBranchesToBeUpToDate,\n requiredConversationResolution,\n requireLastPushApproval,\n defaultBranch: branch ?? defaultBranch,\n enforceAdmins,\n dismissStaleReviews,\n requiredCommitSigning,\n requiredLinearHistory,\n blockCreations,\n });\n },\n });\n },\n });\n}\n"],"names":["createTemplateAction","examples","inputProps.repoUrl","inputProps.branch","inputProps.protectEnforceAdmins","inputProps.requiredApprovingReviewCount","inputProps.requireCodeOwnerReviews","inputProps.dismissStaleReviews","inputProps.bypassPullRequestAllowances","inputProps.restrictions","inputProps.requiredStatusCheckContexts","inputProps.requireBranchesToBeUpToDate","inputProps.requiredConversationResolution","inputProps.requireLastPushApproval","inputProps.requiredCommitSigning","inputProps.requiredLinearHistory","inputProps.blockCreations","inputProps.token","parseRepoUrl","InputError","getOctokitOptions","Octokit","enableBranchProtectionOnDefaultRepoBranch"],"mappings":";;;;;;;;;;AAiCO,SAAS,mCAAmC,OAAA,
|
|
1
|
+
{"version":3,"file":"githubBranchProtection.cjs.js","sources":["../../src/actions/githubBranchProtection.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 createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { examples } from './githubBranchProtection.examples';\nimport * as inputProps from './inputProperties';\nimport { getOctokitOptions } from '../util';\nimport { Octokit } from 'octokit';\nimport { enableBranchProtectionOnDefaultRepoBranch } from './gitHelpers';\n\n/**\n * Creates an `github:branch-protection:create` Scaffolder action that configured Branch Protection in a Github Repository.\n *\n * @public\n */\nexport function createGithubBranchProtectionAction(options: {\n integrations: ScmIntegrationRegistry;\n requireScmUserCredentials?: boolean;\n}) {\n const { integrations, requireScmUserCredentials } = options;\n\n return createTemplateAction({\n id: 'github:branch-protection:create',\n description: 'Configures Branch Protection',\n examples,\n schema: {\n input: {\n repoUrl: inputProps.repoUrl,\n branch: inputProps.branch,\n enforceAdmins: inputProps.protectEnforceAdmins,\n requiredApprovingReviewCount: inputProps.requiredApprovingReviewCount,\n requireCodeOwnerReviews: inputProps.requireCodeOwnerReviews,\n dismissStaleReviews: inputProps.dismissStaleReviews,\n bypassPullRequestAllowances: inputProps.bypassPullRequestAllowances,\n restrictions: inputProps.restrictions,\n requiredStatusCheckContexts: inputProps.requiredStatusCheckContexts,\n requireBranchesToBeUpToDate: inputProps.requireBranchesToBeUpToDate,\n requiredConversationResolution:\n inputProps.requiredConversationResolution,\n requireLastPushApproval: inputProps.requireLastPushApproval,\n requiredCommitSigning: inputProps.requiredCommitSigning,\n requiredLinearHistory: inputProps.requiredLinearHistory,\n blockCreations: inputProps.blockCreations,\n token: inputProps.token,\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n branch,\n enforceAdmins = true,\n requiredApprovingReviewCount = 1,\n requireCodeOwnerReviews = false,\n dismissStaleReviews = false,\n bypassPullRequestAllowances,\n restrictions,\n requiredStatusCheckContexts = [],\n requireBranchesToBeUpToDate = true,\n requiredConversationResolution = false,\n requireLastPushApproval = false,\n requiredCommitSigning = false,\n requiredLinearHistory = false,\n blockCreations,\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 requireScmUserCredentials,\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 defaultBranch = await ctx.checkpoint({\n key: `read.default.branch.${owner}.${repo}`,\n fn: async () => {\n const repository = await client.rest.repos.get({\n owner: owner,\n repo: repo,\n });\n return repository.data.default_branch;\n },\n });\n\n await ctx.checkpoint({\n key: `enable.branch.protection.${owner}.${repo}`,\n fn: async () => {\n await enableBranchProtectionOnDefaultRepoBranch({\n repoName: repo,\n client,\n owner,\n logger: ctx.logger,\n requireCodeOwnerReviews,\n bypassPullRequestAllowances,\n requiredApprovingReviewCount,\n restrictions,\n requiredStatusCheckContexts,\n requireBranchesToBeUpToDate,\n requiredConversationResolution,\n requireLastPushApproval,\n defaultBranch: branch ?? defaultBranch,\n enforceAdmins,\n dismissStaleReviews,\n requiredCommitSigning,\n requiredLinearHistory,\n blockCreations,\n });\n },\n });\n },\n });\n}\n"],"names":["createTemplateAction","examples","inputProps.repoUrl","inputProps.branch","inputProps.protectEnforceAdmins","inputProps.requiredApprovingReviewCount","inputProps.requireCodeOwnerReviews","inputProps.dismissStaleReviews","inputProps.bypassPullRequestAllowances","inputProps.restrictions","inputProps.requiredStatusCheckContexts","inputProps.requireBranchesToBeUpToDate","inputProps.requiredConversationResolution","inputProps.requireLastPushApproval","inputProps.requiredCommitSigning","inputProps.requiredLinearHistory","inputProps.blockCreations","inputProps.token","parseRepoUrl","InputError","getOctokitOptions","Octokit","enableBranchProtectionOnDefaultRepoBranch"],"mappings":";;;;;;;;;;AAiCO,SAAS,mCAAmC,OAAA,EAGhD;AACD,EAAA,MAAM,EAAE,YAAA,EAAc,yBAAA,EAA0B,GAAI,OAAA;AAEpD,EAAA,OAAOA,yCAAA,CAAqB;AAAA,IAC1B,EAAA,EAAI,iCAAA;AAAA,IACJ,WAAA,EAAa,8BAAA;AAAA,cACbC,wCAAA;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,KAAA,EAAO;AAAA,QACL,SAASC,uBAAW;AAAA,QACpB,QAAQC,sBAAW;AAAA,QACnB,eAAeC,oCAAW;AAAA,QAC1B,8BAA8BC,4CAAW;AAAA,QACzC,yBAAyBC,uCAAW;AAAA,QACpC,qBAAqBC,mCAAW;AAAA,QAChC,6BAA6BC,2CAAW;AAAA,QACxC,cAAcC,4BAAW;AAAA,QACzB,6BAA6BC,2CAAW;AAAA,QACxC,6BAA6BC,2CAAW;AAAA,QACxC,gCACEC,8CAAW;AAAA,QACb,yBAAyBC,uCAAW;AAAA,QACpC,uBAAuBC,qCAAW;AAAA,QAClC,uBAAuBC,qCAAW;AAAA,QAClC,gBAAgBC,8BAAW;AAAA,QAC3B,OAAOC;AAAW;AACpB,KACF;AAAA,IACA,MAAM,QAAQ,GAAA,EAAK;AACjB,MAAA,MAAM;AAAA,QACJ,OAAA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AA;AAAA,YACA;AAAA,WACD,CAAA;AACD,UAAA,OAAO,WAAW,IAAA,CAAK,cAAA;AAAA,QACzB;AAAA,OACD,CAAA;AAED,MAAA,MAAM,IAAI,UAAA,CAAW;AAAA,QACnB,GAAA,EAAK,CAAA,yBAAA,EAA4B,KAAK,CAAA,CAAA,EAAI,IAAI,CAAA,CAAA;AAAA,QAC9C,IAAI,YAAY;AACd,UAAA,MAAMC,oDAAA,CAA0C;AAAA,YAC9C,QAAA,EAAU,IAAA;AAAA,YACV,MAAA;AAAA,YACA,KAAA;AAAA,YACA,QAAQ,GAAA,CAAI,MAAA;AAAA,YACZ,uBAAA;AAAA,YACA,2BAAA;AAAA,YACA,4BAAA;AAAA,YACA,YAAA;AAAA,YACA,2BAAA;AAAA,YACA,2BAAA;AAAA,YACA,8BAAA;AAAA,YACA,uBAAA;AAAA,YACA,eAAe,MAAA,IAAU,aAAA;AAAA,YACzB,aAAA;AAAA,YACA,mBAAA;AAAA,YACA,qBAAA;AAAA,YACA,qBAAA;AAAA,YACA;AAAA,WACD,CAAA;AAAA,QACH;AAAA,OACD,CAAA;AAAA,IACH;AAAA,GACD,CAAA;AACH;;;;"}
|
|
@@ -12,7 +12,7 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
12
12
|
var Sodium__default = /*#__PURE__*/_interopDefaultCompat(Sodium);
|
|
13
13
|
|
|
14
14
|
function createGithubDeployKeyAction(options) {
|
|
15
|
-
const { integrations } = options;
|
|
15
|
+
const { integrations, requireScmUserCredentials } = options;
|
|
16
16
|
return pluginScaffolderNode.createTemplateAction({
|
|
17
17
|
id: "github:deployKey:create",
|
|
18
18
|
description: "Creates and stores Deploy Keys",
|
|
@@ -59,6 +59,7 @@ function createGithubDeployKeyAction(options) {
|
|
|
59
59
|
}
|
|
60
60
|
const octokitOptions = await util.getOctokitOptions({
|
|
61
61
|
integrations,
|
|
62
|
+
requireScmUserCredentials,
|
|
62
63
|
token: providedToken,
|
|
63
64
|
host,
|
|
64
65
|
owner,
|
|
@@ -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({\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,OAAA,
|
|
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 requireScmUserCredentials?: boolean;\n}) {\n const { integrations, requireScmUserCredentials } = 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 requireScmUserCredentials,\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,OAAA,EAGzC;AACD,EAAA,MAAM,EAAE,YAAA,EAAc,yBAAA,EAA0B,GAAI,OAAA;AAGpD,EAAA,OAAOA,yCAAA,CAAqB;AAAA,IAC1B,EAAA,EAAI,yBAAA;AAAA,IACJ,WAAA,EAAa,gCAAA;AAAA,cACbC,iCAAA;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,KAAA,EAAO;AAAA,QACL,OAAA,EAAS,CAAA,CAAA,KACP,CAAA,CAAE,MAAA,CAAO;AAAA,UACP,WAAA,EACE;AAAA,SACH,CAAA;AAAA,QACH,SAAA,EAAW,CAAA,CAAA,KACT,CAAA,CAAE,MAAA,CAAO;AAAA,UACP,WAAA,EACE;AAAA,SACH,CAAA;AAAA,QACH,UAAA,EAAY,CAAA,CAAA,KACV,CAAA,CAAE,MAAA,CAAO;AAAA,UACP,WAAA,EAAa;AAAA,SACd,CAA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,MAAA,MAAM,wBAAwBA,uBAAA,CAAO,SAAA;AAAA,QACnC,qBAAA;AAAA,QACAA,wBAAO,eAAA,CAAgB;AAAA,OACzB;AAEA,MAAA,MAAM,IAAI,UAAA,CAAW;AAAA,QACnB,KAAK,CAAA,6BAAA,EAAgC,KAAK,CAAA,CAAA,EAAI,IAAI,IAAI,KAAK,CAAA,CAAA;AAAA,QAC3D,IAAI,YAAY;AACd,UAAA,MAAM,MAAA,CAAO,IAAA,CAAK,OAAA,CAAQ,wBAAA,CAAyB;AAAA,YACjD,KAAA;AAAA,YACA,IAAA;AAAA,YACA,WAAA,EAAa,oBAAA;AAAA,YACb,eAAA,EAAiB,qBAAA;AAAA,YACjB,MAAA,EAAQ;AAAA,WACT,CAAA;AAAA,QACH;AAAA,OACD,CAAA;AAED,MAAA,GAAA,CAAI,MAAA,CAAO,wBAAwB,oBAAoB,CAAA;AAAA,IACzD;AAAA,GACD,CAAA;AACH;;;;"}
|
|
@@ -12,7 +12,7 @@ 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, catalog } = options;
|
|
15
|
+
const { integrations, catalog, requireScmUserCredentials } = options;
|
|
16
16
|
return pluginScaffolderNode.createTemplateAction({
|
|
17
17
|
id: "github:environment:create",
|
|
18
18
|
description: "Creates Deployment Environments",
|
|
@@ -89,6 +89,7 @@ Wildcard characters will not match \`/\`. For example, to match tags that begin
|
|
|
89
89
|
}
|
|
90
90
|
const octokitOptions = await util.getOctokitOptions({
|
|
91
91
|
integrations,
|
|
92
|
+
requireScmUserCredentials,
|
|
92
93
|
token: providedToken,
|
|
93
94
|
host,
|
|
94
95
|
owner,
|
|
@@ -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 { 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 minutes)',\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,OAAA,EAG3C;AACD,EAAA,MAAM,EAAE,YAAA,EAAc,OAAA,EAAQ,GAAI,OAAA;AAGlC,EAAA,OAAOA,yCAAA,CAAqB;AAAA,IAC1B,EAAA,EAAI,2BAAA;AAAA,IACJ,WAAA,EAAa,iCAAA;AAAA,cACbC,mCAAA;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,KAAA,EAAO;AAAA,QACL,OAAA,EAAS,CAAA,CAAA,KACP,CAAA,CAAE,MAAA,CAAO;AAAA,UACP,WAAA,EACE;AAAA,SACH,CAAA;AAAA,QACH,IAAA,EAAM,CAAA,CAAA,KACJ,CAAA,CAAE,MAAA,CAAO;AAAA,UACP,WAAA,EAAa,CAAA,4CAAA;AAAA,SACd,CAAA;AAAA,QACH,sBAAA,EAAwB,OACtB,CAAA,CACG,MAAA;AAAA,UACC;AAAA,YACE,kBAAA,EAAoB,EAAE,OAAA,CAAQ;AAAA,cAC5B,WAAA,EACE;AAAA,aACH,CAAA;AAAA,YACD,sBAAA,EAAwB,EAAE,OAAA,CAAQ;AAAA,cAChC,WAAA,EACE;AAAA,aACH;AAAA,WACH;AAAA,UACA;AAAA,YACE,WAAA,EACE;AAAA;AACJ,UAED,QAAA,EAAS;AAAA,QACd,yBAAyB,CAAA,CAAA,KACvB,CAAA,CACG,KAAA,CAAM,CAAA,CAAE,QAAO,EAAG;AAAA,UACjB,WAAA,EAAa,CAAA;;AAAA,+PAAA;AAAA,SAGd,EACA,QAAA,EA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CAAO,IAAA,CAAK,OAAA,CAAQ,+BAAA,CAAgC;AAAA,gBACxD,aAAA,EAAe,YAAA;AAAA,gBACf,KAAA;AAAA,gBACA,IAAA;AAAA,gBACA,gBAAA,EAAkB,IAAA;AAAA,gBAClB,WAAA,EAAa,GAAA;AAAA,gBACb,eAAA,EAAiB,qBAAA;AAAA,gBACjB,MAAA,EAAQ;AAAA,eACT,CAAA;AAAA,YACH;AAAA,WACD,CAAA;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,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 requireScmUserCredentials?: boolean;\n}) {\n const { integrations, catalog, requireScmUserCredentials } = 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 minutes)',\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 requireScmUserCredentials,\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,OAAA,EAI3C;AACD,EAAA,MAAM,EAAE,YAAA,EAAc,OAAA,EAAS,yBAAA,EAA0B,GAAI,OAAA;AAG7D,EAAA,OAAOA,yCAAA,CAAqB;AAAA,IAC1B,EAAA,EAAI,2BAAA;AAAA,IACJ,WAAA,EAAa,iCAAA;AAAA,cACbC,mCAAA;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,KAAA,EAAO;AAAA,QACL,OAAA,EAAS,CAAA,CAAA,KACP,CAAA,CAAE,MAAA,CAAO;AAAA,UACP,WAAA,EACE;AAAA,SACH,CAAA;AAAA,QACH,IAAA,EAAM,CAAA,CAAA,KACJ,CAAA,CAAE,MAAA,CAAO;AAAA,UACP,WAAA,E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AAA,CAAO,OAAA,CAAQ,OAAO,CAAA,EAAG;AAClD,UAAA,MAAM,YAAA,GAAeA,uBAAA,CAAO,WAAA,CAAY,KAAK,CAAA;AAC7C,UAAA,MAAM,wBAAwBA,uBAAA,CAAO,eAAA;AAAA,YACnC,YAAA;AAAA,YACA;AAAA,WACF;AACA,UAAA,MAAM,wBAAwBA,uBAAA,CAAO,SAAA;AAAA,YACnC,qBAAA;AAAA,YACAA,wBAAO,eAAA,CAAgB;AAAA,WACzB;AAEA,UAAA,MAAM,IAAI,UAAA,CAAW;AAAA,YACnB,GAAA,EAAK,+BAA+B,KAAK,CAAA,CAAA,EAAI,IAAI,CAAA,CAAA,EAAI,IAAI,IAAI,GAAG,CAAA,CAAA;AAAA,YAChE,IAAI,YAAY;AACd,cAAA,MAAM,MAAA,CAAO,IAAA,CAAK,OAAA,CAAQ,+BAAA,CAAgC;AAAA,gBACxD,aAAA,EAAe,YAAA;AAAA,gBACf,KAAA;AAAA,gBACA,IAAA;AAAA,gBACA,gBAAA,EAAkB,IAAA;AAAA,gBAClB,WAAA,EAAa,GAAA;AAAA,gBACb,eAAA,EAAiB,qBAAA;AAAA,gBACjB,MAAA,EAAQ;AAAA,eACT,CAAA;AAAA,YACH;AAAA,WACD,CAAA;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,GACD,CAAA;AACH;;;;"}
|
|
@@ -7,7 +7,7 @@ var util = require('../util.cjs.js');
|
|
|
7
7
|
var githubIssuesCreate_examples = require('./githubIssuesCreate.examples.cjs.js');
|
|
8
8
|
|
|
9
9
|
function createGithubIssuesCreateAction(options) {
|
|
10
|
-
const { integrations, githubCredentialsProvider } = options;
|
|
10
|
+
const { integrations, githubCredentialsProvider, requireScmUserCredentials } = options;
|
|
11
11
|
return pluginScaffolderNode.createTemplateAction({
|
|
12
12
|
id: "github:issues:create",
|
|
13
13
|
description: "Creates an issue on GitHub.",
|
|
@@ -63,6 +63,7 @@ function createGithubIssuesCreateAction(options) {
|
|
|
63
63
|
}
|
|
64
64
|
const octokitOptions = await util.getOctokitOptions({
|
|
65
65
|
integrations,
|
|
66
|
+
requireScmUserCredentials,
|
|
66
67
|
credentialsProvider: githubCredentialsProvider,
|
|
67
68
|
host,
|
|
68
69
|
owner,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"githubIssuesCreate.cjs.js","sources":["../../src/actions/githubIssuesCreate.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 { InputError, toError } from '@backstage/errors';\nimport { Octokit } from 'octokit';\nimport { getOctokitOptions } from '../util';\nimport { examples } from './githubIssuesCreate.examples';\n\n/**\n * Creates an issue on GitHub\n * @public\n */\nexport function createGithubIssuesCreateAction(options: {\n integrations: ScmIntegrationRegistry;\n githubCredentialsProvider?: GithubCredentialsProvider;\n}) {\n const { integrations, githubCredentialsProvider }
|
|
1
|
+
{"version":3,"file":"githubIssuesCreate.cjs.js","sources":["../../src/actions/githubIssuesCreate.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 { InputError, toError } from '@backstage/errors';\nimport { Octokit } from 'octokit';\nimport { getOctokitOptions } from '../util';\nimport { examples } from './githubIssuesCreate.examples';\n\n/**\n * Creates an issue on GitHub\n * @public\n */\nexport function createGithubIssuesCreateAction(options: {\n integrations: ScmIntegrationRegistry;\n githubCredentialsProvider?: GithubCredentialsProvider;\n requireScmUserCredentials?: boolean;\n}) {\n const { integrations, githubCredentialsProvider, requireScmUserCredentials } =\n options;\n\n return createTemplateAction({\n id: 'github:issues:create',\n description: 'Creates an issue on GitHub.',\n examples,\n supportsDryRun: true,\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 title: z =>\n z.string({\n description: 'The title of the issue',\n }),\n body: z =>\n z\n .string({\n description: 'The contents of the issue',\n })\n .optional(),\n assignees: z =>\n z\n .array(z.string(), {\n description:\n 'Logins for Users to assign to this issue. NOTE: Only users with push access can set assignees for new issues. Assignees are silently dropped otherwise.',\n })\n .optional(),\n milestone: z =>\n z\n .union([z.string(), z.number()], {\n description:\n 'The number of the milestone to associate this issue with. NOTE: Only users with push access can set the milestone for new issues. The milestone is silently dropped otherwise.',\n })\n .optional(),\n labels: z =>\n z\n .array(z.string(), {\n description:\n 'Labels to associate with this issue. NOTE: Only users with push access can set labels for new issues. Labels are silently dropped otherwise.',\n })\n .optional(),\n token: z =>\n z\n .string({\n description:\n 'The `GITHUB_TOKEN` to use for authorization to GitHub',\n })\n .optional(),\n },\n output: {\n issueUrl: z =>\n z.string({\n description: 'The URL of the created issue',\n }),\n issueNumber: z =>\n z.number({\n description: 'The number of the created issue',\n }),\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n title,\n body,\n assignees,\n milestone,\n labels,\n token: providedToken,\n } = ctx.input;\n\n const { host, owner, repo } = parseRepoUrl(repoUrl, integrations);\n ctx.logger.info(`Creating issue \"${title}\" 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 requireScmUserCredentials,\n credentialsProvider: githubCredentialsProvider,\n host,\n owner,\n repo,\n token: providedToken,\n });\n\n const client = new Octokit({\n ...octokitOptions,\n log: ctx.logger,\n });\n\n if (ctx.isDryRun) {\n ctx.logger.info(`Performing dry run of creating issue \"${title}\"`);\n ctx.output('issueUrl', `https://github.com/${owner}/${repo}/issues/42`);\n ctx.output('issueNumber', 42);\n ctx.logger.info(`Dry run complete`);\n return;\n }\n\n try {\n const issue = await ctx.checkpoint({\n key: `github.issues.create.${owner}.${repo}.${title}`,\n fn: async () => {\n const response = await client.rest.issues.create({\n owner,\n repo,\n title,\n body,\n assignees,\n milestone,\n labels,\n });\n\n return {\n html_url: response.data.html_url,\n number: response.data.number,\n };\n },\n });\n\n if (!issue) {\n throw new Error('Failed to create issue');\n }\n\n ctx.output('issueUrl', issue.html_url);\n ctx.output('issueNumber', issue.number);\n\n ctx.logger.info(\n `Successfully created issue #${issue.number}: ${issue.html_url}`,\n );\n } catch (e) {\n const error = toError(e);\n ctx.logger.warn(\n `Failed: creating issue '${title}' on repo: '${repo}', ${error.message}`,\n );\n throw error;\n }\n },\n });\n}\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","getOctokitOptions","Octokit","toError"],"mappings":";;;;;;;;AAiCO,SAAS,+BAA+B,OAAA,EAI5C;AACD,EAAA,MAAM,EAAE,YAAA,EAAc,yBAAA,EAA2B,yBAAA,EAA0B,GACzE,OAAA;AAEF,EAAA,OAAOA,yCAAA,CAAqB;AAAA,IAC1B,EAAA,EAAI,sBAAA;AAAA,IACJ,WAAA,EAAa,6BAAA;AAAA,cACbC,oCAAA;AAAA,I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');
|
|
|
7
7
|
var githubIssuesLabel_examples = require('./githubIssuesLabel.examples.cjs.js');
|
|
8
8
|
|
|
9
9
|
function createGithubIssuesLabelAction(options) {
|
|
10
|
-
const { integrations, githubCredentialsProvider } = options;
|
|
10
|
+
const { integrations, githubCredentialsProvider, requireScmUserCredentials } = options;
|
|
11
11
|
return pluginScaffolderNode.createTemplateAction({
|
|
12
12
|
id: "github:issues:label",
|
|
13
13
|
description: "Adds labels to a pull request or issue on GitHub.",
|
|
@@ -37,6 +37,7 @@ function createGithubIssuesLabelAction(options) {
|
|
|
37
37
|
}
|
|
38
38
|
const octokitOptions = await util.getOctokitOptions({
|
|
39
39
|
integrations,
|
|
40
|
+
requireScmUserCredentials,
|
|
40
41
|
credentialsProvider: githubCredentialsProvider,
|
|
41
42
|
host,
|
|
42
43
|
owner,
|
|
@@ -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 { InputError, toError } 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 }
|
|
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 { InputError, toError } 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 requireScmUserCredentials?: boolean;\n}) {\n const { integrations, githubCredentialsProvider, requireScmUserCredentials } =\n 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 requireScmUserCredentials,\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 ctx.logger.warn(\n `Failed: adding labels to issue: '${number}' on repo: '${repo}', ${\n toError(e).message\n }`,\n );\n }\n },\n });\n}\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","getOctokitOptions","Octokit","toError"],"mappings":";;;;;;;;AAiCO,SAAS,8BAA8B,OAAA,EAI3C;AACD,EAAA,MAAM,EAAE,YAAA,EAAc,yBAAA,EAA2B,yBAAA,EAA0B,GACzE,OAAA;AAEF,EAAA,OAAOA,yCAAA,CAAqB;AAAA,IAC1B,EAAA,EAAI,qBAAA;AAAA,IACJ,WAAA,EAAa,mDAAA;AAAA,cACbC,mCAAA;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,KAAA,EAAO;AAAA,QACL,OAAA,EAAS,CAAA,CAAA,KACP,CAAA,CAAE,MAAA,CAAO;AAAA,UACP,WAAA,EACE;AAAA,SACH,CAAA;AAAA,QACH,MAAA,EAAQ,CAAA,CAAA,KACN,CAAA,CAAE,MAAA,CAAO;AAAA,UACP,WAAA,EAAa;AAAA,SACd,CAAA;AAAA,QACH,QAAQ,CAAA,CAAA,KACN,CAAA,CAAE,KAAA,CAAM,CAAA,CAAE,QAAO,EAAG;AAAA,UAClB,WAAA,EAAa;AAAA,SACd,CAAA;AAAA,QACH,KAAA,EAAO,CAAA,CAAA,KACL,CAAA,CACG,MAAA,CAAO;AAAA,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