@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.
Files changed (33) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/actions/github.cjs.js +7 -1
  3. package/dist/actions/github.cjs.js.map +1 -1
  4. package/dist/actions/githubActionsDispatch.cjs.js +2 -1
  5. package/dist/actions/githubActionsDispatch.cjs.js.map +1 -1
  6. package/dist/actions/githubAutolinks.cjs.js +2 -1
  7. package/dist/actions/githubAutolinks.cjs.js.map +1 -1
  8. package/dist/actions/githubBranchProtection.cjs.js +2 -1
  9. package/dist/actions/githubBranchProtection.cjs.js.map +1 -1
  10. package/dist/actions/githubDeployKey.cjs.js +2 -1
  11. package/dist/actions/githubDeployKey.cjs.js.map +1 -1
  12. package/dist/actions/githubEnvironment.cjs.js +2 -1
  13. package/dist/actions/githubEnvironment.cjs.js.map +1 -1
  14. package/dist/actions/githubIssuesCreate.cjs.js +2 -1
  15. package/dist/actions/githubIssuesCreate.cjs.js.map +1 -1
  16. package/dist/actions/githubIssuesLabel.cjs.js +2 -1
  17. package/dist/actions/githubIssuesLabel.cjs.js.map +1 -1
  18. package/dist/actions/githubPagesEnable.cjs.js +2 -1
  19. package/dist/actions/githubPagesEnable.cjs.js.map +1 -1
  20. package/dist/actions/githubPullRequest.cjs.js +7 -1
  21. package/dist/actions/githubPullRequest.cjs.js.map +1 -1
  22. package/dist/actions/githubRepoCreate.cjs.js +2 -1
  23. package/dist/actions/githubRepoCreate.cjs.js.map +1 -1
  24. package/dist/actions/githubRepoPush.cjs.js +7 -1
  25. package/dist/actions/githubRepoPush.cjs.js.map +1 -1
  26. package/dist/actions/githubWebhook.cjs.js +7 -1
  27. package/dist/actions/githubWebhook.cjs.js.map +1 -1
  28. package/dist/index.d.ts +18 -0
  29. package/dist/module.cjs.js +30 -13
  30. package/dist/module.cjs.js.map +1 -1
  31. package/dist/util.cjs.js +12 -1
  32. package/dist/util.cjs.js.map +1 -1
  33. package/package.json +7 -7
@@ -7,7 +7,7 @@ var githubPagesEnable_examples = require('./githubPagesEnable.examples.cjs.js');
7
7
  var util = require('../util.cjs.js');
8
8
 
