@backstage/plugin-scaffolder-backend-module-github 0.5.6-next.0 → 0.6.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/actions/github.cjs.js +9 -6
  3. package/dist/actions/github.cjs.js.map +1 -1
  4. package/dist/actions/githubActionsDispatch.cjs.js +6 -4
  5. package/dist/actions/githubActionsDispatch.cjs.js.map +1 -1
  6. package/dist/actions/githubAutolinks.cjs.js +6 -4
  7. package/dist/actions/githubAutolinks.cjs.js.map +1 -1
  8. package/dist/actions/githubBranchProtection.cjs.js +9 -7
  9. package/dist/actions/githubBranchProtection.cjs.js.map +1 -1
  10. package/dist/actions/githubDeployKey.cjs.js +9 -7
  11. package/dist/actions/githubDeployKey.cjs.js.map +1 -1
  12. package/dist/actions/githubEnvironment.cjs.js +9 -7
  13. package/dist/actions/githubEnvironment.cjs.js.map +1 -1
  14. package/dist/actions/githubIssuesLabel.cjs.js +6 -4
  15. package/dist/actions/githubIssuesLabel.cjs.js.map +1 -1
  16. package/dist/actions/githubPagesEnable.cjs.js +9 -7
  17. package/dist/actions/githubPagesEnable.cjs.js.map +1 -1
  18. package/dist/actions/githubPullRequest.cjs.js +19 -9
  19. package/dist/actions/githubPullRequest.cjs.js.map +1 -1
  20. package/dist/actions/githubPullRequest.examples.cjs.js +33 -14
  21. package/dist/actions/githubPullRequest.examples.cjs.js.map +1 -1
  22. package/dist/actions/githubRepoCreate.cjs.js +9 -6
  23. package/dist/actions/githubRepoCreate.cjs.js.map +1 -1
  24. package/dist/actions/githubRepoPush.cjs.js +6 -3
  25. package/dist/actions/githubRepoPush.cjs.js.map +1 -1
  26. package/dist/actions/githubWebhook.cjs.js +6 -4
  27. package/dist/actions/githubWebhook.cjs.js.map +1 -1
  28. package/dist/actions/helpers.cjs.js +0 -42
  29. package/dist/actions/helpers.cjs.js.map +1 -1
  30. package/dist/autocomplete/autocomplete.cjs.js +47 -0
  31. package/dist/autocomplete/autocomplete.cjs.js.map +1 -0
  32. package/dist/index.cjs.js +2 -2
  33. package/dist/index.d.ts +20 -5
  34. package/dist/module.cjs.js +8 -5
  35. package/dist/module.cjs.js.map +1 -1
  36. package/dist/util.cjs.js +51 -0
  37. package/dist/util.cjs.js.map +1 -0
  38. package/package.json +10 -7
@@ -4,6 +4,7 @@ var errors = require('@backstage/errors');
4
4
  var octokit = require('octokit');
5
5
  var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
6
6
  var helpers = require('./helpers.cjs.js');
7
+ var util = require('../util.cjs.js');
7
8
  var inputProperties = require('./inputProperties.cjs.js');
8
9
  var outputProperties = require('./outputProperties.cjs.js');
9
10
  var githubRepoPush_examples = require('./githubRepoPush.examples.cjs.js');
@@ -72,15 +73,17 @@ function createGithubRepoPushAction(options) {
72
73
  requiredCommitSigning = false,
73
74
  requiredLinearHistory = false
74
75
  } = ctx.input;
75
- const { owner, repo } = pluginScaffolderNode.parseRepoUrl(repoUrl, integrations);
76
+ const { host, owner, repo } = pluginScaffolderNode.parseRepoUrl(repoUrl, integrations);
76
77
  if (!owner) {
77
78
  throw new errors.InputError("Invalid repository owner provided in repoUrl");
78
79
  }
