@backstage/plugin-scaffolder-backend-module-bitbucket-cloud 0.2.10-next.0 → 0.2.10-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @backstage/plugin-scaffolder-backend-module-bitbucket-cloud
2
2
 
3
+ ## 0.2.10-next.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @backstage/plugin-scaffolder-node@0.9.0-next.2
9
+ - @backstage/backend-plugin-api@1.4.0-next.1
10
+ - @backstage/config@1.3.2
11
+ - @backstage/errors@1.2.7
12
+ - @backstage/integration@1.17.0
13
+ - @backstage/plugin-bitbucket-cloud-common@0.3.0
14
+
15
+ ## 0.2.10-next.1
16
+
17
+ ### Patch Changes
18
+
19
+ - ca9fdc0: Migrate `bitbucket-cloud` to new actions format
20
+ - 280611d: Fix `bitbucketCloudBranchRestrictions` API calls to accept null to prevent 400 errors for some branch restriction kinds defined.
21
+ - Updated dependencies
22
+ - @backstage/plugin-scaffolder-node@0.8.3-next.1
23
+ - @backstage/backend-plugin-api@1.4.0-next.1
24
+ - @backstage/config@1.3.2
25
+ - @backstage/errors@1.2.7
26
+ - @backstage/integration@1.17.0
27
+ - @backstage/plugin-bitbucket-cloud-common@0.3.0
28
+
3
29
  ## 0.2.10-next.0
4
30
 
5
31
  ### Patch Changes