9
9
  function createGithubPagesEnableAction(options) {
10
- const { integrations, githubCredentialsProvider } = options;
10
+ const { integrations, githubCredentialsProvider, requireScmUserCredentials } = options;
11
11
  return pluginScaffolderNode.createTemplateAction({
12
12
  id: "github:pages:enable",
13
13
  examples: githubPagesEnable_examples.examples,
@@ -45,6 +45,7 @@ function createGithubPagesEnableAction(options) {
45
45
  }
46
46
  const octokitOptions = await util.getOctokitOptions({
47
47
  integrations,
48
+ requireScmUserCredentials,
48
49
  credentialsProvider: githubCredentialsProvider,
49
50
  token: providedToken,
50
51
  host,
@@ -1 +1 @@
1
- {"version":3,"file":"githubPagesEnable.cjs.js","sources":["../../src/actions/githubPagesEnable.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport {\n GithubCredentialsProvider,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\nimport { Octokit } from 'octokit';\nimport {\n createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { examples } from './githubPagesEnable.examples';\nimport { getOctokitOptions } from '../util';\n\n/**\n * Creates a new action that enables GitHub Pages for a repository.\n *\n * @public\n */\nexport function createGithubPagesEnableAction(options: {\n integrations: ScmIntegrationRegistry;\n githubCredentialsProvider?: GithubCredentialsProvider;\n}) {\n const { integrations, githubCredentialsProvider } = options;\n\n return createTemplateAction({\n id: 'github:pages:enable',\n examples,\n description: 'Enables GitHub Pages for a repository.',\n schema: {\n input: {\n repoUrl: z =>\n z.string({\n description:\n 'Accepts the format `github.com?repo=reponame&owner=owner` where `reponame` is the new repository name and `owner` is an organization or username',\n }),\n buildType: z =>\n z\n .enum(['legacy', 'workflow'], {\n description:\n 'The GitHub Pages build type - `legacy` or `workflow`. Default is `workflow`',\n })\n .default('workflow')\n .optional(),\n sourceBranch: z =>\n z\n .string({\n description: 'The GitHub Pages source branch. Default is \"main\"',\n })\n .default('main')\n .optional(),\n sourcePath: z =>\n z\n .enum(['/', '/docs'], {\n description:\n 'The GitHub Pages source path - \"/\" or \"/docs\". Default is \"/\"',\n })\n .default('/')\n .optional(),\n token: z =>\n z\n .string({\n description: 'The token to use for authorization to GitHub',\n })\n .optional(),\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n buildType = 'workflow',\n sourceBranch = 'main',\n sourcePath = '/',\n token: providedToken,\n } = ctx.input;\n\n const { host, owner, repo } = parseRepoUrl(repoUrl, integrations);\n\n if (!owner) {\n throw new InputError('Invalid repository owner provided in repoUrl');\n }\n\n const octokitOptions = await getOctokitOptions({\n integrations,\n credentialsProvider: githubCredentialsProvider,\n token: providedToken,\n host,\n owner,\n repo,\n });\n const client = new Octokit({\n ...octokitOptions,\n log: ctx.logger,\n });\n\n ctx.logger.info(\n `Attempting to enable GitHub Pages for ${owner}/${repo} with \"${buildType}\" build type, on source branch \"${sourceBranch}\" and source path \"${sourcePath}\"`,\n );\n\n await ctx.checkpoint({\n key: `enabled.github.pages.${owner}.${repo}`,\n fn: async () => {\n await client.request('POST /repos/{owner}/{repo}/pages', {\n owner: owner,\n repo: repo,\n build_type: buildType,\n source: {\n branch: sourceBranch,\n path: sourcePath,\n },\n headers: {\n 'X-GitHub-Api-Version': '2022-11-28',\n },\n });\n },\n });\n\n ctx.logger.info('Completed enabling GitHub Pages');\n },\n });\n}\n"],"names":["createTemplateAction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ACH;;;;"}
1
+ {"version":3,"file":"githubPagesEnable.cjs.js","sources":["../../src/actions/githubPagesEnable.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport {\n GithubCredentialsProvider,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\nimport { Octokit } from 'octokit';\nimport {\n createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { examples } from './githubPagesEnable.examples';\nimport { getOctokitOptions } from '../util';\n\n/**\n * Creates a new action that enables GitHub Pages for a repository.\n *\n * @public\n */\nexport function createGithubPagesEnableAction(options: {\n integrations: ScmIntegrationRegistry;\n githubCredentialsProvider?: GithubCredentialsProvider;\n requireScmUserCredentials?: boolean;\n}) {\n const { integrations, githubCredentialsProvider, requireScmUserCredentials } =\n options;\n\n return createTemplateAction({\n id: 'github:pages:enable',\n examples,\n description: 'Enables GitHub Pages for a repository.',\n schema: {\n input: {\n repoUrl: z =>\n z.string({\n description:\n 'Accepts the format `github.com?repo=reponame&owner=owner` where `reponame` is the new repository name and `owner` is an organization or username',\n }),\n buildType: z =>\n z\n .enum(['legacy', 'workflow'], {\n description:\n 'The GitHub Pages build type - `legacy` or `workflow`. Default is `workflow`',\n })\n .default('workflow')\n .optional(),\n sourceBranch: z =>\n z\n .string({\n description: 'The GitHub Pages source branch. Default is \"main\"',\n })\n .default('main')\n .optional(),\n sourcePath: z =>\n z\n .enum(['/', '/docs'], {\n description:\n 'The GitHub Pages source path - \"/\" or \"/docs\". Default is \"/\"',\n })\n .default('/')\n .optional(),\n token: z =>\n z\n .string({\n description: 'The token to use for authorization to GitHub',\n })\n .optional(),\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n buildType = 'workflow',\n sourceBranch = 'main',\n sourcePath = '/',\n token: providedToken,\n } = ctx.input;\n\n const { host, owner, repo } = parseRepoUrl(repoUrl, integrations);\n\n if (!owner) {\n throw new InputError('Invalid repository owner provided in repoUrl');\n }\n\n const octokitOptions = await getOctokitOptions({\n integrations,\n 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 ctx.logger.info(\n `Attempting to enable GitHub Pages for ${owner}/${repo} with \"${buildType}\" build type, on source branch \"${sourceBranch}\" and source path \"${sourcePath}\"`,\n );\n\n await ctx.checkpoint({\n key: `enabled.github.pages.${owner}.${repo}`,\n fn: async () => {\n await client.request('POST /repos/{owner}/{repo}/pages', {\n owner: owner,\n repo: repo,\n build_type: buildType,\n source: {\n branch: sourceBranch,\n path: sourcePath,\n },\n headers: {\n 'X-GitHub-Api-Version': '2022-11-28',\n },\n });\n },\n });\n\n ctx.logger.info('Completed enabling GitHub Pages');\n },\n });\n}\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","getOctokitOptions","Octokit"],"mappings":";;;;;;;;AAkCO,SAAS,8BAA8B,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,cACJC,mCAAA;AAAA,IACA,WAAA,EAAa,wCAAA;AAAA,IACb,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,WAAW,CAAA,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AAA,CAAQ;AAAA,QACzB,GAAG,cAAA;AAAA,QACH,KAAK,GAAA,CAAI;AAAA,OACV,CAAA;AAED,MAAA,GAAA,CAAI,MAAA,CAAO,IAAA;AAAA,QACT,CAAA,sCAAA,EAAyC,KAAK,CAAA,CAAA,EAAI,IAAI,UAAU,SAAS,CAAA,gCAAA,EAAmC,YAAY,CAAA,mBAAA,EAAsB,UAAU,CAAA,CAAA;AAAA,OAC1J;AAEA,MAAA,MAAM,IAAI,UAAA,CAAW;AAAA,QACnB,GAAA,EAAK,CAAA,qBAAA,EAAwB,KAAK,CAAA,CAAA,EAAI,IAAI,CAAA,CAAA;AAAA,QAC1C,IAAI,YAAY;AACd,UAAA,MAAM,MAAA,CAAO,QAAQ,kCAAA,EAAoC;AAAA,YACvD,KAAA;AAAA,YACA,IAAA;AAAA,YACA,UAAA,EAAY,SAAA;AAAA,YACZ,MAAA,EAAQ;AAAA,cACN,MAAA,EAAQ,YAAA;AAAA,cACR,IAAA,EAAM;AAAA,aACR;AAAA,YACA,OAAA,EAAS;AAAA,cACP,sBAAA,EAAwB;AAAA;AAC1B,WACD,CAAA;AAAA,QACH;AAAA,OACD,CAAA;AAED,MAAA,GAAA,CAAI,MAAA,CAAO,KAAK,iCAAiC,CAAA;AAAA,IACnD;AAAA,GACD,CAAA;AACH;;;;"}
@@ -42,7 +42,8 @@ const createPublishGithubPullRequestAction = (options) => {
42
42
  integrations,
43
43
  githubCredentialsProvider,
44
44
  clientFactory = defaultClientFactory,
45
- config
45
+ config,
46
+ requireScmUserCredentials
46
47
  } = options;
47
48
  return pluginScaffolderNode.createTemplateAction({
48
49
  id: "publish:github:pull-request",
@@ -152,6 +153,11 @@ const createPublishGithubPullRequestAction = (options) => {
152
153
  `No owner provided for host: ${host}, and repo ${repo}`
153
154
  );
154
155
  }
156
+ if (requireScmUserCredentials && !providedToken) {
157
+ throw new errors.InputError(
158
+ `No user credentials provided for host ${host}, but scaffolder.requireScmUserCredentials is enabled`
159
+ );
160
+ }
155
161
  const client = await clientFactory({
156
162
  integrations,
157
163
  githubCredentialsProvider,
@@ -1 +1 @@
1
- {"version":3,"file":"githubPullRequest.cjs.js","sources":["../../src/actions/githubPullRequest.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 path from 'node:path';\nimport {\n GithubCredentialsProvider,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\nimport {\n createTemplateAction,\n parseRepoUrl,\n SerializedFile,\n serializeDirectoryContents,\n} from '@backstage/plugin-scaffolder-node';\nimport { Octokit } from 'octokit';\nimport { CustomErrorBase, InputError } from '@backstage/errors';\nimport {\n createPullRequest,\n DELETE_FILE,\n} from 'octokit-plugin-create-pull-request';\nimport { getOctokitOptions } from '../util';\nimport { examples } from './githubPullRequest.examples';\nimport {\n LoggerService,\n resolveSafeChildPath,\n} from '@backstage/backend-plugin-api';\nimport { Config } from '@backstage/config';\nimport { JsonValue } from '@backstage/types';\n\nexport type Encoding = 'utf-8' | 'base64';\n\nclass GithubResponseError extends CustomErrorBase {}\n\nexport const defaultClientFactory: CreateGithubPullRequestActionOptions['clientFactory'] =\n async ({\n integrations,\n githubCredentialsProvider,\n owner,\n repo,\n host = 'github.com',\n token: providedToken,\n }) => {\n const octokitOptions = await getOctokitOptions({\n integrations,\n credentialsProvider: githubCredentialsProvider,\n host,\n owner,\n repo,\n token: providedToken,\n });\n\n const OctokitPR = Octokit.plugin(createPullRequest);\n return new OctokitPR({\n ...octokitOptions,\n ...{ throttle: { enabled: false } },\n });\n };\n\n/**\n * The options passed to {@link createPublishGithubPullRequestAction} method\n * @public\n */\nexport interface CreateGithubPullRequestActionOptions {\n /**\n * An instance of {@link @backstage/integration#ScmIntegrationRegistry} that will be used in the action.\n */\n integrations: ScmIntegrationRegistry;\n /**\n * An instance of {@link @backstage/integration#GithubCredentialsProvider} that will be used to get credentials for the action.\n */\n githubCredentialsProvider?: GithubCredentialsProvider;\n /**\n * A method to return the Octokit client with the Pull Request Plugin.\n */\n clientFactory?: (input: {\n integrations: ScmIntegrationRegistry;\n githubCredentialsProvider?: GithubCredentialsProvider;\n host: string;\n owner: string;\n repo: string;\n token?: string;\n }) => Promise<\n Octokit & {\n createPullRequest(options: createPullRequest.Options): Promise<{\n data: {\n html_url: string;\n number: number;\n base: {\n ref: string;\n };\n };\n } | null>;\n }\n >;\n /**\n * An instance of {@link @backstage/config#Config} that will be used in the action.\n */\n config?: Config;\n}\n\ntype GithubPullRequest = {\n owner: string;\n repo: string;\n number: number;\n};\n\n/**\n * Creates a Github Pull Request action.\n * @public\n */\nexport const createPublishGithubPullRequestAction = (\n options: CreateGithubPullRequestActionOptions,\n) => {\n const {\n integrations,\n githubCredentialsProvider,\n clientFactory = defaultClientFactory,\n config,\n } = options;\n\n return createTemplateAction({\n id: 'publish:github:pull-request',\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 branchName: z =>\n z.string({\n description: 'The name for the branch',\n }),\n filesToDelete: z =>\n z\n .array(z.string(), {\n description: 'List of files that will be deleted',\n })\n .optional(),\n targetBranchName: z =>\n z\n .string({\n description: 'The target branch name of the pull request',\n })\n .optional(),\n title: z =>\n z.string({\n description: 'The name for the pull request',\n }),\n description: z =>\n z.string({\n description: 'The description of the pull request',\n }),\n draft: z =>\n z\n .boolean({\n description: 'Create a draft pull request',\n })\n .optional(),\n sourcePath: z =>\n z\n .string({\n description:\n 'Subdirectory of working directory to copy changes from',\n })\n .optional(),\n targetPath: z =>\n z\n .string({\n description: 'Subdirectory of repository to apply changes to',\n })\n .optional(),\n token: z =>\n z\n .string({\n description: 'The token to use for authorization to GitHub',\n })\n .optional(),\n reviewers: z =>\n z\n .array(z.string(), {\n description:\n 'The users that will be added as reviewers to the pull request',\n })\n .optional(),\n assignees: z =>\n z\n .array(z.string(), {\n description:\n 'The users that will be added as assignees to the pull request',\n })\n .optional(),\n teamReviewers: z =>\n z\n .array(z.string(), {\n description:\n 'The teams that will be added as reviewers to the pull request',\n })\n .optional(),\n commitMessage: z =>\n z\n .string({\n description: 'The commit message for the pull request commit',\n })\n .optional(),\n update: z =>\n z\n .boolean({\n description: 'Update pull request if already exists',\n })\n .optional(),\n forceFork: z =>\n z\n .boolean({\n description: 'Create pull request from a fork',\n })\n .optional(),\n gitAuthorName: z =>\n z\n .string({\n description:\n 'Sets the default author name for the commit. The default value is the authenticated user or `Scaffolder`',\n })\n .optional(),\n gitAuthorEmail: z =>\n z\n .string({\n description:\n 'Sets the default author email for the commit. The default value is the authenticated user or `scaffolder@backstage.io`',\n })\n .optional(),\n forceEmptyGitAuthor: z =>\n z\n .boolean({\n description:\n 'Forces the author to be empty. This is useful when using a Github App, it permit the commit to be verified on Github',\n })\n .optional(),\n createWhenEmpty: z =>\n z\n .boolean({\n description:\n 'Set whether to create pull request when there are no changes to commit. The default value is true. If set to false, remoteUrl is no longer a required output.',\n })\n .optional(),\n },\n output: {\n targetBranchName: z =>\n z.string({\n description: 'Target branch name of the merge request',\n }),\n remoteUrl: z =>\n z.string({\n description: 'Link to the pull request in Github',\n }),\n pullRequestNumber: z =>\n z.number({\n description: 'The pull request number',\n }),\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n branchName,\n filesToDelete,\n targetBranchName,\n title,\n description,\n draft,\n targetPath,\n sourcePath,\n token: providedToken,\n reviewers,\n assignees,\n teamReviewers,\n commitMessage,\n update,\n forceFork,\n gitAuthorEmail,\n gitAuthorName,\n forceEmptyGitAuthor,\n createWhenEmpty,\n } = ctx.input;\n\n const { owner, repo, host } = parseRepoUrl(repoUrl, integrations);\n\n if (!owner) {\n throw new InputError(\n `No owner provided for host: ${host}, and repo ${repo}`,\n );\n }\n\n const client = await clientFactory({\n integrations,\n githubCredentialsProvider,\n host,\n owner,\n repo,\n token: providedToken,\n });\n\n const fileRoot = sourcePath\n ? resolveSafeChildPath(ctx.workspacePath, sourcePath)\n : ctx.workspacePath;\n\n const directoryContents = await serializeDirectoryContents(fileRoot, {\n gitignore: true,\n });\n\n const determineFileMode = (file: SerializedFile): string => {\n if (file.symlink) return '120000';\n if (file.executable) return '100755';\n return '100644';\n };\n\n const determineFileEncoding = (\n file: SerializedFile,\n ): 'utf-8' | 'base64' => (file.symlink ? 'utf-8' : 'base64');\n\n const files = Object.fromEntries([\n ...directoryContents.map(file => [\n targetPath ? path.posix.join(targetPath, file.path) : file.path,\n {\n // See the properties of tree items\n // in https://docs.github.com/en/rest/reference/git#trees\n mode: determineFileMode(file),\n // Always use base64 encoding where possible to avoid doubling a binary file in size\n // due to interpreting a binary file as utf-8 and sending github\n // the utf-8 encoded content. Symlinks are kept as utf-8 to avoid them\n // being formatted as a series of scrambled characters\n //\n // For example, the original gradle-wrapper.jar is 57.8k in https://github.com/kennethzfeng/pull-request-test/pull/5/files.\n // Its size could be doubled to 98.3K (See https://github.com/kennethzfeng/pull-request-test/pull/4/files)\n encoding: determineFileEncoding(file),\n content: file.content.toString(determineFileEncoding(file)),\n },\n ]),\n // order of arrays is important so filesToDelete will overwrite\n // changes from files above\n ...(filesToDelete || []).map(filePath => [\n targetPath ? path.posix.join(targetPath, filePath) : filePath,\n DELETE_FILE,\n ]),\n ]);\n\n // If this is a dry run, log and return\n if (ctx.isDryRun) {\n ctx.logger.info(`Performing dry run of creating pull request`);\n ctx.output('targetBranchName', branchName);\n ctx.output('remoteUrl', repoUrl);\n ctx.output('pullRequestNumber', 43);\n ctx.logger.info(`Dry run complete`);\n return;\n }\n\n try {\n const createOptions: createPullRequest.Options = {\n owner,\n repo,\n title,\n changes: [\n {\n files,\n commit:\n commitMessage ??\n config?.getOptionalString('scaffolder.defaultCommitMessage') ??\n title,\n },\n ],\n body: description,\n head: branchName,\n draft,\n update,\n forceFork,\n createWhenEmpty,\n };\n\n const gitAuthorInfo = {\n name:\n gitAuthorName ??\n config?.getOptionalString('scaffolder.defaultAuthor.name'),\n email:\n gitAuthorEmail ??\n config?.getOptionalString('scaffolder.defaultAuthor.email'),\n };\n\n if (!forceEmptyGitAuthor) {\n if (gitAuthorInfo.name || gitAuthorInfo.email) {\n if (Array.isArray(createOptions.changes)) {\n createOptions.changes = createOptions.changes.map(change => ({\n ...change,\n author: {\n name: gitAuthorInfo.name || 'Scaffolder',\n email: gitAuthorInfo.email || 'scaffolder@backstage.io',\n },\n }));\n } else {\n createOptions.changes = {\n ...createOptions.changes,\n author: {\n name: gitAuthorInfo.name || 'Scaffolder',\n email: gitAuthorInfo.email || 'scaffolder@backstage.io',\n },\n };\n }\n }\n }\n\n if (targetBranchName) {\n createOptions.base = targetBranchName;\n }\n\n const pr = await ctx.checkpoint({\n key: `create.pr.${owner}.${repo}.${branchName}`,\n fn: async () => {\n const response = await client.createPullRequest(createOptions);\n if (!response) {\n return null;\n }\n\n return {\n base: response?.data.base,\n html_url: response?.data.html_url,\n number: response?.data.number,\n };\n },\n });\n\n if (createWhenEmpty === false && !pr) {\n ctx.logger.info('No changes to commit, pull request was not created');\n return;\n }\n\n if (!pr) {\n throw new GithubResponseError('null response from Github');\n }\n\n const pullRequestNumber = pr.number;\n const pullRequest = { owner, repo, number: pullRequestNumber };\n if (reviewers || teamReviewers) {\n await requestReviewersOnPullRequest(\n pullRequest,\n reviewers,\n teamReviewers,\n client,\n ctx.logger,\n ctx.checkpoint,\n );\n }\n\n if (assignees) {\n if (assignees.length > 10) {\n ctx.logger.warn(\n 'Assignees list is too long, only the first 10 will be used.',\n );\n }\n await addAssigneesToPullRequest(\n pullRequest,\n assignees,\n client,\n ctx.logger,\n ctx.checkpoint,\n );\n }\n\n const targetBranch = pr.base.ref;\n ctx.output('targetBranchName', targetBranch);\n ctx.output('remoteUrl', pr.html_url);\n ctx.output('pullRequestNumber', pullRequestNumber);\n } catch (e) {\n throw new GithubResponseError('Pull request creation failed', e);\n }\n },\n });\n\n async function addAssigneesToPullRequest(\n pr: GithubPullRequest,\n assignees: string[],\n client: Octokit,\n logger: LoggerService,\n checkpoint: <T extends JsonValue | void>(opts: {\n key: string;\n fn: () => Promise<T> | T;\n }) => Promise<T>,\n ) {\n try {\n await checkpoint({\n key: `add.assignees.${pr.owner}.${pr.repo}.${pr.number}`,\n fn: async () => {\n const result = await client.rest.issues.addAssignees({\n owner: pr.owner,\n repo: pr.repo,\n issue_number: pr.number,\n assignees,\n });\n\n const addedAssignees = result.data.assignees?.join(', ') ?? '';\n\n logger.info(\n `Added assignees [${addedAssignees}] to Pull request ${pr.number}`,\n );\n },\n });\n } catch (e) {\n logger.error(\n `Failure when adding assignees to Pull request ${pr.number}`,\n e,\n );\n }\n }\n\n async function requestReviewersOnPullRequest(\n pr: GithubPullRequest,\n reviewers: string[] | undefined,\n teamReviewers: string[] | undefined,\n client: Octokit,\n logger: LoggerService,\n checkpoint: <T extends JsonValue | void>(opts: {\n key: string;\n fn: () => Promise<T> | T;\n }) => Promise<T>,\n ) {\n try {\n await checkpoint({\n key: `request.reviewers.${pr.owner}.${pr.repo}.${pr.number}`,\n fn: async () => {\n const result = await client.rest.pulls.requestReviewers({\n owner: pr.owner,\n repo: pr.repo,\n pull_number: pr.number,\n reviewers,\n team_reviewers: teamReviewers\n ? [...new Set(teamReviewers)]\n : undefined,\n });\n\n const addedUsers = result.data.requested_reviewers?.join(', ') ?? '';\n const addedTeams = result.data.requested_teams?.join(', ') ?? '';\n\n logger.info(\n `Added users [${addedUsers}] and teams [${addedTeams}] as reviewers to Pull request ${pr.number}`,\n );\n },\n });\n } catch (e) {\n logger.error(\n `Failure when adding reviewers to Pull request ${pr.number}`,\n e,\n );\n }\n }\n};\n"],"names":["CustomErrorBase","getOctokitOptions","Octokit","createPullRequest","createTemplateAction","examples","parseRepoUrl","InputError","resolveSafeChildPath","serializeDirectoryContents","path","DELETE_FILE"],"mappings":";;;;;;;;;;;;;;;AA4CA,MAAM,4BAA4BA,sBAAA,CAAgB;AAAC;AAE5C,MAAM,uBACX,OAAO;AAAA,EACL,YAAA;AAAA,EACA,yBAAA;AAAA,EACA,KAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA,GAAO,YAAA;AAAA,EACP,KAAA,EAAO;AACT,CAAA,KAAM;AACJ,EAAA,MAAM,cAAA,GAAiB,MAAMC,sBAAA,CAAkB;AAAA,IAC7C,YAAA;AAAA,IACA,mBAAA,EAAqB,yBAAA;AAAA,IACrB,IAAA;AAAA,IACA,KAAA;AAAA,IACA,IAAA;AAAA,IACA,KAAA,EAAO;AAAA,GACR,CAAA;AAED,EAAA,MAAM,SAAA,GAAYC,eAAA,CAAQ,MAAA,CAAOC,gDAAiB,CAAA;AAClD,EAAA,OAAO,IAAI,SAAA,CAAU;AAAA,IACnB,GAAG,cAAA;AAAA,IACH,GAAG,EAAE,QAAA,EAAU,EAAE,OAAA,EAAS,OAAM;AAAE,GACnC,CAAA;AACH;AAsDK,MAAM,oCAAA,GAAuC,CAClD,OAAA,KACG;AACH,EAAA,MAAM;AAAA,IACJ,YAAA;AAAA,IACA,yBAAA;AAAA,IACA,aAAA,GAAgB,oBAAA;AAAA,IAChB;AAAA,GACF,GAAI,OAAA;AAEJ,EAAA,OAAOC,yCAAA,CAAqB;AAAA,IAC1B,EAAA,EAAI,6BAAA;AAAA,cACJC,mCAAA;AAAA,IACA,cAAA,EAAgB,IAAA;AAAA,IAChB,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,MA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WACjG;AAAA,QACF;AAAA,OACD,CAAA;AAAA,IACH,SAAS,CAAA,EAAG;AACV,MAAA,MAAA,CAAO,KAAA;AAAA,QACL,CAAA,8CAAA,EAAiD,GAAG,MAAM,CAAA,CAAA;AAAA,QAC1D;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACF;;;;;"}
1
+ {"version":3,"file":"githubPullRequest.cjs.js","sources":["../../src/actions/githubPullRequest.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 path from 'node:path';\nimport {\n GithubCredentialsProvider,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\nimport {\n createTemplateAction,\n parseRepoUrl,\n SerializedFile,\n serializeDirectoryContents,\n} from '@backstage/plugin-scaffolder-node';\nimport { Octokit } from 'octokit';\nimport { CustomErrorBase, InputError } from '@backstage/errors';\nimport {\n createPullRequest,\n DELETE_FILE,\n} from 'octokit-plugin-create-pull-request';\nimport { getOctokitOptions } from '../util';\nimport { examples } from './githubPullRequest.examples';\nimport {\n LoggerService,\n resolveSafeChildPath,\n} from '@backstage/backend-plugin-api';\nimport { Config } from '@backstage/config';\nimport { JsonValue } from '@backstage/types';\n\nexport type Encoding = 'utf-8' | 'base64';\n\nclass GithubResponseError extends CustomErrorBase {}\n\nexport const defaultClientFactory: CreateGithubPullRequestActionOptions['clientFactory'] =\n async ({\n integrations,\n githubCredentialsProvider,\n owner,\n repo,\n host = 'github.com',\n token: providedToken,\n }) => {\n const octokitOptions = await getOctokitOptions({\n integrations,\n credentialsProvider: githubCredentialsProvider,\n host,\n owner,\n repo,\n token: providedToken,\n });\n\n const OctokitPR = Octokit.plugin(createPullRequest);\n return new OctokitPR({\n ...octokitOptions,\n ...{ throttle: { enabled: false } },\n });\n };\n\n/**\n * The options passed to {@link createPublishGithubPullRequestAction} method\n * @public\n */\nexport interface CreateGithubPullRequestActionOptions {\n /**\n * An instance of {@link @backstage/integration#ScmIntegrationRegistry} that will be used in the action.\n */\n integrations: ScmIntegrationRegistry;\n /**\n * An instance of {@link @backstage/integration#GithubCredentialsProvider} that will be used to get credentials for the action.\n */\n githubCredentialsProvider?: GithubCredentialsProvider;\n /**\n * Whether this action must use credentials provided through its input.\n */\n requireScmUserCredentials?: boolean;\n /**\n * A method to return the Octokit client with the Pull Request Plugin.\n */\n clientFactory?: (input: {\n integrations: ScmIntegrationRegistry;\n githubCredentialsProvider?: GithubCredentialsProvider;\n host: string;\n owner: string;\n repo: string;\n token?: string;\n }) => Promise<\n Octokit & {\n createPullRequest(options: createPullRequest.Options): Promise<{\n data: {\n html_url: string;\n number: number;\n base: {\n ref: string;\n };\n };\n } | null>;\n }\n >;\n /**\n * An instance of {@link @backstage/config#Config} that will be used in the action.\n */\n config?: Config;\n}\n\ntype GithubPullRequest = {\n owner: string;\n repo: string;\n number: number;\n};\n\n/**\n * Creates a Github Pull Request action.\n * @public\n */\nexport const createPublishGithubPullRequestAction = (\n options: CreateGithubPullRequestActionOptions,\n) => {\n const {\n integrations,\n githubCredentialsProvider,\n clientFactory = defaultClientFactory,\n config,\n requireScmUserCredentials,\n } = options;\n\n return createTemplateAction({\n id: 'publish:github:pull-request',\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 branchName: z =>\n z.string({\n description: 'The name for the branch',\n }),\n filesToDelete: z =>\n z\n .array(z.string(), {\n description: 'List of files that will be deleted',\n })\n .optional(),\n targetBranchName: z =>\n z\n .string({\n description: 'The target branch name of the pull request',\n })\n .optional(),\n title: z =>\n z.string({\n description: 'The name for the pull request',\n }),\n description: z =>\n z.string({\n description: 'The description of the pull request',\n }),\n draft: z =>\n z\n .boolean({\n description: 'Create a draft pull request',\n })\n .optional(),\n sourcePath: z =>\n z\n .string({\n description:\n 'Subdirectory of working directory to copy changes from',\n })\n .optional(),\n targetPath: z =>\n z\n .string({\n description: 'Subdirectory of repository to apply changes to',\n })\n .optional(),\n token: z =>\n z\n .string({\n description: 'The token to use for authorization to GitHub',\n })\n .optional(),\n reviewers: z =>\n z\n .array(z.string(), {\n description:\n 'The users that will be added as reviewers to the pull request',\n })\n .optional(),\n assignees: z =>\n z\n .array(z.string(), {\n description:\n 'The users that will be added as assignees to the pull request',\n })\n .optional(),\n teamReviewers: z =>\n z\n .array(z.string(), {\n description:\n 'The teams that will be added as reviewers to the pull request',\n })\n .optional(),\n commitMessage: z =>\n z\n .string({\n description: 'The commit message for the pull request commit',\n })\n .optional(),\n update: z =>\n z\n .boolean({\n description: 'Update pull request if already exists',\n })\n .optional(),\n forceFork: z =>\n z\n .boolean({\n description: 'Create pull request from a fork',\n })\n .optional(),\n gitAuthorName: z =>\n z\n .string({\n description:\n 'Sets the default author name for the commit. The default value is the authenticated user or `Scaffolder`',\n })\n .optional(),\n gitAuthorEmail: z =>\n z\n .string({\n description:\n 'Sets the default author email for the commit. The default value is the authenticated user or `scaffolder@backstage.io`',\n })\n .optional(),\n forceEmptyGitAuthor: z =>\n z\n .boolean({\n description:\n 'Forces the author to be empty. This is useful when using a Github App, it permit the commit to be verified on Github',\n })\n .optional(),\n createWhenEmpty: z =>\n z\n .boolean({\n description:\n 'Set whether to create pull request when there are no changes to commit. The default value is true. If set to false, remoteUrl is no longer a required output.',\n })\n .optional(),\n },\n output: {\n targetBranchName: z =>\n z.string({\n description: 'Target branch name of the merge request',\n }),\n remoteUrl: z =>\n z.string({\n description: 'Link to the pull request in Github',\n }),\n pullRequestNumber: z =>\n z.number({\n description: 'The pull request number',\n }),\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n branchName,\n filesToDelete,\n targetBranchName,\n title,\n description,\n draft,\n targetPath,\n sourcePath,\n token: providedToken,\n reviewers,\n assignees,\n teamReviewers,\n commitMessage,\n update,\n forceFork,\n gitAuthorEmail,\n gitAuthorName,\n forceEmptyGitAuthor,\n createWhenEmpty,\n } = ctx.input;\n\n const { owner, repo, host } = parseRepoUrl(repoUrl, integrations);\n\n if (!owner) {\n throw new InputError(\n `No owner provided for host: ${host}, and repo ${repo}`,\n );\n }\n\n if (requireScmUserCredentials && !providedToken) {\n throw new InputError(\n `No user credentials provided for host ${host}, but scaffolder.requireScmUserCredentials is enabled`,\n );\n }\n\n const client = await clientFactory({\n integrations,\n githubCredentialsProvider,\n host,\n owner,\n repo,\n token: providedToken,\n });\n\n const fileRoot = sourcePath\n ? resolveSafeChildPath(ctx.workspacePath, sourcePath)\n : ctx.workspacePath;\n\n const directoryContents = await serializeDirectoryContents(fileRoot, {\n gitignore: true,\n });\n\n const determineFileMode = (file: SerializedFile): string => {\n if (file.symlink) return '120000';\n if (file.executable) return '100755';\n return '100644';\n };\n\n const determineFileEncoding = (\n file: SerializedFile,\n ): 'utf-8' | 'base64' => (file.symlink ? 'utf-8' : 'base64');\n\n const files = Object.fromEntries([\n ...directoryContents.map(file => [\n targetPath ? path.posix.join(targetPath, file.path) : file.path,\n {\n // See the properties of tree items\n // in https://docs.github.com/en/rest/reference/git#trees\n mode: determineFileMode(file),\n // Always use base64 encoding where possible to avoid doubling a binary file in size\n // due to interpreting a binary file as utf-8 and sending github\n // the utf-8 encoded content. Symlinks are kept as utf-8 to avoid them\n // being formatted as a series of scrambled characters\n //\n // For example, the original gradle-wrapper.jar is 57.8k in https://github.com/kennethzfeng/pull-request-test/pull/5/files.\n // Its size could be doubled to 98.3K (See https://github.com/kennethzfeng/pull-request-test/pull/4/files)\n encoding: determineFileEncoding(file),\n content: file.content.toString(determineFileEncoding(file)),\n },\n ]),\n // order of arrays is important so filesToDelete will overwrite\n // changes from files above\n ...(filesToDelete || []).map(filePath => [\n targetPath ? path.posix.join(targetPath, filePath) : filePath,\n DELETE_FILE,\n ]),\n ]);\n\n // If this is a dry run, log and return\n if (ctx.isDryRun) {\n ctx.logger.info(`Performing dry run of creating pull request`);\n ctx.output('targetBranchName', branchName);\n ctx.output('remoteUrl', repoUrl);\n ctx.output('pullRequestNumber', 43);\n ctx.logger.info(`Dry run complete`);\n return;\n }\n\n try {\n const createOptions: createPullRequest.Options = {\n owner,\n repo,\n title,\n changes: [\n {\n files,\n commit:\n commitMessage ??\n config?.getOptionalString('scaffolder.defaultCommitMessage') ??\n title,\n },\n ],\n body: description,\n head: branchName,\n draft,\n update,\n forceFork,\n createWhenEmpty,\n };\n\n const gitAuthorInfo = {\n name:\n gitAuthorName ??\n config?.getOptionalString('scaffolder.defaultAuthor.name'),\n email:\n gitAuthorEmail ??\n config?.getOptionalString('scaffolder.defaultAuthor.email'),\n };\n\n if (!forceEmptyGitAuthor) {\n if (gitAuthorInfo.name || gitAuthorInfo.email) {\n if (Array.isArray(createOptions.changes)) {\n createOptions.changes = createOptions.changes.map(change => ({\n ...change,\n author: {\n name: gitAuthorInfo.name || 'Scaffolder',\n email: gitAuthorInfo.email || 'scaffolder@backstage.io',\n },\n }));\n } else {\n createOptions.changes = {\n ...createOptions.changes,\n author: {\n name: gitAuthorInfo.name || 'Scaffolder',\n email: gitAuthorInfo.email || 'scaffolder@backstage.io',\n },\n };\n }\n }\n }\n\n if (targetBranchName) {\n createOptions.base = targetBranchName;\n }\n\n const pr = await ctx.checkpoint({\n key: `create.pr.${owner}.${repo}.${branchName}`,\n fn: async () => {\n const response = await client.createPullRequest(createOptions);\n if (!response) {\n return null;\n }\n\n return {\n base: response?.data.base,\n html_url: response?.data.html_url,\n number: response?.data.number,\n };\n },\n });\n\n if (createWhenEmpty === false && !pr) {\n ctx.logger.info('No changes to commit, pull request was not created');\n return;\n }\n\n if (!pr) {\n throw new GithubResponseError('null response from Github');\n }\n\n const pullRequestNumber = pr.number;\n const pullRequest = { owner, repo, number: pullRequestNumber };\n if (reviewers || teamReviewers) {\n await requestReviewersOnPullRequest(\n pullRequest,\n reviewers,\n teamReviewers,\n client,\n ctx.logger,\n ctx.checkpoint,\n );\n }\n\n if (assignees) {\n if (assignees.length > 10) {\n ctx.logger.warn(\n 'Assignees list is too long, only the first 10 will be used.',\n );\n }\n await addAssigneesToPullRequest(\n pullRequest,\n assignees,\n client,\n ctx.logger,\n ctx.checkpoint,\n );\n }\n\n const targetBranch = pr.base.ref;\n ctx.output('targetBranchName', targetBranch);\n ctx.output('remoteUrl', pr.html_url);\n ctx.output('pullRequestNumber', pullRequestNumber);\n } catch (e) {\n throw new GithubResponseError('Pull request creation failed', e);\n }\n },\n });\n\n async function addAssigneesToPullRequest(\n pr: GithubPullRequest,\n assignees: string[],\n client: Octokit,\n logger: LoggerService,\n checkpoint: <T extends JsonValue | void>(opts: {\n key: string;\n fn: () => Promise<T> | T;\n }) => Promise<T>,\n ) {\n try {\n await checkpoint({\n key: `add.assignees.${pr.owner}.${pr.repo}.${pr.number}`,\n fn: async () => {\n const result = await client.rest.issues.addAssignees({\n owner: pr.owner,\n repo: pr.repo,\n issue_number: pr.number,\n assignees,\n });\n\n const addedAssignees = result.data.assignees?.join(', ') ?? '';\n\n logger.info(\n `Added assignees [${addedAssignees}] to Pull request ${pr.number}`,\n );\n },\n });\n } catch (e) {\n logger.error(\n `Failure when adding assignees to Pull request ${pr.number}`,\n e,\n );\n }\n }\n\n async function requestReviewersOnPullRequest(\n pr: GithubPullRequest,\n reviewers: string[] | undefined,\n teamReviewers: string[] | undefined,\n client: Octokit,\n logger: LoggerService,\n checkpoint: <T extends JsonValue | void>(opts: {\n key: string;\n fn: () => Promise<T> | T;\n }) => Promise<T>,\n ) {\n try {\n await checkpoint({\n key: `request.reviewers.${pr.owner}.${pr.repo}.${pr.number}`,\n fn: async () => {\n const result = await client.rest.pulls.requestReviewers({\n owner: pr.owner,\n repo: pr.repo,\n pull_number: pr.number,\n reviewers,\n team_reviewers: teamReviewers\n ? [...new Set(teamReviewers)]\n : undefined,\n });\n\n const addedUsers = result.data.requested_reviewers?.join(', ') ?? '';\n const addedTeams = result.data.requested_teams?.join(', ') ?? '';\n\n logger.info(\n `Added users [${addedUsers}] and teams [${addedTeams}] as reviewers to Pull request ${pr.number}`,\n );\n },\n });\n } catch (e) {\n logger.error(\n `Failure when adding reviewers to Pull request ${pr.number}`,\n e,\n );\n }\n }\n};\n"],"names":["CustomErrorBase","getOctokitOptions","Octokit","createPullRequest","createTemplateAction","examples","parseRepoUrl","InputError","resolveSafeChildPath","serializeDirectoryContents","path","DELETE_FILE"],"mappings":";;;;;;;;;;;;;;;AA4CA,MAAM,4BAA4BA,sBAAA,CAAgB;AAAC;AAE5C,MAAM,uBACX,OAAO;AAAA,EACL,YAAA;AAAA,EACA,yBAAA;AAAA,EACA,KAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA,GAAO,YAAA;AAAA,EACP,KAAA,EAAO;AACT,CAAA,KAAM;AACJ,EAAA,MAAM,cAAA,GAAiB,MAAMC,sBAAA,CAAkB;AAAA,IAC7C,YAAA;AAAA,IACA,mBAAA,EAAqB,yBAAA;AAAA,IACrB,IAAA;AAAA,IACA,KAAA;AAAA,IACA,IAAA;AAAA,IACA,KAAA,EAAO;AAAA,GACR,CAAA;AAED,EAAA,MAAM,SAAA,GAAYC,eAAA,CAAQ,MAAA,CAAOC,gDAAiB,CAAA;AAClD,EAAA,OAAO,IAAI,SAAA,CAAU;AAAA,IACnB,GAAG,cAAA;AAAA,IACH,GAAG,EAAE,QAAA,EAAU,EAAE,OAAA,EAAS,OAAM;AAAE,GACnC,CAAA;AACH;AA0DK,MAAM,oCAAA,GAAuC,CAClD,OAAA,KACG;AACH,EAAA,MAAM;AAAA,IACJ,YAAA;AAAA,IACA,yBAAA;AAAA,IACA,aAAA,GAAgB,oBAAA;AAAA,IAChB,MAAA;AAAA,IACA;AAAA,GACF,GAAI,OAAA;AA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AAA,CAAG,MAAA;AAAA,YAChB,SAAA;AAAA,YACA,cAAA,EAAgB,gBACZ,CAAC,GAAG,IAAI,GAAA,CAAI,aAAa,CAAC,CAAA,GAC1B,KAAA;AAAA,WACL,CAAA;AAED,UAAA,MAAM,aAAa,MAAA,CAAO,IAAA,CAAK,mBAAA,EAAqB,IAAA,CAAK,IAAI,CAAA,IAAK,EAAA;AAClE,UAAA,MAAM,aAAa,MAAA,CAAO,IAAA,CAAK,eAAA,EAAiB,IAAA,CAAK,IAAI,CAAA,IAAK,EAAA;AAE9D,UAAA,MAAA,CAAO,IAAA;AAAA,YACL,gBAAgB,UAAU,CAAA,aAAA,EAAgB,UAAU,CAAA,+BAAA,EAAkC,GAAG,MAAM,CAAA;AAAA,WACjG;AAAA,QACF;AAAA,OACD,CAAA;AAAA,IACH,SAAS,CAAA,EAAG;AACV,MAAA,MAAA,CAAO,KAAA;AAAA,QACL,CAAA,8CAAA,EAAiD,GAAG,MAAM,CAAA,CAAA;AAAA,QAC1D;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACF;;;;;"}
@@ -10,7 +10,7 @@ var outputProperties = require('./outputProperties.cjs.js');
10
10
  var githubRepoCreate_examples = require('./githubRepoCreate.examples.cjs.js');
11
11
 
12
12
  function createGithubRepoCreateAction(options) {
13
- const { integrations, githubCredentialsProvider } = options;
13
+ const { integrations, githubCredentialsProvider, requireScmUserCredentials } = options;
14
14
  return pluginScaffolderNode.createTemplateAction({
15
15
  id: "github:repo:create",
16
16
  description: "Creates a GitHub repository.",
@@ -59,6 +59,7 @@ function createGithubRepoCreateAction(options) {
59
59
  }
60
60
  const octokitOptions = await util.getOctokitOptions({
61
61
  integrations,
62
+ requireScmUserCredentials,
62
63
  credentialsProvider: githubCredentialsProvider,
63
64
  token: providedToken,
64
65
  host,
@@ -1 +1 @@
1
- {"version":3,"file":"githubRepoCreate.cjs.js","sources":["../../src/actions/githubRepoCreate.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 ScmIntegrationRegistry,\n} from '@backstage/integration';\nimport { Octokit } from 'octokit';\nimport {\n createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { createGithubRepoWithCollaboratorsAndTopics } from './helpers';\nimport { getOctokitOptions } from '../util';\nimport * as inputProps from './inputProperties';\nimport * as outputProps from './outputProperties';\nimport { examples } from './githubRepoCreate.examples';\n\n/**\n * Creates a new action that initializes a git repository\n *\n * @public\n */\nexport function createGithubRepoCreateAction(options: {\n integrations: ScmIntegrationRegistry;\n githubCredentialsProvider?: GithubCredentialsProvider;\n}) {\n const { integrations, githubCredentialsProvider } = options;\n\n return createTemplateAction({\n id: 'github:repo:create',\n description: 'Creates a GitHub repository.',\n examples,\n schema: {\n input: {\n ...inputProps,\n },\n output: {\n remoteUrl: outputProps.remoteUrl,\n repoContentsUrl: outputProps.repoContentsUrl,\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n description,\n homepage,\n access,\n repoVisibility = 'private',\n deleteBranchOnMerge = false,\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 customProperties,\n subscribe,\n token: providedToken,\n autoInit = undefined,\n workflowAccess,\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 = await ctx.checkpoint({\n key: `create.repo.and.topics.${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 autoInit,\n workflowAccess,\n );\n return newRepo.clone_url;\n },\n });\n\n ctx.output('remoteUrl', remoteUrl);\n },\n });\n}\n"],"names":["createTemplateAction","examples","inputProps","outputProps.remoteUrl","outputProps.repoContentsUrl","parseRepoUrl","InputError","getOctokitOptions","Octokit","createGithubRepoWithCollaboratorsAndTopics"],"mappings":";;;;;;;;;;;AAqCO,SAAS,6BAA6B,OAAA,EAG1C;AACD,EAAA,MAAM,EAAE,YAAA,EAAc,yBAAA,EAA0B,GAAI,OAAA;AAEpD,EAAA,OAAOA,yCAAA,CAAqB;AAAA,IAC1B,EAAA,EAAI,oBAAA;AAAA,IACJ,WAAA,EAAa,8BAAA;AAAA,cACbC,kCAAA;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,KAAA,EAAO;AAAA,QACL,GAAGC;AAAA,OACL;AAAA,MACA,MAAA,EAAQ;AAAA,QACN,WAAWC,0BAAY;AAAA,QACvB,iBAAiBC;AAAY;AAC/B,KACF;AAAA,IACA,MAAM,QAAQ,G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,GAAA,CAAI,UAAA,CAAW;AAAA,QACrC,GAAA,EAAK,CAAA,uBAAA,EAA0B,KAAK,CAAA,CAAA,EAAI,IAAI,CAAA,CAAA;AAAA,QAC5C,IAAI,YAAY;AACd,UAAA,MAAM,UAAU,MAAMC,kDAAA;AAAA,YACpB,MAAA;AAAA,YACA,IAAA;AAAA,YACA,KAAA;AAAA,YACA,cAAA;AAAA,YACA,WAAA;AAAA,YACA,QAAA;AAAA,YACA,mBAAA;AAAA,YACA,gBAAA;AAAA,YACA,gBAAA;AAAA,YACA,sBAAA;AAAA,YACA,wBAAA;AAAA,YACA,gBAAA;AAAA,YACA,cAAA;AAAA,YACA,iBAAA;AAAA,YACA,MAAA;AAAA,YACA,aAAA;AAAA,YACA,WAAA;AAAA,YACA,OAAA;AAAA,YACA,SAAA;AAAA,YACA,MAAA;AAAA,YACA,aAAA;AAAA,YACA,OAAA;AAAA,YACA,iBAAA;AAAA,YACA,gBAAA;AAAA,YACA,SAAA;AAAA,YACA,GAAA,CAAI,MAAA;AAAA,YACJ,QAAA;AAAA,YACA;AAAA,WACF;AACA,UAAA,OAAO,OAAA,CAAQ,SAAA;AAAA,QACjB;AAAA,OACD,CAAA;AAED,MAAA,GAAA,CAAI,MAAA,CAAO,aAAa,SAAS,CAAA;AAAA,IACnC;AAAA,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"githubRepoCreate.cjs.js","sources":["../../src/actions/githubRepoCreate.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 ScmIntegrationRegistry,\n} from '@backstage/integration';\nimport { Octokit } from 'octokit';\nimport {\n createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { createGithubRepoWithCollaboratorsAndTopics } from './helpers';\nimport { getOctokitOptions } from '../util';\nimport * as inputProps from './inputProperties';\nimport * as outputProps from './outputProperties';\nimport { examples } from './githubRepoCreate.examples';\n\n/**\n * Creates a new action that initializes a git repository\n *\n * @public\n */\nexport function createGithubRepoCreateAction(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:repo:create',\n description: 'Creates a GitHub repository.',\n examples,\n schema: {\n input: {\n ...inputProps,\n },\n output: {\n remoteUrl: outputProps.remoteUrl,\n repoContentsUrl: outputProps.repoContentsUrl,\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n description,\n homepage,\n access,\n repoVisibility = 'private',\n deleteBranchOnMerge = false,\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 customProperties,\n subscribe,\n token: providedToken,\n autoInit = undefined,\n workflowAccess,\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 = await ctx.checkpoint({\n key: `create.repo.and.topics.${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 autoInit,\n workflowAccess,\n );\n return newRepo.clone_url;\n },\n });\n\n ctx.output('remoteUrl', remoteUrl);\n },\n });\n}\n"],"names":["createTemplateAction","examples","inputProps","outputProps.remoteUrl","outputProps.repoContentsUrl","parseRepoUrl","InputError","getOctokitOptions","Octokit","createGithubRepoWithCollaboratorsAndTopics"],"mappings":";;;;;;;;;;;AAqCO,SAAS,6BAA6B,OAAA,EAI1C;AACD,EAAA,MAAM,EAAE,YAAA,EAAc,yBAAA,EAA2B,yBAAA,EAA0B,GACzE,OAAA;AAEF,EAAA,OAAOA,yCAAA,CAAqB;AAAA,IAC1B,EAAA,EAAI,oBAAA;AAAA,IACJ,WAAA,EAAa,8BAAA;AAAA,cACbC,kCAAA;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,KAAA,EAAO;AAAA,QACL,GAAGC;AAAA,OACL;AAAA,MACA,MAAA,EAAQ;AAAA,QACN,WAAWC,0BAAY;AAAA,QACvB,iBAAiBC;AAAY;AAC/B,KACF;AAAA,IACA,MAAM,QAAQ,GAAA,EAAK;AACjB,MAAA,MAAM;AAAA,QACJ,OAAA;AAAA,QACA,WAAA;AAAA,QACA,QAAA;AAAA,QACA,MAAA;AAAA,QACA,cAAA,GAAiB,SAAA;AAAA,QACjB,mBAAA,GAAsB,KAAA;AAAA,QACtB,gBAAA,GAAmB,IAAA;AAAA,QACnB,gBAAA,GAAmB,IAAA;AAA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AAA,YACA,KAAA;AAAA,YACA,cAAA;AAAA,YACA,WAAA;AAAA,YACA,QAAA;AAAA,YACA,mBAAA;AAAA,YACA,gBAAA;AAAA,YACA,gBAAA;AAAA,YACA,sBAAA;AAAA,YACA,wBAAA;AAAA,YACA,gBAAA;AAAA,YACA,cAAA;AAAA,YACA,iBAAA;AAAA,YACA,MAAA;AAAA,YACA,aAAA;AAAA,YACA,WAAA;AAAA,YACA,OAAA;AAAA,YACA,SAAA;AAAA,YACA,MAAA;AAAA,YACA,aAAA;AAAA,YACA,OAAA;AAAA,YACA,iBAAA;AAAA,YACA,gBAAA;AAAA,YACA,SAAA;AAAA,YACA,GAAA,CAAI,MAAA;AAAA,YACJ,QAAA;AAAA,YACA;AAAA,WACF;AACA,UAAA,OAAO,OAAA,CAAQ,SAAA;AAAA,QACjB;AAAA,OACD,CAAA;AAED,MAAA,GAAA,CAAI,MAAA,CAAO,aAAa,SAAS,CAAA;AAAA,IACnC;AAAA,GACD,CAAA;AACH;;;;"}
@@ -10,7 +10,12 @@ var outputProperties = require('./outputProperties.cjs.js');
10
10
  var githubRepoPush_examples = require('./githubRepoPush.examples.cjs.js');
11
11
 
12
12
  function createGithubRepoPushAction(options) {
13
- const { integrations, config, githubCredentialsProvider } = options;
13
+ const {
14
+ integrations,
15
+ config,
16
+ githubCredentialsProvider,
17
+ requireScmUserCredentials
18
+ } = options;
14
19
  return pluginScaffolderNode.createTemplateAction({
15
20
  id: "github:repo:push",
16
21
  description: "Initializes a git repository of contents in workspace and publishes it to GitHub.",
@@ -72,6 +77,7 @@ function createGithubRepoPushAction(options) {
72
77
  }
73
78
  const octokitOptions = await util.getOctokitOptions({
74
79
  integrations,
80
+ requireScmUserCredentials,
75
81
  credentialsProvider: githubCredentialsProvider,
76
82
  token: providedToken,
77
83
  host,
@@ -1 +1 @@
1
- {"version":3,"file":"githubRepoPush.cjs.js","sources":["../../src/actions/githubRepoPush.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 { initRepoPushAndProtect } from './helpers';\nimport { getOctokitOptions } from '../util';\nimport * as inputProps from './inputProperties';\nimport * as outputProps from './outputProperties';\nimport { examples } from './githubRepoPush.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 createGithubRepoPushAction(options: {\n integrations: ScmIntegrationRegistry;\n config: Config;\n githubCredentialsProvider?: GithubCredentialsProvider;\n}) {\n const { integrations, config, githubCredentialsProvider } = options;\n\n return createTemplateAction({\n id: 'github:repo:push',\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 requireCodeOwnerReviews: inputProps.requireCodeOwnerReviews,\n dismissStaleReviews: inputProps.dismissStaleReviews,\n requiredStatusCheckContexts: inputProps.requiredStatusCheckContexts,\n bypassPullRequestAllowances: inputProps.bypassPullRequestAllowances,\n requiredApprovingReviewCount: inputProps.requiredApprovingReviewCount,\n restrictions: inputProps.restrictions,\n requireBranchesToBeUpToDate: inputProps.requireBranchesToBeUpToDate,\n requiredConversationResolution:\n inputProps.requiredConversationResolution,\n requireLastPushApproval: inputProps.requireLastPushApproval,\n defaultBranch: inputProps.defaultBranch,\n protectDefaultBranch: inputProps.protectDefaultBranch,\n protectEnforceAdmins: inputProps.protectEnforceAdmins,\n gitCommitMessage: inputProps.gitCommitMessage,\n gitAuthorName: inputProps.gitAuthorName,\n gitAuthorEmail: inputProps.gitAuthorEmail,\n sourcePath: inputProps.sourcePath,\n token: inputProps.token,\n requiredCommitSigning: inputProps.requiredCommitSigning,\n requiredLinearHistory: inputProps.requiredLinearHistory,\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 defaultBranch = 'main',\n protectDefaultBranch = true,\n protectEnforceAdmins = true,\n gitCommitMessage = 'initial commit',\n gitAuthorName,\n gitAuthorEmail,\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 token: providedToken,\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\n const client = new Octokit({\n ...octokitOptions,\n log: ctx.logger,\n });\n\n const targetRepo = await client.rest.repos.get({ owner, repo });\n\n const remoteUrl = targetRepo.data.clone_url;\n const repoContentsUrl = `${targetRepo.data.html_url}/blob/${defaultBranch}`;\n\n const commitHash = await ctx.checkpoint({\n key: `init.repo.publish.${owner}.${client}.${repo}`,\n fn: async () => {\n const { commitHash: hash } = 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 return hash;\n },\n });\n\n ctx.output('remoteUrl', remoteUrl);\n ctx.output('repoContentsUrl', repoContentsUrl);\n ctx.output('commitHash', commitHash);\n },\n });\n}\n"],"names":["createTemplateAction","examples","inputProps.repoUrl","inputProps.requireCodeOwnerReviews","inputProps.dismissStaleReviews","inputProps.requiredStatusCheckContexts","inputProps.bypassPullRequestAllowances","inputProps.requiredApprovingReviewCount","inputProps.restrictions","inputProps.requireBranchesToBeUpToDate","inputProps.requiredConversationResolution","inputProps.requireLastPushApproval","inputProps.defaultBranch","inputProps.protectDefaultBranch","inputProps.protectEnforceAdmins","inputProps.gitCommitMessage","inputProps.gitAuthorName","inputProps.gitAuthorEmail","inputProps.sourcePath","inputProps.token","inputProps.requiredCommitSigning","inputProps.requiredLinearHistory","outputProps.remoteUrl","outputProps.repoContentsUrl","outputProps.commitHash","parseRepoUrl","InputError","getOctokitOptions","Octokit","initRepoPushAndProtect"],"mappings":";;;;;;;;;;;AAuCO,SAAS,2BAA2B,OAAA,EAIxC;AACD,EAAA,MAAM,EAAE,YAAA,EAAc,MAAA,EAAQ,yBAAA,EAA0B,GAAI,OAAA;AAE5D,EAAA,OAAOA,yCAAA,CAAqB;AAAA,IAC1B,EAAA,EAAI,kBAAA;AAAA,IACJ,WAAA,EACE,mFAAA;AAAA,cACFC,gCAAA;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,KAAA,EAAO;AAAA,QACL,SAASC,uBAAW;AAAA,QACpB,yBAAyBC,uCAAW;AAAA,QACpC,qBAAqBC,mCAAW;AAAA,QAChC,6BAA6BC,2CAAW;AAAA,QACxC,6BAA6BC,2CAAW;AA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BAAA;AAAA,YACA,2BAAA;AAAA,YACA,8BAAA;AAAA,YACA,uBAAA;AAAA,YACA,MAAA;AAAA,YACA,GAAA,CAAI,MAAA;AAAA,YACJ,gBAAA;AAAA,YACA,aAAA;AAAA,YACA,cAAA;AAAA,YACA,mBAAA;AAAA,YACA,qBAAA;AAAA,YACA;AAAA,WACF;AACA,UAAA,OAAO,IAAA;AAAA,QACT;AAAA,OACD,CAAA;AAED,MAAA,GAAA,CAAI,MAAA,CAAO,aAAa,SAAS,CAAA;AACjC,MAAA,GAAA,CAAI,MAAA,CAAO,mBAAmB,eAAe,CAAA;AAC7C,MAAA,GAAA,CAAI,MAAA,CAAO,cAAc,UAAU,CAAA;AAAA,IACrC;AAAA,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"githubRepoPush.cjs.js","sources":["../../src/actions/githubRepoPush.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 { initRepoPushAndProtect } from './helpers';\nimport { getOctokitOptions } from '../util';\nimport * as inputProps from './inputProperties';\nimport * as outputProps from './outputProperties';\nimport { examples } from './githubRepoPush.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 createGithubRepoPushAction(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: 'github:repo:push',\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 requireCodeOwnerReviews: inputProps.requireCodeOwnerReviews,\n dismissStaleReviews: inputProps.dismissStaleReviews,\n requiredStatusCheckContexts: inputProps.requiredStatusCheckContexts,\n bypassPullRequestAllowances: inputProps.bypassPullRequestAllowances,\n requiredApprovingReviewCount: inputProps.requiredApprovingReviewCount,\n restrictions: inputProps.restrictions,\n requireBranchesToBeUpToDate: inputProps.requireBranchesToBeUpToDate,\n requiredConversationResolution:\n inputProps.requiredConversationResolution,\n requireLastPushApproval: inputProps.requireLastPushApproval,\n defaultBranch: inputProps.defaultBranch,\n protectDefaultBranch: inputProps.protectDefaultBranch,\n protectEnforceAdmins: inputProps.protectEnforceAdmins,\n gitCommitMessage: inputProps.gitCommitMessage,\n gitAuthorName: inputProps.gitAuthorName,\n gitAuthorEmail: inputProps.gitAuthorEmail,\n sourcePath: inputProps.sourcePath,\n token: inputProps.token,\n requiredCommitSigning: inputProps.requiredCommitSigning,\n requiredLinearHistory: inputProps.requiredLinearHistory,\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 defaultBranch = 'main',\n protectDefaultBranch = true,\n protectEnforceAdmins = true,\n gitCommitMessage = 'initial commit',\n gitAuthorName,\n gitAuthorEmail,\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 token: providedToken,\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\n const client = new Octokit({\n ...octokitOptions,\n log: ctx.logger,\n });\n\n const targetRepo = await client.rest.repos.get({ owner, repo });\n\n const remoteUrl = targetRepo.data.clone_url;\n const repoContentsUrl = `${targetRepo.data.html_url}/blob/${defaultBranch}`;\n\n const commitHash = await ctx.checkpoint({\n key: `init.repo.publish.${owner}.${client}.${repo}`,\n fn: async () => {\n const { commitHash: hash } = 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 return hash;\n },\n });\n\n ctx.output('remoteUrl', remoteUrl);\n ctx.output('repoContentsUrl', repoContentsUrl);\n ctx.output('commitHash', commitHash);\n },\n });\n}\n"],"names":["createTemplateAction","examples","inputProps.repoUrl","inputProps.requireCodeOwnerReviews","inputProps.dismissStaleReviews","inputProps.requiredStatusCheckContexts","inputProps.bypassPullRequestAllowances","inputProps.requiredApprovingReviewCount","inputProps.restrictions","inputProps.requireBranchesToBeUpToDate","inputProps.requiredConversationResolution","inputProps.requireLastPushApproval","inputProps.defaultBranch","inputProps.protectDefaultBranch","inputProps.protectEnforceAdmins","inputProps.gitCommitMessage","inputProps.gitAuthorName","inputProps.gitAuthorEmail","inputProps.sourcePath","inputProps.token","inputProps.requiredCommitSigning","inputProps.requiredLinearHistory","outputProps.remoteUrl","outputProps.repoContentsUrl","outputProps.commitHash","parseRepoUrl","InputError","getOctokitOptions","Octokit","initRepoPushAndProtect"],"mappings":";;;;;;;;;;;AAuCO,SAAS,2BAA2B,OAAA,EAKxC;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,kBAAA;AAAA,IACJ,WAAA,EACE,mFAAA;AAAA,cACFC,gCAAA;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,KAAA,EAAO;AAAA,QACL,SAASC,uBAAW;AAAA,QACpB,yBAAyBC,uCAAW;AAAA,QACpC,qBAAqBC,mCAAW;AAAA,QAChC,6BAA6BC,2CAAW;AAAA,QACxC,6BAA6BC,2CAAW;AAAA,QACxC,8BAA8BC,4CAAW;AAAA,QACzC,cAAcC,4BAAW;AAAA,QACzB,6BAA6BC,2CAAW;AAAA,QACxC,gCACEC,8CAAW;AAAA,QACb,yBAAyBC,uCAAW;AAAA,QACpC,eAAeC,6BAAW;AAAA,QAC1B,sBAAsBC,oCAAW;AAAA,QACjC,sBAAsBC,oCAAW;AAAA,QACjC,kBAAkBC,gCAAW;AAAA,QAC7B,eAAeC,6BAAW;AAAA,QAC1B,gBAAgBC,8BAAW;AAAA,QAC3B,YAAYC,0BAAW;AAAA,QACvB,OAAOC,qBAAW;AAAA,QAClB,uBAAuBC,qCAAW;AAAA,QAClC,uBAAuBC;AAAW,OACpC;AAAA,MACA,MAAA,EAAQ;AAAA,QACN,WAAWC,0BAAY;AAAA,QACvB,iBAAiBC,gCAAY;AAAA,QAC7B,YAAYC;AAAY;AAC1B,KACF;AAAA,IACA,MAAM,QAAQ,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s.js');
9
9
 
10
10
  function createGithubWebhookAction(options) {
11
- const { integrations, defaultWebhookSecret, githubCredentialsProvider } = options;
11
+ const {
12
+ integrations,
13
+ defaultWebhookSecret,
14
+ githubCredentialsProvider,
15
+ requireScmUserCredentials
16
+ } = options;
12
17
  const eventNames = webhooks.emitterEventNames.filter((event) => !event.includes("."));
13
18
  return pluginScaffolderNode.createTemplateAction({
14
19
  id: "github:webhook",
@@ -66,6 +71,7 @@ function createGithubWebhookAction(options) {
66
71
  }
67
72
  const octokitOptions = await util.getOctokitOptions({
68
73
  integrations,
74
+ requireScmUserCredentials,
69
75
  credentialsProvider: githubCredentialsProvider,
70
76
  host,
71
77
  owner,
@@ -1 +1 @@
1
- {"version":3,"file":"githubWebhook.cjs.js","sources":["../../src/actions/githubWebhook.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 { emitterEventNames } from '@octokit/webhooks';\nimport { InputError, toError } from '@backstage/errors';\nimport { Octokit } from 'octokit';\nimport { getOctokitOptions } from '../util';\nimport { examples } from './githubWebhook.examples';\n\n/**\n * Creates new action that creates a webhook for a repository on GitHub.\n * @public\n */\nexport function createGithubWebhookAction(options: {\n integrations: ScmIntegrationRegistry;\n defaultWebhookSecret?: string;\n githubCredentialsProvider?: GithubCredentialsProvider;\n}) {\n const { integrations, defaultWebhookSecret, githubCredentialsProvider } =\n options;\n\n const eventNames = emitterEventNames.filter(event => !event.includes('.'));\n\n return createTemplateAction({\n id: 'github:webhook',\n description: 'Creates webhook for a repository 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 new repository name and `owner` is an organization or username',\n }),\n webhookUrl: z =>\n z.string({\n description: 'The URL to which the payloads will be delivered',\n }),\n webhookSecret: z =>\n z\n .string({\n description:\n 'Webhook secret value. The default can be provided internally in action creation',\n })\n .optional(),\n events: z =>\n z\n .union([\n z.array(z.enum(eventNames as [string, ...string[]]), {\n description:\n 'Determines what events the hook is triggered for. Default: `[push]`',\n }),\n z.array(z.literal('*'), {\n description:\n 'Determines what events the hook is triggered for. Use \"*\" for all events. Default: `[push]`',\n }),\n ])\n .default(['push'])\n .optional(),\n active: z =>\n z\n .boolean({\n description:\n 'Determines if notifications are sent when the webhook is triggered. Default: `true`',\n })\n .default(true)\n .optional(),\n contentType: z =>\n z\n .enum(['form', 'json'], {\n description:\n 'The media type used to serialize the payloads. The default is `form`',\n })\n .default('form')\n .optional(),\n insecureSsl: z =>\n z\n .boolean({\n description:\n 'Determines whether the SSL certificate of the host for url will be verified when delivering payloads. Default `false`',\n })\n .default(false)\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 },\n async handler(ctx) {\n const {\n repoUrl,\n webhookUrl,\n webhookSecret = defaultWebhookSecret,\n events = ['push'],\n active = true,\n contentType = 'form',\n insecureSsl = false,\n token: providedToken,\n } = ctx.input;\n\n ctx.logger.info(`Creating webhook ${webhookUrl} for repo ${repoUrl}`);\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 host,\n owner,\n repo,\n token: providedToken,\n });\n const client = new Octokit({\n ...octokitOptions,\n log: ctx.logger,\n });\n\n // If this is a dry run, log and return\n if (ctx.isDryRun) {\n ctx.logger.info(`Dry run complete`);\n return;\n }\n\n try {\n const insecure_ssl = insecureSsl ? '1' : '0';\n\n await ctx.checkpoint({\n key: `create.webhhook.${owner}.${repo}.${webhookUrl}`,\n fn: async () => {\n await client.rest.repos.createWebhook({\n owner,\n repo,\n config: {\n url: webhookUrl,\n content_type: contentType,\n secret: webhookSecret,\n insecure_ssl,\n },\n events,\n active,\n });\n },\n });\n\n ctx.logger.info(`Webhook '${webhookUrl}' created successfully`);\n } catch (e) {\n ctx.logger.warn(\n `Failed: create webhook '${webhookUrl}' on repo: '${repo}', ${\n toError(e).message\n }`,\n );\n }\n },\n });\n}\n"],"names":["emitterEventNames","createTemplateAction","examples","parseRepoUrl","InputError","getOctokitOptions","Octokit","toError"],"mappings":";;;;;;;;;AAkCO,SAAS,0BAA0B,OAAA,EAIvC;AACD,EAAA,MAAM,EAAE,YAAA,EAAc,oBAAA,EAAsB,yBAAA,EAA0B,GACpE,OAAA;AAEF,EAAA,MAAM,UAAA,GAAaA,2BAAkB,MAAA,CAAO,CAAA,KAAA,KAAS,CAAC,KAAA,CAAM,QAAA,CAAS,GAAG,CAAC,CAAA;AAEzE,EAAA,OAAOC,yCAAA,CAAqB;AAAA,IAC1B,EAAA,EAAI,gBAAA;AAAA,IACJ,WAAA,EAAa,6CAAA;AAAA,cACbC,+BAAA;AAAA,IACA,cAAA,EAAgB,IAAA;AAAA,IAChB,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,aAAA,EAAe,CAAA,CAAA,KACb,CAAA,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AA,gBACd,MAAA,EAAQ,aAAA;AAAA,gBACR;AAAA,eACF;AAAA,cACA,MAAA;AAAA,cACA;AAAA,aACD,CAAA;AAAA,UACH;AAAA,SACD,CAAA;AAED,QAAA,GAAA,CAAI,MAAA,CAAO,IAAA,CAAK,CAAA,SAAA,EAAY,UAAU,CAAA,sBAAA,CAAwB,CAAA;AAAA,MAChE,SAAS,CAAA,EAAG;AACV,QAAA,GAAA,CAAI,MAAA,CAAO,IAAA;AAAA,UACT,CAAA,wBAAA,EAA2B,UAAU,CAAA,YAAA,EAAe,IAAI,MACtDC,cAAA,CAAQ,CAAC,EAAE,OACb,CAAA;AAAA,SACF;AAAA,MACF;AAAA,IACF;AAAA,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"githubWebhook.cjs.js","sources":["../../src/actions/githubWebhook.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 { emitterEventNames } from '@octokit/webhooks';\nimport { InputError, toError } from '@backstage/errors';\nimport { Octokit } from 'octokit';\nimport { getOctokitOptions } from '../util';\nimport { examples } from './githubWebhook.examples';\n\n/**\n * Creates new action that creates a webhook for a repository on GitHub.\n * @public\n */\nexport function createGithubWebhookAction(options: {\n integrations: ScmIntegrationRegistry;\n defaultWebhookSecret?: string;\n githubCredentialsProvider?: GithubCredentialsProvider;\n requireScmUserCredentials?: boolean;\n}) {\n const {\n integrations,\n defaultWebhookSecret,\n githubCredentialsProvider,\n requireScmUserCredentials,\n } = options;\n\n const eventNames = emitterEventNames.filter(event => !event.includes('.'));\n\n return createTemplateAction({\n id: 'github:webhook',\n description: 'Creates webhook for a repository 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 new repository name and `owner` is an organization or username',\n }),\n webhookUrl: z =>\n z.string({\n description: 'The URL to which the payloads will be delivered',\n }),\n webhookSecret: z =>\n z\n .string({\n description:\n 'Webhook secret value. The default can be provided internally in action creation',\n })\n .optional(),\n events: z =>\n z\n .union([\n z.array(z.enum(eventNames as [string, ...string[]]), {\n description:\n 'Determines what events the hook is triggered for. Default: `[push]`',\n }),\n z.array(z.literal('*'), {\n description:\n 'Determines what events the hook is triggered for. Use \"*\" for all events. Default: `[push]`',\n }),\n ])\n .default(['push'])\n .optional(),\n active: z =>\n z\n .boolean({\n description:\n 'Determines if notifications are sent when the webhook is triggered. Default: `true`',\n })\n .default(true)\n .optional(),\n contentType: z =>\n z\n .enum(['form', 'json'], {\n description:\n 'The media type used to serialize the payloads. The default is `form`',\n })\n .default('form')\n .optional(),\n insecureSsl: z =>\n z\n .boolean({\n description:\n 'Determines whether the SSL certificate of the host for url will be verified when delivering payloads. Default `false`',\n })\n .default(false)\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 },\n async handler(ctx) {\n const {\n repoUrl,\n webhookUrl,\n webhookSecret = defaultWebhookSecret,\n events = ['push'],\n active = true,\n contentType = 'form',\n insecureSsl = false,\n token: providedToken,\n } = ctx.input;\n\n ctx.logger.info(`Creating webhook ${webhookUrl} for repo ${repoUrl}`);\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 host,\n owner,\n repo,\n token: providedToken,\n });\n const client = new Octokit({\n ...octokitOptions,\n log: ctx.logger,\n });\n\n // If this is a dry run, log and return\n if (ctx.isDryRun) {\n ctx.logger.info(`Dry run complete`);\n return;\n }\n\n try {\n const insecure_ssl = insecureSsl ? '1' : '0';\n\n await ctx.checkpoint({\n key: `create.webhhook.${owner}.${repo}.${webhookUrl}`,\n fn: async () => {\n await client.rest.repos.createWebhook({\n owner,\n repo,\n config: {\n url: webhookUrl,\n content_type: contentType,\n secret: webhookSecret,\n insecure_ssl,\n },\n events,\n active,\n });\n },\n });\n\n ctx.logger.info(`Webhook '${webhookUrl}' created successfully`);\n } catch (e) {\n ctx.logger.warn(\n `Failed: create webhook '${webhookUrl}' on repo: '${repo}', ${\n toError(e).message\n }`,\n );\n }\n },\n });\n}\n"],"names":["emitterEventNames","createTemplateAction","examples","parseRepoUrl","InputError","getOctokitOptions","Octokit","toError"],"mappings":";;;;;;;;;AAkCO,SAAS,0BAA0B,OAAA,EAKvC;AACD,EAAA,MAAM;AAAA,IACJ,YAAA;AAAA,IACA,oBAAA;AAAA,IACA,yBAAA;AAAA,IACA;AAAA,GACF,GAAI,OAAA;AAEJ,EAAA,MAAM,UAAA,GAAaA,2BAAkB,MAAA,CAAO,CAAA,KAAA,KAAS,CAAC,KAAA,CAAM,QAAA,CAAS,GAAG,CAAC,CAAA;AAEzE,EAAA,OAAOC,yCAAA,CAAqB;AAAA,IAC1B,EAAA,EAAI,gBAAA;AAAA,IACJ,WAAA,EAAa,6CAAA;AAAA,cACbC,+BAAA;AAAA,IACA,cAAA,EAAgB,IAAA;AAAA,IAChB,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,K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AA,CAAc;AAAA,cACpC,KAAA;AAAA,cACA,IAAA;AAAA,cACA,MAAA,EAAQ;AAAA,gBACN,GAAA,EAAK,UAAA;AAAA,gBACL,YAAA,EAAc,WAAA;AAAA,gBACd,MAAA,EAAQ,aAAA;AAAA,gBACR;AAAA,eACF;AAAA,cACA,MAAA;AAAA,cACA;AAAA,aACD,CAAA;AAAA,UACH;AAAA,SACD,CAAA;AAED,QAAA,GAAA,CAAI,MAAA,CAAO,IAAA,CAAK,CAAA,SAAA,EAAY,UAAU,CAAA,sBAAA,CAAwB,CAAA;AAAA,MAChE,SAAS,CAAA,EAAG;AACV,QAAA,GAAA,CAAI,MAAA,CAAO,IAAA;AAAA,UACT,CAAA,wBAAA,EAA2B,UAAU,CAAA,YAAA,EAAe,IAAI,MACtDC,cAAA,CAAQ,CAAC,EAAE,OACb,CAAA;AAAA,SACF;AAAA,MACF;AAAA,IACF;AAAA,GACD,CAAA;AACH;;;;"}
package/dist/index.d.ts CHANGED
@@ -15,6 +15,7 @@ import { OctokitOptions } from '@octokit/core/dist-types/types';
15
15
  declare function createGithubActionsDispatchAction(options: {
16
16
  integrations: ScmIntegrations;
17
17
  githubCredentialsProvider?: GithubCredentialsProvider;
18
+ requireScmUserCredentials?: boolean;
18
19
  }): _backstage_plugin_scaffolder_node.TemplateAction<{
19
20
  repoUrl: string;
20
21
  workflowId: string;
@@ -35,6 +36,7 @@ declare function createGithubActionsDispatchAction(options: {
35
36
  declare function createGithubIssuesLabelAction(options: {
36
37
  integrations: ScmIntegrationRegistry;
37
38
  githubCredentialsProvider?: GithubCredentialsProvider;
39
+ requireScmUserCredentials?: boolean;
38
40
  }): _backstage_plugin_scaffolder_node.TemplateAction<{
39
41
  repoUrl: string;
40
42
  number: number;
@@ -51,6 +53,7 @@ declare function createGithubIssuesLabelAction(options: {
51
53
  declare function createGithubIssuesCreateAction(options: {
52
54
  integrations: ScmIntegrationRegistry;
53
55
  githubCredentialsProvider?: GithubCredentialsProvider;
56
+ requireScmUserCredentials?: boolean;
54
57
  }): _backstage_plugin_scaffolder_node.TemplateAction<{
55
58
  repoUrl: string;
56
59
  title: string;
@@ -72,6 +75,7 @@ declare function createGithubIssuesCreateAction(options: {
72
75
  declare function createGithubRepoCreateAction(options: {
73
76
  integrations: ScmIntegrationRegistry;
74
77
  githubCredentialsProvider?: GithubCredentialsProvider;
78
+ requireScmUserCredentials?: boolean;
75
79
  }): _backstage_plugin_scaffolder_node.TemplateAction<{
76
80
  repoUrl: string;
77
81
  access?: string | undefined;
@@ -151,6 +155,7 @@ declare function createGithubRepoPushAction(options: {
151
155
  integrations: ScmIntegrationRegistry;
152
156
  config: Config;
153
157
  githubCredentialsProvider?: GithubCredentialsProvider;
158
+ requireScmUserCredentials?: boolean;
154
159
  }): _backstage_plugin_scaffolder_node.TemplateAction<{
155
160
  repoUrl: string;
156
161
  requireCodeOwnerReviews?: boolean | undefined;
@@ -194,6 +199,7 @@ declare function createGithubWebhookAction(options: {
194
199
  integrations: ScmIntegrationRegistry;
195
200
  defaultWebhookSecret?: string;
196
201
  githubCredentialsProvider?: GithubCredentialsProvider;
202
+ requireScmUserCredentials?: boolean;
197
203
  }): _backstage_plugin_scaffolder_node.TemplateAction<{
198
204
  repoUrl: string;
199
205
  webhookUrl: string;
@@ -214,6 +220,7 @@ declare function createGithubWebhookAction(options: {
214
220
  */
215
221
  declare function createGithubDeployKeyAction(options: {
216
222
  integrations: ScmIntegrationRegistry;
223
+ requireScmUserCredentials?: boolean;
217
224
  }): _backstage_plugin_scaffolder_node.TemplateAction<{
218
225
  repoUrl: string;
219
226
  publicKey: string;
@@ -233,6 +240,7 @@ declare function createGithubDeployKeyAction(options: {
233
240
  declare function createGithubEnvironmentAction(options: {
234
241
  integrations: ScmIntegrationRegistry;
235
242
  catalog: CatalogService;
243
+ requireScmUserCredentials?: boolean;
236
244
  }): _backstage_plugin_scaffolder_node.TemplateAction<{
237
245
  repoUrl: string;
238
246
  name: string;
@@ -265,6 +273,10 @@ interface CreateGithubPullRequestActionOptions {
265
273
  * An instance of {@link @backstage/integration#GithubCredentialsProvider} that will be used to get credentials for the action.
266
274
  */
267
275
  githubCredentialsProvider?: GithubCredentialsProvider;
276
+ /**
277
+ * Whether this action must use credentials provided through its input.
278
+ */
279
+ requireScmUserCredentials?: boolean;
268
280
  /**
269
281
  * A method to return the Octokit client with the Pull Request Plugin.
270
282
  */
@@ -332,6 +344,7 @@ declare function createPublishGithubAction(options: {
332
344
  integrations: ScmIntegrationRegistry;
333
345
  config: Config;
334
346
  githubCredentialsProvider?: GithubCredentialsProvider;
347
+ requireScmUserCredentials?: boolean;
335
348
  }): _backstage_plugin_scaffolder_node.TemplateAction<{
336
349
  repoUrl: string;
337
350
  description?: string | undefined;
@@ -405,6 +418,7 @@ declare function createPublishGithubAction(options: {
405
418
  declare function createGithubAutolinksAction(options: {
406
419
  integrations: ScmIntegrations;
407
420
  githubCredentialsProvider?: GithubCredentialsProvider;
421
+ requireScmUserCredentials?: boolean;
408
422
  }): _backstage_plugin_scaffolder_node.TemplateAction<{
409
423
  repoUrl: string;
410
424
  keyPrefix: string;
@@ -423,6 +437,7 @@ declare function createGithubAutolinksAction(options: {
423
437
  declare function createGithubPagesEnableAction(options: {
424
438
  integrations: ScmIntegrationRegistry;
425
439
  githubCredentialsProvider?: GithubCredentialsProvider;
440
+ requireScmUserCredentials?: boolean;
426
441
  }): _backstage_plugin_scaffolder_node.TemplateAction<{
427
442
  repoUrl: string;
428
443
  buildType?: "legacy" | "workflow" | undefined;
@@ -440,6 +455,7 @@ declare function createGithubPagesEnableAction(options: {
440
455
  */
441
456
  declare function createGithubBranchProtectionAction(options: {
442
457
  integrations: ScmIntegrationRegistry;
458
+ requireScmUserCredentials?: boolean;
443
459
  }): _backstage_plugin_scaffolder_node.TemplateAction<{
444
460
  repoUrl: string;
445
461
  branch?: string | undefined;
@@ -511,6 +527,7 @@ declare function getOctokitClient(octokitOptions: OctokitOptions, logger: Logger
511
527
  declare function getOctokitOptions(options: {
512
528
  integrations: ScmIntegrationRegistry;
513
529
  credentialsProvider?: GithubCredentialsProvider;
530
+ requireScmUserCredentials?: boolean;
514
531
  token?: string;
515
532
  host: string;
516
533
  owner?: string;
@@ -525,6 +542,7 @@ declare function getOctokitOptions(options: {
525
542
  declare function getOctokitOptions(options: {
526
543
  integrations: ScmIntegrationRegistry;
527
544
  credentialsProvider?: GithubCredentialsProvider;
545
+ requireScmUserCredentials?: boolean;
528
546
  token?: string;
529
547
  repoUrl: string;
530
548
  }): Promise<OctokitOptions>;
@@ -33,56 +33,73 @@ const githubModule = backendPluginApi.createBackendModule({
33
33
  },
34
34
  async init({ scaffolder, config, autocomplete: autocomplete$1, catalog }) {
35
35
  const integrations = integration.ScmIntegrations.fromConfig(config);
36
+ const requireScmUserCredentials = config.getOptionalBoolean("scaffolder.requireScmUserCredentials") ?? false;
36
37
  const githubCredentialsProvider = integration.DefaultGithubCredentialsProvider.fromIntegrations(integrations);
37
38
  scaffolder.addActions(
38
39
  githubActionsDispatch.createGithubActionsDispatchAction({
39
40
  integrations,
40
- githubCredentialsProvider
41
+ githubCredentialsProvider,
42
+ requireScmUserCredentials
41
43
  }),
42
44
  githubAutolinks.createGithubAutolinksAction({
43
45
  integrations,
44
- githubCredentialsProvider
46
+ githubCredentialsProvider,
47
+ requireScmUserCredentials
45
48
  }),
46
49
  githubDeployKey.createGithubDeployKeyAction({
47
- integrations
50
+ integrations,
51
+ requireScmUserCredentials
48
52
  }),
49
53
  githubEnvironment.createGithubEnvironmentAction({
50
54
  integrations,
51
- catalog
55
+ catalog,
56
+ requireScmUserCredentials
52
57
  }),
53
58
  githubIssuesLabel.createGithubIssuesLabelAction({
54
59
  integrations,
55
- githubCredentialsProvider
60
+ githubCredentialsProvider,
61
+ requireScmUserCredentials
56
62
  }),
57
63
  githubIssuesCreate.createGithubIssuesCreateAction({
58
64
  integrations,
59
- githubCredentialsProvider
65
+ githubCredentialsProvider,
66
+ requireScmUserCredentials
60
67
  }),
61
68
  githubRepoCreate.createGithubRepoCreateAction({
62
69
  integrations,
63
- githubCredentialsProvider
70
+ githubCredentialsProvider,
71
+ requireScmUserCredentials
72
+ }),
73
+ githubRepoPush.createGithubRepoPushAction({
74
+ integrations,
75
+ config,
76
+ requireScmUserCredentials
64
77
  }),
65
- githubRepoPush.createGithubRepoPushAction({ integrations, config }),
66
78
  githubWebhook.createGithubWebhookAction({
67
79
  integrations,
68
- githubCredentialsProvider
80
+ githubCredentialsProvider,
81
+ requireScmUserCredentials
69
82
  }),
70
83
  github.createPublishGithubAction({
71
84
  integrations,
72
85
  config,
73
- githubCredentialsProvider
86
+ githubCredentialsProvider,
87
+ requireScmUserCredentials
74
88
  }),
75
89
  githubPullRequest.createPublishGithubPullRequestAction({
76
90
  integrations,
77
91
  githubCredentialsProvider,
78
- config
92
+ config,
93
+ requireScmUserCredentials
79
94
  }),
80
95
  githubPagesEnable.createGithubPagesEnableAction({
81
96
  integrations,
82
- githubCredentialsProvider
97
+ githubCredentialsProvider,
98
+ requireScmUserCredentials
83
99
  }),
84
100
  githubBranchProtection.createGithubBranchProtectionAction({
85
- integrations
101
+ integrations,
102
+ requireScmUserCredentials
86
103
  })
87
104
  );
88
105
  autocomplete$1.addAutocompleteProvider({