@backstage/plugin-scaffolder-backend-module-bitbucket-cloud 0.2.16-next.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,50 @@
1
1
  # @backstage/plugin-scaffolder-backend-module-bitbucket-cloud
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 37fba1d: Added support for Bitbucket Cloud OAuth. This introduces an alternative authentication method using a workspace OAuth consumer, alongside App Passwords (deprecated) and API tokens. OAuth does not require a bot or service account and avoids token expiry issues.
8
+
9
+ **BREAKING CHANGES**
10
+
11
+ - **@backstage/integration** (`src/bitbucketCloud/core.ts`)
12
+
13
+ - `getBitbucketCloudRequestOptions` now returns a `Promise` and **must** be awaited.
14
+
15
+ - **@backstage/plugin-scaffolder-backend-module-bitbucket-cloud** (`src/actions/helpers.ts`)
16
+ - `getBitbucketClient` now returns a `Promise` and **must** be awaited.
17
+ - `getAuthorizationHeader` now returns a `Promise` and **must** be awaited.
18
+
19
+ **OAuth usage example**
20
+
21
+ ```yaml
22
+ integrations:
23
+ bitbucketCloud:
24
+ - clientId: client-id
25
+ clientSecret: client-secret
26
+ ```
27
+
28
+ ### Patch Changes
29
+
30
+ - Updated dependencies
31
+ - @backstage/integration@1.19.0
32
+ - @backstage/plugin-bitbucket-cloud-common@0.3.5
33
+ - @backstage/backend-plugin-api@1.6.0
34
+ - @backstage/plugin-scaffolder-node@0.12.2
35
+
36
+ ## 0.2.16-next.1
37
+
38
+ ### Patch Changes
39
+
40
+ - Updated dependencies
41
+ - @backstage/integration@1.18.3-next.1
42
+ - @backstage/backend-plugin-api@1.6.0-next.1
43
+ - @backstage/config@1.3.6
44
+ - @backstage/errors@1.2.7
45
+ - @backstage/plugin-bitbucket-cloud-common@0.3.5-next.0
46
+ - @backstage/plugin-scaffolder-node@0.12.2-next.1
47
+
3
48
  ## 0.2.16-next.0
4
49
 
5
50
  ### Patch Changes
@@ -3,6 +3,7 @@
3
3
  var errors = require('@backstage/errors');
4
4
  var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
5
5
  var helpers = require('./helpers.cjs.js');
6
+ var integration = require('@backstage/integration');
6
7
  var bitbucketCloud_examples = require('./bitbucketCloud.examples.cjs.js');
7
8
 
8
9
  const createRepository = async (opts) => {
@@ -127,7 +128,7 @@ function createPublishBitbucketCloudAction(options) {
127
128
  `No matching integration configuration for host ${host}, please check your integrations config`
128
129
  );
129
130
  }