79
- const octokitOptions = await helpers.getOctokitOptions({
80
+ const octokitOptions = await util.getOctokitOptions({
80
81
  integrations,
81
82
  credentialsProvider: githubCredentialsProvider,
82
83
  token: providedToken,
83
- repoUrl
84
+ host,
85
+ owner,
86
+ repo
84
87
  });
85
88
  const client = new octokit.Octokit(octokitOptions);
86
89
  const targetRepo = await client.rest.repos.get({ owner, repo });
@@ -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 { getOctokitOptions, initRepoPushAndProtect } from './helpers';\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 repoUrl: string;\n description?: string;\n defaultBranch?: string;\n protectDefaultBranch?: boolean;\n protectEnforceAdmins?: boolean;\n gitCommitMessage?: string;\n gitAuthorName?: string;\n gitAuthorEmail?: string;\n requireCodeOwnerReviews?: boolean;\n dismissStaleReviews?: boolean;\n bypassPullRequestAllowances?:\n | {\n users?: string[];\n teams?: string[];\n apps?: string[];\n }\n | undefined;\n requiredApprovingReviewCount?: number;\n restrictions?:\n | {\n users: string[];\n teams: string[];\n apps?: string[];\n }\n | undefined;\n requiredStatusCheckContexts?: string[];\n requireBranchesToBeUpToDate?: boolean;\n requiredConversationResolution?: boolean;\n sourcePath?: string;\n token?: string;\n requiredCommitSigning?: boolean;\n requiredLinearHistory?: boolean;\n requireLastPushApproval?: boolean;\n }>({\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 type: 'object',\n required: ['repoUrl'],\n properties: {\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 },\n output: {\n type: 'object',\n properties: {\n remoteUrl: outputProps.remoteUrl,\n repoContentsUrl: outputProps.repoContentsUrl,\n commitHash: outputProps.commitHash,\n },\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n defaultBranch = 'master',\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 { 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 repoUrl,\n });\n\n const client = new Octokit(octokitOptions);\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 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('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":";;;;;;;;;;AAsCO,SAAS,2BAA2B,OAIxC,EAAA;AACD,EAAA,MAAM,EAAE,YAAA,EAAc,MAAQ,EAAA,yBAAA,EAA8B,GAAA,OAAA;AAE5D,EAAA,OAAO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AA;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,GAAI,CAAA,MAAA;AAAA,QACJ,gBAAA;AAAA,QACA,aAAA;AAAA,QACA,cAAA;AAAA,QACA,mBAAA;AAAA,QACA,qBAAA;AAAA,QACA;AAAA,OACF;AAEA,MAAI,GAAA,CAAA,MAAA,CAAO,aAAa,SAAS,CAAA;AACjC,MAAI,GAAA,CAAA,MAAA,CAAO,mBAAmB,eAAe,CAAA;AAC7C,MAAI,GAAA,CAAA,MAAA,CAAO,cAAc,UAAU,CAAA;AAAA;AACrC,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}) {\n const { integrations, config, githubCredentialsProvider } = options;\n\n return createTemplateAction<{\n repoUrl: string;\n description?: string;\n defaultBranch?: string;\n protectDefaultBranch?: boolean;\n protectEnforceAdmins?: boolean;\n gitCommitMessage?: string;\n gitAuthorName?: string;\n gitAuthorEmail?: string;\n requireCodeOwnerReviews?: boolean;\n dismissStaleReviews?: boolean;\n bypassPullRequestAllowances?:\n | {\n users?: string[];\n teams?: string[];\n apps?: string[];\n }\n | undefined;\n requiredApprovingReviewCount?: number;\n restrictions?:\n | {\n users: string[];\n teams: string[];\n apps?: string[];\n }\n | undefined;\n requiredStatusCheckContexts?: string[];\n requireBranchesToBeUpToDate?: boolean;\n requiredConversationResolution?: boolean;\n sourcePath?: string;\n token?: string;\n requiredCommitSigning?: boolean;\n requiredLinearHistory?: boolean;\n requireLastPushApproval?: boolean;\n }>({\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 type: 'object',\n required: ['repoUrl'],\n properties: {\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 },\n output: {\n type: 'object',\n properties: {\n remoteUrl: outputProps.remoteUrl,\n repoContentsUrl: outputProps.repoContentsUrl,\n commitHash: outputProps.commitHash,\n },\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n defaultBranch = 'master',\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(octokitOptions);\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 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('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,OAIxC,EAAA;AACD,EAAA,MAAM,EAAE,YAAA,EAAc,MAAQ,EAAA,yBAAA,EAA8B,GAAA,OAAA;AAE5D,EAAA,OAAOA,yCAkCJ,CAAA;AAAA,IACD,EAAI,EAAA,kBAAA;AAAA,IACJ,WACE,EAAA,mFAAA;AAAA,cACFC,gCAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,IAAM,EAAA,QAAA;AAAA,QACN,QAAA,EAAU,CAAC,SAAS,CAAA;AAAA,QACpB,UAAY,EAAA;AAAA,UACV,SAASC,uBAAW;AAAA,UACpB,yBAAyBC,uCAAW;AAAA,UACpC,qBAAqBC,mCAAW;AAAA,UAChC,6BAA6BC,2CAAW;AAAA,UACxC,6BAA6BC,2CAAW;AAAA,UACxC,8BAA8BC,4CAAW;AAAA,UACzC,c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AI,GAAA,CAAA,MAAA,CAAO,aAAa,SAAS,CAAA;AACjC,MAAI,GAAA,CAAA,MAAA,CAAO,mBAAmB,eAAe,CAAA;AAC7C,MAAI,GAAA,CAAA,MAAA,CAAO,cAAc,UAAU,CAAA;AAAA;AACrC,GACD,CAAA;AACH;;;;"}
@@ -4,7 +4,7 @@ var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
4
4
  var webhooks = require('@octokit/webhooks');
5
5
  var errors = require('@backstage/errors');
6
6
  var octokit = require('octokit');
7
- var helpers = require('./helpers.cjs.js');
7
+ var util = require('../util.cjs.js');
8
8
  var githubWebhook_examples = require('./githubWebhook.examples.cjs.js');
9
9
 
10
10
  function createGithubWebhookAction(options) {
@@ -90,15 +90,17 @@ function createGithubWebhookAction(options) {
90
90
  token: providedToken
91
91
  } = ctx.input;
92
92
  ctx.logger.info(`Creating webhook ${webhookUrl} for repo ${repoUrl}`);
93
- const { owner, repo } = pluginScaffolderNode.parseRepoUrl(repoUrl, integrations);
93
+ const { host, owner, repo } = pluginScaffolderNode.parseRepoUrl(repoUrl, integrations);
94
94
  if (!owner) {
95
95
  throw new errors.InputError("Invalid repository owner provided in repoUrl");
96
96
  }
97
97
  const client = new octokit.Octokit(
98
- await helpers.getOctokitOptions({
98
+ await util.getOctokitOptions({
99
99
  integrations,
100
100
  credentialsProvider: githubCredentialsProvider,
101
- repoUrl,
101
+ host,
102
+ owner,
103
+ repo,
102
104
  token: providedToken
103
105
  })
104
106
  );
@@ -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 { assertError, InputError } from '@backstage/errors';\nimport { Octokit } from 'octokit';\nimport { getOctokitOptions } from './helpers';\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 repoUrl: string;\n webhookUrl: string;\n webhookSecret?: string;\n events?: string[];\n active?: boolean;\n contentType?: 'form' | 'json';\n insecureSsl?: boolean;\n token?: string;\n }>({\n id: 'github:webhook',\n description: 'Creates webhook for a repository on GitHub.',\n examples,\n supportsDryRun: true,\n schema: {\n input: {\n type: 'object',\n required: ['repoUrl', 'webhookUrl'],\n properties: {\n repoUrl: {\n title: 'Repository Location',\n description: `Accepts the format 'github.com?repo=reponame&owner=owner' where 'reponame' is the new repository name and 'owner' is an organization or username`,\n type: 'string',\n },\n webhookUrl: {\n title: 'Webhook URL',\n description: 'The URL to which the payloads will be delivered',\n type: 'string',\n },\n webhookSecret: {\n title: 'Webhook Secret',\n description:\n 'Webhook secret value. The default can be provided internally in action creation',\n type: 'string',\n },\n events: {\n title: 'Triggering Events',\n description:\n 'Determines what events the hook is triggered for. Default: push',\n type: 'array',\n oneOf: [\n {\n items: {\n type: 'string',\n enum: eventNames,\n },\n },\n {\n items: {\n type: 'string',\n const: '*',\n },\n },\n ],\n },\n active: {\n title: 'Active',\n type: 'boolean',\n description: `Determines if notifications are sent when the webhook is triggered. Default: true`,\n },\n contentType: {\n title: 'Content Type',\n type: 'string',\n enum: ['form', 'json'],\n description: `The media type used to serialize the payloads. The default is 'form'`,\n },\n insecureSsl: {\n title: 'Insecure SSL',\n type: 'boolean',\n description: `Determines whether the SSL certificate of the host for url will be verified when delivering payloads. Default 'false'`,\n },\n token: {\n title: 'Authentication Token',\n type: 'string',\n description: 'The GITHUB_TOKEN to use for authorization to GitHub',\n },\n },\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 { owner, repo } = parseRepoUrl(repoUrl, integrations);\n\n if (!owner) {\n throw new InputError('Invalid repository owner provided in repoUrl');\n }\n\n const client = new Octokit(\n await getOctokitOptions({\n integrations,\n credentialsProvider: githubCredentialsProvider,\n repoUrl: repoUrl,\n token: providedToken,\n }),\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 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 ctx.logger.info(`Webhook '${webhookUrl}' created successfully`);\n } catch (e) {\n assertError(e);\n ctx.logger.warn(\n `Failed: create webhook '${webhookUrl}' on repo: '${repo}', ${e.message}`,\n );\n }\n },\n });\n}\n"],"names":["emitterEventNames","createTemplateAction","examples","parseRepoUrl","InputError","Octokit","getOctokitOptions","assertError"],"mappings":";;;;;;;;;AAkCO,SAAS,0BAA0B,OAIvC,EAAA;AACD,EAAA,MAAM,EAAE,YAAA,EAAc,oBAAsB,EAAA,yBAAA,EAC1C,GAAA,OAAA;AAEF,EAAM,MAAA,UAAA,GAAaA,2BAAkB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AAA;AAChB,QAAI,GAAA,CAAA,MAAA,CAAO,KAAK,CAAkB,gBAAA,CAAA,CAAA;AAClC,QAAA;AAAA;AAGF,MAAI,IAAA;AACF,QAAM,MAAA,YAAA,GAAe,cAAc,GAAM,GAAA,GAAA;AACzC,QAAM,MAAA,MAAA,CAAO,IAAK,CAAA,KAAA,CAAM,aAAc,CAAA;AAAA,UACpC,KAAA;AAAA,UACA,IAAA;AAAA,UACA,MAAQ,EAAA;AAAA,YACN,GAAK,EAAA,UAAA;AAAA,YACL,YAAc,EAAA,WAAA;AAAA,YACd,MAAQ,EAAA,aAAA;AAAA,YACR;AAAA,WACF;AAAA,UACA,MAAA;AAAA,UACA;AAAA,SACD,CAAA;AACD,QAAA,GAAA,CAAI,MAAO,CAAA,IAAA,CAAK,CAAY,SAAA,EAAA,UAAU,CAAwB,sBAAA,CAAA,CAAA;AAAA,eACvD,CAAG,EAAA;AACV,QAAAC,kBAAA,CAAY,CAAC,CAAA;AACb,QAAA,GAAA,CAAI,MAAO,CAAA,IAAA;AAAA,UACT,2BAA2B,UAAU,CAAA,YAAA,EAAe,IAAI,CAAA,GAAA,EAAM,EAAE,OAAO,CAAA;AAAA,SACzE;AAAA;AACF;AACF,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 { assertError, InputError } 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 repoUrl: string;\n webhookUrl: string;\n webhookSecret?: string;\n events?: string[];\n active?: boolean;\n contentType?: 'form' | 'json';\n insecureSsl?: boolean;\n token?: string;\n }>({\n id: 'github:webhook',\n description: 'Creates webhook for a repository on GitHub.',\n examples,\n supportsDryRun: true,\n schema: {\n input: {\n type: 'object',\n required: ['repoUrl', 'webhookUrl'],\n properties: {\n repoUrl: {\n title: 'Repository Location',\n description: `Accepts the format 'github.com?repo=reponame&owner=owner' where 'reponame' is the new repository name and 'owner' is an organization or username`,\n type: 'string',\n },\n webhookUrl: {\n title: 'Webhook URL',\n description: 'The URL to which the payloads will be delivered',\n type: 'string',\n },\n webhookSecret: {\n title: 'Webhook Secret',\n description:\n 'Webhook secret value. The default can be provided internally in action creation',\n type: 'string',\n },\n events: {\n title: 'Triggering Events',\n description:\n 'Determines what events the hook is triggered for. Default: push',\n type: 'array',\n oneOf: [\n {\n items: {\n type: 'string',\n enum: eventNames,\n },\n },\n {\n items: {\n type: 'string',\n const: '*',\n },\n },\n ],\n },\n active: {\n title: 'Active',\n type: 'boolean',\n description: `Determines if notifications are sent when the webhook is triggered. Default: true`,\n },\n contentType: {\n title: 'Content Type',\n type: 'string',\n enum: ['form', 'json'],\n description: `The media type used to serialize the payloads. The default is 'form'`,\n },\n insecureSsl: {\n title: 'Insecure SSL',\n type: 'boolean',\n description: `Determines whether the SSL certificate of the host for url will be verified when delivering payloads. Default 'false'`,\n },\n token: {\n title: 'Authentication Token',\n type: 'string',\n description: 'The GITHUB_TOKEN to use for authorization to GitHub',\n },\n },\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 client = new Octokit(\n await getOctokitOptions({\n integrations,\n credentialsProvider: githubCredentialsProvider,\n host,\n owner,\n repo,\n token: providedToken,\n }),\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 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 ctx.logger.info(`Webhook '${webhookUrl}' created successfully`);\n } catch (e) {\n assertError(e);\n ctx.logger.warn(\n `Failed: create webhook '${webhookUrl}' on repo: '${repo}', ${e.message}`,\n );\n }\n },\n });\n}\n"],"names":["emitterEventNames","createTemplateAction","examples","parseRepoUrl","InputError","Octokit","getOctokitOptions","assertError"],"mappings":";;;;;;;;;AAkCO,SAAS,0BAA0B,OAIvC,EAAA;AACD,EAAA,MAAM,EAAE,YAAA,EAAc,oBAAsB,EAAA,yBAAA,EAC1C,GAAA,OAAA;AAEF,EAAM,MAAA,UAAA,GAAaA,2BAAkB,MAAO,CAAA,CAAA,KAAA,KAAS,CAAC,KAAM,CAAA,QAAA,CAAS,GAAG,CAAC,CAAA;AAEzE,EAAA,OAAOC,yCASJ,CAAA;AAAA,IACD,EAAI,EAAA,gBAAA;AAAA,IACJ,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AAM,MAAA,YAAA,GAAe,cAAc,GAAM,GAAA,GAAA;AACzC,QAAM,MAAA,MAAA,CAAO,IAAK,CAAA,KAAA,CAAM,aAAc,CAAA;AAAA,UACpC,KAAA;AAAA,UACA,IAAA;AAAA,UACA,MAAQ,EAAA;AAAA,YACN,GAAK,EAAA,UAAA;AAAA,YACL,YAAc,EAAA,WAAA;AAAA,YACd,MAAQ,EAAA,aAAA;AAAA,YACR;AAAA,WACF;AAAA,UACA,MAAA;AAAA,UACA;AAAA,SACD,CAAA;AACD,QAAA,GAAA,CAAI,MAAO,CAAA,IAAA,CAAK,CAAY,SAAA,EAAA,UAAU,CAAwB,sBAAA,CAAA,CAAA;AAAA,eACvD,CAAG,EAAA;AACV,QAAAC,kBAAA,CAAY,CAAC,CAAA;AACb,QAAA,GAAA,CAAI,MAAO,CAAA,IAAA;AAAA,UACT,2BAA2B,UAAU,CAAA,YAAA,EAAe,IAAI,CAAA,GAAA,EAAM,EAAE,OAAO,CAAA;AAAA,SACzE;AAAA;AACF;AACF,GACD,CAAA;AACH;;;;"}
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  var errors = require('@backstage/errors');
4
- var integration = require('@backstage/integration');
5
4
  var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
6
5
  var Sodium = require('libsodium-wrappers');
7
6
  var gitHelpers = require('./gitHelpers.cjs.js');
@@ -10,46 +9,6 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
10
9
 
11
10
  var Sodium__default = /*#__PURE__*/_interopDefaultCompat(Sodium);
12
11
 
13
- const DEFAULT_TIMEOUT_MS = 6e4;
14
- async function getOctokitOptions(options) {
15
- const { integrations, credentialsProvider, repoUrl, token } = options;
16
- const { owner, repo, host } = pluginScaffolderNode.parseRepoUrl(repoUrl, integrations);
17
- const requestOptions = {
18
- // set timeout to 60 seconds
19
- timeout: DEFAULT_TIMEOUT_MS
20
- };
21
- if (!owner) {
22
- throw new errors.InputError(`No owner provided for repo ${repoUrl}`);
23
- }
24
- const integrationConfig = integrations.github.byHost(host)?.config;
25
- if (!integrationConfig) {
26
- throw new errors.InputError(`No integration for host ${host}`);
27
- }
28
- if (token) {
29
- return {
30
- auth: token,
31
- baseUrl: integrationConfig.apiBaseUrl,
32
- previews: ["nebula-preview"],
33
- request: requestOptions
34
- };
35
- }
36
- const githubCredentialsProvider = credentialsProvider ?? integration.DefaultGithubCredentialsProvider.fromIntegrations(integrations);
37
- const { token: credentialProviderToken } = await githubCredentialsProvider.getCredentials({
38
- url: `https://${host}/${encodeURIComponent(owner)}/${encodeURIComponent(
39
- repo
40
- )}`
41
- });
42
- if (!credentialProviderToken) {
43
- throw new errors.InputError(
44
- `No token available for host: ${host}, with owner ${owner}, and repo ${repo}. Make sure GitHub auth is configured correctly. See https://backstage.io/docs/auth/github/provider for more details.`
45
- );
46
- }
47
- return {
48
- auth: credentialProviderToken,
49
- baseUrl: integrationConfig.apiBaseUrl,
50
- previews: ["nebula-preview"]
51
- };
52
- }
53
12
  async function createGithubRepoWithCollaboratorsAndTopics(client, repo, owner, repoVisibility, description, homepage, deleteBranchOnMerge, allowMergeCommit, allowSquashMerge, squashMergeCommitTitle, squashMergeCommitMessage, allowRebaseMerge, allowAutoMerge, access, collaborators, hasProjects, hasWiki, hasIssues, topics, repoVariables, secrets, oidcCustomization, customProperties, subscribe, logger) {
54
13
  const user = await client.rest.users.getByUsername({
55
14
  username: owner
@@ -296,6 +255,5 @@ function getGitCommitMessage(gitCommitMessage, config) {
296
255
 
297
256
  exports.createGithubRepoWithCollaboratorsAndTopics = createGithubRepoWithCollaboratorsAndTopics;
298
257
  exports.getGitCommitMessage = getGitCommitMessage;
299
- exports.getOctokitOptions = getOctokitOptions;
300
258
  exports.initRepoPushAndProtect = initRepoPushAndProtect;
301
259
  //# sourceMappingURL=helpers.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.cjs.js","sources":["../../src/actions/helpers.ts"],"sourcesContent":["/*\n * Copyright 2022 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 { assertError, InputError, NotFoundError } from '@backstage/errors';\nimport {\n DefaultGithubCredentialsProvider,\n GithubCredentialsProvider,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\nimport { OctokitOptions } from '@octokit/core/dist-types/types';\nimport { Octokit } from 'octokit';\n\nimport {\n getRepoSourceDirectory,\n initRepoAndPush,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\n\nimport Sodium from 'libsodium-wrappers';\nimport {\n enableBranchProtectionOnDefaultRepoBranch,\n entityRefToName,\n} from './gitHelpers';\nimport { LoggerService } from '@backstage/backend-plugin-api';\n\nconst DEFAULT_TIMEOUT_MS = 60_000;\n\n/**\n * Helper for generating octokit configuration options for given repoUrl.\n * If no token is provided, it will attempt to get a token from the credentials provider.\n * @public\n */\nexport async function getOctokitOptions(options: {\n integrations: ScmIntegrationRegistry;\n credentialsProvider?: GithubCredentialsProvider;\n token?: string;\n repoUrl: string;\n}): Promise<OctokitOptions> {\n const { integrations, credentialsProvider, repoUrl, token } = options;\n const { owner, repo, host } = parseRepoUrl(repoUrl, integrations);\n\n const requestOptions = {\n // set timeout to 60 seconds\n timeout: DEFAULT_TIMEOUT_MS,\n };\n\n if (!owner) {\n throw new InputError(`No owner provided for repo ${repoUrl}`);\n }\n\n const integrationConfig = integrations.github.byHost(host)?.config;\n\n if (!integrationConfig) {\n throw new InputError(`No integration for host ${host}`);\n }\n\n // short circuit the `githubCredentialsProvider` if there is a token provided by the caller already\n if (token) {\n return {\n auth: token,\n baseUrl: integrationConfig.apiBaseUrl,\n previews: ['nebula-preview'],\n request: requestOptions,\n };\n }\n\n const githubCredentialsProvider =\n credentialsProvider ??\n DefaultGithubCredentialsProvider.fromIntegrations(integrations);\n\n // TODO(blam): Consider changing this API to take host and repo instead of repoUrl, as we end up parsing in this function\n // and then parsing in the `getCredentials` function too the other side\n const { token: credentialProviderToken } =\n await githubCredentialsProvider.getCredentials({\n url: `https://${host}/${encodeURIComponent(owner)}/${encodeURIComponent(\n repo,\n )}`,\n });\n\n if (!credentialProviderToken) {\n throw new InputError(\n `No token available for host: ${host}, with owner ${owner}, and repo ${repo}. Make sure GitHub auth is configured correctly. See https://backstage.io/docs/auth/github/provider for more details.`,\n );\n }\n\n return {\n auth: credentialProviderToken,\n baseUrl: integrationConfig.apiBaseUrl,\n previews: ['nebula-preview'],\n };\n}\n\nexport async function createGithubRepoWithCollaboratorsAndTopics(\n client: Octokit,\n repo: string,\n owner: string,\n repoVisibility: 'private' | 'internal' | 'public' | undefined,\n description: string | undefined,\n homepage: string | undefined,\n deleteBranchOnMerge: boolean,\n allowMergeCommit: boolean,\n allowSquashMerge: boolean,\n squashMergeCommitTitle: 'PR_TITLE' | 'COMMIT_OR_PR_TITLE' | undefined,\n squashMergeCommitMessage: 'PR_BODY' | 'COMMIT_MESSAGES' | 'BLANK' | undefined,\n allowRebaseMerge: boolean,\n allowAutoMerge: boolean,\n access: string | undefined,\n collaborators:\n | (\n | {\n user: string;\n access: string;\n }\n | {\n team: string;\n access: string;\n }\n | {\n /** @deprecated This field is deprecated in favor of team */\n username: string;\n access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage';\n }\n )[]\n | undefined,\n hasProjects: boolean | undefined,\n hasWiki: boolean | undefined,\n hasIssues: boolean | undefined,\n topics: string[] | undefined,\n repoVariables: { [key: string]: string } | undefined,\n secrets: { [key: string]: string } | undefined,\n oidcCustomization:\n | {\n useDefault: boolean;\n includeClaimKeys?: string[];\n }\n | undefined,\n customProperties: { [key: string]: string } | undefined,\n subscribe: boolean | undefined,\n logger: LoggerService,\n) {\n // eslint-disable-next-line testing-library/no-await-sync-queries\n const user = await client.rest.users.getByUsername({\n username: owner,\n });\n\n if (access?.startsWith(`${owner}/`)) {\n await validateAccessTeam(client, access);\n }\n\n const repoCreationPromise =\n user.data.type === 'Organization'\n ? client.rest.repos.createInOrg({\n name: repo,\n org: owner,\n private: repoVisibility === 'private',\n // @ts-ignore https://github.com/octokit/types.ts/issues/522\n visibility: repoVisibility,\n description: description,\n delete_branch_on_merge: deleteBranchOnMerge,\n allow_merge_commit: allowMergeCommit,\n allow_squash_merge: allowSquashMerge,\n squash_merge_commit_title: squashMergeCommitTitle,\n squash_merge_commit_message: squashMergeCommitMessage,\n allow_rebase_merge: allowRebaseMerge,\n allow_auto_merge: allowAutoMerge,\n homepage: homepage,\n has_projects: hasProjects,\n has_wiki: hasWiki,\n has_issues: hasIssues,\n // Custom properties only available on org repos\n custom_properties: customProperties,\n })\n : client.rest.repos.createForAuthenticatedUser({\n name: repo,\n private: repoVisibility === 'private',\n description: description,\n delete_branch_on_merge: deleteBranchOnMerge,\n allow_merge_commit: allowMergeCommit,\n allow_squash_merge: allowSquashMerge,\n squash_merge_commit_title: squashMergeCommitTitle,\n squash_merge_commit_message: squashMergeCommitMessage,\n allow_rebase_merge: allowRebaseMerge,\n allow_auto_merge: allowAutoMerge,\n homepage: homepage,\n has_projects: hasProjects,\n has_wiki: hasWiki,\n has_issues: hasIssues,\n });\n\n let newRepo;\n\n try {\n newRepo = (await repoCreationPromise).data;\n } catch (e) {\n assertError(e);\n if (e.message === 'Resource not accessible by integration') {\n logger.warn(\n `The GitHub app or token provided may not have the required permissions to create the ${user.data.type} repository ${owner}/${repo}.`,\n );\n }\n throw new Error(\n `Failed to create the ${user.data.type} repository ${owner}/${repo}, ${e.message}`,\n );\n }\n\n if (access?.startsWith(`${owner}/`)) {\n const [, team] = access.split('/');\n await client.rest.teams.addOrUpdateRepoPermissionsInOrg({\n org: owner,\n team_slug: team,\n owner,\n repo,\n permission: 'admin',\n });\n // No need to add access if it's the person who owns the personal account\n } else if (access && access !== owner) {\n await client.rest.repos.addCollaborator({\n owner,\n repo,\n username: access,\n permission: 'admin',\n });\n }\n\n if (collaborators) {\n for (const collaborator of collaborators) {\n try {\n if ('user' in collaborator) {\n await client.rest.repos.addCollaborator({\n owner,\n repo,\n username: entityRefToName(collaborator.user),\n permission: collaborator.access,\n });\n } else if ('team' in collaborator) {\n await client.rest.teams.addOrUpdateRepoPermissionsInOrg({\n org: owner,\n team_slug: entityRefToName(collaborator.team),\n owner,\n repo,\n permission: collaborator.access,\n });\n }\n } catch (e) {\n assertError(e);\n const name = extractCollaboratorName(collaborator);\n logger.warn(\n `Skipping ${collaborator.access} access for ${name}, ${e.message}`,\n );\n }\n }\n }\n\n if (topics) {\n try {\n await client.rest.repos.replaceAllTopics({\n owner,\n repo,\n names: topics.map(t => t.toLowerCase()),\n });\n } catch (e) {\n assertError(e);\n logger.warn(`Skipping topics ${topics.join(' ')}, ${e.message}`);\n }\n }\n\n for (const [key, value] of Object.entries(repoVariables ?? {})) {\n await client.rest.actions.createRepoVariable({\n owner,\n repo,\n name: key,\n value: value,\n });\n }\n\n if (secrets) {\n const publicKeyResponse = await client.rest.actions.getRepoPublicKey({\n owner,\n repo,\n });\n\n await Sodium.ready;\n const binaryKey = Sodium.from_base64(\n publicKeyResponse.data.key,\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 client.rest.actions.createOrUpdateRepoSecret({\n owner,\n repo,\n secret_name: key,\n encrypted_value: encryptedBase64Secret,\n key_id: publicKeyResponse.data.key_id,\n });\n }\n }\n\n if (oidcCustomization) {\n await client.request(\n 'PUT /repos/{owner}/{repo}/actions/oidc/customization/sub',\n {\n owner,\n repo,\n use_default: oidcCustomization.useDefault,\n include_claim_keys: oidcCustomization.includeClaimKeys,\n },\n );\n }\n\n if (subscribe) {\n await client.rest.activity.setRepoSubscription({\n subscribed: true,\n ignored: false,\n owner,\n repo,\n });\n }\n\n return newRepo;\n}\n\nexport async function initRepoPushAndProtect(\n remoteUrl: string,\n password: string,\n workspacePath: string,\n sourcePath: string | undefined,\n defaultBranch: string,\n protectDefaultBranch: boolean,\n protectEnforceAdmins: boolean,\n owner: string,\n client: Octokit,\n repo: string,\n requireCodeOwnerReviews: boolean,\n bypassPullRequestAllowances:\n | {\n users?: string[];\n teams?: string[];\n apps?: string[];\n }\n | undefined,\n requiredApprovingReviewCount: number,\n restrictions:\n | {\n users: string[];\n teams: string[];\n apps?: string[];\n }\n | undefined,\n requiredStatusCheckContexts: string[],\n requireBranchesToBeUpToDate: boolean,\n requiredConversationResolution: boolean,\n requireLastPushApproval: boolean,\n config: Config,\n logger: any,\n gitCommitMessage?: string,\n gitAuthorName?: string,\n gitAuthorEmail?: string,\n dismissStaleReviews?: boolean,\n requiredCommitSigning?: boolean,\n requiredLinearHistory?: boolean,\n): Promise<{ commitHash: string }> {\n const gitAuthorInfo = {\n name: gitAuthorName\n ? gitAuthorName\n : config.getOptionalString('scaffolder.defaultAuthor.name'),\n email: gitAuthorEmail\n ? gitAuthorEmail\n : config.getOptionalString('scaffolder.defaultAuthor.email'),\n };\n\n const commitMessage =\n getGitCommitMessage(gitCommitMessage, config) || 'initial commit';\n\n const commitResult = await initRepoAndPush({\n dir: getRepoSourceDirectory(workspacePath, sourcePath),\n remoteUrl,\n defaultBranch,\n auth: {\n username: 'x-access-token',\n password,\n },\n logger,\n commitMessage,\n gitAuthorInfo,\n });\n\n if (protectDefaultBranch) {\n try {\n await enableBranchProtectionOnDefaultRepoBranch({\n owner,\n client,\n repoName: repo,\n logger,\n defaultBranch,\n bypassPullRequestAllowances,\n requiredApprovingReviewCount,\n restrictions,\n requireCodeOwnerReviews,\n requiredStatusCheckContexts,\n requireBranchesToBeUpToDate,\n requiredConversationResolution,\n requireLastPushApproval,\n enforceAdmins: protectEnforceAdmins,\n dismissStaleReviews: dismissStaleReviews,\n requiredCommitSigning: requiredCommitSigning,\n requiredLinearHistory: requiredLinearHistory,\n });\n } catch (e) {\n assertError(e);\n logger.warn(\n `Skipping: default branch protection on '${repo}', ${e.message}`,\n );\n }\n }\n\n return { commitHash: commitResult.commitHash };\n}\n\nfunction extractCollaboratorName(\n collaborator: { user: string } | { team: string } | { username: string },\n) {\n if ('username' in collaborator) return collaborator.username;\n if ('user' in collaborator) return collaborator.user;\n return collaborator.team;\n}\n\nasync function validateAccessTeam(client: Octokit, access: string) {\n const [org, team_slug] = access.split('/');\n try {\n // Below rule disabled because of a 'getByName' check for a different library\n // incorrectly triggers here.\n // eslint-disable-next-line testing-library/no-await-sync-queries\n await client.rest.teams.getByName({\n org,\n team_slug,\n });\n } catch (e) {\n if (e.response.data.message === 'Not Found') {\n const message = `Received 'Not Found' from the API; one of org:\n ${org} or team: ${team_slug} was not found within GitHub.`;\n throw new NotFoundError(message);\n }\n }\n}\n\nexport function getGitCommitMessage(\n gitCommitMessage: string | undefined,\n config: Config,\n): string | undefined {\n return gitCommitMessage\n ? gitCommitMessage\n : config.getOptionalString('scaffolder.defaultCommitMessage');\n}\n"],"names":["parseRepoUrl","InputError","DefaultGithubCredentialsProvider","assertError","entityRefToName","Sodium","initRepoAndPush","getRepoSourceDirectory","enableBranchProtectionOnDefaultRepoBranch","NotFoundError"],"mappings":";;;;;;;;;;;;AAuCA,MAAM,kBAAqB,GAAA,GAAA;AAO3B,eAAsB,kBAAkB,OAKZ,EAAA;AAC1B,EAAA,MAAM,EAAE,YAAA,EAAc,mBAAqB,EAAA,OAAA,EAAS,OAAU,GAAA,OAAA;AAC9D,EAAA,MAAM,EAAE,KAAO,EAAA,IAAA,EAAM,MAAS,GAAAA,iCAAA,CAAa,SAAS,YAAY,CAAA;AAEhE,EAAA,MA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YAAA,CAAa,UAAW,EAAA;AAC/C;AAEA,SAAS,wBACP,YACA,EAAA;AACA,EAAI,IAAA,UAAA,IAAc,YAAc,EAAA,OAAO,YAAa,CAAA,QAAA;AACpD,EAAI,IAAA,MAAA,IAAU,YAAc,EAAA,OAAO,YAAa,CAAA,IAAA;AAChD,EAAA,OAAO,YAAa,CAAA,IAAA;AACtB;AAEA,eAAe,kBAAA,CAAmB,QAAiB,MAAgB,EAAA;AACjE,EAAA,MAAM,CAAC,GAAK,EAAA,SAAS,CAAI,GAAA,MAAA,CAAO,MAAM,GAAG,CAAA;AACzC,EAAI,IAAA;AAIF,IAAM,MAAA,MAAA,CAAO,IAAK,CAAA,KAAA,CAAM,SAAU,CAAA;AAAA,MAChC,GAAA;AAAA,MACA;AAAA,KACD,CAAA;AAAA,WACM,CAAG,EAAA;AACV,IAAA,IAAI,CAAE,CAAA,QAAA,CAAS,IAAK,CAAA,OAAA,KAAY,WAAa,EAAA;AAC3C,MAAA,MAAM,OAAU,GAAA,CAAA;AAAA,QACZ,EAAA,GAAG,aAAa,SAAS,CAAA,6BAAA,CAAA;AAC7B,MAAM,MAAA,IAAIM,qBAAc,OAAO,CAAA;AAAA;AACjC;AAEJ;AAEgB,SAAA,mBAAA,CACd,kBACA,MACoB,EAAA;AACpB,EAAA,OAAO,gBACH,GAAA,gBAAA,GACA,MAAO,CAAA,iBAAA,CAAkB,iCAAiC,CAAA;AAChE;;;;;;;"}
1
+ {"version":3,"file":"helpers.cjs.js","sources":["../../src/actions/helpers.ts"],"sourcesContent":["/*\n * Copyright 2022 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 { assertError, NotFoundError } from '@backstage/errors';\nimport { Octokit } from 'octokit';\n\nimport {\n getRepoSourceDirectory,\n initRepoAndPush,\n} from '@backstage/plugin-scaffolder-node';\n\nimport Sodium from 'libsodium-wrappers';\nimport {\n enableBranchProtectionOnDefaultRepoBranch,\n entityRefToName,\n} from './gitHelpers';\nimport { LoggerService } from '@backstage/backend-plugin-api';\n\nexport async function createGithubRepoWithCollaboratorsAndTopics(\n client: Octokit,\n repo: string,\n owner: string,\n repoVisibility: 'private' | 'internal' | 'public' | undefined,\n description: string | undefined,\n homepage: string | undefined,\n deleteBranchOnMerge: boolean,\n allowMergeCommit: boolean,\n allowSquashMerge: boolean,\n squashMergeCommitTitle: 'PR_TITLE' | 'COMMIT_OR_PR_TITLE' | undefined,\n squashMergeCommitMessage: 'PR_BODY' | 'COMMIT_MESSAGES' | 'BLANK' | undefined,\n allowRebaseMerge: boolean,\n allowAutoMerge: boolean,\n access: string | undefined,\n collaborators:\n | (\n | {\n user: string;\n access: string;\n }\n | {\n team: string;\n access: string;\n }\n | {\n /** @deprecated This field is deprecated in favor of team */\n username: string;\n access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage';\n }\n )[]\n | undefined,\n hasProjects: boolean | undefined,\n hasWiki: boolean | undefined,\n hasIssues: boolean | undefined,\n topics: string[] | undefined,\n repoVariables: { [key: string]: string } | undefined,\n secrets: { [key: string]: string } | undefined,\n oidcCustomization:\n | {\n useDefault: boolean;\n includeClaimKeys?: string[];\n }\n | undefined,\n customProperties: { [key: string]: string } | undefined,\n subscribe: boolean | undefined,\n logger: LoggerService,\n) {\n // eslint-disable-next-line testing-library/no-await-sync-queries\n const user = await client.rest.users.getByUsername({\n username: owner,\n });\n\n if (access?.startsWith(`${owner}/`)) {\n await validateAccessTeam(client, access);\n }\n\n const repoCreationPromise =\n user.data.type === 'Organization'\n ? client.rest.repos.createInOrg({\n name: repo,\n org: owner,\n private: repoVisibility === 'private',\n // @ts-ignore https://github.com/octokit/types.ts/issues/522\n visibility: repoVisibility,\n description: description,\n delete_branch_on_merge: deleteBranchOnMerge,\n allow_merge_commit: allowMergeCommit,\n allow_squash_merge: allowSquashMerge,\n squash_merge_commit_title: squashMergeCommitTitle,\n squash_merge_commit_message: squashMergeCommitMessage,\n allow_rebase_merge: allowRebaseMerge,\n allow_auto_merge: allowAutoMerge,\n homepage: homepage,\n has_projects: hasProjects,\n has_wiki: hasWiki,\n has_issues: hasIssues,\n // Custom properties only available on org repos\n custom_properties: customProperties,\n })\n : client.rest.repos.createForAuthenticatedUser({\n name: repo,\n private: repoVisibility === 'private',\n description: description,\n delete_branch_on_merge: deleteBranchOnMerge,\n allow_merge_commit: allowMergeCommit,\n allow_squash_merge: allowSquashMerge,\n squash_merge_commit_title: squashMergeCommitTitle,\n squash_merge_commit_message: squashMergeCommitMessage,\n allow_rebase_merge: allowRebaseMerge,\n allow_auto_merge: allowAutoMerge,\n homepage: homepage,\n has_projects: hasProjects,\n has_wiki: hasWiki,\n has_issues: hasIssues,\n });\n\n let newRepo;\n\n try {\n newRepo = (await repoCreationPromise).data;\n } catch (e) {\n assertError(e);\n if (e.message === 'Resource not accessible by integration') {\n logger.warn(\n `The GitHub app or token provided may not have the required permissions to create the ${user.data.type} repository ${owner}/${repo}.`,\n );\n }\n throw new Error(\n `Failed to create the ${user.data.type} repository ${owner}/${repo}, ${e.message}`,\n );\n }\n\n if (access?.startsWith(`${owner}/`)) {\n const [, team] = access.split('/');\n await client.rest.teams.addOrUpdateRepoPermissionsInOrg({\n org: owner,\n team_slug: team,\n owner,\n repo,\n permission: 'admin',\n });\n // No need to add access if it's the person who owns the personal account\n } else if (access && access !== owner) {\n await client.rest.repos.addCollaborator({\n owner,\n repo,\n username: access,\n permission: 'admin',\n });\n }\n\n if (collaborators) {\n for (const collaborator of collaborators) {\n try {\n if ('user' in collaborator) {\n await client.rest.repos.addCollaborator({\n owner,\n repo,\n username: entityRefToName(collaborator.user),\n permission: collaborator.access,\n });\n } else if ('team' in collaborator) {\n await client.rest.teams.addOrUpdateRepoPermissionsInOrg({\n org: owner,\n team_slug: entityRefToName(collaborator.team),\n owner,\n repo,\n permission: collaborator.access,\n });\n }\n } catch (e) {\n assertError(e);\n const name = extractCollaboratorName(collaborator);\n logger.warn(\n `Skipping ${collaborator.access} access for ${name}, ${e.message}`,\n );\n }\n }\n }\n\n if (topics) {\n try {\n await client.rest.repos.replaceAllTopics({\n owner,\n repo,\n names: topics.map(t => t.toLowerCase()),\n });\n } catch (e) {\n assertError(e);\n logger.warn(`Skipping topics ${topics.join(' ')}, ${e.message}`);\n }\n }\n\n for (const [key, value] of Object.entries(repoVariables ?? {})) {\n await client.rest.actions.createRepoVariable({\n owner,\n repo,\n name: key,\n value: value,\n });\n }\n\n if (secrets) {\n const publicKeyResponse = await client.rest.actions.getRepoPublicKey({\n owner,\n repo,\n });\n\n await Sodium.ready;\n const binaryKey = Sodium.from_base64(\n publicKeyResponse.data.key,\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 client.rest.actions.createOrUpdateRepoSecret({\n owner,\n repo,\n secret_name: key,\n encrypted_value: encryptedBase64Secret,\n key_id: publicKeyResponse.data.key_id,\n });\n }\n }\n\n if (oidcCustomization) {\n await client.request(\n 'PUT /repos/{owner}/{repo}/actions/oidc/customization/sub',\n {\n owner,\n repo,\n use_default: oidcCustomization.useDefault,\n include_claim_keys: oidcCustomization.includeClaimKeys,\n },\n );\n }\n\n if (subscribe) {\n await client.rest.activity.setRepoSubscription({\n subscribed: true,\n ignored: false,\n owner,\n repo,\n });\n }\n\n return newRepo;\n}\n\nexport async function initRepoPushAndProtect(\n remoteUrl: string,\n password: string,\n workspacePath: string,\n sourcePath: string | undefined,\n defaultBranch: string,\n protectDefaultBranch: boolean,\n protectEnforceAdmins: boolean,\n owner: string,\n client: Octokit,\n repo: string,\n requireCodeOwnerReviews: boolean,\n bypassPullRequestAllowances:\n | {\n users?: string[];\n teams?: string[];\n apps?: string[];\n }\n | undefined,\n requiredApprovingReviewCount: number,\n restrictions:\n | {\n users: string[];\n teams: string[];\n apps?: string[];\n }\n | undefined,\n requiredStatusCheckContexts: string[],\n requireBranchesToBeUpToDate: boolean,\n requiredConversationResolution: boolean,\n requireLastPushApproval: boolean,\n config: Config,\n logger: any,\n gitCommitMessage?: string,\n gitAuthorName?: string,\n gitAuthorEmail?: string,\n dismissStaleReviews?: boolean,\n requiredCommitSigning?: boolean,\n requiredLinearHistory?: boolean,\n): Promise<{ commitHash: string }> {\n const gitAuthorInfo = {\n name: gitAuthorName\n ? gitAuthorName\n : config.getOptionalString('scaffolder.defaultAuthor.name'),\n email: gitAuthorEmail\n ? gitAuthorEmail\n : config.getOptionalString('scaffolder.defaultAuthor.email'),\n };\n\n const commitMessage =\n getGitCommitMessage(gitCommitMessage, config) || 'initial commit';\n\n const commitResult = await initRepoAndPush({\n dir: getRepoSourceDirectory(workspacePath, sourcePath),\n remoteUrl,\n defaultBranch,\n auth: {\n username: 'x-access-token',\n password,\n },\n logger,\n commitMessage,\n gitAuthorInfo,\n });\n\n if (protectDefaultBranch) {\n try {\n await enableBranchProtectionOnDefaultRepoBranch({\n owner,\n client,\n repoName: repo,\n logger,\n defaultBranch,\n bypassPullRequestAllowances,\n requiredApprovingReviewCount,\n restrictions,\n requireCodeOwnerReviews,\n requiredStatusCheckContexts,\n requireBranchesToBeUpToDate,\n requiredConversationResolution,\n requireLastPushApproval,\n enforceAdmins: protectEnforceAdmins,\n dismissStaleReviews: dismissStaleReviews,\n requiredCommitSigning: requiredCommitSigning,\n requiredLinearHistory: requiredLinearHistory,\n });\n } catch (e) {\n assertError(e);\n logger.warn(\n `Skipping: default branch protection on '${repo}', ${e.message}`,\n );\n }\n }\n\n return { commitHash: commitResult.commitHash };\n}\n\nfunction extractCollaboratorName(\n collaborator: { user: string } | { team: string } | { username: string },\n) {\n if ('username' in collaborator) return collaborator.username;\n if ('user' in collaborator) return collaborator.user;\n return collaborator.team;\n}\n\nasync function validateAccessTeam(client: Octokit, access: string) {\n const [org, team_slug] = access.split('/');\n try {\n // Below rule disabled because of a 'getByName' check for a different library\n // incorrectly triggers here.\n // eslint-disable-next-line testing-library/no-await-sync-queries\n await client.rest.teams.getByName({\n org,\n team_slug,\n });\n } catch (e) {\n if (e.response.data.message === 'Not Found') {\n const message = `Received 'Not Found' from the API; one of org:\n ${org} or team: ${team_slug} was not found within GitHub.`;\n throw new NotFoundError(message);\n }\n }\n}\n\nexport function getGitCommitMessage(\n gitCommitMessage: string | undefined,\n config: Config,\n): string | undefined {\n return gitCommitMessage\n ? gitCommitMessage\n : config.getOptionalString('scaffolder.defaultCommitMessage');\n}\n"],"names":["assertError","entityRefToName","Sodium","initRepoAndPush","getRepoSourceDirectory","enableBranchProtectionOnDefaultRepoBranch","NotFoundError"],"mappings":";;;;;;;;;;;AAgCsB,eAAA,0CAAA,CACpB,MACA,EAAA,IAAA,EACA,KACA,EAAA,cAAA,EACA,aACA,QACA,EAAA,mBAAA,EACA,gBACA,EAAA,gBAAA,EACA,sBACA,EAAA,wBAAA,EACA,kBACA,cACA,EAAA,MAAA,EACA,aAiBA,EAAA,WAAA,EACA,OACA,EAAA,SAAA,EACA,MACA,EAAA,aAAA,EACA,OACA,EAAA,iBAAA,EAMA,gBACA,EAAA,SAAA,EACA,MACA,EAAA;AAEA,EAAA,MAAM,IAAO,GAAA,MAAM,MAAO,CAAA,IAAA,CAAK,MAAM,aAAc,CAAA;AAAA,IACjD,QAAU,EAAA;AAAA,GACX,CAAA;AAED,EAAA,IAAI,MAAQ,EAAA,UAAA,CAAW,CAAG,EAAA,KAAK,GAAG,CAAG,EAAA;AACnC,IAAM,MAAA,kBAAA,CAAmB,QAAQ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AA,QAAA,CAAS,IAAK,CAAA,OAAA,KAAY,WAAa,EAAA;AAC3C,MAAA,MAAM,OAAU,GAAA,CAAA;AAAA,QACZ,EAAA,GAAG,aAAa,SAAS,CAAA,6BAAA,CAAA;AAC7B,MAAM,MAAA,IAAIM,qBAAc,OAAO,CAAA;AAAA;AACjC;AAEJ;AAEgB,SAAA,mBAAA,CACd,kBACA,MACoB,EAAA;AACpB,EAAA,OAAO,gBACH,GAAA,gBAAA,GACA,MAAO,CAAA,iBAAA,CAAkB,iCAAiC,CAAA;AAChE;;;;;;"}
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ var errors = require('@backstage/errors');
4
+ var util = require('../util.cjs.js');
5
+ var octokit = require('octokit');
6
+
7
+ function createHandleAutocompleteRequest(options) {
8
+ return async function handleAutocompleteRequest({
9
+ resource,
10
+ token,
11
+ context
12
+ }) {
13
+ const { integrations } = options;
14
+ const octokitOptions = await util.getOctokitOptions({
15
+ integrations,
16
+ token,
17
+ host: context.host ?? "github.com"
18
+ });
19
+ const client = new octokit.Octokit(octokitOptions);
20
+ switch (resource) {
21
+ case "repositoriesWithOwner": {
22
+ const repositoriesWithOwner = await client.paginate(
23
+ client.rest.repos.listForAuthenticatedUser
24
+ );
25
+ const results = repositoriesWithOwner.map((r) => ({ id: r.full_name }));
26
+ return { results };
27
+ }
28
+ case "branches": {
29
+ if (!context.owner || !context.repository)
30
+ throw new errors.InputError(
31
+ "Missing owner and/or repository context parameter"
32
+ );
33
+ const branches = await client.paginate(client.rest.repos.listBranches, {
34
+ owner: context.owner,
35
+ repo: context.repository
36
+ });
37
+ const results = branches.map((r) => ({ id: r.name }));
38
+ return { results };
39
+ }
40
+ default:
41
+ throw new errors.InputError(`Invalid resource: ${resource}`);
42
+ }
43
+ };
44
+ }
45
+
46
+ exports.createHandleAutocompleteRequest = createHandleAutocompleteRequest;
47
+ //# sourceMappingURL=autocomplete.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autocomplete.cjs.js","sources":["../../src/autocomplete/autocomplete.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 { getOctokitOptions } from '../util';\nimport { Octokit } from 'octokit';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\n\nexport function createHandleAutocompleteRequest(options: {\n integrations: ScmIntegrationRegistry;\n}) {\n return async function handleAutocompleteRequest({\n resource,\n token,\n context,\n }: {\n resource: string;\n token: string;\n context: Record<string, string>;\n }): Promise<{ results: { title?: string; id: string }[] }> {\n const { integrations } = options;\n const octokitOptions = await getOctokitOptions({\n integrations,\n token,\n host: context.host ?? 'github.com',\n });\n const client = new Octokit(octokitOptions);\n\n switch (resource) {\n case 'repositoriesWithOwner': {\n const repositoriesWithOwner = await client.paginate(\n client.rest.repos.listForAuthenticatedUser,\n );\n\n const results = repositoriesWithOwner.map(r => ({ id: r.full_name }));\n\n return { results };\n }\n case 'branches': {\n if (!context.owner || !context.repository)\n throw new InputError(\n 'Missing owner and/or repository context parameter',\n );\n\n const branches = await client.paginate(client.rest.repos.listBranches, {\n owner: context.owner,\n repo: context.repository,\n });\n\n const results = branches.map(r => ({ id: r.name }));\n\n return { results };\n }\n default:\n throw new InputError(`Invalid resource: ${resource}`);\n }\n };\n}\n"],"names":["getOctokitOptions","Octokit","InputError"],"mappings":";;;;;;AAqBO,SAAS,gCAAgC,OAE7C,EAAA;AACD,EAAA,OAAO,eAAe,yBAA0B,CAAA;AAAA,IAC9C,QAAA;AAAA,IACA,KAAA;AAAA,IACA;AAAA,GAKyD,EAA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+14,8 @@ var github = require('./actions/github.cjs.js');
14
14
  var githubAutolinks = require('./actions/githubAutolinks.cjs.js');
15
15
  var githubPagesEnable = require('./actions/githubPagesEnable.cjs.js');
16
16
  var githubBranchProtection = require('./actions/githubBranchProtection.cjs.js');
17
- var helpers = require('./actions/helpers.cjs.js');
18
17
  var module$1 = require('./module.cjs.js');
18
+ var util = require('./util.cjs.js');
19
19
 
20
20
 
21
21
 
@@ -31,6 +31,6 @@ exports.createPublishGithubAction = github.createPublishGithubAction;
31
31
  exports.createGithubAutolinksAction = githubAutolinks.createGithubAutolinksAction;
32
32
  exports.createGithubPagesEnableAction = githubPagesEnable.createGithubPagesEnableAction;
33
33
  exports.createGithubBranchProtectionAction = githubBranchProtection.createGithubBranchProtectionAction;
34
- exports.getOctokitOptions = helpers.getOctokitOptions;
35
34
  exports.default = module$1.githubModule;
35
+ exports.getOctokitOptions = util.getOctokitOptions;
36
36
  //# sourceMappingURL=index.cjs.js.map
package/dist/index.d.ts CHANGED
@@ -280,6 +280,7 @@ declare const createPublishGithubPullRequestAction: (options: CreateGithubPullRe
280
280
  gitAuthorName?: string | undefined;
281
281
  gitAuthorEmail?: string | undefined;
282
282
  forceEmptyGitAuthor?: boolean | undefined;
283
+ createWhenEmpty?: boolean | undefined;
283
284
  }, _backstage_types.JsonObject>;
284
285
 
285
286
  /**
@@ -428,7 +429,13 @@ declare function createGithubBranchProtectionAction(options: {
428
429
  }, _backstage_types.JsonObject>;
429
430
 
430
431
  /**
431
- * Helper for generating octokit configuration options for given repoUrl.
432
+ * @public
433
+ * The GitHub Module for the Scaffolder Backend
434
+ */
435
+ declare const githubModule: _backstage_backend_plugin_api.BackendFeature;
436
+
437
+ /**
438
+ * Helper for generating octokit configuration options.
432
439
  * If no token is provided, it will attempt to get a token from the credentials provider.
433
440
  * @public
434
441
  */
@@ -436,13 +443,21 @@ declare function getOctokitOptions(options: {
436
443
  integrations: ScmIntegrationRegistry;
437
444
  credentialsProvider?: GithubCredentialsProvider;
438
445
  token?: string;
439
- repoUrl: string;
446
+ host: string;
447
+ owner?: string;
448
+ repo?: string;
440
449
  }): Promise<OctokitOptions>;
441
-
442
450
  /**
451
+ * Helper for generating octokit configuration options for given repoUrl.
452
+ * If no token is provided, it will attempt to get a token from the credentials provider.
443
453
  * @public
444
- * The GitHub Module for the Scaffolder Backend
454
+ * @deprecated Use options `host`, `owner` and `repo` instead of `repoUrl`.
445
455
  */
446
- declare const githubModule: _backstage_backend_plugin_api.BackendFeature;
456
+ declare function getOctokitOptions(options: {
457
+ integrations: ScmIntegrationRegistry;
458
+ credentialsProvider?: GithubCredentialsProvider;
459
+ token?: string;
460
+ repoUrl: string;
461
+ }): Promise<OctokitOptions>;
447
462
 
448
463
  export { type CreateGithubPullRequestActionOptions, createGithubActionsDispatchAction, createGithubAutolinksAction, createGithubBranchProtectionAction, createGithubDeployKeyAction, createGithubEnvironmentAction, createGithubIssuesLabelAction, createGithubPagesEnableAction, createGithubRepoCreateAction, createGithubRepoPushAction, createGithubWebhookAction, createPublishGithubAction, createPublishGithubPullRequestAction, githubModule as default, getOctokitOptions };
@@ -14,11 +14,9 @@ var github = require('./actions/github.cjs.js');
14
14
  var githubAutolinks = require('./actions/githubAutolinks.cjs.js');
15
15
  var githubPagesEnable = require('./actions/githubPagesEnable.cjs.js');
16
16
  var githubBranchProtection = require('./actions/githubBranchProtection.cjs.js');
17
- require('@backstage/errors');
18
17
  var integration = require('@backstage/integration');
19
- require('@backstage/plugin-scaffolder-node');
20
- require('libsodium-wrappers');
21
18
  var catalogClient = require('@backstage/catalog-client');
19
+ var autocomplete = require('./autocomplete/autocomplete.cjs.js');
22
20
 
23
21
  const githubModule = backendPluginApi.createBackendModule({
24
22
  pluginId: "scaffolder",
@@ -29,9 +27,10 @@ const githubModule = backendPluginApi.createBackendModule({
29
27
  scaffolder: alpha.scaffolderActionsExtensionPoint,
30
28
  config: backendPluginApi.coreServices.rootConfig,
31
29
  discovery: backendPluginApi.coreServices.discovery,
32
- auth: backendPluginApi.coreServices.auth
30
+ auth: backendPluginApi.coreServices.auth,
31
+ autocomplete: alpha.scaffolderAutocompleteExtensionPoint
33
32
  },
34
- async init({ scaffolder, config, discovery, auth }) {
33
+ async init({ scaffolder, config, discovery, auth, autocomplete: autocomplete$1 }) {
35
34
  const integrations = integration.ScmIntegrations.fromConfig(config);
36
35
  const githubCredentialsProvider = integration.DefaultGithubCredentialsProvider.fromIntegrations(integrations);
37
36
  const catalogClient$1 = new catalogClient.CatalogClient({
@@ -85,6 +84,10 @@ const githubModule = backendPluginApi.createBackendModule({
85
84
  integrations
86
85
  })
87
86
  );
87
+ autocomplete$1.addAutocompleteProvider({
88
+ id: "github",
89
+ handler: autocomplete.createHandleAutocompleteRequest({ integrations })
90
+ });
88
91
  }
89
92
  });
90
93
  }
@@ -1 +1 @@
1
- {"version":3,"file":"module.cjs.js","sources":["../src/module.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 */\nimport {\n coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { scaffolderActionsExtensionPoint } from '@backstage/plugin-scaffolder-node/alpha';\nimport {\n createGithubActionsDispatchAction,\n createGithubAutolinksAction,\n createGithubDeployKeyAction,\n createGithubEnvironmentAction,\n createGithubIssuesLabelAction,\n createGithubRepoCreateAction,\n createGithubRepoPushAction,\n createGithubWebhookAction,\n createPublishGithubAction,\n createPublishGithubPullRequestAction,\n createGithubPagesEnableAction,\n createGithubBranchProtectionAction,\n} from './actions';\nimport {\n DefaultGithubCredentialsProvider,\n ScmIntegrations,\n} from '@backstage/integration';\nimport { CatalogClient } from '@backstage/catalog-client';\n\n/**\n * @public\n * The GitHub Module for the Scaffolder Backend\n */\nexport const githubModule = createBackendModule({\n pluginId: 'scaffolder',\n moduleId: 'github',\n register({ registerInit }) {\n registerInit({\n deps: {\n scaffolder: scaffolderActionsExtensionPoint,\n config: coreServices.rootConfig,\n discovery: coreServices.discovery,\n auth: coreServices.auth,\n },\n async init({ scaffolder, config, discovery, auth }) {\n const integrations = ScmIntegrations.fromConfig(config);\n const githubCredentialsProvider =\n DefaultGithubCredentialsProvider.fromIntegrations(integrations);\n const catalogClient = new CatalogClient({\n discoveryApi: discovery,\n });\n\n scaffolder.addActions(\n createGithubActionsDispatchAction({\n integrations,\n githubCredentialsProvider,\n }),\n createGithubAutolinksAction({\n integrations,\n githubCredentialsProvider,\n }),\n createGithubDeployKeyAction({\n integrations,\n }),\n createGithubEnvironmentAction({\n integrations,\n catalogClient,\n auth,\n }),\n createGithubIssuesLabelAction({\n integrations,\n githubCredentialsProvider,\n }),\n createGithubRepoCreateAction({\n integrations,\n githubCredentialsProvider,\n }),\n createGithubRepoPushAction({ integrations, config }),\n createGithubWebhookAction({\n integrations,\n githubCredentialsProvider,\n }),\n createPublishGithubAction({\n integrations,\n config,\n githubCredentialsProvider,\n }),\n createPublishGithubPullRequestAction({\n integrations,\n githubCredentialsProvider,\n config,\n }),\n createGithubPagesEnableAction({\n integrations,\n githubCredentialsProvider,\n }),\n createGithubBranchProtectionAction({\n integrations,\n }),\n );\n },\n });\n },\n});\n"],"names":["createBackendModule","scaffolderActionsExtensionPoint","coreServices","ScmIntegrations","DefaultGithubCredentialsProvider","catalogClient","CatalogClient","createGithubActionsDispatchAction","createGithubAutolinksAction","createGithubDeployKeyAction","createGithubEnvironmentAction","createGithubIssuesLabelAction","createGithubRepoCreateAction","createGithubRepoPushAction","createGithubWebhookAction","createPublishGithubAction","createPublishGithubPullRequestAction","createGithubPagesEnableAction","createGithubBranchProtectionAction"],"mappings":";;;;;;;;;;;;;;;;;;;;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xB,YAAA;AAAA,YACA;AAAA,WACD,CAAA;AAAA,UACDC,gCAA0B,CAAA;AAAA,YACxB,YAAA;AAAA,YACA,MAAA;AAAA,YACA;AAAA,WACD,CAAA;AAAA,UACDC,sDAAqC,CAAA;AAAA,YACnC,YAAA;AAAA,YACA,yBAAA;AAAA,YACA;AAAA,WACD,CAAA;AAAA,UACDC,+CAA8B,CAAA;AAAA,YAC5B,YAAA;AAAA,YACA;AAAA,WACD,CAAA;AAAA,UACDC,yDAAmC,CAAA;AAAA,YACjC;AAAA,WACD;AAAA,SACH;AAAA;AACF,KACD,CAAA;AAAA;AAEL,CAAC;;;;"}
1
+ {"version":3,"file":"module.cjs.js","sources":["../src/module.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 */\nimport {\n coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport {\n scaffolderActionsExtensionPoint,\n scaffolderAutocompleteExtensionPoint,\n} from '@backstage/plugin-scaffolder-node/alpha';\nimport {\n createGithubActionsDispatchAction,\n createGithubAutolinksAction,\n createGithubDeployKeyAction,\n createGithubEnvironmentAction,\n createGithubIssuesLabelAction,\n createGithubRepoCreateAction,\n createGithubRepoPushAction,\n createGithubWebhookAction,\n createPublishGithubAction,\n createPublishGithubPullRequestAction,\n createGithubPagesEnableAction,\n createGithubBranchProtectionAction,\n} from './actions';\nimport {\n DefaultGithubCredentialsProvider,\n ScmIntegrations,\n} from '@backstage/integration';\nimport { CatalogClient } from '@backstage/catalog-client';\nimport { createHandleAutocompleteRequest } from './autocomplete/autocomplete';\n\n/**\n * @public\n * The GitHub Module for the Scaffolder Backend\n */\nexport const githubModule = createBackendModule({\n pluginId: 'scaffolder',\n moduleId: 'github',\n register({ registerInit }) {\n registerInit({\n deps: {\n scaffolder: scaffolderActionsExtensionPoint,\n config: coreServices.rootConfig,\n discovery: coreServices.discovery,\n auth: coreServices.auth,\n autocomplete: scaffolderAutocompleteExtensionPoint,\n },\n async init({ scaffolder, config, discovery, auth, autocomplete }) {\n const integrations = ScmIntegrations.fromConfig(config);\n const githubCredentialsProvider =\n DefaultGithubCredentialsProvider.fromIntegrations(integrations);\n const catalogClient = new CatalogClient({\n discoveryApi: discovery,\n });\n\n scaffolder.addActions(\n createGithubActionsDispatchAction({\n integrations,\n githubCredentialsProvider,\n }),\n createGithubAutolinksAction({\n integrations,\n githubCredentialsProvider,\n }),\n createGithubDeployKeyAction({\n integrations,\n }),\n createGithubEnvironmentAction({\n integrations,\n catalogClient,\n auth,\n }),\n createGithubIssuesLabelAction({\n integrations,\n githubCredentialsProvider,\n }),\n createGithubRepoCreateAction({\n integrations,\n githubCredentialsProvider,\n }),\n createGithubRepoPushAction({ integrations, config }),\n createGithubWebhookAction({\n integrations,\n githubCredentialsProvider,\n }),\n createPublishGithubAction({\n integrations,\n config,\n githubCredentialsProvider,\n }),\n createPublishGithubPullRequestAction({\n integrations,\n githubCredentialsProvider,\n config,\n }),\n createGithubPagesEnableAction({\n integrations,\n githubCredentialsProvider,\n }),\n createGithubBranchProtectionAction({\n integrations,\n }),\n );\n\n autocomplete.addAutocompleteProvider({\n id: 'github',\n handler: createHandleAutocompleteRequest({ integrations }),\n });\n },\n });\n },\n});\n"],"names":["createBackendModule","scaffolderActionsExtensionPoint","coreServices","scaffolderAutocompleteExtensionPoint","autocomplete","ScmIntegrations","DefaultGithubCredentialsProvider","catalogClient","CatalogClient","createGithubActionsDispatchAction","createGithubAutolinksAction","createGithubDeployKeyAction","createGithubEnvironmentAction","createGithubIssuesLabelAction","createGithubRepoCreateAction","createGithubRepoPushAction","createGithubWebhookAction","createPublishGithubAction","createPublishGithubPullRequestAction","createGithubPagesEnableAction","createGithubBranchProtectionAction","createHandleAutocompleteRequest"],"mappings":";;;;;;;;;;;;;;;;;;;;AAgDO,MAAM,eAAeA,oCAAoB,CAAA;AAAA,EAC9C,QAAU,EAAA,YAAA;AAAA,EACV,QAAU,EAAA,QAAA;AAAA,EACV,QAAA,CAAS,EAAE,YAAA,EAAgB,EAAA;AACzB,IAAa,YAAA,CAAA;AAAA,MACX,IAAM,EAAA;AAAA,QACJ,UAAY,EAAAC,qCAAA;AAAA,QACZ,QAAQC,6BAAa,CAAA,UAAA;AAAA,QACrB,WAAWA,6BAAa,CAAA,SAAA;AAAA,QACxB,MAAMA,6BAAa,CAAA,IAAA;AAAA,QACnB,YAAc,EAAAC;AAAA,OAChB;AAAA,MACA,MAAM,KAAK,EAAE,UAAA,EAAY,QAAQ,SAAW,EAAA,IAAA,gBAAMC,gBAAgB,EAAA;AAChE,QAAM,MAAA,YAAA,GAAeC,2BAAgB,CAAA,UAAA,CAAW,MAAM,CAAA;AACtD,QAAM,MAAA,yBAAA,GACJC,4CAAiC,CAAA,gBAAA,CAAiB,YAAY,CAAA;AAChE,QAAM,MAAAC,eAAA,GAAgB,IAAIC,2BAAc,CAAA;AAAA,UACtC,YAAc,EAAA;AAAA,SACf,CAAA;AAED,QAAW,UAAA,CAAA,UAAA;AAAA,UACTC,uDAAkC,CAAA;AAAA,YAChC,YAAA;AAAA,YACA;AAAA,WACD,CAAA;AAAA,UACDC,2CAA4B,CAAA;AAAA,YAC1B,YAAA;AAAA,YACA;AAAA,WACD,CAAA;AAAA,UACDC,2CAA4B,CAAA;AAAA,YAC1B;AAAA,WACD,CAAA;AAAA,UACDC,+CAA8B,CAAA;AAAA,YAC5B,YAAA;AAAA,2BACAL,eAAA;AAAA,YACA;AAAA,WACD,CAAA;AAAA,UACDM,+CAA8B,CAAA;AAAA,YAC5B,YAAA;AAAA,YACA;AAAA,WACD,CAAA;AAAA,UACDC,6CAA6B,CAAA;AAAA,YAC3B,YAAA;AAAA,YACA;AAAA,WACD,CAAA;AAAA,UACDC,yCAA2B,CAAA,EAAE,YAAc,EAAA,MAAA,EAAQ,CAAA;AAAA,UACnDC,uCAA0B,CAAA;AAAA,YACxB,YAAA;AAAA,YACA;AAAA,WACD,CAAA;AAAA,UACDC,gCAA0B,CAAA;AAAA,YACxB,YAAA;AAAA,YACA,MAAA;AAAA,YACA;AAAA,WACD,CAAA;AAAA,UACDC,sDAAqC,CAAA;AAAA,YACnC,YAAA;AAAA,YACA,yBAAA;AAAA,YACA;AAAA,WACD,CAAA;AAAA,UACDC,+CAA8B,CAAA;AAAA,YAC5B,YAAA;AAAA,YACA;AAAA,WACD,CAAA;AAAA,UACDC,yDAAmC,CAAA;AAAA,YACjC;AAAA,WACD;AAAA,SACH;AAEA,QAAAhB,cAAA,CAAa,uBAAwB,CAAA;AAAA,UACnC,EAAI,EAAA,QAAA;AAAA,UACJ,OAAS,EAAAiB,4CAAA,CAAgC,EAAE,YAAA,EAAc;AAAA,SAC1D,CAAA;AAAA;AACH,KACD,CAAA;AAAA;AAEL,CAAC;;;;"}
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+
3
+ var errors = require('@backstage/errors');
4
+ var integration = require('@backstage/integration');
5
+ var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
6
+
7
+ const DEFAULT_TIMEOUT_MS = 6e4;
8
+ async function getOctokitOptions(options) {
9
+ const { integrations, credentialsProvider, token, repoUrl } = options;
10
+ const { host, owner, repo } = repoUrl ? pluginScaffolderNode.parseRepoUrl(repoUrl, integrations) : options;
11
+ const requestOptions = {
12
+ // set timeout to 60 seconds
13
+ timeout: DEFAULT_TIMEOUT_MS
14
+ };
15
+ const integrationConfig = integrations.github.byHost(host)?.config;
16
+ if (!integrationConfig) {
17
+ throw new errors.InputError(`No integration for host ${host}`);
18
+ }
19
+ if (token) {
20
+ return {
21
+ auth: token,
22
+ baseUrl: integrationConfig.apiBaseUrl,
23
+ previews: ["nebula-preview"],
24
+ request: requestOptions
25
+ };
26
+ }
27
+ if (!owner || !repo) {
28
+ throw new errors.InputError(
29
+ `No owner and/or owner provided, which is required if a token is not provided`
30
+ );
31
+ }
32
+ const githubCredentialsProvider = credentialsProvider ?? integration.DefaultGithubCredentialsProvider.fromIntegrations(integrations);
33
+ const { token: credentialProviderToken } = await githubCredentialsProvider.getCredentials({
34
+ url: `https://${host}/${encodeURIComponent(owner)}/${encodeURIComponent(
35
+ repo
36
+ )}`
37
+ });
38
+ if (!credentialProviderToken) {
39
+ throw new errors.InputError(
40
+ `No token available for host: ${host}, with owner ${owner}, and repo ${repo}. Make sure GitHub auth is configured correctly. See https://backstage.io/docs/auth/github/provider for more details.`
41
+ );
42
+ }
43
+ return {
44
+ auth: credentialProviderToken,
45
+ baseUrl: integrationConfig.apiBaseUrl,
46
+ previews: ["nebula-preview"]
47
+ };
48
+ }
49
+
50
+ exports.getOctokitOptions = getOctokitOptions;
51
+ //# sourceMappingURL=util.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.cjs.js","sources":["../src/util.ts"],"sourcesContent":["/*\n * Copyright 2025 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 DefaultGithubCredentialsProvider,\n GithubCredentialsProvider,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\nimport { parseRepoUrl } from '@backstage/plugin-scaffolder-node';\nimport { OctokitOptions } from '@octokit/core/dist-types/types';\n\nconst DEFAULT_TIMEOUT_MS = 60_000;\n\n/**\n * Helper for generating octokit configuration options.\n * If no token is provided, it will attempt to get a token from the credentials provider.\n * @public\n */\nexport async function getOctokitOptions(options: {\n integrations: ScmIntegrationRegistry;\n credentialsProvider?: GithubCredentialsProvider;\n token?: string;\n host: string;\n owner?: string;\n repo?: string;\n}): Promise<OctokitOptions>;\n\n/**\n * Helper for generating octokit configuration options for given repoUrl.\n * If no token is provided, it will attempt to get a token from the credentials provider.\n * @public\n * @deprecated Use options `host`, `owner` and `repo` instead of `repoUrl`.\n */\nexport async function getOctokitOptions(options: {\n integrations: ScmIntegrationRegistry;\n credentialsProvider?: GithubCredentialsProvider;\n token?: string;\n repoUrl: string;\n}): Promise<OctokitOptions>;\n\nexport async function getOctokitOptions(options: {\n integrations: ScmIntegrationRegistry;\n credentialsProvider?: GithubCredentialsProvider;\n token?: string;\n host?: string;\n owner?: string;\n repo?: string;\n repoUrl?: string;\n}): Promise<OctokitOptions> {\n const { integrations, credentialsProvider, token, repoUrl } = options;\n const { host, owner, repo } = repoUrl\n ? parseRepoUrl(repoUrl, integrations)\n : options;\n\n const requestOptions = {\n // set timeout to 60 seconds\n timeout: DEFAULT_TIMEOUT_MS,\n };\n\n const integrationConfig = integrations.github.byHost(host!)?.config;\n\n if (!integrationConfig) {\n throw new InputError(`No integration for host ${host}`);\n }\n\n // short circuit the `githubCredentialsProvider` if there is a token provided by the caller already\n if (token) {\n return {\n auth: token,\n baseUrl: integrationConfig.apiBaseUrl,\n previews: ['nebula-preview'],\n request: requestOptions,\n };\n }\n\n if (!owner || !repo) {\n throw new InputError(\n `No owner and/or owner provided, which is required if a token is not provided`,\n );\n }\n\n const githubCredentialsProvider =\n credentialsProvider ??\n DefaultGithubCredentialsProvider.fromIntegrations(integrations);\n\n const { token: credentialProviderToken } =\n await githubCredentialsProvider.getCredentials({\n url: `https://${host}/${encodeURIComponent(owner)}/${encodeURIComponent(\n repo,\n )}`,\n });\n\n if (!credentialProviderToken) {\n throw new InputError(\n `No token available for host: ${host}, with owner ${owner}, and repo ${repo}. Make sure GitHub auth is configured correctly. See https://backstage.io/docs/auth/github/provider for more details.`,\n );\n }\n\n return {\n auth: credentialProviderToken,\n baseUrl: integrationConfig.apiBaseUrl,\n previews: ['nebula-preview'],\n };\n}\n"],"names":["parseRepoUrl","InputError","DefaultGithubCredentialsProvider"],"mappings":";;;;;;AAyBA,MAAM,kBAAqB,GAAA,GAAA;AA6B3B,eAAsB,kBAAkB,OAQZ,EAAA;AAC1B,EAAA,MAAM,EAAE,YAAA,EAAc,mBAAqB,EAAA,KAAA,EAAO,SAAY,GAAA,OAAA;AAC9D,EAAM,MAAA,EAAE,MAAM,KAAO,EAAA,IAAA,KAAS,OAC1B,GAAAA,iCAAA,CAAa,OAAS,EAAA,YAAY,CAClC,GAAA,OAAA;AAEJ,EAAA,MAAM,cAAiB,GAAA;AAAA;AAAA,IAErB,OAAS,EAAA;AAAA,GACX;AAEA,EAAA,MAAM,iBAAoB,GAAA,YAAA,CAAa,MAAO,CAAA,MAAA,CAAO,IAAK,CAAG,EAAA,MAAA;AAE7D,EAAA,IAAI,CAAC,iBAAmB,EAAA;AACtB,IAAA,MAAM,IAAIC,iBAAA,CAAW,CAA2B,wBAAA,EAAA,IAAI,CAAE,CAAA,CAAA;AAAA;AAIxD,EAAA,IAAI,KAAO,EAAA;AACT,IAAO,OAAA;AAAA,MACL,IAAM,EAAA,KAAA;AAAA,MACN,SAAS,iBAAkB,CAAA,UAAA;AAAA,MAC3B,QAAA,EAAU,CAAC,gBAAgB,CAAA;AAAA,MAC3B,OAAS,EAAA;AAAA,KACX;AAAA;AAGF,EAAI,IAAA,CAAC,KAAS,IAAA,CAAC,IAAM,EAAA;AACnB,IAAA,MAAM,IAAIA,iBAAA;AAAA,MACR,CAAA,4EAAA;AAAA,KACF;AAAA;AAGF,EAAA,MAAM,yBACJ,GAAA,mBAAA,IACAC,4CAAiC,CAAA,gBAAA,CAAiB,YAAY,CAAA;AAEhE,EAAA,MAAM,EAAE,KAAO,EAAA,uBAAA,EACb,GAAA,MAAM,0BAA0B,cAAe,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