@backstage/plugin-scaffolder-backend-module-bitbucket-cloud 0.3.9 → 0.3.10
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 +9 -0
- package/dist/actions/bitbucketCloud.cjs.js +7 -2
- package/dist/actions/bitbucketCloud.cjs.js.map +1 -1
- package/dist/actions/bitbucketCloudBranchRestriction.cjs.js +7 -2
- package/dist/actions/bitbucketCloudBranchRestriction.cjs.js.map +1 -1
- package/dist/actions/bitbucketCloudPipelinesRun.cjs.js +8 -2
- package/dist/actions/bitbucketCloudPipelinesRun.cjs.js.map +1 -1
- package/dist/actions/bitbucketCloudPullRequest.cjs.js +8 -4
- package/dist/actions/bitbucketCloudPullRequest.cjs.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/module.cjs.js +14 -4
- package/dist/module.cjs.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @backstage/plugin-scaffolder-backend-module-bitbucket-cloud
|
|
2
2
|
|
|
3
|
+
## 0.3.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 818528e: Fixed a security issue in pull request workspace handling.
|
|
8
|
+
- 6fb2a41: Added support for requiring user-provided credentials for Bitbucket Cloud mutation actions when `scaffolder.requireScmUserCredentials` is enabled.
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
- @backstage/integration@2.1.1
|
|
11
|
+
|
|
3
12
|
## 0.3.9
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
|
@@ -54,7 +54,7 @@ const createRepository = async (opts) => {
|
|
|
54
54
|
return { remoteUrl, repoContentsUrl };
|
|
55
55
|
};
|
|
56
56
|
function createPublishBitbucketCloudAction(options) {
|
|
57
|
-
const { integrations, config } = options;
|
|
57
|
+
const { integrations, config, requireScmUserCredentials } = options;
|
|
58
58
|
return pluginScaffolderNode.createTemplateAction({
|
|
59
59
|
id: "publish:bitbucketCloud",
|
|
60
60
|
examples: bitbucketCloud_examples.examples,
|
|
@@ -127,8 +127,13 @@ function createPublishBitbucketCloudAction(options) {
|
|
|
127
127
|
`No matching integration configuration for host ${host}, please check your integrations config`
|
|
128
128
|
);
|
|
129
129
|
}
|
|
130
|
+
if (requireScmUserCredentials && !ctx.input.token) {
|
|
131
|
+
throw new errors.InputError(
|
|
132
|
+
`No user credentials provided for host ${host}, but scaffolder.requireScmUserCredentials is enabled`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
130
135
|
const authorization = await helpers.getAuthorizationHeader(
|
|
131
|
-
ctx.input.token ? { token: ctx.input.token } : integrationConfig.config
|
|
136
|
+
ctx.input.token || requireScmUserCredentials ? { token: ctx.input.token } : integrationConfig.config
|
|
132
137
|
);
|
|
133
138
|
const apiBaseUrl = integrationConfig.config.apiBaseUrl;
|
|
134
139
|
const { remoteUrl, repoContentsUrl } = await ctx.checkpoint({
|
|
@@ -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, getGitAuth } 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 = 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 const auth = await getGitAuth(\n ctx.input.token ? { token: ctx.input.token } : integrationConfig.config,\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","getGitAuth","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;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;AA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C,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;;;;"}
|
|
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, getGitAuth } 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 requireScmUserCredentials?: boolean;\n}) {\n const { integrations, config, requireScmUserCredentials } = 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 if (requireScmUserCredentials && !ctx.input.token) {\n throw new InputError(\n `No user credentials provided for host ${host}, but scaffolder.requireScmUserCredentials is enabled`,\n );\n }\n\n const authorization = await getAuthorizationHeader(\n ctx.input.token || requireScmUserCredentials\n ? { token: ctx.input.token }\n : 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 const auth = await getGitAuth(\n ctx.input.token ? { token: ctx.input.token } : integrationConfig.config,\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","getGitAuth","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;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,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,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;;;;"}
|
|
@@ -36,7 +36,7 @@ const createBitbucketCloudBranchRestriction = async (opts) => {
|
|
|
36
36
|
});
|
|
37
37
|
};
|
|
38
38
|
function createBitbucketCloudBranchRestrictionAction(options) {
|
|
39
|
-
const { integrations } = options;
|
|
39
|
+
const { integrations, requireScmUserCredentials } = options;
|
|
40
40
|
return pluginScaffolderNode.createTemplateAction({
|
|
41
41
|
id: "bitbucketCloud:branchRestriction:create",
|
|
42
42
|
examples: bitbucketCloudBranchRestriction_examples.examples,
|
|
@@ -86,7 +86,12 @@ function createBitbucketCloudBranchRestrictionAction(options) {
|
|
|
86
86
|
`No matching integration configuration for host ${host}, please check your integrations config`
|
|
87
87
|
);
|
|
88
88
|
}
|
|
89
|
-
|
|
89
|
+
if (requireScmUserCredentials && !token) {
|
|
90
|
+
throw new errors.InputError(
|
|
91
|
+
`No user credentials provided for host ${host}, but scaffolder.requireScmUserCredentials is enabled`
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
const authorization = token || requireScmUserCredentials ? { token } : integrationConfig.config;
|
|
90
95
|
const response = await createBitbucketCloudBranchRestriction({
|
|
91
96
|
workspace,
|
|
92
97
|
repo,
|
|
@@ -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 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
|
|
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 requireScmUserCredentials?: boolean;\n}) {\n const { integrations, requireScmUserCredentials } = 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 if (requireScmUserCredentials && !token) {\n throw new InputError(\n `No user credentials provided for host ${host}, but scaffolder.requireScmUserCredentials is enabled`,\n );\n }\n\n const authorization =\n token || requireScmUserCredentials\n ? { token: token }\n : 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,GAAwC,OAAO,IAAA,KAiB/C;AACJ,EAAA,MAAM;AAAA,IACJ,SAAA;AAAA,IACA,IAAA;AAAA,IACA,IAAA;AAAA,IACA,eAAA;AAAA,IACA,UAAA;AAAA,IACA,OAAA;AAAA,IACA,KAAA;AAAA,IACA,KAAA;AAAA,IACA,MAAA;AAAA,IACA;AAAA,GACF,GAAI,IAAA;AAEJ,EAAA,MAAM,SAAA,GAAY,MAAMA,0BAAA,CAAmB,aAAa,CAAA;AACxD,EAAA,OAAO,MAAM,SAAA,CAAU,kBAAA,CAAmB,MAAA,CAAO;AAAA,IAC/C,KAAA,EAAO;AAAA,MACL,MAAA;AAAA,MACA,KAAA;AAAA,MACA,iBAAA,EAAmB,eAAA;AAAA,MACnB,IAAA;AAAA,MACA,IAAA,EAAM,mBAAA;AAAA,MACN,KAAA,EAAO,IAAA,KAAS,MAAA,GAAS,IAAA,GAAO,KAAA;AAAA,MAChC,OAAA,EAAS,eAAA,KAAoB,MAAA,GAAS,OAAA,GAAU,MAAA;AAAA,MAChD,WAAA,EACE,eAAA,KAAoB,iBAAA,GAAoB,UAAA,GAAa;AAAA,KACzD;AAAA,IACA,SAAA,EAAW,IAAA;AAAA,IACX;AAAA,GACD,CAAA;AACH,CAAA;AAMO,SAAS,4CAA4C,OAAA,EAGzD;AACD,EAAA,MAAM,EAAE,YAAA,EAAc,yBAAA,EAA0B,GAAI,OAAA;AACpD,EAAA,OAAOC,yCAAA,CAAqB;AAAA,IAC1B,EAAA,EAAI,yCAAA;AAAA,cACJC,iDAAA;AAAA,IAC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A,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;;;;"}
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
var bitbucketCloudPipelinesRun_examples = require('./bitbucketCloudPipelinesRun.examples.cjs.js');
|
|
4
4
|
var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
|
|
5
5
|
var inputProperties = require('./inputProperties.cjs.js');
|
|
6
|
+
var errors = require('@backstage/errors');
|
|
6
7
|
var helpers = require('./helpers.cjs.js');
|
|
7
8
|
|
|
8
9
|
const id = "bitbucket:pipelines:run";
|
|
9
10
|
const createBitbucketPipelinesRunAction = (options) => {
|
|
10
|
-
const { integrations } = options;
|
|
11
|
+
const { integrations, requireScmUserCredentials } = options;
|
|
11
12
|
return pluginScaffolderNode.createTemplateAction({
|
|
12
13
|
id,
|
|
13
14
|
description: "Run a bitbucket cloud pipeline",
|
|
@@ -36,8 +37,13 @@ const createBitbucketPipelinesRunAction = (options) => {
|
|
|
36
37
|
const { workspace, repo_slug, body, token } = ctx.input;
|
|
37
38
|
const host = "bitbucket.org";
|
|
38
39
|
const integrationConfig = integrations.bitbucketCloud.byHost(host);
|
|
40
|
+
if (requireScmUserCredentials && !token) {
|
|
41
|
+
throw new errors.InputError(
|
|
42
|
+
`No user credentials provided for host ${host}, but scaffolder.requireScmUserCredentials is enabled`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
39
45
|
const authorization = await helpers.getAuthorizationHeader(
|
|
40
|
-
token ? { token } : integrationConfig.config
|
|
46
|
+
token || requireScmUserCredentials ? { token } : integrationConfig.config
|
|
41
47
|
);
|
|
42
48
|
let response;
|
|
43
49
|
try {
|
|
@@ -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 = await getAuthorizationHeader(\n token ? { token }
|
|
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 { InputError } from '@backstage/errors';\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 requireScmUserCredentials?: boolean;\n}) => {\n const { integrations, requireScmUserCredentials } = 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 if (requireScmUserCredentials && !token) {\n throw new InputError(\n `No user credentials provided for host ${host}, but scaffolder.requireScmUserCredentials is enabled`,\n );\n }\n\n const authorization = await getAuthorizationHeader(\n token || requireScmUserCredentials\n ? { token }\n : 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","InputError","getAuthorizationHeader"],"mappings":";;;;;;;;AAuBA,MAAM,EAAA,GAAK,yBAAA;AAMJ,MAAM,iCAAA,GAAoC,CAAC,OAAA,KAG5C;AACJ,EAAA,MAAM,EAAE,YAAA,EAAc,yBAAA,EAA0B,GAAI,OAAA;AACpD,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,EA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A,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;;;;"}
|
|
@@ -149,7 +149,7 @@ const getDefaultBranch = async (opts) => {
|
|
|
149
149
|
return defaultBranch;
|
|
150
150
|
};
|
|
151
151
|
function createPublishBitbucketCloudPullRequestAction(options) {
|
|
152
|
-
const { integrations, config } = options;
|
|
152
|
+
const { integrations, config, requireScmUserCredentials } = options;
|
|
153
153
|
return pluginScaffolderNode.createTemplateAction({
|
|
154
154
|
id: "publish:bitbucketCloud:pull-request",
|
|
155
155
|
examples: bitbucketCloudPullRequest_examples.examples,
|
|
@@ -208,8 +208,13 @@ function createPublishBitbucketCloudPullRequestAction(options) {
|
|
|
208
208
|
`No matching integration configuration for host ${host}, please check your integrations config`
|
|
209
209
|
);
|
|
210
210
|
}
|
|
211
|
+
if (requireScmUserCredentials && !ctx.input.token) {
|
|
212
|
+
throw new errors.InputError(
|
|
213
|
+
`No user credentials provided for host ${host}, but scaffolder.requireScmUserCredentials is enabled`
|
|
214
|
+
);
|
|
215
|
+
}
|
|
211
216
|
const authorization = await helpers.getAuthorizationHeader(
|
|
212
|
-
ctx.input.token ? { token: ctx.input.token } : integrationConfig.config
|
|
217
|
+
ctx.input.token || requireScmUserCredentials ? { token: ctx.input.token } : integrationConfig.config
|
|
213
218
|
);
|
|
214
219
|
const apiBaseUrl = integrationConfig.config.apiBaseUrl;
|
|
215
220
|
let finalTargetBranch = targetBranch;
|
|
@@ -257,8 +262,7 @@ function createPublishBitbucketCloudPullRequestAction(options) {
|
|
|
257
262
|
logger: ctx.logger,
|
|
258
263
|
ref: sourceBranch
|
|
259
264
|
});
|
|
260
|
-
fs__default.default.
|
|
261
|
-
recursive: true,
|
|
265
|
+
fs__default.default.copySync(sourceDir, tempDir, {
|
|
262
266
|
filter: pluginScaffolderNode.isNotGitDirectoryOrContents
|
|
263
267
|
});
|
|
264
268
|
await pluginScaffolderNode.addFiles({
|
|
@@ -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, getGitAuth } 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\n const options: RequestInit = {\n method: 'GET',\n headers: {\n Authorization: authorization,\n 'Content-Type': 'application/json',\n },\n };\n\n const response = await fetch(\n `${apiBaseUrl}/repositories/${workspace}/${repo}`,\n options,\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 const auth = await getGitAuth(\n ctx.input.token\n ? { token: ctx.input.token }\n : integrationConfig.config,\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","getGitAuth","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,QACN,MAAA,EAAQ;AAAA,UACN,IAAA,EAAM;AAAA;AACR,O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,UACX,MAAA,EAAQC;AAAA,SACT,CAAA;AAED,QAAA,MAAMC,6BAAA,CAAS;AAAA,UACb,GAAA,EAAK,OAAA;AAAA,UACL,IAAA;AAAA,UACA,QAAQ,GAAA,CAAI,MAAA;AAAA,UACZ,QAAA,EAAU;AAAA,SACX,CAAA;AAED,QAAA,MAAMC,wCAAA,CAAoB;AAAA,UACxB,GAAA,EAAK,OAAA;AAAA,UACL,IAAA;AAAA,UACA,QAAQ,GAAA,CAAI,MAAA;AAAA,UACZ,aAAA,EACE,WAAA,IACA,MAAA,CAAO,iBAAA,CAAkB,iCAAiC,CAAA,IAC1D,EAAA;AAAA,UACF,aAAA;AAAA,UACA,MAAA,EAAQ;AAAA,SACT,CAAA;AAAA,MACH;AAEA,MAAA,MAAM,cAAA,GAAiB,MAAM,iBAAA,CAAkB;AAAA,QAC7C,SAAA;AAAA,QACA,IAAA;AAAA,QACA,KAAA;AAAA,QACA,WAAA;AAAA,QACA,YAAA,EAAc,iBAAA;AAAA,QACd,YAAA;AAAA,QACA,aAAA;AAAA,QACA;AAAA,OACD,CAAA;AAED,MAAA,GAAA,CAAI,MAAA,CAAO,kBAAkB,cAAc,CAAA;AAAA,IAC7C;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, getGitAuth } 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\n const options: RequestInit = {\n method: 'GET',\n headers: {\n Authorization: authorization,\n 'Content-Type': 'application/json',\n },\n };\n\n const response = await fetch(\n `${apiBaseUrl}/repositories/${workspace}/${repo}`,\n options,\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 requireScmUserCredentials?: boolean;\n}) {\n const { integrations, config, requireScmUserCredentials } = 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 if (requireScmUserCredentials && !ctx.input.token) {\n throw new InputError(\n `No user credentials provided for host ${host}, but scaffolder.requireScmUserCredentials is enabled`,\n );\n }\n\n const authorization = await getAuthorizationHeader(\n ctx.input.token || requireScmUserCredentials\n ? { token: ctx.input.token }\n : 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 const auth = await getGitAuth(\n ctx.input.token\n ? { token: ctx.input.token }\n : integrationConfig.config,\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.copySync(sourceDir, tempDir, {\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","getGitAuth","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,I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AA,CAAO,kBAAkB,cAAc,CAAA;AAAA,IAC7C;AAAA,GACD,CAAA;AACH;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
|
11
11
|
declare function createPublishBitbucketCloudAction(options: {
|
|
12
12
|
integrations: ScmIntegrationRegistry;
|
|
13
13
|
config: Config;
|
|
14
|
+
requireScmUserCredentials?: boolean;
|
|
14
15
|
}): _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
15
16
|
repoUrl: string;
|
|
16
17
|
description?: string | undefined;
|
|
@@ -33,6 +34,7 @@ declare function createPublishBitbucketCloudAction(options: {
|
|
|
33
34
|
*/
|
|
34
35
|
declare const createBitbucketPipelinesRunAction: (options: {
|
|
35
36
|
integrations: ScmIntegrationRegistry;
|
|
37
|
+
requireScmUserCredentials?: boolean;
|
|
36
38
|
}) => _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
37
39
|
workspace: string;
|
|
38
40
|
repo_slug: string;
|
|
@@ -78,6 +80,7 @@ declare const createBitbucketPipelinesRunAction: (options: {
|
|
|
78
80
|
declare function createPublishBitbucketCloudPullRequestAction(options: {
|
|
79
81
|
integrations: ScmIntegrationRegistry;
|
|
80
82
|
config: Config;
|
|
83
|
+
requireScmUserCredentials?: boolean;
|
|
81
84
|
}): _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
82
85
|
repoUrl: string;
|
|
83
86
|
title: string;
|
package/dist/module.cjs.js
CHANGED
|
@@ -22,15 +22,25 @@ const bitbucketCloudModule = backendPluginApi.createBackendModule({
|
|
|
22
22
|
},
|
|
23
23
|
async init({ scaffolder, config, autocomplete: autocomplete$1 }) {
|
|
24
24
|
const integrations = integration.ScmIntegrations.fromConfig(config);
|
|
25
|
+
const requireScmUserCredentials = config.getOptionalBoolean("scaffolder.requireScmUserCredentials") ?? false;
|
|
25
26
|
scaffolder.addActions(
|
|
26
|
-
bitbucketCloud.createPublishBitbucketCloudAction({
|
|
27
|
-
|
|
27
|
+
bitbucketCloud.createPublishBitbucketCloudAction({
|
|
28
|
+
integrations,
|
|
29
|
+
config,
|
|
30
|
+
requireScmUserCredentials
|
|
31
|
+
}),
|
|
32
|
+
bitbucketCloudPipelinesRun.createBitbucketPipelinesRunAction({
|
|
33
|
+
integrations,
|
|
34
|
+
requireScmUserCredentials
|
|
35
|
+
}),
|
|
28
36
|
bitbucketCloudPullRequest.createPublishBitbucketCloudPullRequestAction({
|
|
29
37
|
integrations,
|
|
30
|
-
config
|
|
38
|
+
config,
|
|
39
|
+
requireScmUserCredentials
|
|
31
40
|
}),
|
|
32
41
|
bitbucketCloudBranchRestriction.createBitbucketCloudBranchRestrictionAction({
|
|
33
|
-
integrations
|
|
42
|
+
integrations,
|
|
43
|
+
requireScmUserCredentials
|
|
34
44
|
})
|
|
35
45
|
);
|
|
36
46
|
autocomplete$1.addAutocompleteProvider({
|
package/dist/module.cjs.js.map
CHANGED
|
@@ -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 { scaffolderAutocompleteExtensionPoint } from '@backstage/plugin-scaffolder-node/alpha';\nimport { createBitbucketCloudBranchRestrictionAction } from './actions/bitbucketCloudBranchRestriction';\nimport {\n createBitbucketPipelinesRunAction,\n createPublishBitbucketCloudAction,\n createPublishBitbucketCloudPullRequestAction,\n} from './actions';\nimport { ScmIntegrations } from '@backstage/integration';\nimport { handleAutocompleteRequest } from './autocomplete/autocomplete';\nimport { scaffolderActionsExtensionPoint } from '@backstage/plugin-scaffolder-node';\n\n/**\n * @public\n * The Bitbucket Cloud Module for the Scaffolder Backend\n */\nexport const bitbucketCloudModule = createBackendModule({\n moduleId: 'bitbucketCloud',\n pluginId: 'scaffolder',\n register({ registerInit }) {\n registerInit({\n deps: {\n scaffolder: scaffolderActionsExtensionPoint,\n autocomplete: scaffolderAutocompleteExtensionPoint,\n config: coreServices.rootConfig,\n },\n async init({ scaffolder, config, autocomplete }) {\n const integrations = ScmIntegrations.fromConfig(config);\n\n scaffolder.addActions(\n createPublishBitbucketCloudAction({
|
|
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 { scaffolderAutocompleteExtensionPoint } from '@backstage/plugin-scaffolder-node/alpha';\nimport { createBitbucketCloudBranchRestrictionAction } from './actions/bitbucketCloudBranchRestriction';\nimport {\n createBitbucketPipelinesRunAction,\n createPublishBitbucketCloudAction,\n createPublishBitbucketCloudPullRequestAction,\n} from './actions';\nimport { ScmIntegrations } from '@backstage/integration';\nimport { handleAutocompleteRequest } from './autocomplete/autocomplete';\nimport { scaffolderActionsExtensionPoint } from '@backstage/plugin-scaffolder-node';\n\n/**\n * @public\n * The Bitbucket Cloud Module for the Scaffolder Backend\n */\nexport const bitbucketCloudModule = createBackendModule({\n moduleId: 'bitbucketCloud',\n pluginId: 'scaffolder',\n register({ registerInit }) {\n registerInit({\n deps: {\n scaffolder: scaffolderActionsExtensionPoint,\n autocomplete: scaffolderAutocompleteExtensionPoint,\n config: coreServices.rootConfig,\n },\n async init({ scaffolder, config, autocomplete }) {\n const integrations = ScmIntegrations.fromConfig(config);\n const requireScmUserCredentials =\n config.getOptionalBoolean('scaffolder.requireScmUserCredentials') ??\n false;\n\n scaffolder.addActions(\n createPublishBitbucketCloudAction({\n integrations,\n config,\n requireScmUserCredentials,\n }),\n createBitbucketPipelinesRunAction({\n integrations,\n requireScmUserCredentials,\n }),\n createPublishBitbucketCloudPullRequestAction({\n integrations,\n config,\n requireScmUserCredentials,\n }),\n createBitbucketCloudBranchRestrictionAction({\n integrations,\n requireScmUserCredentials,\n }),\n );\n\n autocomplete.addAutocompleteProvider({\n id: 'bitbucket-cloud',\n handler: handleAutocompleteRequest,\n });\n },\n });\n },\n});\n"],"names":["createBackendModule","scaffolderActionsExtensionPoint","scaffolderAutocompleteExtensionPoint","coreServices","autocomplete","ScmIntegrations","createPublishBitbucketCloudAction","createBitbucketPipelinesRunAction","createPublishBitbucketCloudPullRequestAction","createBitbucketCloudBranchRestrictionAction","handleAutocompleteRequest"],"mappings":";;;;;;;;;;;;AAkCO,MAAM,uBAAuBA,oCAAA,CAAoB;AAAA,EACtD,QAAA,EAAU,gBAAA;AAAA,EACV,QAAA,EAAU,YAAA;AAAA,EACV,QAAA,CAAS,EAAE,YAAA,EAAa,EAAG;AACzB,IAAA,YAAA,CAAa;AAAA,MACX,IAAA,EAAM;AAAA,QACJ,UAAA,EAAYC,oDAAA;AAAA,QACZ,YAAA,EAAcC,0CAAA;AAAA,QACd,QAAQC,6BAAA,CAAa;AAAA,OACvB;AAAA,MACA,MAAM,IAAA,CAAK,EAAE,UAAA,EAAY,MAAA,gBAAQC,gBAAa,EAAG;AAC/C,QAAA,MAAM,YAAA,GAAeC,2BAAA,CAAgB,UAAA,CAAW,MAAM,CAAA;AACtD,QAAA,MAAM,yBAAA,GACJ,MAAA,CAAO,kBAAA,CAAmB,sCAAsC,CAAA,IAChE,KAAA;AAEF,QAAA,UAAA,CAAW,UAAA;AAAA,UACTC,gDAAA,CAAkC;AAAA,YAChC,YAAA;AAAA,YACA,MAAA;AAAA,YACA;AAAA,WACD,CAAA;AAAA,UACDC,4DAAA,CAAkC;AAAA,YAChC,YAAA;AAAA,YACA;AAAA,WACD,CAAA;AAAA,UACDC,sEAAA,CAA6C;AAAA,YAC3C,YAAA;AAAA,YACA,MAAA;AAAA,YACA;AAAA,WACD,CAAA;AAAA,UACDC,2EAAA,CAA4C;AAAA,YAC1C,YAAA;AAAA,YACA;AAAA,WACD;AAAA,SACH;AAEA,QAAAL,cAAA,CAAa,uBAAA,CAAwB;AAAA,UACnC,EAAA,EAAI,iBAAA;AAAA,UACJ,OAAA,EAASM;AAAA,SACV,CAAA;AAAA,MACH;AAAA,KACD,CAAA;AAAA,EACH;AACF,CAAC;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-scaffolder-backend-module-bitbucket-cloud",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.10",
|
|
4
4
|
"description": "The Bitbucket Cloud module for @backstage/plugin-scaffolder-backend",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "backend-plugin-module",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@backstage/backend-plugin-api": "^1.10.0",
|
|
54
54
|
"@backstage/config": "^1.3.8",
|
|
55
55
|
"@backstage/errors": "^1.3.1",
|
|
56
|
-
"@backstage/integration": "^2.1.
|
|
56
|
+
"@backstage/integration": "^2.1.1",
|
|
57
57
|
"@backstage/plugin-bitbucket-cloud-common": "^0.3.12",
|
|
58
58
|
"@backstage/plugin-scaffolder-node": "^0.13.6",
|
|
59
59
|
"bitbucket": "^2.12.0",
|