130
- const authorization = helpers.getAuthorizationHeader(
131
+ const authorization = await helpers.getAuthorizationHeader(
131
132
  ctx.input.token ? { token: ctx.input.token } : integrationConfig.config
132
133
  );
133
134
  const apiBaseUrl = integrationConfig.config.apiBaseUrl;
@@ -154,6 +155,15 @@ function createPublishBitbucketCloudAction(options) {
154
155
  username: "x-token-auth",
155
156
  password: ctx.input.token
156
157
  };
158
+ } else if (integrationConfig.config.clientId && integrationConfig.config.clientSecret) {
159
+ const token = await integration.getBitbucketCloudOAuthToken(
160
+ integrationConfig.config.clientId,
161
+ integrationConfig.config.clientSecret
162
+ );
163
+ auth = {
164
+ username: "x-token-auth",
165
+ password: token
166
+ };
157
167
  } else {
158
168
  if (!integrationConfig.config.username || !integrationConfig.config.appPassword) {
159
169
  throw new Error(
@@ -1 +1 @@
1
- {"version":3,"file":"bitbucketCloud.cjs.js","sources":["../../src/actions/bitbucketCloud.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 { ScmIntegrationRegistry } from '@backstage/integration';\nimport {\n createTemplateAction,\n getRepoSourceDirectory,\n initRepoAndPush,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\n\nimport { Config } from '@backstage/config';\nimport { getAuthorizationHeader } from './helpers';\nimport { examples } from './bitbucketCloud.examples';\n\nconst createRepository = async (opts: {\n workspace: string;\n project: string;\n repo: string;\n description?: string;\n repoVisibility: 'private' | 'public';\n mainBranch: string;\n authorization: string;\n apiBaseUrl: string;\n}) => {\n const {\n workspace,\n project,\n repo,\n description,\n repoVisibility,\n mainBranch,\n authorization,\n apiBaseUrl,\n } = opts;\n\n const options: RequestInit = {\n method: 'POST',\n body: JSON.stringify({\n scm: 'git',\n description: description,\n is_private: repoVisibility === 'private',\n project: { key: project },\n }),\n headers: {\n Authorization: authorization,\n 'Content-Type': 'application/json',\n },\n };\n\n let response: Response;\n try {\n response = await fetch(\n `${apiBaseUrl}/repositories/${workspace}/${repo}`,\n options,\n );\n } catch (e) {\n throw new Error(`Unable to create repository, ${e}`);\n }\n\n if (response.status !== 200) {\n throw new Error(\n `Unable to create repository, ${response.status} ${\n response.statusText\n }, ${await response.text()}`,\n );\n }\n\n const r = await response.json();\n let remoteUrl = '';\n for (const link of r.links.clone) {\n if (link.name === 'https') {\n remoteUrl = link.href;\n }\n }\n\n // \"mainbranch.name\" cannot be set neither at create nor update of the repo\n // the first pushed branch will be set as \"main branch\" then\n const repoContentsUrl = `${r.links.html.href}/src/${mainBranch}`;\n return { remoteUrl, repoContentsUrl };\n};\n\n/**\n * Creates a new action that initializes a git repository of the content in the workspace\n * and publishes it to Bitbucket Cloud.\n * @public\n */\nexport function createPublishBitbucketCloudAction(options: {\n integrations: ScmIntegrationRegistry;\n config: Config;\n}) {\n const { integrations, config } = options;\n\n return createTemplateAction({\n id: 'publish:bitbucketCloud',\n examples,\n description:\n 'Initializes a git repository of the content in the workspace, and publishes it to Bitbucket Cloud.',\n schema: {\n input: {\n repoUrl: z =>\n z.string({\n description: 'Repository Location',\n }),\n description: z =>\n z\n .string({\n description: 'Repository Description',\n })\n .optional(),\n defaultBranch: z =>\n z\n .string({\n description: `Sets the default branch on the repository. The default value is 'master'`,\n })\n .optional(),\n repoVisibility: z =>\n z\n .enum(['private', 'public'], {\n description: 'Repository Visibility',\n })\n .optional(),\n gitCommitMessage: z =>\n z\n .string({\n description: `Sets the commit message on the repository. The default value is 'initial commit'`,\n })\n .optional(),\n sourcePath: z =>\n z\n .string({\n description:\n 'Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.',\n })\n .optional(),\n token: z =>\n z\n .string({\n description:\n 'The token to use for authorization to BitBucket Cloud',\n })\n .optional(),\n signCommit: z =>\n z\n .boolean({\n description: 'Sign commit with configured PGP private key',\n })\n .optional(),\n },\n output: {\n remoteUrl: z =>\n z\n .string({\n description: 'A URL to the repository with the provider',\n })\n .optional(),\n repoContentsUrl: z =>\n z\n .string({\n description: 'A URL to the root of the repository',\n })\n .optional(),\n commitHash: z =>\n z\n .string({\n description: 'The git commit hash of the initial commit',\n })\n .optional(),\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n description,\n defaultBranch = 'master',\n gitCommitMessage,\n repoVisibility = 'private',\n signCommit,\n } = ctx.input;\n\n const { workspace, project, repo, host } = parseRepoUrl(\n repoUrl,\n integrations,\n );\n\n if (!workspace) {\n throw new InputError(\n `Invalid URL provider was included in the repo URL to create ${ctx.input.repoUrl}, missing workspace`,\n );\n }\n\n if (!project) {\n throw new InputError(\n `Invalid URL provider was included in the repo URL to create ${ctx.input.repoUrl}, missing project`,\n );\n }\n\n const integrationConfig = integrations.bitbucketCloud.byHost(host);\n if (!integrationConfig) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n const authorization = getAuthorizationHeader(\n ctx.input.token ? { token: ctx.input.token } : integrationConfig.config,\n );\n\n const apiBaseUrl = integrationConfig.config.apiBaseUrl;\n\n const { remoteUrl, repoContentsUrl } = await ctx.checkpoint({\n key: `create.repo.${host}.${repo}`,\n fn: async () =>\n await createRepository({\n authorization,\n workspace: workspace || '',\n project,\n repo,\n repoVisibility,\n mainBranch: defaultBranch,\n description,\n apiBaseUrl,\n }),\n });\n\n const gitAuthorInfo = {\n name: config.getOptionalString('scaffolder.defaultAuthor.name'),\n email: config.getOptionalString('scaffolder.defaultAuthor.email'),\n };\n\n let auth;\n\n if (ctx.input.token) {\n auth = {\n username: 'x-token-auth',\n password: ctx.input.token,\n };\n } else {\n if (\n !integrationConfig.config.username ||\n !integrationConfig.config.appPassword\n ) {\n throw new Error(\n 'Credentials for Bitbucket Cloud integration required for this action.',\n );\n }\n\n auth = {\n username: integrationConfig.config.username,\n password: integrationConfig.config.appPassword,\n };\n }\n\n const signingKey =\n integrationConfig.config.commitSigningKey ??\n config.getOptionalString('scaffolder.defaultCommitSigningKey');\n if (signCommit && !signingKey) {\n throw new Error(\n 'Signing commits is enabled but no signing key is provided in the configuration',\n );\n }\n\n const commitHash = await ctx.checkpoint({\n key: `init.repo.and.push${host}.${repo}`,\n fn: async () => {\n const commitResult = await initRepoAndPush({\n dir: getRepoSourceDirectory(\n ctx.workspacePath,\n ctx.input.sourcePath,\n ),\n remoteUrl,\n auth,\n defaultBranch,\n logger: ctx.logger,\n commitMessage:\n gitCommitMessage ||\n config.getOptionalString('scaffolder.defaultCommitMessage'),\n gitAuthorInfo,\n signingKey: signCommit ? signingKey : undefined,\n });\n return commitResult?.commitHash;\n },\n });\n\n ctx.output('commitHash', commitHash);\n ctx.output('remoteUrl', remoteUrl);\n ctx.output('repoContentsUrl', repoContentsUrl);\n },\n });\n}\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","getAuthorizationHeader","initRepoAndPush","getRepoSourceDirectory"],"mappings":";;;;;;;AA6BA,MAAM,gBAAA,GAAmB,OAAO,IAAA,KAS1B;AACJ,EAAA,MAAM;AAAA,IACJ,SAAA;AAAA,IACA,OAAA;AAAA,IACA,IAAA;AAAA,IACA,WAAA;AAAA,IACA,cAAA;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;AAAA,IAC/C;AAAA,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"bitbucketCloud.cjs.js","sources":["../../src/actions/bitbucketCloud.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 { ScmIntegrationRegistry } from '@backstage/integration';\nimport {\n createTemplateAction,\n getRepoSourceDirectory,\n initRepoAndPush,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\n\nimport { Config } from '@backstage/config';\nimport { getAuthorizationHeader } from './helpers';\nimport { getBitbucketCloudOAuthToken } from '@backstage/integration';\nimport { examples } from './bitbucketCloud.examples';\n\nconst createRepository = async (opts: {\n workspace: string;\n project: string;\n repo: string;\n description?: string;\n repoVisibility: 'private' | 'public';\n mainBranch: string;\n authorization: string;\n apiBaseUrl: string;\n}) => {\n const {\n workspace,\n project,\n repo,\n description,\n repoVisibility,\n mainBranch,\n authorization,\n apiBaseUrl,\n } = opts;\n\n const options: RequestInit = {\n method: 'POST',\n body: JSON.stringify({\n scm: 'git',\n description: description,\n is_private: repoVisibility === 'private',\n project: { key: project },\n }),\n headers: {\n Authorization: authorization,\n 'Content-Type': 'application/json',\n },\n };\n\n let response: Response;\n try {\n response = await fetch(\n `${apiBaseUrl}/repositories/${workspace}/${repo}`,\n options,\n );\n } catch (e) {\n throw new Error(`Unable to create repository, ${e}`);\n }\n\n if (response.status !== 200) {\n throw new Error(\n `Unable to create repository, ${response.status} ${\n response.statusText\n }, ${await response.text()}`,\n );\n }\n\n const r = await response.json();\n let remoteUrl = '';\n for (const link of r.links.clone) {\n if (link.name === 'https') {\n remoteUrl = link.href;\n }\n }\n\n // \"mainbranch.name\" cannot be set neither at create nor update of the repo\n // the first pushed branch will be set as \"main branch\" then\n const repoContentsUrl = `${r.links.html.href}/src/${mainBranch}`;\n return { remoteUrl, repoContentsUrl };\n};\n\n/**\n * Creates a new action that initializes a git repository of the content in the workspace\n * and publishes it to Bitbucket Cloud.\n * @public\n */\nexport function createPublishBitbucketCloudAction(options: {\n integrations: ScmIntegrationRegistry;\n config: Config;\n}) {\n const { integrations, config } = options;\n\n return createTemplateAction({\n id: 'publish:bitbucketCloud',\n examples,\n description:\n 'Initializes a git repository of the content in the workspace, and publishes it to Bitbucket Cloud.',\n schema: {\n input: {\n repoUrl: z =>\n z.string({\n description: 'Repository Location',\n }),\n description: z =>\n z\n .string({\n description: 'Repository Description',\n })\n .optional(),\n defaultBranch: z =>\n z\n .string({\n description: `Sets the default branch on the repository. The default value is 'master'`,\n })\n .optional(),\n repoVisibility: z =>\n z\n .enum(['private', 'public'], {\n description: 'Repository Visibility',\n })\n .optional(),\n gitCommitMessage: z =>\n z\n .string({\n description: `Sets the commit message on the repository. The default value is 'initial commit'`,\n })\n .optional(),\n sourcePath: z =>\n z\n .string({\n description:\n 'Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.',\n })\n .optional(),\n token: z =>\n z\n .string({\n description:\n 'The token to use for authorization to BitBucket Cloud',\n })\n .optional(),\n signCommit: z =>\n z\n .boolean({\n description: 'Sign commit with configured PGP private key',\n })\n .optional(),\n },\n output: {\n remoteUrl: z =>\n z\n .string({\n description: 'A URL to the repository with the provider',\n })\n .optional(),\n repoContentsUrl: z =>\n z\n .string({\n description: 'A URL to the root of the repository',\n })\n .optional(),\n commitHash: z =>\n z\n .string({\n description: 'The git commit hash of the initial commit',\n })\n .optional(),\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n description,\n defaultBranch = 'master',\n gitCommitMessage,\n repoVisibility = 'private',\n signCommit,\n } = ctx.input;\n\n const { workspace, project, repo, host } = parseRepoUrl(\n repoUrl,\n integrations,\n );\n\n if (!workspace) {\n throw new InputError(\n `Invalid URL provider was included in the repo URL to create ${ctx.input.repoUrl}, missing workspace`,\n );\n }\n\n if (!project) {\n throw new InputError(\n `Invalid URL provider was included in the repo URL to create ${ctx.input.repoUrl}, missing project`,\n );\n }\n\n const integrationConfig = integrations.bitbucketCloud.byHost(host);\n if (!integrationConfig) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n const authorization = await getAuthorizationHeader(\n ctx.input.token ? { token: ctx.input.token } : integrationConfig.config,\n );\n\n const apiBaseUrl = integrationConfig.config.apiBaseUrl;\n\n const { remoteUrl, repoContentsUrl } = await ctx.checkpoint({\n key: `create.repo.${host}.${repo}`,\n fn: async () =>\n await createRepository({\n authorization,\n workspace: workspace || '',\n project,\n repo,\n repoVisibility,\n mainBranch: defaultBranch,\n description,\n apiBaseUrl,\n }),\n });\n\n const gitAuthorInfo = {\n name: config.getOptionalString('scaffolder.defaultAuthor.name'),\n email: config.getOptionalString('scaffolder.defaultAuthor.email'),\n };\n\n let auth;\n\n if (ctx.input.token) {\n auth = {\n username: 'x-token-auth',\n password: ctx.input.token,\n };\n } else if (\n integrationConfig.config.clientId &&\n integrationConfig.config.clientSecret\n ) {\n const token = await getBitbucketCloudOAuthToken(\n integrationConfig.config.clientId,\n integrationConfig.config.clientSecret,\n );\n auth = {\n username: 'x-token-auth',\n password: token,\n };\n } else {\n if (\n !integrationConfig.config.username ||\n !integrationConfig.config.appPassword\n ) {\n throw new Error(\n 'Credentials for Bitbucket Cloud integration required for this action.',\n );\n }\n\n auth = {\n username: integrationConfig.config.username,\n password: integrationConfig.config.appPassword,\n };\n }\n\n const signingKey =\n integrationConfig.config.commitSigningKey ??\n config.getOptionalString('scaffolder.defaultCommitSigningKey');\n if (signCommit && !signingKey) {\n throw new Error(\n 'Signing commits is enabled but no signing key is provided in the configuration',\n );\n }\n\n const commitHash = await ctx.checkpoint({\n key: `init.repo.and.push${host}.${repo}`,\n fn: async () => {\n const commitResult = await initRepoAndPush({\n dir: getRepoSourceDirectory(\n ctx.workspacePath,\n ctx.input.sourcePath,\n ),\n remoteUrl,\n auth,\n defaultBranch,\n logger: ctx.logger,\n commitMessage:\n gitCommitMessage ||\n config.getOptionalString('scaffolder.defaultCommitMessage'),\n gitAuthorInfo,\n signingKey: signCommit ? signingKey : undefined,\n });\n return commitResult?.commitHash;\n },\n });\n\n ctx.output('commitHash', commitHash);\n ctx.output('remoteUrl', remoteUrl);\n ctx.output('repoContentsUrl', repoContentsUrl);\n },\n });\n}\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","getAuthorizationHeader","getBitbucketCloudOAuthToken","initRepoAndPush","getRepoSourceDirectory"],"mappings":";;;;;;;;AA8BA,MAAM,gBAAA,GAAmB,OAAO,IAAA,KAS1B;AACJ,EAAA,MAAM;AAAA,IACJ,SAAA;AAAA,IACA,OAAA;AAAA,IACA,IAAA;AAAA,IACA,WAAA;AAAA,IACA,cAAA;AAAA,IACA,UAAA;AAAA,IACA,aAAA;AAAA,IACA;AAAA,GACF,GAAI,IAAA;AAEJ,EAAA,MAAM,OAAA,GAAuB;AAAA,IAC3B,MAAA,EAAQ,MAAA;AAAA,IACR,IAAA,EAAM,KAAK,SAAA,CAAU;AAAA,MACnB,GAAA,EAAK,KAAA;AAAA,MACL,WAAA;AAAA,MACA,YAAY,cAAA,KAAmB,SAAA;AAAA,MAC/B,OAAA,EAAS,EAAE,GAAA,EAAK,OAAA;AAAQ,KACzB,CAAA;AAAA,IACD,OAAA,EAAS;AAAA,MACP,aAAA,EAAe,aAAA;AAAA,MACf,cAAA,EAAgB;AAAA;AAClB,GACF;AAEA,EAAA,IAAI,QAAA;AACJ,EAAA,IAAI;AACF,IAAA,QAAA,GAAW,MAAM,KAAA;AAAA,MACf,CAAA,EAAG,UAAU,CAAA,cAAA,EAAiB,SAAS,IAAI,IAAI,CAAA,CAAA;AA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O,gBAAA,IACzB,MAAA,CAAO,kBAAkB,oCAAoC,CAAA;AAC/D,MAAA,IAAI,UAAA,IAAc,CAAC,UAAA,EAAY;AAC7B,QAAA,MAAM,IAAI,KAAA;AAAA,UACR;AAAA,SACF;AAAA,MACF;AAEA,MAAA,MAAM,UAAA,GAAa,MAAM,GAAA,CAAI,UAAA,CAAW;AAAA,QACtC,GAAA,EAAK,CAAA,kBAAA,EAAqB,IAAI,CAAA,CAAA,EAAI,IAAI,CAAA,CAAA;AAAA,QACtC,IAAI,YAAY;AACd,UAAA,MAAM,YAAA,GAAe,MAAMC,oCAAA,CAAgB;AAAA,YACzC,GAAA,EAAKC,2CAAA;AAAA,cACH,GAAA,CAAI,aAAA;AAAA,cACJ,IAAI,KAAA,CAAM;AAAA,aACZ;AAAA,YACA,SAAA;AAAA,YACA,IAAA;AAAA,YACA,aAAA;AAAA,YACA,QAAQ,GAAA,CAAI,MAAA;AAAA,YACZ,aAAA,EACE,gBAAA,IACA,MAAA,CAAO,iBAAA,CAAkB,iCAAiC,CAAA;AAAA,YAC5D,aAAA;AAAA,YACA,UAAA,EAAY,aAAa,UAAA,GAAa;AAAA,WACvC,CAAA;AACD,UAAA,OAAO,YAAA,EAAc,UAAA;AAAA,QACvB;AAAA,OACD,CAAA;AAED,MAAA,GAAA,CAAI,MAAA,CAAO,cAAc,UAAU,CAAA;AACnC,MAAA,GAAA,CAAI,MAAA,CAAO,aAAa,SAAS,CAAA;AACjC,MAAA,GAAA,CAAI,MAAA,CAAO,mBAAmB,eAAe,CAAA;AAAA,IAC/C;AAAA,GACD,CAAA;AACH;;;;"}
@@ -19,7 +19,7 @@ const createBitbucketCloudBranchRestriction = async (opts) => {
19
19
  groups,
20
20
  authorization
21
21
  } = opts;
22
- const bitbucket = helpers.getBitbucketClient(authorization);
22
+ const bitbucket = await helpers.getBitbucketClient(authorization);
23
23
  return await bitbucket.branchrestrictions.create({
24
24
  _body: {
25
25
  groups,
@@ -1 +1 @@
1
- {"version":3,"file":"bitbucketCloudBranchRestriction.cjs.js","sources":["../../src/actions/bitbucketCloudBranchRestriction.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 */\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport {\n createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { InputError } from '@backstage/errors';\nimport { getBitbucketClient } from './helpers';\nimport * as inputProps from './inputProperties';\nimport { examples } from './bitbucketCloudBranchRestriction.examples';\n\nconst createBitbucketCloudBranchRestriction = async (opts: {\n workspace: string;\n repo: string;\n kind: string;\n branchMatchKind?: string;\n branchType?: string;\n pattern?: string;\n value?: number | null;\n users?: { uuid: string; type: string }[];\n groups?: { slug: string; type: string }[];\n authorization: {\n token?: string;\n username?: string;\n appPassword?: string;\n };\n}) => {\n const {\n workspace,\n repo,\n kind,\n branchMatchKind,\n branchType,\n pattern,\n value,\n users,\n groups,\n authorization,\n } = opts;\n\n const bitbucket = getBitbucketClient(authorization);\n return await bitbucket.branchrestrictions.create({\n _body: {\n groups: groups,\n users: users,\n branch_match_kind: branchMatchKind,\n kind: kind,\n type: 'branchrestriction',\n value: kind === 'push' ? null : value,\n pattern: branchMatchKind === 'glob' ? pattern : undefined,\n branch_type:\n branchMatchKind === 'branching_model' ? branchType : undefined,\n },\n repo_slug: repo,\n workspace: workspace,\n });\n};\n\n/**\n * Creates a new action that adds a branch restriction to a Bitbucket Cloud repository.\n * @public\n */\nexport function createBitbucketCloudBranchRestrictionAction(options: {\n integrations: ScmIntegrationRegistry;\n}) {\n const { integrations } = options;\n return createTemplateAction({\n id: 'bitbucketCloud:branchRestriction:create',\n examples,\n description:\n 'Creates branch restrictions for a Bitbucket Cloud repository.',\n schema: {\n input: {\n repoUrl: inputProps.repoUrl,\n kind: inputProps.restriction.kind,\n branchMatchKind: inputProps.restriction.branchMatchKind,\n branchType: inputProps.restriction.branchType,\n pattern: inputProps.restriction.pattern,\n value: inputProps.restriction.value,\n users: inputProps.restriction.users,\n groups: inputProps.restriction.groups,\n token: inputProps.token,\n },\n output: {\n json: z =>\n z\n .string({\n description: 'The response from bitbucket cloud',\n })\n .optional(),\n statusCode: z =>\n z\n .number({\n description: 'The status code of the response',\n })\n .optional(),\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n kind,\n branchMatchKind = 'branching_model',\n branchType = 'development',\n pattern = '',\n value = 1,\n users = [],\n groups = [],\n token = '',\n } = ctx.input;\n\n const { workspace, repo, host } = parseRepoUrl(repoUrl, integrations);\n\n if (!workspace) {\n throw new InputError(\n `Invalid URL provider was included in the repo URL to create ${ctx.input.repoUrl}, missing workspace`,\n );\n }\n\n const integrationConfig = integrations.bitbucketCloud.byHost(host);\n if (!integrationConfig) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n const authorization = token ? { token: token } : integrationConfig.config;\n\n const response = await createBitbucketCloudBranchRestriction({\n workspace: workspace,\n repo,\n kind: kind,\n branchMatchKind: branchMatchKind,\n branchType: branchType,\n pattern: pattern,\n value: value,\n users: users.map(user => ({ uuid: user.uuid, type: 'user' })),\n groups: groups.map(group => ({ slug: group.slug, type: 'group' })),\n authorization,\n });\n if (response.data.errors) {\n ctx.logger.error(\n `Error from Bitbucket Cloud Branch Restrictions: ${JSON.stringify(\n response.data.errors,\n )}`,\n );\n }\n ctx.logger.info(\n `Response from Bitbucket Cloud: ${JSON.stringify(response)}`,\n );\n ctx.output('statusCode', response.status);\n ctx.output('json', JSON.stringify(response));\n },\n });\n}\n"],"names":["getBitbucketClient","createTemplateAction","examples","inputProps.repo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AAA,SACxD;AAAA,MACF;AAEA,MAAA,MAAM,aAAA,GAAgB,KAAA,GAAQ,EAAE,KAAA,KAAiB,iBAAA,CAAkB,MAAA;AAEnE,MAAA,MAAM,QAAA,GAAW,MAAM,qCAAA,CAAsC;AAAA,QAC3D,SAAA;AAAA,QACA,IAAA;AAAA,QACA,IAAA;AAAA,QACA,eAAA;AAAA,QACA,UAAA;AAAA,QACA,OAAA;AAAA,QACA,KAAA;AAAA,QACA,KAAA,EAAO,KAAA,CAAM,GAAA,CAAI,CAAA,IAAA,MAAS,EAAE,MAAM,IAAA,CAAK,IAAA,EAAM,IAAA,EAAM,MAAA,EAAO,CAAE,CAAA;AAAA,QAC5D,MAAA,EAAQ,MAAA,CAAO,GAAA,CAAI,CAAA,KAAA,MAAU,EAAE,MAAM,KAAA,CAAM,IAAA,EAAM,IAAA,EAAM,OAAA,EAAQ,CAAE,CAAA;AAAA,QACjE;AAAA,OACD,CAAA;AACD,MAAA,IAAI,QAAA,CAAS,KAAK,MAAA,EAAQ;AACxB,QAAA,GAAA,CAAI,MAAA,CAAO,KAAA;AAAA,UACT,mDAAmD,IAAA,CAAK,SAAA;AAAA,YACtD,SAAS,IAAA,CAAK;AAAA,WACf,CAAA;AAAA,SACH;AAAA,MACF;AACA,MAAA,GAAA,CAAI,MAAA,CAAO,IAAA;AAAA,QACT,CAAA,+BAAA,EAAkC,IAAA,CAAK,SAAA,CAAU,QAAQ,CAAC,CAAA;AAAA,OAC5D;AACA,MAAA,GAAA,CAAI,MAAA,CAAO,YAAA,EAAc,QAAA,CAAS,MAAM,CAAA;AACxC,MAAA,GAAA,CAAI,MAAA,CAAO,MAAA,EAAQ,IAAA,CAAK,SAAA,CAAU,QAAQ,CAAC,CAAA;AAAA,IAC7C;AAAA,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"bitbucketCloudBranchRestriction.cjs.js","sources":["../../src/actions/bitbucketCloudBranchRestriction.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 */\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport {\n createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { InputError } from '@backstage/errors';\nimport { getBitbucketClient } from './helpers';\nimport * as inputProps from './inputProperties';\nimport { examples } from './bitbucketCloudBranchRestriction.examples';\n\nconst createBitbucketCloudBranchRestriction = async (opts: {\n workspace: string;\n repo: string;\n kind: string;\n branchMatchKind?: string;\n branchType?: string;\n pattern?: string;\n value?: number | null;\n users?: { uuid: string; type: string }[];\n groups?: { slug: string; type: string }[];\n authorization: {\n token?: string;\n username?: string;\n appPassword?: string;\n clientId?: string;\n clientSecret?: string;\n };\n}) => {\n const {\n workspace,\n repo,\n kind,\n branchMatchKind,\n branchType,\n pattern,\n value,\n users,\n groups,\n authorization,\n } = opts;\n\n const bitbucket = await getBitbucketClient(authorization);\n return await bitbucket.branchrestrictions.create({\n _body: {\n groups: groups,\n users: users,\n branch_match_kind: branchMatchKind,\n kind: kind,\n type: 'branchrestriction',\n value: kind === 'push' ? null : value,\n pattern: branchMatchKind === 'glob' ? pattern : undefined,\n branch_type:\n branchMatchKind === 'branching_model' ? branchType : undefined,\n },\n repo_slug: repo,\n workspace: workspace,\n });\n};\n\n/**\n * Creates a new action that adds a branch restriction to a Bitbucket Cloud repository.\n * @public\n */\nexport function createBitbucketCloudBranchRestrictionAction(options: {\n integrations: ScmIntegrationRegistry;\n}) {\n const { integrations } = options;\n return createTemplateAction({\n id: 'bitbucketCloud:branchRestriction:create',\n examples,\n description:\n 'Creates branch restrictions for a Bitbucket Cloud repository.',\n schema: {\n input: {\n repoUrl: inputProps.repoUrl,\n kind: inputProps.restriction.kind,\n branchMatchKind: inputProps.restriction.branchMatchKind,\n branchType: inputProps.restriction.branchType,\n pattern: inputProps.restriction.pattern,\n value: inputProps.restriction.value,\n users: inputProps.restriction.users,\n groups: inputProps.restriction.groups,\n token: inputProps.token,\n },\n output: {\n json: z =>\n z\n .string({\n description: 'The response from bitbucket cloud',\n })\n .optional(),\n statusCode: z =>\n z\n .number({\n description: 'The status code of the response',\n })\n .optional(),\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n kind,\n branchMatchKind = 'branching_model',\n branchType = 'development',\n pattern = '',\n value = 1,\n users = [],\n groups = [],\n token = '',\n } = ctx.input;\n\n const { workspace, repo, host } = parseRepoUrl(repoUrl, integrations);\n\n if (!workspace) {\n throw new InputError(\n `Invalid URL provider was included in the repo URL to create ${ctx.input.repoUrl}, missing workspace`,\n );\n }\n\n const integrationConfig = integrations.bitbucketCloud.byHost(host);\n if (!integrationConfig) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n const authorization = token ? { token: token } : integrationConfig.config;\n\n const response = await createBitbucketCloudBranchRestriction({\n workspace: workspace,\n repo,\n kind: kind,\n branchMatchKind: branchMatchKind,\n branchType: branchType,\n pattern: pattern,\n value: value,\n users: users.map(user => ({ uuid: user.uuid, type: 'user' })),\n groups: groups.map(group => ({ slug: group.slug, type: 'group' })),\n authorization,\n });\n if (response.data.errors) {\n ctx.logger.error(\n `Error from Bitbucket Cloud Branch Restrictions: ${JSON.stringify(\n response.data.errors,\n )}`,\n );\n }\n ctx.logger.info(\n `Response from Bitbucket Cloud: ${JSON.stringify(response)}`,\n );\n ctx.output('statusCode', response.status);\n ctx.output('json', JSON.stringify(response));\n },\n });\n}\n"],"names":["getBitbucketClient","createTemplateAction","examples","inputProps.repoUrl","inputProps.restriction","inputProps.token","parseRepoUrl","InputError"],"mappings":";;;;;;;;AAyBA,MAAM,qCAAA,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,EAAE,KAAA,KAAiB,iBAAA,CAAkB,MAAA;AAEnE,MAAA,MAAM,QAAA,GAAW,MAAM,qCAAA,CAAsC;AAAA,QAC3D,SAAA;AAAA,QACA,IAAA;AAAA,QACA,IAAA;AAAA,QACA,eAAA;AAAA,QACA,UAAA;AAAA,QACA,OAAA;AAAA,QACA,KAAA;AAAA,QACA,KAAA,EAAO,KAAA,CAAM,GAAA,CAAI,CAAA,IAAA,MAAS,EAAE,MAAM,IAAA,CAAK,IAAA,EAAM,IAAA,EAAM,MAAA,EAAO,CAAE,CAAA;AAAA,QAC5D,MAAA,EAAQ,MAAA,CAAO,GAAA,CAAI,CAAA,KAAA,MAAU,EAAE,MAAM,KAAA,CAAM,IAAA,EAAM,IAAA,EAAM,OAAA,EAAQ,CAAE,CAAA;AAAA,QACjE;AAAA,OACD,CAAA;AACD,MAAA,IAAI,QAAA,CAAS,KAAK,MAAA,EAAQ;AACxB,QAAA,GAAA,CAAI,MAAA,CAAO,KAAA;AAAA,UACT,mDAAmD,IAAA,CAAK,SAAA;AAAA,YACtD,SAAS,IAAA,CAAK;AAAA,WACf,CAAA;AAAA,SACH;AAAA,MACF;AACA,MAAA,GAAA,CAAI,MAAA,CAAO,IAAA;AAAA,QACT,CAAA,+BAAA,EAAkC,IAAA,CAAK,SAAA,CAAU,QAAQ,CAAC,CAAA;AAAA,OAC5D;AACA,MAAA,GAAA,CAAI,MAAA,CAAO,YAAA,EAAc,QAAA,CAAS,MAAM,CAAA;AACxC,MAAA,GAAA,CAAI,MAAA,CAAO,MAAA,EAAQ,IAAA,CAAK,SAAA,CAAU,QAAQ,CAAC,CAAA;AAAA,IAC7C;AAAA,GACD,CAAA;AACH;;;;"}
@@ -36,7 +36,7 @@ const createBitbucketPipelinesRunAction = (options) => {
36
36
  const { workspace, repo_slug, body, token } = ctx.input;
37
37
  const host = "bitbucket.org";
38
38
  const integrationConfig = integrations.bitbucketCloud.byHost(host);
39
- const authorization = helpers.getAuthorizationHeader(
39
+ const authorization = await helpers.getAuthorizationHeader(
40
40
  token ? { token } : integrationConfig.config
41
41
  );
42
42
  let response;
@@ -1 +1 @@
1
- {"version":3,"file":"bitbucketCloudPipelinesRun.cjs.js","sources":["../../src/actions/bitbucketCloudPipelinesRun.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 { examples } from './bitbucketCloudPipelinesRun.examples';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport * as inputProps from './inputProperties';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { getAuthorizationHeader } from './helpers';\n\nconst id = 'bitbucket:pipelines:run';\n/**\n * Creates a new action that triggers a run of a bitbucket pipeline\n *\n * @public\n */\nexport const createBitbucketPipelinesRunAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n return createTemplateAction({\n id,\n description: 'Run a bitbucket cloud pipeline',\n examples,\n schema: {\n input: {\n workspace: inputProps.workspace,\n repo_slug: inputProps.repo_slug,\n body: inputProps.pipelinesRunBody,\n token: inputProps.token,\n },\n output: {\n buildNumber: z =>\n z\n .number({\n description: 'Build number',\n })\n .optional(),\n repoUrl: z =>\n z\n .string({\n description: 'A URL to the pipeline repository',\n })\n .optional(),\n pipelinesUrl: z =>\n z\n .string({\n description: 'A URL to the pipeline',\n })\n .optional(),\n },\n },\n supportsDryRun: false,\n async handler(ctx) {\n const { workspace, repo_slug, body, token } = ctx.input;\n const host = 'bitbucket.org';\n const integrationConfig = integrations.bitbucketCloud.byHost(host);\n\n const authorization = getAuthorizationHeader(\n token ? { token } : integrationConfig!.config,\n );\n let response: Response;\n try {\n response = await fetch(\n `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/pipelines`,\n {\n method: 'POST',\n headers: {\n Authorization: authorization,\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(body) ?? {},\n },\n );\n } catch (e) {\n throw new Error(`Unable to run pipeline, ${e}`);\n }\n\n if (response.status !== 201) {\n throw new Error(\n `Unable to run pipeline, ${response.status} ${\n response.statusText\n }, ${await response.text()}`,\n );\n }\n\n const responseObject = await response.json();\n\n ctx.output('buildNumber', responseObject.build_number);\n ctx.output('repoUrl', responseObject.repository.links.html.href);\n ctx.output(\n 'pipelinesUrl',\n `${responseObject.repository.links.html.href}/pipelines`,\n );\n },\n });\n};\n"],"names":["createTemplateAction","examples","inputProps.workspace","inputProps.repo_slug","inputProps.pipelinesRunBody","inputProps.token","getAuthorizationHeader"],"mappings":";;;;;;;AAsBA,MAAM,EAAA,GAAK,yBAAA;AAMJ,MAAM,iCAAA,GAAoC,CAAC,OAAA,KAE5C;AACJ,EAAA,MAAM,EAAE,cAAa,GAAI,OAAA;AACzB,EAAA,OAAOA,yCAAA,CAAqB;AAAA,IAC1B,EAAA;AAAA,IACA,WAAA,EAAa,gCAAA;AAAA,cACbC,4CAAA;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,KAAA,EAAO;AAAA,QACL,WAAWC,yBAAW;AAAA,QACtB,WAAWC,yBAAW;AAAA,QACtB,MAAMC,gCAAW;AAAA,QACjB,OAAOC;AAAW,OACpB;AAAA,MACA,MAAA,EAAQ;AAAA,QACN,WAAA,EAAa,CAAA,CAAA,KACX,CAAA,CACG,MAAA,CAAO;AAAA,UACN,WAAA,EAAa;AAAA,SACd,EACA,QAAA,EAAS;AAAA,QACd,OAAA,EAAS,CAAA,CAAA,KACP,CAAA,CACG,MAAA,CAAO;AAAA,UACN,WAAA,EAAa;AAAA,SACd,EACA,QAAA,EAAS;AAAA,QACd,YAAA,EAAc,CA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;AAAA,MACF;AAEA,MAAA,MAAM,cAAA,GAAiB,MAAM,QAAA,CAAS,IAAA,EAAK;AAE3C,MAAA,GAAA,CAAI,MAAA,CAAO,aAAA,EAAe,cAAA,CAAe,YAAY,CAAA;AACrD,MAAA,GAAA,CAAI,OAAO,SAAA,EAAW,cAAA,CAAe,UAAA,CAAW,KAAA,CAAM,KAAK,IAAI,CAAA;AAC/D,MAAA,GAAA,CAAI,MAAA;AAAA,QACF,cAAA;AAAA,QACA,CAAA,EAAG,cAAA,CAAe,UAAA,CAAW,KAAA,CAAM,KAAK,IAAI,CAAA,UAAA;AAAA,OAC9C;AAAA,IACF;AAAA,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"bitbucketCloudPipelinesRun.cjs.js","sources":["../../src/actions/bitbucketCloudPipelinesRun.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 { examples } from './bitbucketCloudPipelinesRun.examples';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport * as inputProps from './inputProperties';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { getAuthorizationHeader } from './helpers';\n\nconst id = 'bitbucket:pipelines:run';\n/**\n * Creates a new action that triggers a run of a bitbucket pipeline\n *\n * @public\n */\nexport const createBitbucketPipelinesRunAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n return createTemplateAction({\n id,\n description: 'Run a bitbucket cloud pipeline',\n examples,\n schema: {\n input: {\n workspace: inputProps.workspace,\n repo_slug: inputProps.repo_slug,\n body: inputProps.pipelinesRunBody,\n token: inputProps.token,\n },\n output: {\n buildNumber: z =>\n z\n .number({\n description: 'Build number',\n })\n .optional(),\n repoUrl: z =>\n z\n .string({\n description: 'A URL to the pipeline repository',\n })\n .optional(),\n pipelinesUrl: z =>\n z\n .string({\n description: 'A URL to the pipeline',\n })\n .optional(),\n },\n },\n supportsDryRun: false,\n async handler(ctx) {\n const { workspace, repo_slug, body, token } = ctx.input;\n const host = 'bitbucket.org';\n const integrationConfig = integrations.bitbucketCloud.byHost(host);\n\n const authorization = await getAuthorizationHeader(\n token ? { token } : integrationConfig!.config,\n );\n let response: Response;\n try {\n response = await fetch(\n `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/pipelines`,\n {\n method: 'POST',\n headers: {\n Authorization: authorization,\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(body) ?? {},\n },\n );\n } catch (e) {\n throw new Error(`Unable to run pipeline, ${e}`);\n }\n\n if (response.status !== 201) {\n throw new Error(\n `Unable to run pipeline, ${response.status} ${\n response.statusText\n }, ${await response.text()}`,\n );\n }\n\n const responseObject = await response.json();\n\n ctx.output('buildNumber', responseObject.build_number);\n ctx.output('repoUrl', responseObject.repository.links.html.href);\n ctx.output(\n 'pipelinesUrl',\n `${responseObject.repository.links.html.href}/pipelines`,\n );\n },\n });\n};\n"],"names":["createTemplateAction","examples","inputProps.workspace","inputProps.repo_slug","inputProps.pipelinesRunBody","inputProps.token","getAuthorizationHeader"],"mappings":";;;;;;;AAsBA,MAAM,EAAA,GAAK,yBAAA;AAMJ,MAAM,iCAAA,GAAoC,CAAC,OAAA,KAE5C;AACJ,EAAA,MAAM,EAAE,cAAa,GAAI,OAAA;AACzB,EAAA,OAAOA,yCAAA,CAAqB;AAAA,IAC1B,EAAA;AAAA,IACA,WAAA,EAAa,gCAAA;AAAA,cACbC,4CAAA;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,KAAA,EAAO;AAAA,QACL,WAAWC,yBAAW;AAAA,QACtB,W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AAA,MACF,SAAS,CAAA,EAAG;AACV,QAAA,MAAM,IAAI,KAAA,CAAM,CAAA,wBAAA,EAA2B,CAAC,CAAA,CAAE,CAAA;AAAA,MAChD;AAEA,MAAA,IAAI,QAAA,CAAS,WAAW,GAAA,EAAK;AAC3B,QAAA,MAAM,IAAI,KAAA;AAAA,UACR,CAAA,wBAAA,EAA2B,QAAA,CAAS,MAAM,CAAA,CAAA,EACxC,QAAA,CAAS,UACX,CAAA,EAAA,EAAK,MAAM,QAAA,CAAS,IAAA,EAAM,CAAA;AAAA,SAC5B;AAAA,MACF;AAEA,MAAA,MAAM,cAAA,GAAiB,MAAM,QAAA,CAAS,IAAA,EAAK;AAE3C,MAAA,GAAA,CAAI,MAAA,CAAO,aAAA,EAAe,cAAA,CAAe,YAAY,CAAA;AACrD,MAAA,GAAA,CAAI,OAAO,SAAA,EAAW,cAAA,CAAe,UAAA,CAAW,KAAA,CAAM,KAAK,IAAI,CAAA;AAC/D,MAAA,GAAA,CAAI,MAAA;AAAA,QACF,cAAA;AAAA,QACA,CAAA,EAAG,cAAA,CAAe,UAAA,CAAW,KAAA,CAAM,KAAK,IAAI,CAAA,UAAA;AAAA,OAC9C;AAAA,IACF;AAAA,GACD,CAAA;AACH;;;;"}
@@ -4,6 +4,7 @@ var errors = require('@backstage/errors');
4
4
  var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
5
5
  var fs = require('fs-extra');
6
6
  var helpers = require('./helpers.cjs.js');
7
+ var integration = require('@backstage/integration');
7
8
  var bitbucketCloudPullRequest_examples = require('./bitbucketCloudPullRequest.examples.cjs.js');
8
9
 
9
10
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
@@ -213,7 +214,7 @@ function createPublishBitbucketCloudPullRequestAction(options) {
213
214
  `No matching integration configuration for host ${host}, please check your integrations config`
214
215
  );
215
216
  }
216
- const authorization = helpers.getAuthorizationHeader(
217
+ const authorization = await helpers.getAuthorizationHeader(
217
218
  ctx.input.token ? { token: ctx.input.token } : integrationConfig.config
218
219
  );
219
220
  const apiBaseUrl = integrationConfig.config.apiBaseUrl;
@@ -252,6 +253,15 @@ function createPublishBitbucketCloudPullRequestAction(options) {
252
253
  username: "x-token-auth",
253
254
  password: ctx.input.token
254
255
  };
256
+ } else if (integrationConfig.config.clientId && integrationConfig.config.clientSecret) {
257
+ const token = await integration.getBitbucketCloudOAuthToken(
258
+ integrationConfig.config.clientId,
259
+ integrationConfig.config.clientSecret
260
+ );
261
+ auth = {
262
+ username: "x-token-auth",
263
+ password: token
264
+ };
255
265
  } else {
256
266
  if (!integrationConfig.config.username || !integrationConfig.config.appPassword) {
257
267
  throw new Error(
@@ -1 +1 @@
1
- {"version":3,"file":"bitbucketCloudPullRequest.cjs.js","sources":["../../src/actions/bitbucketCloudPullRequest.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 { ScmIntegrationRegistry } from '@backstage/integration';\nimport {\n createTemplateAction,\n getRepoSourceDirectory,\n commitAndPushBranch,\n addFiles,\n cloneRepo,\n parseRepoUrl,\n isNotGitDirectoryOrContents,\n} from '@backstage/plugin-scaffolder-node';\nimport { Config } from '@backstage/config';\nimport fs from 'fs-extra';\nimport { getAuthorizationHeader } from './helpers';\nimport { examples } from './bitbucketCloudPullRequest.examples';\n\nconst createPullRequest = async (opts: {\n workspace: string;\n repo: string;\n title: string;\n description?: string;\n targetBranch: string;\n sourceBranch: string;\n authorization: string;\n apiBaseUrl: string;\n}) => {\n const {\n workspace,\n repo,\n title,\n description,\n targetBranch,\n sourceBranch,\n authorization,\n apiBaseUrl,\n } = opts;\n\n let response: Response;\n const data: RequestInit = {\n method: 'POST',\n body: JSON.stringify({\n title: title,\n summary: {\n raw: description,\n },\n state: 'OPEN',\n source: {\n branch: {\n name: sourceBranch,\n },\n },\n destination: {\n branch: {\n name: targetBranch,\n },\n },\n }),\n headers: {\n Authorization: authorization,\n 'Content-Type': 'application/json',\n },\n };\n\n try {\n response = await fetch(\n `${apiBaseUrl}/repositories/${workspace}/${repo}/pullrequests`,\n data,\n );\n } catch (e) {\n throw new Error(`Unable to create pull-requests, ${e}`);\n }\n\n if (response.status !== 201) {\n throw new Error(\n `Unable to create pull requests, ${response.status} ${\n response.statusText\n }, ${await response.text()}`,\n );\n }\n\n const r = await response.json();\n return r.links.html.href;\n};\n\nconst findBranches = async (opts: {\n workspace: string;\n repo: string;\n branchName: string;\n authorization: string;\n apiBaseUrl: string;\n}) => {\n const { workspace, repo, branchName, authorization, apiBaseUrl } = opts;\n\n let response: Response;\n const options: RequestInit = {\n method: 'GET',\n headers: {\n Authorization: authorization,\n 'Content-Type': 'application/json',\n },\n };\n\n try {\n response = await fetch(\n `${apiBaseUrl}/repositories/${workspace}/${repo}/refs/branches?q=${encodeURIComponent(\n `name = \"${branchName}\"`,\n )}`,\n options,\n );\n } catch (e) {\n throw new Error(`Unable to get branches, ${e}`);\n }\n\n if (response.status !== 200) {\n throw new Error(\n `Unable to get branches, ${response.status} ${\n response.statusText\n }, ${await response.text()}`,\n );\n }\n\n const r = await response.json();\n\n return r.values[0];\n};\n\nconst createBranch = async (opts: {\n workspace: string;\n repo: string;\n branchName: string;\n authorization: string;\n apiBaseUrl: string;\n startBranch: string;\n}) => {\n const {\n workspace,\n repo,\n branchName,\n authorization,\n apiBaseUrl,\n startBranch,\n } = opts;\n\n let response: Response;\n const options: RequestInit = {\n method: 'POST',\n body: JSON.stringify({\n name: branchName,\n target: {\n hash: startBranch,\n },\n }),\n headers: {\n Authorization: authorization,\n 'Content-Type': 'application/json',\n },\n };\n\n try {\n response = await fetch(\n `${apiBaseUrl}/repositories/${workspace}/${repo}/refs/branches`,\n options,\n );\n } catch (e) {\n throw new Error(`Unable to create branch, ${e}`);\n }\n\n if (response.status !== 201) {\n throw new Error(\n `Unable to create branch, ${response.status} ${\n response.statusText\n }, ${await response.text()}`,\n );\n }\n\n return await response.json();\n};\n\nconst getDefaultBranch = async (opts: {\n workspace: string;\n repo: string;\n authorization: string;\n apiBaseUrl: string;\n}): Promise<string> => {\n const { workspace, repo, authorization, apiBaseUrl } = opts;\n let response: Response;\n\n const options: RequestInit = {\n method: 'GET',\n headers: {\n Authorization: authorization,\n 'Content-Type': 'application/json',\n },\n };\n\n try {\n response = await fetch(\n `${apiBaseUrl}/repositories/${workspace}/${repo}`,\n options,\n );\n } catch (error) {\n throw error;\n }\n\n const { mainbranch } = await response.json();\n const defaultBranch = mainbranch.name;\n if (!defaultBranch) {\n throw new Error(`Could not fetch default branch for ${workspace}/${repo}`);\n }\n return defaultBranch;\n};\n/**\n * Creates a Bitbucket Cloud Pull Request action.\n * @public\n */\nexport function createPublishBitbucketCloudPullRequestAction(options: {\n integrations: ScmIntegrationRegistry;\n config: Config;\n}) {\n const { integrations, config } = options;\n\n return createTemplateAction({\n id: 'publish:bitbucketCloud:pull-request',\n examples,\n schema: {\n input: {\n repoUrl: z =>\n z.string({\n description: 'Repository Location',\n }),\n title: z =>\n z.string({\n description: 'The title for the pull request',\n }),\n description: z =>\n z\n .string({\n description: 'The description of the pull request',\n })\n .optional(),\n targetBranch: z =>\n z\n .string({\n description: `Branch of repository to apply changes to. The default value is 'master'`,\n })\n .optional(),\n sourceBranch: z =>\n z.string({\n description: 'Branch of repository to copy changes from',\n }),\n token: z =>\n z\n .string({\n description:\n 'The token to use for authorization to BitBucket Cloud',\n })\n .optional(),\n gitAuthorName: z =>\n z\n .string({\n description: `Sets the author name for the commit. The default value is 'Scaffolder'`,\n })\n .optional(),\n gitAuthorEmail: z =>\n z\n .string({\n description: `Sets the author email for the commit.`,\n })\n .optional(),\n },\n output: {\n pullRequestUrl: z =>\n z.string({\n description: 'A URL to the pull request with the provider',\n }),\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n title,\n description,\n targetBranch,\n sourceBranch,\n gitAuthorName,\n gitAuthorEmail,\n } = ctx.input;\n\n const { workspace, repo, host } = parseRepoUrl(repoUrl, integrations);\n\n if (!workspace) {\n throw new InputError(\n `Invalid URL provider was included in the repo URL to create ${ctx.input.repoUrl}, missing workspace`,\n );\n }\n\n const integrationConfig = integrations.bitbucketCloud.byHost(host);\n if (!integrationConfig) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n const authorization = getAuthorizationHeader(\n ctx.input.token ? { token: ctx.input.token } : integrationConfig.config,\n );\n\n const apiBaseUrl = integrationConfig.config.apiBaseUrl;\n\n let finalTargetBranch = targetBranch;\n if (!finalTargetBranch) {\n finalTargetBranch = await getDefaultBranch({\n workspace,\n repo,\n authorization,\n apiBaseUrl,\n });\n }\n\n const sourceBranchRef = await findBranches({\n workspace,\n repo,\n branchName: sourceBranch,\n authorization,\n apiBaseUrl,\n });\n\n if (!sourceBranchRef) {\n // create branch\n ctx.logger.info(\n `source branch not found -> creating branch named: ${sourceBranch}`,\n );\n\n await createBranch({\n workspace,\n repo,\n branchName: sourceBranch,\n authorization,\n apiBaseUrl,\n startBranch: finalTargetBranch,\n });\n\n const remoteUrl = `https://${host}/${workspace}/${repo}.git`;\n\n let auth;\n\n if (ctx.input.token) {\n auth = {\n username: 'x-token-auth',\n password: ctx.input.token,\n };\n } else {\n if (\n !integrationConfig.config.username ||\n !integrationConfig.config.appPassword\n ) {\n throw new Error(\n 'Credentials for Bitbucket Cloud integration required for this action.',\n );\n }\n\n auth = {\n username: integrationConfig.config.username,\n password: integrationConfig.config.appPassword,\n };\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 const tempDir = await ctx.createTemporaryDirectory();\n const sourceDir = getRepoSourceDirectory(ctx.workspacePath, undefined);\n await cloneRepo({\n url: remoteUrl,\n dir: tempDir,\n auth,\n logger: ctx.logger,\n ref: sourceBranch,\n });\n\n // copy files\n fs.cpSync(sourceDir, tempDir, {\n recursive: true,\n filter: isNotGitDirectoryOrContents,\n });\n\n await addFiles({\n dir: tempDir,\n auth,\n logger: ctx.logger,\n filepath: '.',\n });\n\n await commitAndPushBranch({\n dir: tempDir,\n auth,\n logger: ctx.logger,\n commitMessage:\n description ??\n config.getOptionalString('scaffolder.defaultCommitMessage') ??\n '',\n gitAuthorInfo,\n branch: sourceBranch,\n });\n }\n\n const pullRequestUrl = await createPullRequest({\n workspace,\n repo,\n title,\n description,\n targetBranch: finalTargetBranch,\n sourceBranch,\n authorization,\n apiBaseUrl,\n });\n\n ctx.output('pullRequestUrl', pullRequestUrl);\n },\n });\n}\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","getAuthorizationHeader","getRepoSourceDirectory","cloneRepo","fs","isNotGitDirectoryOrContents","addFiles","commitAndPushBranch"],"mappings":";;;;;;;;;;;;AAgCA,MAAM,iBAAA,GAAoB,OAAO,IAAA,KAS3B;AACJ,EAAA,MAAM;AAAA,IACJ,SAAA;AAAA,IACA,IAAA;AAAA,IACA,KAAA;AAAA,IACA,WAAA;AAAA,IACA,YAAA;AAAA,IACA,YAAA;AAAA,IACA,aAAA;AAAA,IACA;AAAA,GACF,GAAI,IAAA;AAEJ,EAAA,IAAI,QAAA;AACJ,EAAA,MAAM,IAAA,GAAoB;AAAA,IACxB,MAAA,EAAQ,MAAA;AAAA,IACR,IAAA,EAAM,KAAK,SAAA,CAAU;AAAA,MACnB,KAAA;AAAA,MACA,OAAA,EAAS;AAAA,QACP,GAAA,EAAK;AAAA,OACP;AAAA,MACA,KAAA,EAAO,MAAA;AAAA,MACP,MAAA,EAAQ;AAAA,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7C;AAAA,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"bitbucketCloudPullRequest.cjs.js","sources":["../../src/actions/bitbucketCloudPullRequest.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 { ScmIntegrationRegistry } from '@backstage/integration';\nimport {\n createTemplateAction,\n getRepoSourceDirectory,\n commitAndPushBranch,\n addFiles,\n cloneRepo,\n parseRepoUrl,\n isNotGitDirectoryOrContents,\n} from '@backstage/plugin-scaffolder-node';\nimport { Config } from '@backstage/config';\nimport fs from 'fs-extra';\nimport { getAuthorizationHeader } from './helpers';\nimport { getBitbucketCloudOAuthToken } from '@backstage/integration';\nimport { examples } from './bitbucketCloudPullRequest.examples';\n\nconst createPullRequest = async (opts: {\n workspace: string;\n repo: string;\n title: string;\n description?: string;\n targetBranch: string;\n sourceBranch: string;\n authorization: string;\n apiBaseUrl: string;\n}) => {\n const {\n workspace,\n repo,\n title,\n description,\n targetBranch,\n sourceBranch,\n authorization,\n apiBaseUrl,\n } = opts;\n\n let response: Response;\n const data: RequestInit = {\n method: 'POST',\n body: JSON.stringify({\n title: title,\n summary: {\n raw: description,\n },\n state: 'OPEN',\n source: {\n branch: {\n name: sourceBranch,\n },\n },\n destination: {\n branch: {\n name: targetBranch,\n },\n },\n }),\n headers: {\n Authorization: authorization,\n 'Content-Type': 'application/json',\n },\n };\n\n try {\n response = await fetch(\n `${apiBaseUrl}/repositories/${workspace}/${repo}/pullrequests`,\n data,\n );\n } catch (e) {\n throw new Error(`Unable to create pull-requests, ${e}`);\n }\n\n if (response.status !== 201) {\n throw new Error(\n `Unable to create pull requests, ${response.status} ${\n response.statusText\n }, ${await response.text()}`,\n );\n }\n\n const r = await response.json();\n return r.links.html.href;\n};\n\nconst findBranches = async (opts: {\n workspace: string;\n repo: string;\n branchName: string;\n authorization: string;\n apiBaseUrl: string;\n}) => {\n const { workspace, repo, branchName, authorization, apiBaseUrl } = opts;\n\n let response: Response;\n const options: RequestInit = {\n method: 'GET',\n headers: {\n Authorization: authorization,\n 'Content-Type': 'application/json',\n },\n };\n\n try {\n response = await fetch(\n `${apiBaseUrl}/repositories/${workspace}/${repo}/refs/branches?q=${encodeURIComponent(\n `name = \"${branchName}\"`,\n )}`,\n options,\n );\n } catch (e) {\n throw new Error(`Unable to get branches, ${e}`);\n }\n\n if (response.status !== 200) {\n throw new Error(\n `Unable to get branches, ${response.status} ${\n response.statusText\n }, ${await response.text()}`,\n );\n }\n\n const r = await response.json();\n\n return r.values[0];\n};\n\nconst createBranch = async (opts: {\n workspace: string;\n repo: string;\n branchName: string;\n authorization: string;\n apiBaseUrl: string;\n startBranch: string;\n}) => {\n const {\n workspace,\n repo,\n branchName,\n authorization,\n apiBaseUrl,\n startBranch,\n } = opts;\n\n let response: Response;\n const options: RequestInit = {\n method: 'POST',\n body: JSON.stringify({\n name: branchName,\n target: {\n hash: startBranch,\n },\n }),\n headers: {\n Authorization: authorization,\n 'Content-Type': 'application/json',\n },\n };\n\n try {\n response = await fetch(\n `${apiBaseUrl}/repositories/${workspace}/${repo}/refs/branches`,\n options,\n );\n } catch (e) {\n throw new Error(`Unable to create branch, ${e}`);\n }\n\n if (response.status !== 201) {\n throw new Error(\n `Unable to create branch, ${response.status} ${\n response.statusText\n }, ${await response.text()}`,\n );\n }\n\n return await response.json();\n};\n\nconst getDefaultBranch = async (opts: {\n workspace: string;\n repo: string;\n authorization: string;\n apiBaseUrl: string;\n}): Promise<string> => {\n const { workspace, repo, authorization, apiBaseUrl } = opts;\n let response: Response;\n\n const options: RequestInit = {\n method: 'GET',\n headers: {\n Authorization: authorization,\n 'Content-Type': 'application/json',\n },\n };\n\n try {\n response = await fetch(\n `${apiBaseUrl}/repositories/${workspace}/${repo}`,\n options,\n );\n } catch (error) {\n throw error;\n }\n\n const { mainbranch } = await response.json();\n const defaultBranch = mainbranch.name;\n if (!defaultBranch) {\n throw new Error(`Could not fetch default branch for ${workspace}/${repo}`);\n }\n return defaultBranch;\n};\n/**\n * Creates a Bitbucket Cloud Pull Request action.\n * @public\n */\nexport function createPublishBitbucketCloudPullRequestAction(options: {\n integrations: ScmIntegrationRegistry;\n config: Config;\n}) {\n const { integrations, config } = options;\n\n return createTemplateAction({\n id: 'publish:bitbucketCloud:pull-request',\n examples,\n schema: {\n input: {\n repoUrl: z =>\n z.string({\n description: 'Repository Location',\n }),\n title: z =>\n z.string({\n description: 'The title for the pull request',\n }),\n description: z =>\n z\n .string({\n description: 'The description of the pull request',\n })\n .optional(),\n targetBranch: z =>\n z\n .string({\n description: `Branch of repository to apply changes to. The default value is 'master'`,\n })\n .optional(),\n sourceBranch: z =>\n z.string({\n description: 'Branch of repository to copy changes from',\n }),\n token: z =>\n z\n .string({\n description:\n 'The token to use for authorization to BitBucket Cloud',\n })\n .optional(),\n gitAuthorName: z =>\n z\n .string({\n description: `Sets the author name for the commit. The default value is 'Scaffolder'`,\n })\n .optional(),\n gitAuthorEmail: z =>\n z\n .string({\n description: `Sets the author email for the commit.`,\n })\n .optional(),\n },\n output: {\n pullRequestUrl: z =>\n z.string({\n description: 'A URL to the pull request with the provider',\n }),\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n title,\n description,\n targetBranch,\n sourceBranch,\n gitAuthorName,\n gitAuthorEmail,\n } = ctx.input;\n\n const { workspace, repo, host } = parseRepoUrl(repoUrl, integrations);\n\n if (!workspace) {\n throw new InputError(\n `Invalid URL provider was included in the repo URL to create ${ctx.input.repoUrl}, missing workspace`,\n );\n }\n\n const integrationConfig = integrations.bitbucketCloud.byHost(host);\n if (!integrationConfig) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n const authorization = await getAuthorizationHeader(\n ctx.input.token ? { token: ctx.input.token } : integrationConfig.config,\n );\n\n const apiBaseUrl = integrationConfig.config.apiBaseUrl;\n\n let finalTargetBranch = targetBranch;\n if (!finalTargetBranch) {\n finalTargetBranch = await getDefaultBranch({\n workspace,\n repo,\n authorization,\n apiBaseUrl,\n });\n }\n\n const sourceBranchRef = await findBranches({\n workspace,\n repo,\n branchName: sourceBranch,\n authorization,\n apiBaseUrl,\n });\n\n if (!sourceBranchRef) {\n // create branch\n ctx.logger.info(\n `source branch not found -> creating branch named: ${sourceBranch}`,\n );\n\n await createBranch({\n workspace,\n repo,\n branchName: sourceBranch,\n authorization,\n apiBaseUrl,\n startBranch: finalTargetBranch,\n });\n\n const remoteUrl = `https://${host}/${workspace}/${repo}.git`;\n\n let auth;\n\n if (ctx.input.token) {\n auth = {\n username: 'x-token-auth',\n password: ctx.input.token,\n };\n } else if (\n integrationConfig.config.clientId &&\n integrationConfig.config.clientSecret\n ) {\n const token = await getBitbucketCloudOAuthToken(\n integrationConfig.config.clientId,\n integrationConfig.config.clientSecret,\n );\n auth = {\n username: 'x-token-auth',\n password: token,\n };\n } else {\n if (\n !integrationConfig.config.username ||\n !integrationConfig.config.appPassword\n ) {\n throw new Error(\n 'Credentials for Bitbucket Cloud integration required for this action.',\n );\n }\n\n auth = {\n username: integrationConfig.config.username,\n password: integrationConfig.config.appPassword,\n };\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 const tempDir = await ctx.createTemporaryDirectory();\n const sourceDir = getRepoSourceDirectory(ctx.workspacePath, undefined);\n await cloneRepo({\n url: remoteUrl,\n dir: tempDir,\n auth,\n logger: ctx.logger,\n ref: sourceBranch,\n });\n\n // copy files\n fs.cpSync(sourceDir, tempDir, {\n recursive: true,\n filter: isNotGitDirectoryOrContents,\n });\n\n await addFiles({\n dir: tempDir,\n auth,\n logger: ctx.logger,\n filepath: '.',\n });\n\n await commitAndPushBranch({\n dir: tempDir,\n auth,\n logger: ctx.logger,\n commitMessage:\n description ??\n config.getOptionalString('scaffolder.defaultCommitMessage') ??\n '',\n gitAuthorInfo,\n branch: sourceBranch,\n });\n }\n\n const pullRequestUrl = await createPullRequest({\n workspace,\n repo,\n title,\n description,\n targetBranch: finalTargetBranch,\n sourceBranch,\n authorization,\n apiBaseUrl,\n });\n\n ctx.output('pullRequestUrl', pullRequestUrl);\n },\n });\n}\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","getAuthorizationHeader","getBitbucketCloudOAuthToken","getRepoSourceDirectory","cloneRepo","fs","isNotGitDirectoryOrContents","addFiles","commitAndPushBranch"],"mappings":";;;;;;;;;;;;;AAiCA,MAAM,iBAAA,GAAoB,OAAO,IAAA,KAS3B;AACJ,EAAA,MAAM;AAAA,IACJ,SAAA;AAAA,IACA,IAAA;AAAA,IACA,KAAA;AAAA,IACA,WAAA;AAAA,IACA,YAAA;AAAA,IACA,YAAA;AAAA,IACA,aAAA;AAAA,IACA;AAAA,GACF,GAAI,IAAA;AAEJ,EAAA,IAAI,QAAA;AACJ,EAAA,MAAM,IAAA,GAAoB;AAAA,IACxB,MAAA,EAAQ,MAAA;AAAA,IACR,IAAA,EAAM,KAAK,SAAA,CAAU;AAAA,MACnB,KAAA;AAAA,MACA,OAAA,EAAS;AAAA,QACP,GAAA,EAAK;AAAA,OACP;AAAA,MACA,KAAA,EAAO,MAAA;AAAA,MACP,MAAA,EAAQ;AAAA,QACN,MAAA,EAAQ;AAAA,UACN,IAAA,EAAM;AAAA;AACR,OACF;AAAA,MACA,WAAA,EAAa;AAAA,QACX,MAAA,EAAQ;AAAA,UACN,IAAA,EAAM;AAAA;AACR;AACF,KACD,CAAA;AAAA,IACD,OAAA,EAAS;AAAA,MACP,aAA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AAA,QACA,aAAA;AAAA,QACA;AAAA,OACD,CAAA;AAED,MAAA,GAAA,CAAI,MAAA,CAAO,kBAAkB,cAAc,CAAA;AAAA,IAC7C;AAAA,GACD,CAAA;AACH;;;;"}
@@ -1,8 +1,20 @@
1
1
  'use strict';
2
2
 
3
3
  var bitbucket = require('bitbucket');
4
+ var integration = require('@backstage/integration');
4
5
 
5
- const getBitbucketClient = (config) => {
6
+ const getBitbucketClient = async (config) => {
7
+ if (config.clientId && config.clientSecret) {
8
+ const token = await integration.getBitbucketCloudOAuthToken(
9
+ config.clientId,
10
+ config.clientSecret
11
+ );
12
+ return new bitbucket.Bitbucket({
13
+ auth: {
14
+ token
15
+ }
16
+ });
17
+ }
6
18
  if (config.token) {
7
19
  return new bitbucket.Bitbucket({
8
20
  auth: {
@@ -18,10 +30,17 @@ const getBitbucketClient = (config) => {
18
30
  });
19
31
  }
20
32
  throw new Error(
21
- `Authorization has not been provided for Bitbucket Cloud. Please add either provide a username and token or username and appPassword to the Integrations config`
33
+ `Authorization has not been provided for Bitbucket Cloud. Please provide either OAuth credentials (clientId/clientSecret), username and token, or username and appPassword in the Integrations config`
22
34
  );
23
35
  };
24
- const getAuthorizationHeader = (config) => {
36
+ const getAuthorizationHeader = async (config) => {
37
+ if (config.clientId && config.clientSecret) {
38
+ const token = await integration.getBitbucketCloudOAuthToken(
39
+ config.clientId,
40
+ config.clientSecret
41
+ );
42
+ return `Bearer ${token}`;
43
+ }
25
44
  if (config.username && (config.token ?? config.appPassword)) {
26
45
  const buffer = Buffer.from(
27
46
  `${config.username}:${config.token ?? config.appPassword}`,
@@ -33,7 +52,7 @@ const getAuthorizationHeader = (config) => {
33
52
  return `Bearer ${config.token}`;
34
53
  }
35
54
  throw new Error(
36
- `Authorization has not been provided for Bitbucket Cloud. Please add either provide a username and token or username and appPassword to the Integrations config`
55
+ `Authorization has not been provided for Bitbucket Cloud. Please provide either OAuth credentials (clientId/clientSecret), username and token, or username and appPassword in the Integrations config`
37
56
  );
38
57
  };
39
58
 
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.cjs.js","sources":["../../src/actions/helpers.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 { Bitbucket } from 'bitbucket';\n\nexport const getBitbucketClient = (config: {\n token?: string;\n username?: string;\n appPassword?: string;\n}) => {\n if (config.token) {\n return new Bitbucket({\n auth: {\n token: config.token,\n },\n });\n } else if (config.username && config.appPassword) {\n // TODO: appPassword can be removed once fully\n // deprecated by BitBucket on 9th June 2026.\n return new Bitbucket({\n auth: {\n username: config.username,\n password: config.appPassword,\n },\n });\n }\n throw new Error(\n `Authorization has not been provided for Bitbucket Cloud. Please add either provide a username and token or username and appPassword to the Integrations config`,\n );\n};\n\nexport const getAuthorizationHeader = (config: {\n username?: string;\n appPassword?: string;\n token?: string;\n}) => {\n // TODO: appPassword can be removed once fully\n // deprecated by BitBucket on 9th June 2026.\n if (config.username && (config.token ?? config.appPassword)) {\n const buffer = Buffer.from(\n `${config.username}:${config.token ?? config.appPassword}`,\n 'utf8',\n );\n return `Basic ${buffer.toString('base64')}`;\n }\n\n if (config.token) {\n return `Bearer ${config.token}`;\n }\n\n throw new Error(\n `Authorization has not been provided for Bitbucket Cloud. Please add either provide a username and token or username and appPassword to the Integrations config`,\n );\n};\n"],"names":["Bitbucket"],"mappings":";;;;AAkBO,MAAM,kBAAA,GAAqB,CAAC,MAAA,KAI7B;AACJ,EAAA,IAAI,OAAO,KAAA,EAAO;AAChB,IAAA,OAAO,IAAIA,mBAAA,CAAU;AAAA,MACnB,IAAA,EAAM;AAAA,QACJ,OAAO,MAAA,CAAO;AAAA;AAChB,KACD,CAAA;AAAA,EACH,CAAA,MAAA,IAAW,MAAA,CAAO,QAAA,IAAY,MAAA,CAAO,WAAA,EAAa;AAGhD,IAAA,OAAO,IAAIA,mBAAA,CAAU;AAAA,MACnB,IAAA,EAAM;AAAA,QACJ,UAAU,MAAA,CAAO,QAAA;AAAA,QACjB,UAAU,MAAA,CAAO;AAAA;AACnB,KACD,CAAA;AAAA,EACH;AACA,EAAA,MAAM,IAAI,KAAA;AAAA,IACR,CAAA,8JAAA;AAAA,GACF;AACF;AAEO,MAAM,sBAAA,GAAyB,CAAC,MAAA,KAIjC;AAGJ,EAAA,IAAI,MAAA,CAAO,QAAA,KAAa,MAAA,CAAO,KAAA,IAAS,OAAO,WAAA,CAAA,EAAc;AAC3D,IAAA,MAAM,SAAS,MAAA,CAAO,IAAA;AAAA,MACpB,GAAG,MAAA,CAAO,QAAQ,IAAI,MAAA,CAAO,KAAA,IAAS,OAAO,WAAW,CAAA,CAAA;AAAA,MACxD;AAAA,KACF;AACA,IAAA,OAAO,CAAA,MAAA,EAAS,MAAA,CAAO,QAAA,CAAS,QAAQ,CAAC,CAAA,CAAA;AAAA,EAC3C;AAEA,EAAA,IAAI,OAAO,KAAA,EAAO;AAChB,IAAA,OAAO,CAAA,OAAA,EAAU,OAAO,KAAK,CAAA,CAAA;AAAA,EAC/B;AAEA,EAAA,MAAM,IAAI,KAAA;AAAA,IACR,CAAA,8JAAA;AAAA,GACF;AACF;;;;;"}
1
+ {"version":3,"file":"helpers.cjs.js","sources":["../../src/actions/helpers.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 { Bitbucket } from 'bitbucket';\nimport { getBitbucketCloudOAuthToken } from '@backstage/integration';\n\nexport const getBitbucketClient = async (config: {\n token?: string;\n username?: string;\n appPassword?: string;\n clientId?: string;\n clientSecret?: string;\n}) => {\n // If OAuth credentials provided, fetch token\n if (config.clientId && config.clientSecret) {\n const token = await getBitbucketCloudOAuthToken(\n config.clientId,\n config.clientSecret,\n );\n return new Bitbucket({\n auth: {\n token,\n },\n });\n }\n\n if (config.token) {\n return new Bitbucket({\n auth: {\n token: config.token,\n },\n });\n } else if (config.username && config.appPassword) {\n // TODO: appPassword can be removed once fully\n // deprecated by BitBucket on 9th June 2026.\n return new Bitbucket({\n auth: {\n username: config.username,\n password: config.appPassword,\n },\n });\n }\n throw new Error(\n `Authorization has not been provided for Bitbucket Cloud. Please provide either OAuth credentials (clientId/clientSecret), username and token, or username and appPassword in the Integrations config`,\n );\n};\n\nexport const getAuthorizationHeader = async (config: {\n username?: string;\n appPassword?: string;\n token?: string;\n clientId?: string;\n clientSecret?: string;\n}): Promise<string> => {\n // OAuth authentication\n if (config.clientId && config.clientSecret) {\n const token = await getBitbucketCloudOAuthToken(\n config.clientId,\n config.clientSecret,\n );\n return `Bearer ${token}`;\n }\n\n // TODO: appPassword can be removed once fully\n // deprecated by BitBucket on 9th June 2026.\n if (config.username && (config.token ?? config.appPassword)) {\n const buffer = Buffer.from(\n `${config.username}:${config.token ?? config.appPassword}`,\n 'utf8',\n );\n return `Basic ${buffer.toString('base64')}`;\n }\n\n if (config.token) {\n return `Bearer ${config.token}`;\n }\n\n throw new Error(\n `Authorization has not been provided for Bitbucket Cloud. Please provide either OAuth credentials (clientId/clientSecret), username and token, or username and appPassword in the Integrations config`,\n );\n};\n"],"names":["getBitbucketCloudOAuthToken","Bitbucket"],"mappings":";;;;;AAmBO,MAAM,kBAAA,GAAqB,OAAO,MAAA,KAMnC;AAEJ,EAAA,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AAAA,KACF;AACA,IAAA,OAAO,CAAA,MAAA,EAAS,MAAA,CAAO,QAAA,CAAS,QAAQ,CAAC,CAAA,CAAA;AAAA,EAC3C;AAEA,EAAA,IAAI,OAAO,KAAA,EAAO;AAChB,IAAA,OAAO,CAAA,OAAA,EAAU,OAAO,KAAK,CAAA,CAAA;AAAA,EAC/B;AAEA,EAAA,MAAM,IAAI,KAAA;AAAA,IACR,CAAA,oMAAA;AAAA,GACF;AACF;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-scaffolder-backend-module-bitbucket-cloud",
3
- "version": "0.2.16-next.0",
3
+ "version": "0.3.0",
4
4
  "description": "The Bitbucket Cloud module for @backstage/plugin-scaffolder-backend",
5
5
  "backstage": {
6
6
  "role": "backend-plugin-module",
@@ -50,21 +50,21 @@
50
50
  "test": "backstage-cli package test"
51
51
  },
52
52
  "dependencies": {
53
- "@backstage/backend-plugin-api": "1.5.1-next.0",
54
- "@backstage/config": "1.3.6",
55
- "@backstage/errors": "1.2.7",
56
- "@backstage/integration": "1.18.3-next.0",
57
- "@backstage/plugin-bitbucket-cloud-common": "0.3.5-next.0",
58
- "@backstage/plugin-scaffolder-node": "0.12.2-next.0",
53
+ "@backstage/backend-plugin-api": "^1.6.0",
54
+ "@backstage/config": "^1.3.6",
55
+ "@backstage/errors": "^1.2.7",
56
+ "@backstage/integration": "^1.19.0",
57
+ "@backstage/plugin-bitbucket-cloud-common": "^0.3.5",
58
+ "@backstage/plugin-scaffolder-node": "^0.12.2",
59
59
  "bitbucket": "^2.12.0",
60
60
  "fs-extra": "^11.2.0",
61
61
  "yaml": "^2.0.0",
62
62
  "zod": "^3.22.4"
63
63
  },
64
64
  "devDependencies": {
65
- "@backstage/backend-test-utils": "1.10.1-next.0",
66
- "@backstage/cli": "0.34.6-next.0",
67
- "@backstage/plugin-scaffolder-node-test-utils": "0.3.6-next.0",
65
+ "@backstage/backend-test-utils": "^1.10.2",
66
+ "@backstage/cli": "^0.35.0",
67
+ "@backstage/plugin-scaffolder-node-test-utils": "^0.3.6",
68
68
  "msw": "^1.0.0"
69
69
  }
70
70
  }