@backstage/plugin-scaffolder-backend-module-bitbucket-server 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,28 @@
1
1
  # @backstage/plugin-scaffolder-backend-module-bitbucket-server
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
+
14
+ ## 0.2.10-next.1
15
+
16
+ ### Patch Changes
17
+
18
+ - d8169fc: Migrate the actions to the new format
19
+ - Updated dependencies
20
+ - @backstage/plugin-scaffolder-node@0.8.3-next.1
21
+ - @backstage/backend-plugin-api@1.4.0-next.1
22
+ - @backstage/config@1.3.2
23
+ - @backstage/errors@1.2.7
24
+ - @backstage/integration@1.17.0
25
+
3
26
  ## 0.2.10-next.0
4
27
 
5
28
  ### Patch Changes
@@ -74,80 +74,50 @@ function createPublishBitbucketServerAction(options) {
74
74
  examples: bitbucketServer_examples.examples,
75
75
  schema: {
76
76
  input: {
77
- type: "object",
78
- required: ["repoUrl"],
79
- properties: {
80
- repoUrl: {
81
- title: "Repository Location",
82
- type: "string"
83
- },
84
- description: {
85
- title: "Repository Description",
86
- type: "string"
87
- },
88
- repoVisibility: {
89
- title: "Repository Visibility",
90
- type: "string",
91
- enum: ["private", "public"]
92
- },
93
- defaultBranch: {
94
- title: "Default Branch",
95
- type: "string",
96
- description: `Sets the default branch on the repository. The default value is 'master'`
97
- },
98
- sourcePath: {
99
- title: "Source Path",
100
- description: "Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.",
101
- type: "string"
102
- },
103
- enableLFS: {
104
- title: "Enable LFS?",
105
- description: "Enable LFS for the repository.",
106
- type: "boolean"
107
- },
108
- token: {
109
- title: "Authentication Token",
110
- type: "string",
111
- description: "The token to use for authorization to BitBucket Server"
112
- },
113
- gitCommitMessage: {
114
- title: "Git Commit Message",
115
- type: "string",
116
- description: `Sets the commit message on the repository. The default value is 'initial commit'`
117
- },
118
- gitAuthorName: {
119
- title: "Author Name",
120
- type: "string",
121
- description: `Sets the author name for the commit. The default value is 'Scaffolder'`
122
- },
123
- gitAuthorEmail: {
124
- title: "Author Email",
125
- type: "string",
126
- description: `Sets the author email for the commit.`
127
- },
128
- signCommit: {
129
- title: "Sign commit",
130
- type: "boolean",
131
- description: "Sign commit with configured PGP private key"
132
- }
133
- }
77
+ repoUrl: (z) => z.string({
78
+ description: "Repository Location"
79
+ }),
80
+ description: (z) => z.string({
81
+ description: "Repository Description"
82
+ }).optional(),
83
+ repoVisibility: (z) => z.enum(["private", "public"], {
84
+ description: "Repository Visibility"
85
+ }).optional(),
86
+ defaultBranch: (z) => z.string({
87
+ description: `Sets the default branch on the repository. The default value is 'master'`
88
+ }).optional(),
89
+ sourcePath: (z) => z.string({
90
+ description: "Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository."
91
+ }).optional(),
92
+ enableLFS: (z) => z.boolean({
93
+ description: "Enable LFS for the repository."
94
+ }).optional(),
95
+ token: (z) => z.string({
96
+ description: "The token to use for authorization to BitBucket Server"
97
+ }).optional(),
98
+ gitCommitMessage: (z) => z.string({
99
+ description: `Sets the commit message on the repository. The default value is 'initial commit'`
100
+ }).optional(),
101
+ gitAuthorName: (z) => z.string({
102
+ description: `Sets the author name for the commit. The default value is 'Scaffolder'`
103
+ }).optional(),
104
+ gitAuthorEmail: (z) => z.string({
105
+ description: `Sets the author email for the commit.`
106
+ }).optional(),
107
+ signCommit: (z) => z.boolean({
108
+ description: "Sign commit with configured PGP private key"
109
+ }).optional()
134
110
  },
135
111
  output: {
136
- type: "object",
137
- properties: {
138
- remoteUrl: {
139
- title: "A URL to the repository with the provider",
140
- type: "string"
141
- },
142
- repoContentsUrl: {
143
- title: "A URL to the root of the repository",
144
- type: "string"
145
- },
146
- commitHash: {
147
- title: "The git commit hash of the initial commit",
148
- type: "string"
149
- }
150
- }
112
+ remoteUrl: (z) => z.string({
113
+ description: "A URL to the repository with the provider"
114
+ }).optional(),
115
+ repoContentsUrl: (z) => z.string({
116
+ description: "A URL to the root of the repository"
117
+ }).optional(),
118
+ commitHash: (z) => z.string({
119
+ description: "The git commit hash of the initial commit"
120
+ }).optional()
151
121
  }
152
122
  },
153
123
  async handler(ctx) {
@@ -1 +1 @@
1
- {"version":3,"file":"bitbucketServer.cjs.js","sources":["../../src/actions/bitbucketServer.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport {\n getBitbucketServerRequestOptions,\n ScmIntegrationRegistry,\n} 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 { examples } from './bitbucketServer.examples';\n\nconst createRepository = async (opts: {\n project: string;\n repo: string;\n description?: string;\n repoVisibility: 'private' | 'public';\n defaultBranch: string;\n authorization: string;\n apiBaseUrl: string;\n}) => {\n const {\n project,\n repo,\n description,\n authorization,\n repoVisibility,\n defaultBranch,\n apiBaseUrl,\n } = opts;\n\n let response: Response;\n const options: RequestInit = {\n method: 'POST',\n body: JSON.stringify({\n name: repo,\n description: description,\n defaultBranch: defaultBranch,\n public: repoVisibility === 'public',\n }),\n headers: {\n Authorization: authorization,\n 'Content-Type': 'application/json',\n },\n };\n\n try {\n response = await fetch(`${apiBaseUrl}/projects/${project}/repos`, options);\n } catch (e) {\n throw new Error(`Unable to create repository, ${e}`);\n }\n\n if (response.status !== 201) {\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 === 'http') {\n remoteUrl = link.href;\n }\n }\n\n const repoContentsUrl = `${r.links.self[0].href}`;\n return { remoteUrl, repoContentsUrl };\n};\n\nconst performEnableLFS = async (opts: {\n authorization: string;\n host: string;\n project: string;\n repo: string;\n}) => {\n const { authorization, host, project, repo } = opts;\n\n const options: RequestInit = {\n method: 'PUT',\n headers: {\n Authorization: authorization,\n },\n };\n\n const { ok, status, statusText } = await fetch(\n `https://${host}/rest/git-lfs/admin/projects/${project}/repos/${repo}/enabled`,\n options,\n );\n\n if (!ok)\n throw new Error(\n `Failed to enable LFS in the repository, ${status}: ${statusText}`,\n );\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 Server.\n * @public\n */\nexport function createPublishBitbucketServerAction(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 sourcePath?: string;\n enableLFS?: boolean;\n token?: string;\n gitCommitMessage?: string;\n gitAuthorName?: string;\n gitAuthorEmail?: string;\n signCommit?: boolean;\n }>({\n id: 'publish:bitbucketServer',\n description:\n 'Initializes a git repository of the content in the workspace, and publishes it to Bitbucket Server.',\n examples,\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 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 enableLFS: {\n title: 'Enable LFS?',\n description: 'Enable LFS for the repository.',\n type: 'boolean',\n },\n token: {\n title: 'Authentication Token',\n type: 'string',\n description:\n 'The token to use for authorization to BitBucket Server',\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 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 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 repoVisibility = 'private',\n enableLFS = false,\n gitCommitMessage = 'initial commit',\n gitAuthorName,\n gitAuthorEmail,\n signCommit,\n } = ctx.input;\n\n const { project, repo, host } = parseRepoUrl(repoUrl, integrations);\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.bitbucketServer.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 token = ctx.input.token ?? integrationConfig.config.token;\n\n const authConfig = {\n ...integrationConfig.config,\n ...{ token },\n };\n const reqOpts = getBitbucketServerRequestOptions(authConfig);\n const authorization = reqOpts.headers.Authorization;\n if (!authorization) {\n throw new Error(\n `Authorization has not been provided for ${integrationConfig.config.host}. Please add either (a) a user login auth token, or (b) a token or (c) username + password to the integration config.`,\n );\n }\n\n const apiBaseUrl = integrationConfig.config.apiBaseUrl;\n\n const { remoteUrl, repoContentsUrl } = await createRepository({\n authorization,\n project,\n repo,\n repoVisibility,\n defaultBranch,\n description,\n apiBaseUrl,\n });\n\n const gitAuthorInfo = {\n name: gitAuthorName\n ? gitAuthorName\n : config.getOptionalString('scaffolder.defaultAuthor.name'),\n email: gitAuthorEmail\n ? gitAuthorEmail\n : config.getOptionalString('scaffolder.defaultAuthor.email'),\n };\n\n const 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 auth = authConfig.token\n ? {\n token: token!,\n }\n : {\n username: authConfig.username!,\n password: authConfig.password!,\n };\n\n const commitResult = await initRepoAndPush({\n dir: getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath),\n remoteUrl,\n auth,\n defaultBranch,\n logger: ctx.logger,\n commitMessage: gitCommitMessage\n ? gitCommitMessage\n : config.getOptionalString('scaffolder.defaultCommitMessage'),\n gitAuthorInfo,\n signingKey: signCommit ? signingKey : undefined,\n });\n\n if (enableLFS) {\n await performEnableLFS({ authorization, host, project, repo });\n }\n\n ctx.output('commitHash', commitResult?.commitHash);\n ctx.output('remoteUrl', remoteUrl);\n ctx.output('repoContentsUrl', repoContentsUrl);\n },\n });\n}\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","getBitbucketServerRequestOptions","initRepoAndPush","getRepoSourceDirectory"],"mappings":";;;;;;;AA+BA,MAAM,gBAAA,GAAmB,OAAO,IAQ1B,KAAA;AACJ,EAAM,MAAA;AAAA,IACJ,OAAA;AAAA,IACA,IAAA;AAAA,IACA,WAAA;AAAA,IAC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QAAQ,GAAI,CAAA,MAAA;AAAA,QACZ,aAAe,EAAA,gBAAA,GACX,gBACA,GAAA,MAAA,CAAO,kBAAkB,iCAAiC,CAAA;AAAA,QAC9D,aAAA;AAAA,QACA,UAAA,EAAY,aAAa,UAAa,GAAA,KAAA;AAAA,OACvC,CAAA;AAED,MAAA,IAAI,SAAW,EAAA;AACb,QAAA,MAAM,iBAAiB,EAAE,aAAA,EAAe,IAAM,EAAA,OAAA,EAAS,MAAM,CAAA;AAAA;AAG/D,MAAI,GAAA,CAAA,MAAA,CAAO,YAAc,EAAA,YAAA,EAAc,UAAU,CAAA;AACjD,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":"bitbucketServer.cjs.js","sources":["../../src/actions/bitbucketServer.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport {\n getBitbucketServerRequestOptions,\n ScmIntegrationRegistry,\n} 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 { examples } from './bitbucketServer.examples';\n\nconst createRepository = async (opts: {\n project: string;\n repo: string;\n description?: string;\n repoVisibility: 'private' | 'public';\n defaultBranch: string;\n authorization: string;\n apiBaseUrl: string;\n}) => {\n const {\n project,\n repo,\n description,\n authorization,\n repoVisibility,\n defaultBranch,\n apiBaseUrl,\n } = opts;\n\n let response: Response;\n const options: RequestInit = {\n method: 'POST',\n body: JSON.stringify({\n name: repo,\n description: description,\n defaultBranch: defaultBranch,\n public: repoVisibility === 'public',\n }),\n headers: {\n Authorization: authorization,\n 'Content-Type': 'application/json',\n },\n };\n\n try {\n response = await fetch(`${apiBaseUrl}/projects/${project}/repos`, options);\n } catch (e) {\n throw new Error(`Unable to create repository, ${e}`);\n }\n\n if (response.status !== 201) {\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 === 'http') {\n remoteUrl = link.href;\n }\n }\n\n const repoContentsUrl = `${r.links.self[0].href}`;\n return { remoteUrl, repoContentsUrl };\n};\n\nconst performEnableLFS = async (opts: {\n authorization: string;\n host: string;\n project: string;\n repo: string;\n}) => {\n const { authorization, host, project, repo } = opts;\n\n const options: RequestInit = {\n method: 'PUT',\n headers: {\n Authorization: authorization,\n },\n };\n\n const { ok, status, statusText } = await fetch(\n `https://${host}/rest/git-lfs/admin/projects/${project}/repos/${repo}/enabled`,\n options,\n );\n\n if (!ok)\n throw new Error(\n `Failed to enable LFS in the repository, ${status}: ${statusText}`,\n );\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 Server.\n * @public\n */\nexport function createPublishBitbucketServerAction(options: {\n integrations: ScmIntegrationRegistry;\n config: Config;\n}) {\n const { integrations, config } = options;\n\n return createTemplateAction({\n id: 'publish:bitbucketServer',\n description:\n 'Initializes a git repository of the content in the workspace, and publishes it to Bitbucket Server.',\n examples,\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 repoVisibility: z =>\n z\n .enum(['private', 'public'], {\n description: 'Repository Visibility',\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 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 enableLFS: z =>\n z\n .boolean({\n description: 'Enable LFS for the repository.',\n })\n .optional(),\n token: z =>\n z\n .string({\n description:\n 'The token to use for authorization to BitBucket Server',\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 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 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 repoVisibility = 'private',\n enableLFS = false,\n gitCommitMessage = 'initial commit',\n gitAuthorName,\n gitAuthorEmail,\n signCommit,\n } = ctx.input;\n\n const { project, repo, host } = parseRepoUrl(repoUrl, integrations);\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.bitbucketServer.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 token = ctx.input.token ?? integrationConfig.config.token;\n\n const authConfig = {\n ...integrationConfig.config,\n ...{ token },\n };\n const reqOpts = getBitbucketServerRequestOptions(authConfig);\n const authorization = reqOpts.headers.Authorization;\n if (!authorization) {\n throw new Error(\n `Authorization has not been provided for ${integrationConfig.config.host}. Please add either (a) a user login auth token, or (b) a token or (c) username + password to the integration config.`,\n );\n }\n\n const apiBaseUrl = integrationConfig.config.apiBaseUrl;\n\n const { remoteUrl, repoContentsUrl } = await createRepository({\n authorization,\n project,\n repo,\n repoVisibility,\n defaultBranch,\n description,\n apiBaseUrl,\n });\n\n const gitAuthorInfo = {\n name: gitAuthorName\n ? gitAuthorName\n : config.getOptionalString('scaffolder.defaultAuthor.name'),\n email: gitAuthorEmail\n ? gitAuthorEmail\n : config.getOptionalString('scaffolder.defaultAuthor.email'),\n };\n\n const 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 auth = authConfig.token\n ? {\n token: token!,\n }\n : {\n username: authConfig.username!,\n password: authConfig.password!,\n };\n\n const commitResult = await initRepoAndPush({\n dir: getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath),\n remoteUrl,\n auth,\n defaultBranch,\n logger: ctx.logger,\n commitMessage: gitCommitMessage\n ? gitCommitMessage\n : config.getOptionalString('scaffolder.defaultCommitMessage'),\n gitAuthorInfo,\n signingKey: signCommit ? signingKey : undefined,\n });\n\n if (enableLFS) {\n await performEnableLFS({ authorization, host, project, repo });\n }\n\n ctx.output('commitHash', commitResult?.commitHash);\n ctx.output('remoteUrl', remoteUrl);\n ctx.output('repoContentsUrl', repoContentsUrl);\n },\n });\n}\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","getBitbucketServerRequestOptions","initRepoAndPush","getRepoSourceDirectory"],"mappings":";;;;;;;AA+BA,MAAM,gBAAA,GAAmB,OAAO,IAQ1B,KAAA;AACJ,EAAM,MAAA;AAAA,IACJ,OAAA;AAAA,IACA,IAAA;AAAA,IACA,WAAA;AAAA,IACA,aAAA;AAAA,IACA,cAAA;AAAA,IACA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,CAAO,kBAAkB,iCAAiC,CAAA;AAAA,QAC9D,aAAA;AAAA,QACA,UAAA,EAAY,aAAa,UAAa,GAAA,KAAA;AAAA,OACvC,CAAA;AAED,MAAA,IAAI,SAAW,EAAA;AACb,QAAA,MAAM,iBAAiB,EAAE,aAAA,EAAe,IAAM,EAAA,OAAA,EAAS,MAAM,CAAA;AAAA;AAG/D,MAAI,GAAA,CAAA,MAAA,CAAO,YAAc,EAAA,YAAA,EAAc,UAAU,CAAA;AACjD,MAAI,GAAA,CAAA,MAAA,CAAO,aAAa,SAAS,CAAA;AACjC,MAAI,GAAA,CAAA,MAAA,CAAO,mBAAmB,eAAe,CAAA;AAAA;AAC/C,GACD,CAAA;AACH;;;;"}
@@ -163,66 +163,38 @@ function createPublishBitbucketServerPullRequestAction(options) {
163
163
  examples: bitbucketServerPullRequest_examples.examples,
164
164
  schema: {
165
165
  input: {
166
- type: "object",
167
- required: ["repoUrl", "title", "sourceBranch"],
168
- properties: {
169
- repoUrl: {
170
- title: "Repository Location",
171
- type: "string"
172
- },
173
- title: {
174
- title: "Pull Request title",
175
- type: "string",
176
- description: "The title for the pull request"
177
- },
178
- description: {
179
- title: "Pull Request Description",
180
- type: "string",
181
- description: "The description of the pull request"
182
- },
183
- targetBranch: {
184
- title: "Target Branch",
185
- type: "string",
186
- description: `Branch of repository to apply changes to. The default value is 'master'`
187
- },
188
- sourceBranch: {
189
- title: "Source Branch",
190
- type: "string",
191
- description: "Branch of repository to copy changes from"
192
- },
193
- reviewers: {
194
- title: "Pull Request Reviewers",
195
- type: "array",
196
- items: {
197
- type: "string"
198
- },
199
- description: "The usernames of reviewers that will be added to the pull request"
200
- },
201
- token: {
202
- title: "Authorization Token",
203
- type: "string",
204
- description: "The token to use for authorization to BitBucket Server"
205
- },
206
- gitAuthorName: {
207
- title: "Author Name",
208
- type: "string",
209
- description: `Sets the author name for the commit. The default value is 'Scaffolder'`
210
- },
211
- gitAuthorEmail: {
212
- title: "Author Email",
213
- type: "string",
214
- description: `Sets the author email for the commit.`
215
- }
216
- }
166
+ repoUrl: (z) => z.string({
167
+ description: "Repository Location"
168
+ }),
169
+ title: (z) => z.string({
170
+ description: "The title for the pull request"
171
+ }),
172
+ description: (z) => z.string({
173
+ description: "The description of the pull request"
174
+ }).optional(),
175
+ targetBranch: (z) => z.string({
176
+ description: `Branch of repository to apply changes to. The default value is 'master'`
177
+ }).optional(),
178
+ sourceBranch: (z) => z.string({
179
+ description: "Branch of repository to copy changes from"
180
+ }),
181
+ reviewers: (z) => z.array(z.string(), {
182
+ description: "The usernames of reviewers that will be added to the pull request"
183
+ }).optional(),
184
+ token: (z) => z.string({
185
+ description: "The token to use for authorization to BitBucket Server"
186
+ }).optional(),
187
+ gitAuthorName: (z) => z.string({
188
+ description: `Sets the author name for the commit. The default value is 'Scaffolder'`
189
+ }).optional(),
190
+ gitAuthorEmail: (z) => z.string({
191
+ description: `Sets the author email for the commit.`
192
+ }).optional()
217
193
  },
218
194
  output: {
219
- type: "object",
220
- properties: {
221
- pullRequestUrl: {
222
- title: "A URL to the pull request with the provider",
223
- type: "string"
224
- }
225
- }
195
+ pullRequestUrl: (z) => z.string({
196
+ description: "A URL to the pull request with the provider"
197
+ }).optional()
226
198
  }
227
199
  },
228
200
  async handler(ctx) {
@@ -1 +1 @@
1
- {"version":3,"file":"bitbucketServerPullRequest.cjs.js","sources":["../../src/actions/bitbucketServerPullRequest.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport {\n getBitbucketServerRequestOptions,\n ScmIntegrationRegistry,\n} 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 { examples } from './bitbucketServerPullRequest.examples';\n\nconst createPullRequest = async (opts: {\n project: string;\n repo: string;\n title: string;\n description?: string;\n toRef: {\n id: string;\n displayId: string;\n type: string;\n latestCommit: string;\n latestChangeset: string;\n isDefault: boolean;\n };\n fromRef: {\n id: string;\n displayId: string;\n type: string;\n latestCommit: string;\n latestChangeset: string;\n isDefault: boolean;\n };\n reviewers?: string[];\n authorization: string;\n apiBaseUrl: string;\n}) => {\n const {\n project,\n repo,\n title,\n description,\n toRef,\n fromRef,\n reviewers,\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 description: description,\n state: 'OPEN',\n open: true,\n closed: false,\n locked: true,\n toRef: toRef,\n fromRef: fromRef,\n reviewers: reviewers?.map(reviewer => ({ user: { name: reviewer } })),\n }),\n headers: {\n Authorization: authorization,\n 'Content-Type': 'application/json',\n },\n };\n\n try {\n response = await fetch(\n `${apiBaseUrl}/projects/${encodeURIComponent(\n project,\n )}/repos/${encodeURIComponent(repo)}/pull-requests`,\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.self[0].href}`;\n};\nconst findBranches = async (opts: {\n project: string;\n repo: string;\n branchName: string;\n authorization: string;\n apiBaseUrl: string;\n}) => {\n const { project, 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}/projects/${encodeURIComponent(\n project,\n )}/repos/${encodeURIComponent(\n repo,\n )}/branches?boostMatches=true&filterText=${encodeURIComponent(\n 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 for (const object of r.values) {\n if (object.displayId === branchName) {\n return object;\n }\n }\n\n return undefined;\n};\nconst createBranch = async (opts: {\n project: string;\n repo: string;\n branchName: string;\n authorization: string;\n apiBaseUrl: string;\n startPoint: string;\n}) => {\n const { project, repo, branchName, authorization, apiBaseUrl, startPoint } =\n opts;\n\n let response: Response;\n const options: RequestInit = {\n method: 'POST',\n body: JSON.stringify({\n name: branchName,\n startPoint,\n }),\n headers: {\n Authorization: authorization,\n 'Content-Type': 'application/json',\n },\n };\n\n try {\n response = await fetch(\n `${apiBaseUrl}/projects/${encodeURIComponent(\n project,\n )}/repos/${encodeURIComponent(repo)}/branches`,\n options,\n );\n } catch (e) {\n throw new Error(`Unable to create branch, ${e}`);\n }\n\n if (response.status !== 200) {\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 project: string;\n repo: string;\n authorization: string;\n apiBaseUrl: string;\n}) => {\n const { project, 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}/projects/${project}/repos/${repo}/default-branch`,\n options,\n );\n } catch (error) {\n throw error;\n }\n\n const { displayId } = await response.json();\n const defaultBranch = displayId;\n if (!defaultBranch) {\n throw new Error(`Could not fetch default branch for ${project}/${repo}`);\n }\n return defaultBranch;\n};\nconst isApiBaseUrlHttps = (apiBaseUrl: string): boolean => {\n const url = new URL(apiBaseUrl);\n return url.protocol === 'https:';\n};\n/**\n * Creates a BitbucketServer Pull Request action.\n * @public\n */\nexport function createPublishBitbucketServerPullRequestAction(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 reviewers?: string[];\n token?: string;\n gitAuthorName?: string;\n gitAuthorEmail?: string;\n }>({\n id: 'publish:bitbucketServer: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 reviewers: {\n title: 'Pull Request Reviewers',\n type: 'array',\n items: {\n type: 'string',\n },\n description:\n 'The usernames of reviewers that will be added to the pull request',\n },\n token: {\n title: 'Authorization Token',\n type: 'string',\n description:\n 'The token to use for authorization to BitBucket Server',\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 reviewers,\n gitAuthorName,\n gitAuthorEmail,\n } = ctx.input;\n\n const { project, repo, host } = parseRepoUrl(repoUrl, integrations);\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.bitbucketServer.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 token = ctx.input.token ?? integrationConfig.config.token;\n\n const authConfig = {\n ...integrationConfig.config,\n ...{ token },\n };\n\n const reqOpts = getBitbucketServerRequestOptions(authConfig);\n const authorization = reqOpts.headers.Authorization;\n if (!authorization) {\n throw new Error(\n `Authorization has not been provided for ${integrationConfig.config.host}. Please add either (a) a user login auth token, or (b) a token input from the template or (c) username + password to the integration config.`,\n );\n }\n\n const apiBaseUrl = integrationConfig.config.apiBaseUrl;\n\n let finalTargetBranch = targetBranch;\n if (!finalTargetBranch) {\n finalTargetBranch = await getDefaultBranch({\n project,\n repo,\n authorization,\n apiBaseUrl,\n });\n }\n\n const toRef = await findBranches({\n project,\n repo,\n branchName: finalTargetBranch!,\n authorization,\n apiBaseUrl,\n });\n\n let fromRef = await findBranches({\n project,\n repo,\n branchName: sourceBranch,\n authorization,\n apiBaseUrl,\n });\n\n if (!fromRef) {\n // create branch\n ctx.logger.info(\n `source branch not found -> creating branch named: ${sourceBranch} lastCommit: ${toRef.latestCommit}`,\n );\n const latestCommit = toRef.latestCommit;\n\n fromRef = await createBranch({\n project,\n repo,\n branchName: sourceBranch,\n authorization,\n apiBaseUrl,\n startPoint: latestCommit,\n });\n\n const isHttps: boolean = isApiBaseUrlHttps(apiBaseUrl);\n const remoteUrl = `${\n isHttps ? 'https' : 'http'\n }://${host}/scm/${project}/${repo}.git`;\n\n const auth = authConfig.token\n ? {\n token: token!,\n }\n : {\n username: authConfig.username!,\n password: authConfig.password!,\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 project,\n repo,\n title,\n description,\n toRef,\n fromRef,\n reviewers,\n authorization,\n apiBaseUrl,\n });\n\n ctx.output('pullRequestUrl', pullRequestUrl);\n },\n });\n}\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","getBitbucketServerRequestOptions","getRepoSourceDirectory","cloneRepo","fs","isNotGitDirectoryOrContents","addFiles","commitAndPushBranch"],"mappings":";;;;;;;;;;;;AAkCA,MAAM,iBAAA,GAAoB,OAAO,IAwB3B,KAAA;AACJ,EAAM,MAAA;AAAA,IACJ,OAAA;AAAA,IACA,IAAA;AAAA,IACA,KAAA;AAAA,IACA,WAAA;AAAA,IACA,KAAA;AAAA,IACA,OAAA;AAAA,IACA,SAAA;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,WAAA;AAAA,MACA,KAAO,EAAA,MAAA;AAAA,MACP,IAAM,EAAA,IAAA;AAAA,MACN,MAAQ,EAAA,KAAA;AAAA,MACR,MAAQ,EAAA,IAAA;AAAA,MACR,KA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C,8BAAU,CAAA;AAAA,UACd,GAAK,EAAA,SAAA;AAAA,UACL,GAAK,EAAA,OAAA;AAAA,UACL,IAAA;AAAA,UACA,QAAQ,GAAI,CAAA,MAAA;AAAA,UACZ,GAAK,EAAA;AAAA,SACN,CAAA;AAGD,QAAGC,mBAAA,CAAA,MAAA,CAAO,WAAW,OAAS,EAAA;AAAA,UAC5B,SAAW,EAAA,IAAA;AAAA,UACX,MAAQ,EAAAC;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,OAAA;AAAA,QACA,IAAA;AAAA,QACA,KAAA;AAAA,QACA,WAAA;AAAA,QACA,KAAA;AAAA,QACA,OAAA;AAAA,QACA,SAAA;AAAA,QACA,aAAA;AAAA,QACA;AAAA,OACD,CAAA;AAED,MAAI,GAAA,CAAA,MAAA,CAAO,kBAAkB,cAAc,CAAA;AAAA;AAC7C,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"bitbucketServerPullRequest.cjs.js","sources":["../../src/actions/bitbucketServerPullRequest.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport {\n getBitbucketServerRequestOptions,\n ScmIntegrationRegistry,\n} 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 { examples } from './bitbucketServerPullRequest.examples';\n\nconst createPullRequest = async (opts: {\n project: string;\n repo: string;\n title: string;\n description?: string;\n toRef: {\n id: string;\n displayId: string;\n type: string;\n latestCommit: string;\n latestChangeset: string;\n isDefault: boolean;\n };\n fromRef: {\n id: string;\n displayId: string;\n type: string;\n latestCommit: string;\n latestChangeset: string;\n isDefault: boolean;\n };\n reviewers?: string[];\n authorization: string;\n apiBaseUrl: string;\n}) => {\n const {\n project,\n repo,\n title,\n description,\n toRef,\n fromRef,\n reviewers,\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 description: description,\n state: 'OPEN',\n open: true,\n closed: false,\n locked: true,\n toRef: toRef,\n fromRef: fromRef,\n reviewers: reviewers?.map(reviewer => ({ user: { name: reviewer } })),\n }),\n headers: {\n Authorization: authorization,\n 'Content-Type': 'application/json',\n },\n };\n\n try {\n response = await fetch(\n `${apiBaseUrl}/projects/${encodeURIComponent(\n project,\n )}/repos/${encodeURIComponent(repo)}/pull-requests`,\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.self[0].href}`;\n};\nconst findBranches = async (opts: {\n project: string;\n repo: string;\n branchName: string;\n authorization: string;\n apiBaseUrl: string;\n}) => {\n const { project, 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}/projects/${encodeURIComponent(\n project,\n )}/repos/${encodeURIComponent(\n repo,\n )}/branches?boostMatches=true&filterText=${encodeURIComponent(\n 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 for (const object of r.values) {\n if (object.displayId === branchName) {\n return object;\n }\n }\n\n return undefined;\n};\nconst createBranch = async (opts: {\n project: string;\n repo: string;\n branchName: string;\n authorization: string;\n apiBaseUrl: string;\n startPoint: string;\n}) => {\n const { project, repo, branchName, authorization, apiBaseUrl, startPoint } =\n opts;\n\n let response: Response;\n const options: RequestInit = {\n method: 'POST',\n body: JSON.stringify({\n name: branchName,\n startPoint,\n }),\n headers: {\n Authorization: authorization,\n 'Content-Type': 'application/json',\n },\n };\n\n try {\n response = await fetch(\n `${apiBaseUrl}/projects/${encodeURIComponent(\n project,\n )}/repos/${encodeURIComponent(repo)}/branches`,\n options,\n );\n } catch (e) {\n throw new Error(`Unable to create branch, ${e}`);\n }\n\n if (response.status !== 200) {\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 project: string;\n repo: string;\n authorization: string;\n apiBaseUrl: string;\n}) => {\n const { project, 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}/projects/${project}/repos/${repo}/default-branch`,\n options,\n );\n } catch (error) {\n throw error;\n }\n\n const { displayId } = await response.json();\n const defaultBranch = displayId;\n if (!defaultBranch) {\n throw new Error(`Could not fetch default branch for ${project}/${repo}`);\n }\n return defaultBranch;\n};\nconst isApiBaseUrlHttps = (apiBaseUrl: string): boolean => {\n const url = new URL(apiBaseUrl);\n return url.protocol === 'https:';\n};\n/**\n * Creates a BitbucketServer Pull Request action.\n * @public\n */\nexport function createPublishBitbucketServerPullRequestAction(options: {\n integrations: ScmIntegrationRegistry;\n config: Config;\n}) {\n const { integrations, config } = options;\n\n return createTemplateAction({\n id: 'publish:bitbucketServer: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 reviewers: z =>\n z\n .array(z.string(), {\n description:\n 'The usernames of reviewers that will be added to the pull request',\n })\n .optional(),\n token: z =>\n z\n .string({\n description:\n 'The token to use for authorization to BitBucket Server',\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\n .string({\n description: 'A URL to the pull request with the provider',\n })\n .optional(),\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n title,\n description,\n targetBranch,\n sourceBranch,\n reviewers,\n gitAuthorName,\n gitAuthorEmail,\n } = ctx.input;\n\n const { project, repo, host } = parseRepoUrl(repoUrl, integrations);\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.bitbucketServer.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 token = ctx.input.token ?? integrationConfig.config.token;\n\n const authConfig = {\n ...integrationConfig.config,\n ...{ token },\n };\n\n const reqOpts = getBitbucketServerRequestOptions(authConfig);\n const authorization = reqOpts.headers.Authorization;\n if (!authorization) {\n throw new Error(\n `Authorization has not been provided for ${integrationConfig.config.host}. Please add either (a) a user login auth token, or (b) a token input from the template or (c) username + password to the integration config.`,\n );\n }\n\n const apiBaseUrl = integrationConfig.config.apiBaseUrl;\n\n let finalTargetBranch = targetBranch;\n if (!finalTargetBranch) {\n finalTargetBranch = await getDefaultBranch({\n project,\n repo,\n authorization,\n apiBaseUrl,\n });\n }\n\n const toRef = await findBranches({\n project,\n repo,\n branchName: finalTargetBranch!,\n authorization,\n apiBaseUrl,\n });\n\n let fromRef = await findBranches({\n project,\n repo,\n branchName: sourceBranch,\n authorization,\n apiBaseUrl,\n });\n\n if (!fromRef) {\n // create branch\n ctx.logger.info(\n `source branch not found -> creating branch named: ${sourceBranch} lastCommit: ${toRef.latestCommit}`,\n );\n const latestCommit = toRef.latestCommit;\n\n fromRef = await createBranch({\n project,\n repo,\n branchName: sourceBranch,\n authorization,\n apiBaseUrl,\n startPoint: latestCommit,\n });\n\n const isHttps: boolean = isApiBaseUrlHttps(apiBaseUrl);\n const remoteUrl = `${\n isHttps ? 'https' : 'http'\n }://${host}/scm/${project}/${repo}.git`;\n\n const auth = authConfig.token\n ? {\n token: token!,\n }\n : {\n username: authConfig.username!,\n password: authConfig.password!,\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 project,\n repo,\n title,\n description,\n toRef,\n fromRef,\n reviewers,\n authorization,\n apiBaseUrl,\n });\n\n ctx.output('pullRequestUrl', pullRequestUrl);\n },\n });\n}\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","getBitbucketServerRequestOptions","getRepoSourceDirectory","cloneRepo","fs","isNotGitDirectoryOrContents","addFiles","commitAndPushBranch"],"mappings":";;;;;;;;;;;;AAkCA,MAAM,iBAAA,GAAoB,OAAO,IAwB3B,KAAA;AACJ,EAAM,MAAA;AAAA,IACJ,OAAA;AAAA,IACA,IAAA;AAAA,IACA,KAAA;AAAA,IACA,WAAA;AAAA,IACA,KAAA;AAAA,IACA,OAAA;AAAA,IACA,SAAA;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,WAAA;AAAA,MACA,KAAO,EAAA,MAAA;AAAA,MACP,IAAM,EAAA,IAAA;AAAA,MACN,MAAQ,EAAA,KAAA;AAAA,MACR,MAAQ,EAAA,IAAA;AAAA,MACR,KAAA;AAAA,MACA,OAAA;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AA,UAC5B,SAAW,EAAA,IAAA;AAAA,UACX,MAAQ,EAAAC;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,OAAA;AAAA,QACA,IAAA;AAAA,QACA,KAAA;AAAA,QACA,WAAA;AAAA,QACA,KAAA;AAAA,QACA,OAAA;AAAA,QACA,SAAA;AAAA,QACA,aAAA;AAAA,QACA;AAAA,OACD,CAAA;AAED,MAAI,GAAA,CAAA,MAAA,CAAO,kBAAkB,cAAc,CAAA;AAAA;AAC7C,GACD,CAAA;AACH;;;;"}
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,17 +13,21 @@ declare function createPublishBitbucketServerAction(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
- sourcePath?: string;
21
- enableLFS?: boolean;
22
- token?: string;
23
- gitCommitMessage?: string;
24
- gitAuthorName?: string;
25
- gitAuthorEmail?: string;
26
- signCommit?: boolean;
27
- }, _backstage_types.JsonObject, "v1">;
16
+ description?: string | undefined;
17
+ repoVisibility?: "private" | "public" | undefined;
18
+ defaultBranch?: string | undefined;
19
+ sourcePath?: string | undefined;
20
+ enableLFS?: boolean | undefined;
21
+ token?: string | undefined;
22
+ gitCommitMessage?: string | undefined;
23
+ gitAuthorName?: string | undefined;
24
+ gitAuthorEmail?: string | undefined;
25
+ signCommit?: boolean | undefined;
26
+ }, {
27
+ remoteUrl?: string | undefined;
28
+ repoContentsUrl?: string | undefined;
29
+ commitHash?: string | undefined;
30
+ }, "v2">;
28
31
 
29
32
  /**
30
33
  * Creates a BitbucketServer Pull Request action.
@@ -36,14 +39,16 @@ declare function createPublishBitbucketServerPullRequestAction(options: {
36
39
  }): _backstage_plugin_scaffolder_node.TemplateAction<{
37
40
  repoUrl: string;
38
41
  title: string;
39
- description?: string;
40
- targetBranch?: string;
41
42
  sourceBranch: string;
42
- reviewers?: string[];
43
- token?: string;
44
- gitAuthorName?: string;
45
- gitAuthorEmail?: string;
46
- }, _backstage_types.JsonObject, "v1">;
43
+ description?: string | undefined;
44
+ targetBranch?: string | undefined;
45
+ reviewers?: string[] | undefined;
46
+ token?: string | undefined;
47
+ gitAuthorName?: string | undefined;
48
+ gitAuthorEmail?: string | undefined;
49
+ }, {
50
+ pullRequestUrl?: string | undefined;
51
+ }, "v2">;
47
52
 
48
53
  /**
49
54
  * @public
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-scaffolder-backend-module-bitbucket-server",
3
- "version": "0.2.10-next.0",
3
+ "version": "0.2.10-next.2",
4
4
  "description": "The Bitbucket Server module for @backstage/plugin-scaffolder-backend",
5
5
  "backstage": {
6
6
  "role": "backend-plugin-module",
@@ -50,18 +50,19 @@
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
- "@backstage/plugin-scaffolder-node": "0.8.3-next.0",
57
+ "@backstage/plugin-scaffolder-node": "0.9.0-next.2",
58
58
  "fs-extra": "^11.2.0",
59
- "yaml": "^2.0.0"
59
+ "yaml": "^2.0.0",
60
+ "zod": "^3.22.4"
60
61
  },
61
62
  "devDependencies": {
62
- "@backstage/backend-test-utils": "1.6.0-next.0",
63
- "@backstage/cli": "0.32.1",
64
- "@backstage/plugin-scaffolder-node-test-utils": "0.2.3-next.0",
63
+ "@backstage/backend-test-utils": "1.6.0-next.2",
64
+ "@backstage/cli": "0.33.0-next.1",
65
+ "@backstage/plugin-scaffolder-node-test-utils": "0.3.0-next.2",
65
66
  "msw": "^1.0.0"
66
67
  }
67
68
  }