@@ -61,65 +61,41 @@ function createPublishBitbucketCloudAction(options) {
61
61
  description: "Initializes a git repository of the content in the workspace, and publishes it to Bitbucket Cloud.",
62
62
  schema: {
63
63
  input: {
64
- type: "object",
65
- required: ["repoUrl"],
66
- properties: {
67
- repoUrl: {
68
- title: "Repository Location",
69
- type: "string"
70
- },
71
- description: {
72
- title: "Repository Description",
73
- type: "string"
74
- },
75
- repoVisibility: {
76
- title: "Repository Visibility",
77
- type: "string",
78
- enum: ["private", "public"]
79
- },
80
- defaultBranch: {
81
- title: "Default Branch",
82
- type: "string",
83
- description: `Sets the default branch on the repository. The default value is 'master'`
84
- },
85
- gitCommitMessage: {
86
- title: "Git Commit Message",
87
- type: "string",
88
- description: `Sets the commit message on the repository. The default value is 'initial commit'`
89
- },
90
- sourcePath: {
91
- title: "Source Path",
92
- description: "Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.",
93
- type: "string"
94
- },
95
- token: {
96
- title: "Authentication Token",
97
- type: "string",
98
- description: "The token to use for authorization to BitBucket Cloud"
99
- },
100
- signCommit: {
101
- title: "Sign commit",
102
- type: "boolean",
103
- description: "Sign commit with configured PGP private key"
104
- }
105
- }
64
+ repoUrl: (z) => z.string({
65
+ description: "Repository Location"
66
+ }),
67
+ description: (z) => z.string({
68
+ description: "Repository Description"
69
+ }).optional(),
70
+ defaultBranch: (z) => z.string({
71
+ description: `Sets the default branch on the repository. The default value is 'master'`
72
+ }).optional(),
73
+ repoVisibility: (z) => z.enum(["private", "public"], {
74
+ description: "Repository Visibility"
75
+ }).optional(),
76
+ gitCommitMessage: (z) => z.string({
77
+ description: `Sets the commit message on the repository. The default value is 'initial commit'`
78
+ }).optional(),
79
+ sourcePath: (z) => z.string({
80
+ description: "Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository."
81
+ }).optional(),
82
+ token: (z) => z.string({
83
+ description: "The token to use for authorization to BitBucket Cloud"
84
+ }).optional(),
85
+ signCommit: (z) => z.boolean({
86
+ description: "Sign commit with configured PGP private key"
87
+ }).optional()
106
88
  },
107
89
  output: {
108
- type: "object",
109
- properties: {
110
- remoteUrl: {
111
- title: "A URL to the repository with the provider",
112
- type: "string"
113
- },
114
- repoContentsUrl: {
115
- title: "A URL to the root of the repository",
116
- type: "string"
117
- },
118
- commitHash: {
119
- title: "The git commit hash of the initial commit",
120
- type: "string"
121
- }
122
- }
90
+ remoteUrl: (z) => z.string({
91
+ description: "A URL to the repository with the provider"
92
+ }).optional(),
93
+ repoContentsUrl: (z) => z.string({
94
+ description: "A URL to the root of the repository"
95
+ }).optional(),
96
+ commitHash: (z) => z.string({
97
+ description: "The git commit hash of the initial commit"
98
+ }).optional()
123
99
  }
124
100
  },
125
101
  async handler(ctx) {
@@ -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 repoUrl: string;\n description?: string;\n defaultBranch?: string;\n repoVisibility?: 'private' | 'public';\n gitCommitMessage?: string;\n sourcePath?: string;\n token?: string;\n signCommit?: boolean;\n }>({\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 type: 'object',\n required: ['repoUrl'],\n properties: {\n repoUrl: {\n title: 'Repository Location',\n type: 'string',\n },\n description: {\n title: 'Repository Description',\n type: 'string',\n },\n repoVisibility: {\n title: 'Repository Visibility',\n type: 'string',\n enum: ['private', 'public'],\n },\n defaultBranch: {\n title: 'Default Branch',\n type: 'string',\n description: `Sets the default branch on the repository. The default value is 'master'`,\n },\n gitCommitMessage: {\n title: 'Git Commit Message',\n type: 'string',\n description: `Sets the commit message on the repository. The default value is 'initial commit'`,\n },\n sourcePath: {\n title: 'Source Path',\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 type: 'string',\n },\n token: {\n title: 'Authentication Token',\n type: 'string',\n description:\n 'The token to use for authorization to BitBucket Cloud',\n },\n signCommit: {\n title: 'Sign commit',\n type: 'boolean',\n description: 'Sign commit with configured PGP private key',\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n remoteUrl: {\n title: 'A URL to the repository with the provider',\n type: 'string',\n },\n repoContentsUrl: {\n title: 'A URL to the root of the repository',\n type: 'string',\n },\n commitHash: {\n title: 'The git commit hash of the initial commit',\n type: 'string',\n },\n },\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,IAS1B,KAAA;AACJ,EAAM,MAAA;AAAA,IACJ,SAAA;AAAA,IACA,OAAA;AAAA,IACA,IAAA;AAAA,IACA,WAAA;AAAA,IACA,cAAA;AAAA,IACA,UAAA;AAAA,IACA,aAAA;AAAA,IACA;AAAA,GACE,GAAA,IAAA;AAEJ,EAAA,MAAM,OAAuB,GAAA;AAAA,IAC3B,MAAQ,EAAA,MAAA;AAAA,IACR,IAAA,EAAM,KAAK,SAAU,CAAA;AAAA,MACnB,GAAK,EAAA,KAAA;AAAA,MACL,WAAA;AAAA,MACA,YAAY,cAAmB,KAAA,SAAA;AAAA,MAC/B,OAAA,EAAS,EAAE,GAAA,EAAK,OAAQ;AAAA,KACzB,CAAA;AAAA,IACD,OAAS,EAAA;AAAA,MACP,aAAe,EAAA,aAAA;AAAA,MACf,cAAgB,EAAA;AAAA;AAClB,GACF;AAEA,EAAI,IAAA,QAAA;AACJ,EAAI,IAAA;AACF,IAAA,QAAA,GAAW,MAAM,KAAA;AAAA,MACf,CAAG,EAAA,UAAU,CAAiB,cAAA,EAAA,SAAS,IAAI,IAAI,CAAA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AAA,QACtC,IAAI,YAAY;AACd,UAAM,MAAA,YAAA,GAAe,MAAMC,oCAAgB,CAAA;AAAA,YACzC,GAAK,EAAAC,2CAAA;AAAA,cACH,GAAI,CAAA,aAAA;AAAA,cACJ,IAAI,KAAM,CAAA;AAAA,aACZ;AAAA,YACA,SAAA;AAAA,YACA,IAAA;AAAA,YACA,aAAA;AAAA,YACA,QAAQ,GAAI,CAAA,MAAA;AAAA,YACZ,aACE,EAAA,gBAAA,IACA,MAAO,CAAA,iBAAA,CAAkB,iCAAiC,CAAA;AAAA,YAC5D,aAAA;AAAA,YACA,UAAA,EAAY,aAAa,UAAa,GAAA,KAAA;AAAA,WACvC,CAAA;AACD,UAAA,OAAO,YAAc,EAAA,UAAA;AAAA;AACvB,OACD,CAAA;AAED,MAAI,GAAA,CAAA,MAAA,CAAO,cAAc,UAAU,CAAA;AACnC,MAAI,GAAA,CAAA,MAAA,CAAO,aAAa,SAAS,CAAA;AACjC,MAAI,GAAA,CAAA,MAAA,CAAO,mBAAmB,eAAe,CAAA;AAAA;AAC/C,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 { 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,IAS1B,KAAA;AACJ,EAAM,MAAA;AAAA,IACJ,SAAA;AAAA,IACA,OAAA;AAAA,IACA,IAAA;AAAA,IACA,WAAA;AAAA,IACA,cAAA;AAAA,IACA,UAAA;AAAA,IACA,aAAA;AAAA,IACA;AAAA,GACE,GAAA,IAAA;AAEJ,EAAA,MAAM,OAAuB,GAAA;AAAA,IAC3B,MAAQ,EAAA,MAAA;AAAA,IACR,IAAA,E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AA;AAAA,SACrC;AAAA;AAGF,MAAA,MAAM,aACJ,iBAAkB,CAAA,MAAA,CAAO,gBACzB,IAAA,MAAA,CAAO,kBAAkB,oCAAoC,CAAA;AAC/D,MAAI,IAAA,UAAA,IAAc,CAAC,UAAY,EAAA;AAC7B,QAAA,MAAM,IAAI,KAAA;AAAA,UACR;AAAA,SACF;AAAA;AAGF,MAAM,MAAA,UAAA,GAAa,MAAM,GAAA,CAAI,UAAW,CAAA;AAAA,QACtC,GAAK,EAAA,CAAA,kBAAA,EAAqB,IAAI,CAAA,CAAA,EAAI,IAAI,CAAA,CAAA;AAAA,QACtC,IAAI,YAAY;AACd,UAAM,MAAA,YAAA,GAAe,MAAMC,oCAAgB,CAAA;AAAA,YACzC,GAAK,EAAAC,2CAAA;AAAA,cACH,GAAI,CAAA,aAAA;AAAA,cACJ,IAAI,KAAM,CAAA;AAAA,aACZ;AAAA,YACA,SAAA;AAAA,YACA,IAAA;AAAA,YACA,aAAA;AAAA,YACA,QAAQ,GAAI,CAAA,MAAA;AAAA,YACZ,aACE,EAAA,gBAAA,IACA,MAAO,CAAA,iBAAA,CAAkB,iCAAiC,CAAA;AAAA,YAC5D,aAAA;AAAA,YACA,UAAA,EAAY,aAAa,UAAa,GAAA,KAAA;AAAA,WACvC,CAAA;AACD,UAAA,OAAO,YAAc,EAAA,UAAA;AAAA;AACvB,OACD,CAAA;AAED,MAAI,GAAA,CAAA,MAAA,CAAO,cAAc,UAAU,CAAA;AACnC,MAAI,GAAA,CAAA,MAAA,CAAO,aAAa,SAAS,CAAA;AACjC,MAAI,GAAA,CAAA,MAAA,CAAO,mBAAmB,eAAe,CAAA;AAAA;AAC/C,GACD,CAAA;AACH;;;;"}
@@ -43,32 +43,23 @@ function createBitbucketCloudBranchRestrictionAction(options) {
43
43
  description: "Creates branch restrictions for a Bitbucket Cloud repository.",
44
44
  schema: {
45
45
  input: {
46
- type: "object",
47
- required: ["repoUrl", "kind"],
48
- properties: {
49
- repoUrl: inputProperties.repoUrl,
50
- kind: inputProperties.restriction.kind,
51
- branchMatchKind: inputProperties.restriction.branchMatchKind,
52
- branchType: inputProperties.restriction.branchType,
53
- pattern: inputProperties.restriction.pattern,
54
- value: inputProperties.restriction.value,
55
- users: inputProperties.restriction.users,
56
- groups: inputProperties.restriction.groups,
57
- token: inputProperties.token
58
- }
46
+ repoUrl: inputProperties.repoUrl,
47
+ kind: inputProperties.restriction.kind,
48
+ branchMatchKind: inputProperties.restriction.branchMatchKind,
49
+ branchType: inputProperties.restriction.branchType,
50
+ pattern: inputProperties.restriction.pattern,
51
+ value: inputProperties.restriction.value,
52
+ users: inputProperties.restriction.users,
53
+ groups: inputProperties.restriction.groups,
54
+ token: inputProperties.token
59
55
  },
60
56
  output: {
61
- type: "object",
62
- properties: {
63
- json: {
64
- title: "The response from bitbucket cloud",
65
- type: "string"
66
- },
67
- statusCode: {
68
- title: "The status code of the response",
69
- type: "number"
70
- }
71
- }
57
+ json: (z) => z.string({
58
+ description: "The response from bitbucket cloud"
59
+ }).optional(),
60
+ statusCode: (z) => z.number({
61
+ description: "The status code of the response"
62
+ }).optional()
72
63
  }
73
64
  },
74
65
  async handler(ctx) {
@@ -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;\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 repoUrl: string;\n kind: string;\n branchMatchKind?: string;\n branchType?: string;\n pattern?: string;\n value?: number;\n users?: { uuid: string }[];\n groups?: { slug: string }[];\n token?: string;\n }>({\n id: 'bitbucketCloud:branchRestriction:create',\n examples,\n description:\n 'Creates branch restrictions for a Bitbucket Cloud repository.',\n schema: {\n input: {\n type: 'object',\n required: ['repoUrl', 'kind'],\n properties: {\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 },\n output: {\n type: 'object',\n properties: {\n json: {\n title: 'The response from bitbucket cloud',\n type: 'string',\n },\n statusCode: {\n title: 'The status code of the response',\n type: 'number',\n },\n },\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,GAAwC,OAAO,IAe/C,KAAA;AACJ,EAAM,MAAA;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,GACE,GAAA,IAAA;AAEJ,EAAM,MAAA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A,IAAA;AAAA,QACA,eAAA;AAAA,QACA,UAAA;AAAA,QACA,OAAA;AAAA,QACA,KAAA;AAAA,QACA,KAAA,EAAO,KAAM,CAAA,GAAA,CAAI,CAAS,IAAA,MAAA,EAAE,MAAM,IAAK,CAAA,IAAA,EAAM,IAAM,EAAA,MAAA,EAAS,CAAA,CAAA;AAAA,QAC5D,MAAA,EAAQ,MAAO,CAAA,GAAA,CAAI,CAAU,KAAA,MAAA,EAAE,MAAM,KAAM,CAAA,IAAA,EAAM,IAAM,EAAA,OAAA,EAAU,CAAA,CAAA;AAAA,QACjE;AAAA,OACD,CAAA;AACD,MAAI,IAAA,QAAA,CAAS,KAAK,MAAQ,EAAA;AACxB,QAAA,GAAA,CAAI,MAAO,CAAA,KAAA;AAAA,UACT,mDAAmD,IAAK,CAAA,SAAA;AAAA,YACtD,SAAS,IAAK,CAAA;AAAA,WACf,CAAA;AAAA,SACH;AAAA;AAEF,MAAA,GAAA,CAAI,MAAO,CAAA,IAAA;AAAA,QACT,CAAkC,+BAAA,EAAA,IAAA,CAAK,SAAU,CAAA,QAAQ,CAAC,CAAA;AAAA,OAC5D;AACA,MAAI,GAAA,CAAA,MAAA,CAAO,YAAc,EAAA,QAAA,CAAS,MAAM,CAAA;AACxC,MAAA,GAAA,CAAI,MAAO,CAAA,MAAA,EAAQ,IAAK,CAAA,SAAA,CAAU,QAAQ,CAAC,CAAA;AAAA;AAC7C,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 };\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.repoUrl","inputProps.restriction","inputProps.token","parseRepoUrl","InputError"],"mappings":";;;;;;;;AAyBA,MAAM,qCAAA,GAAwC,OAAO,IAe/C,KAAA;AACJ,EAAM,MAAA;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,GACE,GAAA,IAAA;AAEJ,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AM,CAAA,GAAA,CAAI,CAAS,IAAA,MAAA,EAAE,MAAM,IAAK,CAAA,IAAA,EAAM,IAAM,EAAA,MAAA,EAAS,CAAA,CAAA;AAAA,QAC5D,MAAA,EAAQ,MAAO,CAAA,GAAA,CAAI,CAAU,KAAA,MAAA,EAAE,MAAM,KAAM,CAAA,IAAA,EAAM,IAAM,EAAA,OAAA,EAAU,CAAA,CAAA;AAAA,QACjE;AAAA,OACD,CAAA;AACD,MAAI,IAAA,QAAA,CAAS,KAAK,MAAQ,EAAA;AACxB,QAAA,GAAA,CAAI,MAAO,CAAA,KAAA;AAAA,UACT,mDAAmD,IAAK,CAAA,SAAA;AAAA,YACtD,SAAS,IAAK,CAAA;AAAA,WACf,CAAA;AAAA,SACH;AAAA;AAEF,MAAA,GAAA,CAAI,MAAO,CAAA,IAAA;AAAA,QACT,CAAkC,+BAAA,EAAA,IAAA,CAAK,SAAU,CAAA,QAAQ,CAAC,CAAA;AAAA,OAC5D;AACA,MAAI,GAAA,CAAA,MAAA,CAAO,YAAc,EAAA,QAAA,CAAS,MAAM,CAAA;AACxC,MAAA,GAAA,CAAI,MAAO,CAAA,MAAA,EAAQ,IAAK,CAAA,SAAA,CAAU,QAAQ,CAAC,CAAA;AAAA;AAC7C,GACD,CAAA;AACH;;;;"}
@@ -14,31 +14,21 @@ const createBitbucketPipelinesRunAction = (options) => {
14
14
  examples: bitbucketCloudPipelinesRun_examples.examples,
15
15
  schema: {
16
16
  input: {
17
- type: "object",
18
- required: ["workspace", "repo_slug"],
19
- properties: {
20
- workspace: inputProperties.workspace,
21
- repo_slug: inputProperties.repo_slug,
22
- body: inputProperties.pipelinesRunBody,
23
- token: inputProperties.token
24
- }
17
+ workspace: inputProperties.workspace,
18
+ repo_slug: inputProperties.repo_slug,
19
+ body: inputProperties.pipelinesRunBody,
20
+ token: inputProperties.token
25
21
  },
26
22
  output: {
27
- type: "object",
28
- properties: {
29
- buildNumber: {
30
- title: "Build number",
31
- type: "number"
32
- },
33
- repoUrl: {
34
- title: "A URL to the pipeline repository",
35
- type: "string"
36
- },
37
- repoContentsUrl: {
38
- title: "A URL to the pipeline",
39
- type: "string"
40
- }
41
- }
23
+ buildNumber: (z) => z.number({
24
+ description: "Build number"
25
+ }).optional(),
26
+ repoUrl: (z) => z.string({
27
+ description: "A URL to the pipeline repository"
28
+ }).optional(),
29
+ pipelinesUrl: (z) => z.string({
30
+ description: "A URL to the pipeline"
31
+ }).optional()
42
32
  }
43
33
  },
44
34
  supportsDryRun: false,
@@ -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 {\n workspace: string;\n repo_slug: string;\n body?: object;\n token?: string;\n },\n {\n buildNumber: number;\n repoUrl: string;\n pipelinesUrl: string;\n }\n >({\n id,\n description: 'Run a bitbucket cloud pipeline',\n examples,\n schema: {\n input: {\n type: 'object',\n required: ['workspace', 'repo_slug'],\n properties: {\n workspace: inputProps.workspace,\n repo_slug: inputProps.repo_slug,\n body: inputProps.pipelinesRunBody,\n token: inputProps.token,\n },\n },\n output: {\n type: 'object',\n properties: {\n buildNumber: {\n title: 'Build number',\n type: 'number',\n },\n repoUrl: {\n title: 'A URL to the pipeline repository',\n type: 'string',\n },\n repoContentsUrl: {\n title: 'A URL to the pipeline',\n type: 'string',\n },\n },\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,EAAK,GAAA,yBAAA;AAME,MAAA,iCAAA,GAAoC,CAAC,OAE5C,KAAA;AACJ,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AACzB,EAAA,OAAOA,yCAYL,CAAA;AAAA,IACA,EAAA;AAAA,IACA,WAAa,EAAA,gCAAA;AAAA,cACbC,4CAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,IA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,cACR,cAAgB,EAAA;AAAA,aAClB;AAAA,YACA,IAAM,EAAA,IAAA,CAAK,SAAU,CAAA,IAAI,KAAK;AAAC;AACjC,SACF;AAAA,eACO,CAAG,EAAA;AACV,QAAA,MAAM,IAAI,KAAA,CAAM,CAA2B,wBAAA,EAAA,CAAC,CAAE,CAAA,CAAA;AAAA;AAGhD,MAAI,IAAA,QAAA,CAAS,WAAW,GAAK,EAAA;AAC3B,QAAA,MAAM,IAAI,KAAA;AAAA,UACR,CAAA,wBAAA,EAA2B,QAAS,CAAA,MAAM,CACxC,CAAA,EAAA,QAAA,CAAS,UACX,CAAK,EAAA,EAAA,MAAM,QAAS,CAAA,IAAA,EAAM,CAAA;AAAA,SAC5B;AAAA;AAGF,MAAM,MAAA,cAAA,GAAiB,MAAM,QAAA,CAAS,IAAK,EAAA;AAE3C,MAAI,GAAA,CAAA,MAAA,CAAO,aAAe,EAAA,cAAA,CAAe,YAAY,CAAA;AACrD,MAAA,GAAA,CAAI,OAAO,SAAW,EAAA,cAAA,CAAe,UAAW,CAAA,KAAA,CAAM,KAAK,IAAI,CAAA;AAC/D,MAAI,GAAA,CAAA,MAAA;AAAA,QACF,cAAA;AAAA,QACA,CAAG,EAAA,cAAA,CAAe,UAAW,CAAA,KAAA,CAAM,KAAK,IAAI,CAAA,UAAA;AAAA,OAC9C;AAAA;AACF,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 = 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,EAAK,GAAA,yBAAA;AAME,MAAA,iCAAA,GAAoC,CAAC,OAE5C,KAAA;AACJ,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AACzB,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAA;AAAA,IACA,WAAa,EAAA,gCAAA;AAAA,cACbC,4CAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,WAAWC,yBAAW;AAAA,QACtB,WAAWC,yBAAW;AAAA,QACtB,MAAMC,gCAAW;AAAA,QACjB,OAAOC;AAAW,OACpB;AAAA,MACA,MAAQ,EAAA;AAAA,QACN,WAAA,EAAa,CACX,CAAA,KAAA,CAAA,CACG,MAAO,CAAA;AAAA,UACN,WAAa,EAAA;AAAA,SACd,EACA,QAAS,EAAA;AAAA,QACd,OAAA,EAAS,CACP,CAAA,KAAA,CAAA,CACG,MAAO,CAAA;AAAA,UACN,WAAa,EAAA;AAAA,SACd,EACA,QAAS,EAAA;AAAA,QACd,YAAA,EAAc,CACZ,CAAA,KAAA,CAAA,CACG,MAAO,CAAA;AAAA,UACN,WAAa,EAAA;AAAA,SACd,EACA,QAAS;AAAA;AAChB,KACF;AAAA,IACA,cAAgB,EAAA,KAAA;AAAA,IAChB,MAAM,QAAQ,GAAK,EAAA;AACjB,MAAA,MAAM,EAAE,SAAW,EAAA,SAAA,EAAW,IAAM,EAAA,KAAA,KAAU,GAAI,CAAA,KAAA;AAClD,MAAA,MAAM,IAAO,GAAA,eAAA;AACb,MAAA,MAAM,iBAAoB,GAAA,YAAA,CAAa,cAAe,CAAA,MAAA,CAAO,IAAI,CAAA;AAEjE,MAAA,MAAM,aAAgB,GAAAC,8BAAA;AAAA,QACpB,KAAQ,GAAA,EAAE,KAAM,E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{
160
160
  examples: bitbucketCloudPullRequest_examples.examples,
161
161
  schema: {
162
162
  input: {
163
- type: "object",
164
- required: ["repoUrl", "title", "sourceBranch"],
165
- properties: {
166
- repoUrl: {
167
- title: "Repository Location",
168
- type: "string"
169
- },
170
- title: {
171
- title: "Pull Request title",
172
- type: "string",
173
- description: "The title for the pull request"
174
- },
175
- description: {
176
- title: "Pull Request Description",
177
- type: "string",
178
- description: "The description of the pull request"
179
- },
180
- targetBranch: {
181
- title: "Target Branch",
182
- type: "string",
183
- description: `Branch of repository to apply changes to. The default value is 'master'`
184
- },
185
- sourceBranch: {
186
- title: "Source Branch",
187
- type: "string",
188
- description: "Branch of repository to copy changes from"
189
- },
190
- token: {
191
- title: "Authorization Token",
192
- type: "string",
193
- description: "The token to use for authorization to BitBucket Cloud"
194
- },
195
- gitAuthorName: {
196
- title: "Author Name",
197
- type: "string",
198
- description: `Sets the author name for the commit. The default value is 'Scaffolder'`
199
- },
200
- gitAuthorEmail: {
201
- title: "Author Email",
202
- type: "string",
203
- description: `Sets the author email for the commit.`
204
- }
205
- }
163
+ repoUrl: (z) => z.string({
164
+ description: "Repository Location"
165
+ }),
166
+ title: (z) => z.string({
167
+ description: "The title for the pull request"
168
+ }),
169
+ description: (z) => z.string({
170
+ description: "The description of the pull request"
171
+ }).optional(),
172
+ targetBranch: (z) => z.string({
173
+ description: `Branch of repository to apply changes to. The default value is 'master'`
174
+ }).optional(),
175
+ sourceBranch: (z) => z.string({
176
+ description: "Branch of repository to copy changes from"
177
+ }),
178
+ token: (z) => z.string({
179
+ description: "The token to use for authorization to BitBucket Cloud"
180
+ }).optional(),
181
+ gitAuthorName: (z) => z.string({
182
+ description: `Sets the author name for the commit. The default value is 'Scaffolder'`
183
+ }).optional(),
184
+ gitAuthorEmail: (z) => z.string({
185
+ description: `Sets the author email for the commit.`
186
+ }).optional()
206
187
  },
207
188
  output: {
208
- type: "object",
209
- properties: {
210
- pullRequestUrl: {
211
- title: "A URL to the pull request with the provider",
212
- type: "string"
213
- }
214
- }
189
+ pullRequestUrl: (z) => z.string({
190
+ description: "A URL to the pull request with the provider"
191
+ })
215
192
  }
216
193
  },
217
194
  async handler(ctx) {
@@ -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};\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};\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 repoUrl: string;\n title: string;\n description?: string;\n targetBranch?: string;\n sourceBranch: string;\n token?: string;\n gitAuthorName?: string;\n gitAuthorEmail?: string;\n }>({\n id: 'publish:bitbucketCloud:pull-request',\n examples,\n schema: {\n input: {\n type: 'object',\n required: ['repoUrl', 'title', 'sourceBranch'],\n properties: {\n repoUrl: {\n title: 'Repository Location',\n type: 'string',\n },\n title: {\n title: 'Pull Request title',\n type: 'string',\n description: 'The title for the pull request',\n },\n description: {\n title: 'Pull Request Description',\n type: 'string',\n description: 'The description of the pull request',\n },\n targetBranch: {\n title: 'Target Branch',\n type: 'string',\n description: `Branch of repository to apply changes to. The default value is 'master'`,\n },\n sourceBranch: {\n title: 'Source Branch',\n type: 'string',\n description: 'Branch of repository to copy changes from',\n },\n token: {\n title: 'Authorization Token',\n type: 'string',\n description:\n 'The token to use for authorization to BitBucket Cloud',\n },\n gitAuthorName: {\n title: 'Author Name',\n type: 'string',\n description: `Sets the author name for the commit. The default value is 'Scaffolder'`,\n },\n gitAuthorEmail: {\n title: 'Author Email',\n type: 'string',\n description: `Sets the author email for the commit.`,\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n pullRequestUrl: {\n title: 'A URL to the pull request with the provider',\n type: 'string',\n },\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,IAS3B,KAAA;AACJ,EAAM,MAAA;AAAA,IACJ,SAAA;AAAA,IACA,IAAA;AAAA,IACA,KAAA;AAAA,IACA,WAAA;AAAA,IACA,YAAA;AAAA,IACA,YAAA;AAAA,IACA,aAAA;AAAA,IACA;AAAA,GACE,GAAA,IAAA;AAEJ,EAAI,IAAA,QAAA;AACJ,EAAA,MAAM,IAAoB,GAAA;AAAA,IACxB,MAAQ,EAAA,MAAA;AAAA,IACR,IAAA,EAAM,KAAK,SAAU,CAAA;AAAA,MACnB,KAAA;AAAA,MACA,OAAS,EAAA;AAAA,QACP,GAAK,EAAA;AAAA,OACP;AAAA,MACA,KAAO,EAAA,MAAA;AAAA,MACP,MAAQ,EAAA;AAAA,QACN,MAAQ,EAAA;AAAA,UACN,IAAM,EAAA;AAAA;AACR,OACF;AAAA,MACA,WAAa,EAAA;AAAA,QACX,MAA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A;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 { 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,IAS3B,KAAA;AACJ,EAAM,MAAA;AAAA,IACJ,SAAA;AAAA,IACA,IAAA;AAAA,IACA,KAAA;AAAA,IACA,WAAA;AAAA,IACA,YAAA;AAAA,IACA,YAAA;AAAA,IACA,aAAA;AAAA,IACA;AAAA,GACE,GAAA,IAAA;AAEJ,EAAI,IAAA,QAAA;AACJ,EAAA,MAAM,IAAoB,GAAA;AAAA,IACxB,MAAQ,EAAA,MAAA;AAAA,IACR,IAAA,EAAM,KAAK,SAAU,CAAA;AAAA,MACnB,KAAA;AAAA,MACA,OAAS,EAAA;AAAA,QACP,GAAK,EAAA;AAAA,OACP;AAAA,MACA,KAAO,EAAA,MAAA;AAAA,MACP,MAAQ,EAAA;AAAA,QACN,MAAQ,EAAA;AAAA,UACN,IAAM,EAAA;AAAA;AACR,OACF;AAAA,MACA,WAAa,EAAA;AAAA,QACX,MAAQ,EAAA;AAAA,UACN,IAAM,EAAA;AAAA;AACR;AACF,KACD,CAAA;AAAA,IACD,OAAS,EAAA;AAAA,MACP,aAAe,EAAA,aAAA;AAAA,MACf,cAAgB,EAAA;AAAA;AAClB,GACF;AAEA,EAAI,IAAA;AACF,IAAA,QAAA,GAAW,MAAM,KAAA;AAAA,MACf,CAAG,EAAA,UAAU,CAAiB,cAAA,EAAA,SAAS,IAAI,IAAI,CAAA,aAAA,CAAA;AAAA,MAC/C;AAAA,KACF;AAAA,WACO,CAA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AAC;AAAA,SACT,CAAA;AAED,QAAA,MAAMC,6BAAS,CAAA;AAAA,UACb,GAAK,EAAA,OAAA;AAAA,UACL,IAAA;AAAA,UACA,QAAQ,GAAI,CAAA,MAAA;AAAA,UACZ,QAAU,EAAA;AAAA,SACX,CAAA;AAED,QAAA,MAAMC,wCAAoB,CAAA;AAAA,UACxB,GAAK,EAAA,OAAA;AAAA,UACL,IAAA;AAAA,UACA,QAAQ,GAAI,CAAA,MAAA;AAAA,UACZ,aACE,EAAA,WAAA,IACA,MAAO,CAAA,iBAAA,CAAkB,iCAAiC,CAC1D,IAAA,EAAA;AAAA,UACF,aAAA;AAAA,UACA,MAAQ,EAAA;AAAA,SACT,CAAA;AAAA;AAGH,MAAM,MAAA,cAAA,GAAiB,MAAM,iBAAkB,CAAA;AAAA,QAC7C,SAAA;AAAA,QACA,IAAA;AAAA,QACA,KAAA;AAAA,QACA,WAAA;AAAA,QACA,YAAc,EAAA,iBAAA;AAAA,QACd,YAAA;AAAA,QACA,aAAA;AAAA,QACA;AAAA,OACD,CAAA;AAED,MAAI,GAAA,CAAA,MAAA,CAAO,kBAAkB,cAAc,CAAA;AAAA;AAC7C,GACD,CAAA;AACH;;;;"}
@@ -1,139 +1,92 @@
1
1
  'use strict';
2
2
 
3
- const repoUrl = {
4
- title: "Repository Location",
5
- description: `Accepts the format 'bitbucket.org?repo=reponame&workspace=workspace&project=project' where 'reponame' is the new repository name`,
6
- type: "string"
7
- };
8
- const workspace = {
9
- title: "Workspace",
10
- description: `The workspace name`,
11
- type: "string"
12
- };
13
- const repo_slug = {
14
- title: "Repository name",
15
- description: "The repository name",
16
- type: "string"
17
- };
18
- const ref_type = {
19
- title: "ref_type",
20
- type: "string"
21
- };
22
- const type = {
23
- title: "type",
24
- type: "string"
25
- };
26
- const ref_name = {
27
- title: "ref_name",
28
- type: "string"
29
- };
30
- const source = {
31
- title: "source",
32
- type: "string"
33
- };
34
- const destination = {
35
- title: "destination",
36
- type: "string"
37
- };
38
- const hash = {
39
- title: "hash",
40
- type: "string"
41
- };
42
- const pattern = {
43
- title: "pattern",
44
- type: "string"
45
- };
46
- const id = {
47
- title: "id",
48
- type: "string"
49
- };
50
- const key = {
51
- title: "key",
52
- type: "string"
53
- };
54
- const value = {
55
- title: "value",
56
- type: "string"
57
- };
58
- const secured = {
59
- title: "secured",
60
- type: "boolean"
61
- };
62
- const token = {
63
- title: "Authentication Token",
64
- type: "string",
3
+ const repoUrl = (z) => z.string({
4
+ description: `Accepts the format 'bitbucket.org?repo=reponame&workspace=workspace&project=project' where 'reponame' is the new repository name`
5
+ });
6
+ const workspace = (z) => z.string({
7
+ description: "The workspace name"
8
+ });
9
+ const repo_slug = (z) => z.string({
10
+ description: "The repository name"
11
+ });
12
+ const ref_type = (z) => z.string({
13
+ description: "ref_type"
14
+ });
15
+ const type = (z) => z.string({
16
+ description: "type"
17
+ });
18
+ const ref_name = (z) => z.string({
19
+ description: "ref_name"
20
+ });
21
+ const source = (z) => z.string({
22
+ description: "source"
23
+ });
24
+ const destination = (z) => z.string({
25
+ description: "destination"
26
+ });
27
+ const hash = (z) => z.string({
28
+ description: "hash"
29
+ });
30
+ const pattern = (z) => z.string({
31
+ description: "pattern"
32
+ });
33
+ const id = (z) => z.string({
34
+ description: "id"
35
+ });
36
+ const key = (z) => z.string({
37
+ description: "key"
38
+ });
39
+ const value = (z) => z.string({
40
+ description: "value"
41
+ });
42
+ const secured = (z) => z.boolean({
43
+ description: "secured"
44
+ });
45
+ const token = (z) => z.string({
65
46
  description: "The token to use for authorization to BitBucket Cloud"
66
- };
67
- const destination_commit = {
68
- title: "destination_commit",
69
- type: "object",
70
- properties: {
71
- hash
72
- }
73
- };
74
- const commit = {
75
- title: "commit",
76
- type: "object",
77
- properties: {
78
- type,
79
- hash
80
- }
81
- };
82
- const selector = {
83
- title: "selector",
84
- type: "object",
85
- properties: {
86
- type,
87
- pattern
88
- }
89
- };
90
- const pull_request = {
91
- title: "pull_request",
92
- type: "object",
93
- properties: {
94
- id
95
- }
96
- };
97
- const pipelinesRunBody = {
98
- title: "Request Body",
99
- description: "Request body properties: see Bitbucket Cloud Rest API documentation for more details",
100
- type: "object",
101
- properties: {
102
- target: {
103
- title: "target",
104
- type: "object",
105
- properties: {
106
- ref_type,
107
- type,
108
- ref_name,
109
- source,
110
- destination,
111
- destination_commit,
112
- commit,
113
- selector,
114
- pull_request
115
- }
116
- },
117
- variables: {
118
- title: "variables",
119
- type: "array",
120
- items: {
121
- type: "object",
122
- properties: {
123
- key,
124
- value,
125
- secured
126
- }
127
- }
128
- }
47
+ }).optional();
48
+ const destination_commit = (z) => z.object({
49
+ hash: hash(z)
50
+ });
51
+ const commit = (z) => z.object({
52
+ type: type(z),
53
+ hash: hash(z)
54
+ });
55
+ const selector = (z) => z.object({
56
+ type: type(z),
57
+ pattern: pattern(z)
58
+ });
59
+ const pull_request = (z) => z.object({
60
+ id: id(z)
61
+ });
62
+ const pipelinesRunBody = (z) => z.object(
63
+ {
64
+ target: z.object({
65
+ ref_type: ref_type(z).optional(),
66
+ type: type(z).optional(),
67
+ ref_name: ref_name(z).optional(),
68
+ source: source(z).optional(),
69
+ destination: destination(z).optional(),
70
+ destination_commit: destination_commit(z).optional(),
71
+ commit: commit(z).optional(),
72
+ selector: selector(z).optional(),
73
+ pull_request: pull_request(z).optional()
74
+ }).optional(),
75
+ variables: z.array(
76
+ z.object({
77
+ key: key(z),
78
+ value: value(z),
79
+ secured: secured(z)
80
+ })
81
+ ).optional()
82
+ },
83
+ {
84
+ description: "Request body properties: see Bitbucket Cloud Rest API documentation for more details"
129
85
  }
130
- };
86
+ ).optional();
131
87
  const restriction = {
132
- kind: {
133
- title: "kind",
134
- description: "The kind of restriction.",
135
- type: "string",
136
- enum: [
88
+ kind: (z) => z.enum(
89
+ [
137
90
  "push",
138
91
  "force",
139
92
  "delete",
@@ -150,67 +103,46 @@ const restriction = {
150
103
  "require_all_dependencies_merged",
151
104
  "enforce_merge_checks",
152
105
  "allow_auto_merge_when_builds_pass"
153
- ]
154
- },
155
- branchMatchKind: {
156
- title: "branch_match_kind",
157
- description: "The branch match kind.",
158
- type: "string",
159
- enum: ["glob", "branching_model"]
160
- },
161
- branchType: {
162
- title: "branch_type",
163
- description: "The branch type. When branchMatchKind is set to branching_model, this field is required.",
164
- type: "string",
165
- enum: [
166
- "feature",
167
- "bugfix",
168
- "release",
169
- "hotfix",
170
- "development",
171
- "production"
172
- ]
173
- },
174
- pattern: {
175
- title: "pattern",
176
- description: "The pattern to match branches against. This field is required when branchMatchKind is set to glob.",
177
- type: "string"
178
- },
179
- value: {
180
- title: "value",
181
- description: "The value of the restriction. This field is required when kind is one of require_approvals_to_merge / require_default_reviewer_approvals_to_merge / require_passing_builds_to_merge / require_commits_behind.",
182
- type: "number"
183
- },
184
- users: {
185
- title: "users",
186
- description: "Names of users that can bypass the push / restrict_merges restriction kind. For any other kind, this field will be ignored.",
187
- type: "array",
188
- items: {
189
- type: "object",
190
- properties: {
191
- uuid: {
192
- title: "uuid",
193
- description: 'The UUID of the user in the format "{a-b-c-d}".',
194
- type: "string"
195
- }
196
- }
106
+ ],
107
+ {
108
+ description: "The kind of restriction."
197
109
  }
198
- },
199
- groups: {
200
- title: "groups",
201
- description: "Names of groups that can bypass the push / restrict_merges restriction kind. For any other kind, this field will be ignored.",
202
- type: "array",
203
- items: {
204
- type: "object",
205
- properties: {
206
- slug: {
207
- title: "slug",
208
- description: "The name of the group.",
209
- type: "string"
210
- }
211
- }
110
+ ),
111
+ branchMatchKind: (z) => z.enum(["glob", "branching_model"], {
112
+ description: "The branch match kind."
113
+ }).optional(),
114
+ branchType: (z) => z.enum(
115
+ ["feature", "bugfix", "release", "hotfix", "development", "production"],
116
+ {
117
+ description: "The branch type. When branchMatchKind is set to branching_model, this field is required."
212
118
  }
213
- }
119
+ ).optional(),
120
+ pattern: (z) => z.string({
121
+ description: "The pattern to match branches against. This field is required when branchMatchKind is set to glob."
122
+ }).optional(),
123
+ value: (z) => z.union([z.number(), z.null()], {
124
+ description: "The value of the restriction. This field is required when kind is one of require_approvals_to_merge / require_default_reviewer_approvals_to_merge / require_passing_builds_to_merge / require_commits_behind."
125
+ }).optional(),
126
+ users: (z) => z.array(
127
+ z.object({
128
+ uuid: z.string({
129
+ description: 'The UUID of the user in the format "{a-b-c-d}".'
130
+ })
131
+ }),
132
+ {
133
+ description: "Names of users that can bypass the push / restrict_merges restriction kind. For any other kind, this field will be ignored."
134
+ }
135
+ ).optional(),
136
+ groups: (z) => z.array(
137
+ z.object({
138
+ slug: z.string({
139
+ description: "The name of the group."
140
+ })
141
+ }),
142
+ {
143
+ description: "Names of groups that can bypass the push / restrict_merges restriction kind. For any other kind, this field will be ignored."
144
+ }
145
+ ).optional()
214
146
  };
215
147
 
216
148
  exports.pipelinesRunBody = pipelinesRunBody;
@@ -1 +1 @@
1
- {"version":3,"file":"inputProperties.cjs.js","sources":["../../src/actions/inputProperties.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\nconst repoUrl = {\n title: 'Repository Location',\n description: `Accepts the format 'bitbucket.org?repo=reponame&workspace=workspace&project=project' where 'reponame' is the new repository name`,\n type: 'string',\n};\n\nconst workspace = {\n title: 'Workspace',\n description: `The workspace name`,\n type: 'string',\n};\n\nconst repo_slug = {\n title: 'Repository name',\n description: 'The repository name',\n type: 'string',\n};\n\nconst ref_type = {\n title: 'ref_type',\n type: 'string',\n};\n\nconst type = {\n title: 'type',\n type: 'string',\n};\n\nconst ref_name = {\n title: 'ref_name',\n type: 'string',\n};\nconst source = {\n title: 'source',\n type: 'string',\n};\nconst destination = {\n title: 'destination',\n type: 'string',\n};\nconst hash = {\n title: 'hash',\n type: 'string',\n};\n\nconst pattern = {\n title: 'pattern',\n type: 'string',\n};\n\nconst id = {\n title: 'id',\n type: 'string',\n};\n\nconst key = {\n title: 'key',\n type: 'string',\n};\nconst value = {\n title: 'value',\n type: 'string',\n};\nconst secured = {\n title: 'secured',\n type: 'boolean',\n};\n\nconst token = {\n title: 'Authentication Token',\n type: 'string',\n description: 'The token to use for authorization to BitBucket Cloud',\n};\n\nconst destination_commit = {\n title: 'destination_commit',\n type: 'object',\n properties: {\n hash,\n },\n};\n\nconst commit = {\n title: 'commit',\n type: 'object',\n properties: {\n type,\n hash,\n },\n};\n\nconst selector = {\n title: 'selector',\n type: 'object',\n properties: {\n type,\n pattern,\n },\n};\n\nconst pull_request = {\n title: 'pull_request',\n type: 'object',\n properties: {\n id,\n },\n};\n\nconst pipelinesRunBody = {\n title: 'Request Body',\n description:\n 'Request body properties: see Bitbucket Cloud Rest API documentation for more details',\n type: 'object',\n properties: {\n target: {\n title: 'target',\n type: 'object',\n properties: {\n ref_type,\n type,\n ref_name,\n source,\n destination,\n destination_commit,\n commit,\n selector,\n pull_request,\n },\n },\n variables: {\n title: 'variables',\n type: 'array',\n items: {\n type: 'object',\n properties: {\n key,\n value,\n secured,\n },\n },\n },\n },\n};\n\nconst restriction = {\n kind: {\n title: 'kind',\n description: 'The kind of restriction.',\n type: 'string',\n enum: [\n 'push',\n 'force',\n 'delete',\n 'restrict_merges',\n 'require_tasks_to_be_completed',\n 'require_approvals_to_merge',\n 'require_default_reviewer_approvals_to_merge',\n 'require_no_changes_requested',\n 'require_passing_builds_to_merge',\n 'require_commits_behind',\n 'reset_pullrequest_approvals_on_change',\n 'smart_reset_pullrequest_approvals',\n 'reset_pullrequest_changes_requested_on_change',\n 'require_all_dependencies_merged',\n 'enforce_merge_checks',\n 'allow_auto_merge_when_builds_pass',\n ],\n },\n branchMatchKind: {\n title: 'branch_match_kind',\n description: 'The branch match kind.',\n type: 'string',\n enum: ['glob', 'branching_model'],\n },\n branchType: {\n title: 'branch_type',\n description:\n 'The branch type. When branchMatchKind is set to branching_model, this field is required.',\n type: 'string',\n enum: [\n 'feature',\n 'bugfix',\n 'release',\n 'hotfix',\n 'development',\n 'production',\n ],\n },\n pattern: {\n title: 'pattern',\n description:\n 'The pattern to match branches against. This field is required when branchMatchKind is set to glob.',\n type: 'string',\n },\n value: {\n title: 'value',\n description:\n 'The value of the restriction. This field is required when kind is one of require_approvals_to_merge / require_default_reviewer_approvals_to_merge / require_passing_builds_to_merge / require_commits_behind.',\n type: 'number',\n },\n users: {\n title: 'users',\n description:\n 'Names of users that can bypass the push / restrict_merges restriction kind. For any other kind, this field will be ignored.',\n type: 'array',\n items: {\n type: 'object',\n properties: {\n uuid: {\n title: 'uuid',\n description: 'The UUID of the user in the format \"{a-b-c-d}\".',\n type: 'string',\n },\n },\n },\n },\n groups: {\n title: 'groups',\n description:\n 'Names of groups that can bypass the push / restrict_merges restriction kind. For any other kind, this field will be ignored.',\n type: 'array',\n items: {\n type: 'object',\n properties: {\n slug: {\n title: 'slug',\n description: 'The name of the group.',\n type: 'string',\n },\n },\n },\n },\n};\n\nexport { workspace, repo_slug, pipelinesRunBody, token };\nexport { repoUrl, restriction };\n"],"names":[],"mappings":";;AAgBA,MAAM,OAAU,GAAA;AAAA,EACd,KAAO,EAAA,qBAAA;AAAA,EACP,WAAa,EAAA,CAAA,gIAAA,CAAA;AAAA,EACb,IAAM,EAAA;AACR;AAEA,MAAM,SAAY,GAAA;AAAA,EAChB,KAAO,EAAA,WAAA;AAAA,EACP,WAAa,EAAA,CAAA,kBAAA,CAAA;AAAA,EACb,IAAM,EAAA;AACR;AAEA,MAAM,SAAY,GAAA;AAAA,EAChB,KAAO,EAAA,iBAAA;AAAA,EACP,WAAa,EAAA,qBAAA;AAAA,EACb,IAAM,EAAA;AACR;AAEA,MAAM,QAAW,GAAA;AAAA,EACf,KAAO,EAAA,UAAA;AAAA,EACP,IAAM,E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8HAAA;AAAA,IACF,IAAM,EAAA,OAAA;AAAA,IACN,KAAO,EAAA;AAAA,MACL,IAAM,EAAA,QAAA;AAAA,MACN,UAAY,EAAA;AAAA,QACV,IAAM,EAAA;AAAA,UACJ,KAAO,EAAA,MAAA;AAAA,UACP,WAAa,EAAA,wBAAA;AAAA,UACb,IAAM,EAAA;AAAA;AACR;AACF;AACF;AAEJ;;;;;;;;;"}
1
+ {"version":3,"file":"inputProperties.cjs.js","sources":["../../src/actions/inputProperties.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 { z as zod } from 'zod';\n\nconst repoUrl = (z: typeof zod) =>\n z.string({\n description: `Accepts the format 'bitbucket.org?repo=reponame&workspace=workspace&project=project' where 'reponame' is the new repository name`,\n });\n\nconst workspace = (z: typeof zod) =>\n z.string({\n description: 'The workspace name',\n });\n\nconst repo_slug = (z: typeof zod) =>\n z.string({\n description: 'The repository name',\n });\n\nconst ref_type = (z: typeof zod) =>\n z.string({\n description: 'ref_type',\n });\n\nconst type = (z: typeof zod) =>\n z.string({\n description: 'type',\n });\n\nconst ref_name = (z: typeof zod) =>\n z.string({\n description: 'ref_name',\n });\n\nconst source = (z: typeof zod) =>\n z.string({\n description: 'source',\n });\n\nconst destination = (z: typeof zod) =>\n z.string({\n description: 'destination',\n });\n\nconst hash = (z: typeof zod) =>\n z.string({\n description: 'hash',\n });\n\nconst pattern = (z: typeof zod) =>\n z.string({\n description: 'pattern',\n });\n\nconst id = (z: typeof zod) =>\n z.string({\n description: 'id',\n });\n\nconst key = (z: typeof zod) =>\n z.string({\n description: 'key',\n });\n\nconst value = (z: typeof zod) =>\n z.string({\n description: 'value',\n });\n\nconst secured = (z: typeof zod) =>\n z.boolean({\n description: 'secured',\n });\n\nconst token = (z: typeof zod) =>\n z\n .string({\n description: 'The token to use for authorization to BitBucket Cloud',\n })\n .optional();\n\nconst destination_commit = (z: typeof zod) =>\n z.object({\n hash: hash(z),\n });\n\nconst commit = (z: typeof zod) =>\n z.object({\n type: type(z),\n hash: hash(z),\n });\n\nconst selector = (z: typeof zod) =>\n z.object({\n type: type(z),\n pattern: pattern(z),\n });\n\nconst pull_request = (z: typeof zod) =>\n z.object({\n id: id(z),\n });\n\nconst pipelinesRunBody = (z: typeof zod) =>\n z\n .object(\n {\n target: z\n .object({\n ref_type: ref_type(z).optional(),\n type: type(z).optional(),\n ref_name: ref_name(z).optional(),\n source: source(z).optional(),\n destination: destination(z).optional(),\n destination_commit: destination_commit(z).optional(),\n commit: commit(z).optional(),\n selector: selector(z).optional(),\n pull_request: pull_request(z).optional(),\n })\n .optional(),\n variables: z\n .array(\n z.object({\n key: key(z),\n value: value(z),\n secured: secured(z),\n }),\n )\n .optional(),\n },\n {\n description:\n 'Request body properties: see Bitbucket Cloud Rest API documentation for more details',\n },\n )\n .optional();\n\nconst restriction = {\n kind: (z: typeof zod) =>\n z.enum(\n [\n 'push',\n 'force',\n 'delete',\n 'restrict_merges',\n 'require_tasks_to_be_completed',\n 'require_approvals_to_merge',\n 'require_default_reviewer_approvals_to_merge',\n 'require_no_changes_requested',\n 'require_passing_builds_to_merge',\n 'require_commits_behind',\n 'reset_pullrequest_approvals_on_change',\n 'smart_reset_pullrequest_approvals',\n 'reset_pullrequest_changes_requested_on_change',\n 'require_all_dependencies_merged',\n 'enforce_merge_checks',\n 'allow_auto_merge_when_builds_pass',\n ],\n {\n description: 'The kind of restriction.',\n },\n ),\n branchMatchKind: (z: typeof zod) =>\n z\n .enum(['glob', 'branching_model'], {\n description: 'The branch match kind.',\n })\n .optional(),\n branchType: (z: typeof zod) =>\n z\n .enum(\n ['feature', 'bugfix', 'release', 'hotfix', 'development', 'production'],\n {\n description:\n 'The branch type. When branchMatchKind is set to branching_model, this field is required.',\n },\n )\n .optional(),\n pattern: (z: typeof zod) =>\n z\n .string({\n description:\n 'The pattern to match branches against. This field is required when branchMatchKind is set to glob.',\n })\n .optional(),\n value: (z: typeof zod) =>\n z\n .union([z.number(), z.null()], {\n description:\n 'The value of the restriction. This field is required when kind is one of require_approvals_to_merge / require_default_reviewer_approvals_to_merge / require_passing_builds_to_merge / require_commits_behind.',\n })\n .optional(),\n users: (z: typeof zod) =>\n z\n .array(\n z.object({\n uuid: z.string({\n description: 'The UUID of the user in the format \"{a-b-c-d}\".',\n }),\n }),\n {\n description:\n 'Names of users that can bypass the push / restrict_merges restriction kind. For any other kind, this field will be ignored.',\n },\n )\n .optional(),\n groups: (z: typeof zod) =>\n z\n .array(\n z.object({\n slug: z.string({\n description: 'The name of the group.',\n }),\n }),\n {\n description:\n 'Names of groups that can bypass the push / restrict_merges restriction kind. For any other kind, this field will be ignored.',\n },\n )\n .optional(),\n};\n\nexport { workspace, repo_slug, pipelinesRunBody, token };\nexport { repoUrl, restriction };\n"],"names":[],"mappings":";;AAkBA,MAAM,OAAU,GAAA,CAAC,CACf,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,EACP,WAAa,EAAA,CAAA,gIAAA;AACf,CAAC;AAEH,MAAM,SAAY,GAAA,CAAC,CACjB,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,EACP,WAAa,EAAA;AACf,CAAC;AAEH,MAAM,SAAY,GAAA,CAAC,CACjB,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,EACP,WAAa,EAAA;AACf,CAAC;AAEH,MAAM,QAAW,GAAA,CAAC,CAChB,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,EACP,WAAa,EAAA;AACf,CAAC,CAAA;AAEH,MAAM,IAAO,GAAA,CAAC,CACZ,KAAA,CAAA,CAAE,MAAO,CAAA;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K,EAAC,CAAG,EAAA;AAAA,IAC7B,WACE,EAAA;AAAA,GACH,EACA,QAAS,EAAA;AAAA,EACd,KAAA,EAAO,CAAC,CAAA,KACN,CACG,CAAA,KAAA;AAAA,IACC,EAAE,MAAO,CAAA;AAAA,MACP,IAAA,EAAM,EAAE,MAAO,CAAA;AAAA,QACb,WAAa,EAAA;AAAA,OACd;AAAA,KACF,CAAA;AAAA,IACD;AAAA,MACE,WACE,EAAA;AAAA;AACJ,IAED,QAAS,EAAA;AAAA,EACd,MAAA,EAAQ,CAAC,CAAA,KACP,CACG,CAAA,KAAA;AAAA,IACC,EAAE,MAAO,CAAA;AAAA,MACP,IAAA,EAAM,EAAE,MAAO,CAAA;AAAA,QACb,WAAa,EAAA;AAAA,OACd;AAAA,KACF,CAAA;AAAA,IACD;AAAA,MACE,WACE,EAAA;AAAA;AACJ,IAED,QAAS;AAChB;;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import * as _backstage_plugin_scaffolder_node from '@backstage/plugin-scaffolder-node';
2
- import * as _backstage_types from '@backstage/types';
3
2
  import { ScmIntegrationRegistry } from '@backstage/integration';
4
3
  import { Config } from '@backstage/config';
5
4
  import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
@@ -14,14 +13,18 @@ declare function createPublishBitbucketCloudAction(options: {
14
13
  config: Config;
15
14
  }): _backstage_plugin_scaffolder_node.TemplateAction<{
16
15
  repoUrl: string;
17
- description?: string;
18
- defaultBranch?: string;
19
- repoVisibility?: "private" | "public";
20
- gitCommitMessage?: string;
21
- sourcePath?: string;
22
- token?: string;
23
- signCommit?: boolean;
24
- }, _backstage_types.JsonObject, "v1">;
16
+ description?: string | undefined;
17
+ defaultBranch?: string | undefined;
18
+ repoVisibility?: "private" | "public" | undefined;
19
+ gitCommitMessage?: string | undefined;
20
+ sourcePath?: string | undefined;
21
+ token?: string | undefined;
22
+ signCommit?: boolean | undefined;
23
+ }, {
24
+ remoteUrl?: string | undefined;
25
+ repoContentsUrl?: string | undefined;
26
+ commitHash?: string | undefined;
27
+ }, "v2">;
25
28
 
26
29
  /**
27
30
  * Creates a new action that triggers a run of a bitbucket pipeline
@@ -33,13 +36,40 @@ declare const createBitbucketPipelinesRunAction: (options: {
33
36
  }) => _backstage_plugin_scaffolder_node.TemplateAction<{
34
37
  workspace: string;
35
38
  repo_slug: string;
36
- body?: object;
37
- token?: string;
39
+ body?: {
40
+ target?: {
41
+ type?: string | undefined;
42
+ source?: string | undefined;
43
+ selector?: {
44
+ type: string;
45
+ pattern: string;
46
+ } | undefined;
47
+ pull_request?: {
48
+ id: string;
49
+ } | undefined;
50
+ commit?: {
51
+ type: string;
52
+ hash: string;
53
+ } | undefined;
54
+ destination?: string | undefined;
55
+ ref_name?: string | undefined;
56
+ ref_type?: string | undefined;
57
+ destination_commit?: {
58
+ hash: string;
59
+ } | undefined;
60
+ } | undefined;
61
+ variables?: {
62
+ key: string;
63
+ value: string;
64
+ secured: boolean;
65
+ }[] | undefined;
66
+ } | undefined;
67
+ token?: string | undefined;
38
68
  }, {
39
- buildNumber: number;
40
- repoUrl: string;
41
- pipelinesUrl: string;
42
- }, "v1">;
69
+ buildNumber?: number | undefined;
70
+ repoUrl?: string | undefined;
71
+ pipelinesUrl?: string | undefined;
72
+ }, "v2">;
43
73
 
44
74
  /**
45
75
  * Creates a Bitbucket Cloud Pull Request action.
@@ -51,13 +81,15 @@ declare function createPublishBitbucketCloudPullRequestAction(options: {
51
81
  }): _backstage_plugin_scaffolder_node.TemplateAction<{
52
82
  repoUrl: string;
53
83
  title: string;
54
- description?: string;
55
- targetBranch?: string;
56
84
  sourceBranch: string;
57
- token?: string;
58
- gitAuthorName?: string;
59
- gitAuthorEmail?: string;
60
- }, _backstage_types.JsonObject, "v1">;
85
+ description?: string | undefined;
86
+ targetBranch?: string | undefined;
87
+ token?: string | undefined;
88
+ gitAuthorName?: string | undefined;
89
+ gitAuthorEmail?: string | undefined;
90
+ }, {
91
+ pullRequestUrl: string;
92
+ }, "v2">;
61
93
 
62
94
  /**
63
95
  * @public
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-scaffolder-backend-module-bitbucket-cloud",
3
- "version": "0.2.10-next.0",
3
+ "version": "0.2.10-next.2",
4
4
  "description": "The Bitbucket Cloud module for @backstage/plugin-scaffolder-backend",
5
5
  "backstage": {
6
6
  "role": "backend-plugin-module",
@@ -50,20 +50,21 @@
50
50
  "test": "backstage-cli package test"
51
51
  },
52
52
  "dependencies": {
53
- "@backstage/backend-plugin-api": "1.4.0-next.0",
53
+ "@backstage/backend-plugin-api": "1.4.0-next.1",
54
54
  "@backstage/config": "1.3.2",
55
55
  "@backstage/errors": "1.2.7",
56
56
  "@backstage/integration": "1.17.0",
57
57
  "@backstage/plugin-bitbucket-cloud-common": "0.3.0",
58
- "@backstage/plugin-scaffolder-node": "0.8.3-next.0",
58
+ "@backstage/plugin-scaffolder-node": "0.9.0-next.2",
59
59
  "bitbucket": "^2.12.0",
60
60
  "fs-extra": "^11.2.0",
61
- "yaml": "^2.0.0"
61
+ "yaml": "^2.0.0",
62
+ "zod": "^3.22.4"
62
63
  },
63
64
  "devDependencies": {
64
- "@backstage/backend-test-utils": "1.6.0-next.0",
65
- "@backstage/cli": "0.32.1",
66
- "@backstage/plugin-scaffolder-node-test-utils": "0.2.3-next.0",
65
+ "@backstage/backend-test-utils": "1.6.0-next.2",
66
+ "@backstage/cli": "0.33.0-next.1",
67
+ "@backstage/plugin-scaffolder-node-test-utils": "0.3.0-next.2",
67
68
  "msw": "^1.0.0"
68
69
  }
69
70
  }