@backstage/plugin-scaffolder-backend-module-gerrit 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 +23 -0
- package/dist/actions/gerrit.cjs.js +33 -57
- package/dist/actions/gerrit.cjs.js.map +1 -1
- package/dist/actions/gerritReview.cjs.js +27 -49
- package/dist/actions/gerritReview.cjs.js.map +1 -1
- package/dist/index.d.ts +21 -15
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @backstage/plugin-scaffolder-backend-module-gerrit
|
|
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
|
+
- e24b29b: Migrating to use new format for actions
|
|
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
|
|
@@ -52,65 +52,41 @@ function createPublishGerritAction(options) {
|
|
|
52
52
|
examples: gerrit_examples.examples,
|
|
53
53
|
schema: {
|
|
54
54
|
input: {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
description:
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
description: `Sets the default author name for the commit. The default value is 'Scaffolder'`
|
|
80
|
-
},
|
|
81
|
-
gitAuthorEmail: {
|
|
82
|
-
title: "Default Author Email",
|
|
83
|
-
type: "string",
|
|
84
|
-
description: `Sets the default author email for the commit.`
|
|
85
|
-
},
|
|
86
|
-
sourcePath: {
|
|
87
|
-
title: "Source Path",
|
|
88
|
-
type: "string",
|
|
89
|
-
description: `Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.`
|
|
90
|
-
},
|
|
91
|
-
signCommit: {
|
|
92
|
-
title: "Sign commit",
|
|
93
|
-
type: "boolean",
|
|
94
|
-
description: "Sign commit with configured PGP private key"
|
|
95
|
-
}
|
|
96
|
-
}
|
|
55
|
+
repoUrl: (z) => z.string({
|
|
56
|
+
description: "Repository Location"
|
|
57
|
+
}),
|
|
58
|
+
description: (z) => z.string({
|
|
59
|
+
description: "Repository Description"
|
|
60
|
+
}),
|
|
61
|
+
defaultBranch: (z) => z.string({
|
|
62
|
+
description: `Sets the default branch on the repository. The default value is 'master'`
|
|
63
|
+
}).optional(),
|
|
64
|
+
gitCommitMessage: (z) => z.string({
|
|
65
|
+
description: `Sets the commit message on the repository. The default value is 'initial commit'`
|
|
66
|
+
}).optional(),
|
|
67
|
+
gitAuthorName: (z) => z.string({
|
|
68
|
+
description: `Sets the default author name for the commit. The default value is 'Scaffolder'`
|
|
69
|
+
}).optional(),
|
|
70
|
+
gitAuthorEmail: (z) => z.string({
|
|
71
|
+
description: `Sets the default author email for the commit.`
|
|
72
|
+
}).optional(),
|
|
73
|
+
sourcePath: (z) => z.string({
|
|
74
|
+
description: `Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.`
|
|
75
|
+
}).optional(),
|
|
76
|
+
signCommit: (z) => z.boolean({
|
|
77
|
+
description: "Sign commit with configured PGP private key"
|
|
78
|
+
}).optional()
|
|
97
79
|
},
|
|
98
80
|
output: {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
},
|
|
109
|
-
commitHash: {
|
|
110
|
-
title: "The git commit hash of the initial commit",
|
|
111
|
-
type: "string"
|
|
112
|
-
}
|
|
113
|
-
}
|
|
81
|
+
remoteUrl: (z) => z.string({
|
|
82
|
+
description: "A URL to the repository with the provider"
|
|
83
|
+
}).optional(),
|
|
84
|
+
repoContentsUrl: (z) => z.string({
|
|
85
|
+
description: "A URL to the root of the repository"
|
|
86
|
+
}).optional(),
|
|
87
|
+
commitHash: (z) => z.string({
|
|
88
|
+
description: "The git commit hash of the initial commit"
|
|
89
|
+
}).optional()
|
|
114
90
|
}
|
|
115
91
|
},
|
|
116
92
|
async handler(ctx) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gerrit.cjs.js","sources":["../../src/actions/gerrit.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport crypto from 'crypto';\nimport { InputError } from '@backstage/errors';\nimport { Config } from '@backstage/config';\nimport {\n GerritIntegrationConfig,\n getGerritRequestOptions,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\nimport {\n createTemplateAction,\n getRepoSourceDirectory,\n initRepoAndPush,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { examples } from './gerrit.examples';\n\nconst createGerritProject = async (\n config: GerritIntegrationConfig,\n options: {\n projectName: string;\n parent: string;\n owner?: string;\n description: string;\n defaultBranch: string;\n },\n): Promise<void> => {\n const { projectName, parent, owner, description, defaultBranch } = options;\n\n const fetchOptions: RequestInit = {\n method: 'PUT',\n body: JSON.stringify({\n parent,\n description,\n branches: [defaultBranch],\n owners: owner ? [owner] : [],\n create_empty_commit: false,\n }),\n headers: {\n ...getGerritRequestOptions(config).headers,\n 'Content-Type': 'application/json',\n },\n };\n const response: Response = await fetch(\n `${config.baseUrl}/a/projects/${encodeURIComponent(projectName)}`,\n fetchOptions,\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\nconst generateCommitMessage = (\n config: Config,\n commitSubject?: string,\n): string => {\n const changeId = crypto.randomBytes(20).toString('hex');\n const msg = `${\n config.getOptionalString('scaffolder.defaultCommitMessage') || commitSubject\n }\\n\\nChange-Id: I${changeId}`;\n return msg;\n};\n\n/**\n * Creates a new action that initializes a git repository of the content in the workspace\n * and publishes it to a Gerrit instance.\n * @public\n */\nexport function createPublishGerritAction(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 gitCommitMessage?: string;\n gitAuthorName?: string;\n gitAuthorEmail?: string;\n sourcePath?: string;\n signCommit?: boolean;\n }>({\n id: 'publish:gerrit',\n supportsDryRun: true,\n description:\n 'Initializes a git repository of the content in the workspace, and publishes it to Gerrit.',\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 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 gitAuthorName: {\n title: 'Default Author Name',\n type: 'string',\n description: `Sets the default author name for the commit. The default value is 'Scaffolder'`,\n },\n gitAuthorEmail: {\n title: 'Default Author Email',\n type: 'string',\n description: `Sets the default author email for the commit.`,\n },\n sourcePath: {\n title: 'Source Path',\n type: 'string',\n description: `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 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 gitAuthorName,\n gitAuthorEmail,\n gitCommitMessage = 'initial commit',\n sourcePath,\n signCommit,\n } = ctx.input;\n const { repo, host, owner, workspace } = parseRepoUrl(\n repoUrl,\n integrations,\n );\n\n const integrationConfig = integrations.gerrit.byHost(host);\n\n if (!integrationConfig) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n if (!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 repoContentsUrl = `${integrationConfig.config.gitilesBaseUrl}/${repo}/+/refs/heads/${defaultBranch}`;\n const remoteUrl = `${integrationConfig.config.cloneUrl}/a/${repo}`;\n const gitName = gitAuthorName\n ? gitAuthorName\n : config.getOptionalString('scaffolder.defaultAuthor.name');\n const gitEmail = gitAuthorEmail\n ? gitAuthorEmail\n : config.getOptionalString('scaffolder.defaultAuthor.email');\n const commitMessage = generateCommitMessage(config, gitCommitMessage);\n\n if (ctx.isDryRun) {\n ctx.logger.info(\n `Dry run arguments: ${{\n gitName,\n gitEmail,\n commitMessage,\n ...ctx.input,\n }}`,\n );\n ctx.output('remoteUrl', remoteUrl);\n ctx.output('commitHash', 'abcd-dry-run-1234');\n ctx.output('repoContentsUrl', repoContentsUrl);\n return;\n }\n\n await createGerritProject(integrationConfig.config, {\n description,\n owner: owner,\n projectName: repo,\n parent: workspace,\n defaultBranch,\n });\n const auth = {\n username: integrationConfig.config.username!,\n password: integrationConfig.config.password!,\n };\n const gitAuthorInfo = {\n name: gitName,\n email: gitEmail,\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 commitResult = await initRepoAndPush({\n dir: getRepoSourceDirectory(ctx.workspacePath, sourcePath),\n remoteUrl,\n auth,\n defaultBranch,\n logger: ctx.logger,\n commitMessage: generateCommitMessage(config, gitCommitMessage),\n gitAuthorInfo,\n signingKey: signCommit ? signingKey : undefined,\n });\n\n ctx.output('remoteUrl', remoteUrl);\n ctx.output('commitHash', commitResult?.commitHash);\n ctx.output('repoContentsUrl', repoContentsUrl);\n },\n });\n}\n"],"names":["getGerritRequestOptions","crypto","createTemplateAction","examples","parseRepoUrl","InputError","initRepoAndPush","getRepoSourceDirectory"],"mappings":";;;;;;;;;;;;AAgCA,MAAM,mBAAA,GAAsB,OAC1B,MAAA,EACA,OAOkB,KAAA;AAClB,EAAA,MAAM,EAAE,WAAa,EAAA,MAAA,EAAQ,KAAO,EAAA,WAAA,EAAa,eAAkB,GAAA,OAAA;AAEnE,EAAA,MAAM,YAA4B,GAAA;AAAA,IAChC,MAAQ,EAAA,KAAA;AAAA,IACR,IAAA,EAAM,KAAK,SAAU,CAAA;AAAA,MACnB,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,CAAA;AAAA,QACzC,GAAK,EAAAC,2CAAA,CAAuB,GAAI,CAAA,aAAA,EAAe,UAAU,CAAA;AAAA,QACzD,SAAA;AAAA,QACA,IAAA;AAAA,QACA,aAAA;AAAA,QACA,QAAQ,GAAI,CAAA,MAAA;AAAA,QACZ,aAAA,EAAe,qBAAsB,CAAA,MAAA,EAAQ,gBAAgB,CAAA;AAAA,QAC7D,aAAA;AAAA,QACA,UAAA,EAAY,aAAa,UAAa,GAAA,KAAA;AAAA,OACvC,CAAA;AAED,MAAI,GAAA,CAAA,MAAA,CAAO,aAAa,SAAS,CAAA;AACjC,MAAI,GAAA,CAAA,MAAA,CAAO,YAAc,EAAA,YAAA,EAAc,UAAU,CAAA;AACjD,MAAI,GAAA,CAAA,MAAA,CAAO,mBAAmB,eAAe,CAAA;AAAA;AAC/C,GACD,CAAA;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"gerrit.cjs.js","sources":["../../src/actions/gerrit.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport crypto from 'crypto';\nimport { InputError } from '@backstage/errors';\nimport { Config } from '@backstage/config';\nimport {\n GerritIntegrationConfig,\n getGerritRequestOptions,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\nimport {\n createTemplateAction,\n getRepoSourceDirectory,\n initRepoAndPush,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { examples } from './gerrit.examples';\n\nconst createGerritProject = async (\n config: GerritIntegrationConfig,\n options: {\n projectName: string;\n parent: string;\n owner?: string;\n description: string;\n defaultBranch: string;\n },\n): Promise<void> => {\n const { projectName, parent, owner, description, defaultBranch } = options;\n\n const fetchOptions: RequestInit = {\n method: 'PUT',\n body: JSON.stringify({\n parent,\n description,\n branches: [defaultBranch],\n owners: owner ? [owner] : [],\n create_empty_commit: false,\n }),\n headers: {\n ...getGerritRequestOptions(config).headers,\n 'Content-Type': 'application/json',\n },\n };\n const response: Response = await fetch(\n `${config.baseUrl}/a/projects/${encodeURIComponent(projectName)}`,\n fetchOptions,\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\nconst generateCommitMessage = (\n config: Config,\n commitSubject?: string,\n): string => {\n const changeId = crypto.randomBytes(20).toString('hex');\n const msg = `${\n config.getOptionalString('scaffolder.defaultCommitMessage') || commitSubject\n }\\n\\nChange-Id: I${changeId}`;\n return msg;\n};\n\n/**\n * Creates a new action that initializes a git repository of the content in the workspace\n * and publishes it to a Gerrit instance.\n * @public\n */\nexport function createPublishGerritAction(options: {\n integrations: ScmIntegrationRegistry;\n config: Config;\n}) {\n const { integrations, config } = options;\n\n return createTemplateAction({\n id: 'publish:gerrit',\n supportsDryRun: true,\n description:\n 'Initializes a git repository of the content in the workspace, and publishes it to Gerrit.',\n examples,\n schema: {\n input: {\n repoUrl: z =>\n z.string({\n description: 'Repository Location',\n }),\n description: z =>\n z.string({\n description: 'Repository Description',\n }),\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 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 default author name for the commit. The default value is 'Scaffolder'`,\n })\n .optional(),\n gitAuthorEmail: z =>\n z\n .string({\n description: `Sets the default author email for the commit.`,\n })\n .optional(),\n sourcePath: z =>\n z\n .string({\n description: `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 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 gitAuthorName,\n gitAuthorEmail,\n gitCommitMessage = 'initial commit',\n sourcePath,\n signCommit,\n } = ctx.input;\n const { repo, host, owner, workspace } = parseRepoUrl(\n repoUrl,\n integrations,\n );\n\n const integrationConfig = integrations.gerrit.byHost(host);\n\n if (!integrationConfig) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n if (!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 repoContentsUrl = `${integrationConfig.config.gitilesBaseUrl}/${repo}/+/refs/heads/${defaultBranch}`;\n const remoteUrl = `${integrationConfig.config.cloneUrl}/a/${repo}`;\n const gitName = gitAuthorName\n ? gitAuthorName\n : config.getOptionalString('scaffolder.defaultAuthor.name');\n const gitEmail = gitAuthorEmail\n ? gitAuthorEmail\n : config.getOptionalString('scaffolder.defaultAuthor.email');\n const commitMessage = generateCommitMessage(config, gitCommitMessage);\n\n if (ctx.isDryRun) {\n ctx.logger.info(\n `Dry run arguments: ${{\n gitName,\n gitEmail,\n commitMessage,\n ...ctx.input,\n }}`,\n );\n ctx.output('remoteUrl', remoteUrl);\n ctx.output('commitHash', 'abcd-dry-run-1234');\n ctx.output('repoContentsUrl', repoContentsUrl);\n return;\n }\n\n await createGerritProject(integrationConfig.config, {\n description,\n owner: owner,\n projectName: repo,\n parent: workspace,\n defaultBranch,\n });\n const auth = {\n username: integrationConfig.config.username!,\n password: integrationConfig.config.password!,\n };\n const gitAuthorInfo = {\n name: gitName,\n email: gitEmail,\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 commitResult = await initRepoAndPush({\n dir: getRepoSourceDirectory(ctx.workspacePath, sourcePath),\n remoteUrl,\n auth,\n defaultBranch,\n logger: ctx.logger,\n commitMessage: generateCommitMessage(config, gitCommitMessage),\n gitAuthorInfo,\n signingKey: signCommit ? signingKey : undefined,\n });\n\n ctx.output('remoteUrl', remoteUrl);\n ctx.output('commitHash', commitResult?.commitHash);\n ctx.output('repoContentsUrl', repoContentsUrl);\n },\n });\n}\n"],"names":["getGerritRequestOptions","crypto","createTemplateAction","examples","parseRepoUrl","InputError","initRepoAndPush","getRepoSourceDirectory"],"mappings":";;;;;;;;;;;;AAgCA,MAAM,mBAAA,GAAsB,OAC1B,MAAA,EACA,OAOkB,KAAA;AAClB,EAAA,MAAM,EAAE,WAAa,EAAA,MAAA,EAAQ,KAAO,EAAA,WAAA,EAAa,eAAkB,GAAA,OAAA;AAEnE,EAAA,MAAM,YAA4B,GAAA;AAAA,IAChC,MAAQ,EAAA,KAAA;AAAA,IACR,IAAA,EAAM,KAAK,SAAU,CAAA;AAAA,MACnB,MAAA;AAAA,MACA,WAAA;AAAA,MACA,QAAA,EAAU,CAAC,aAAa,CAAA;AAAA,MACxB,MAAQ,EAAA,KAAA,GAAQ,CAAC,KAAK,IAAI,EAAC;AAAA,MAC3B,mBAAqB,EAAA;AAAA,KACtB,CAAA;AAAA,IACD,OAAS,EAAA;AAAA,MACP,GAAGA,mCAAwB,CAAA,MAAM,CAAE,CAAA,OAAA;AAAA,MACnC,cAAgB,EAAA;AAAA;AAClB,GACF;AACA,EAAA,MAAM,WAAqB,MAAM,KAAA;AAAA,IAC/B,GAAG,MAAO,CAAA,OAAO,CAAe,YAAA,EAAA,kBAAA,C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CAAA;AACjD,MAAI,GAAA,CAAA,MAAA,CAAO,mBAAmB,eAAe,CAAA;AAAA;AAC/C,GACD,CAAA;AACH;;;;"}
|
|
@@ -21,57 +21,35 @@ function createPublishGerritReviewAction(options) {
|
|
|
21
21
|
examples: gerritReview_examples.examples,
|
|
22
22
|
schema: {
|
|
23
23
|
input: {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
},
|
|
46
|
-
gitAuthorName: {
|
|
47
|
-
title: "Default Author Name",
|
|
48
|
-
type: "string",
|
|
49
|
-
description: `Sets the default author name for the commit. The default value is 'Scaffolder'`
|
|
50
|
-
},
|
|
51
|
-
gitAuthorEmail: {
|
|
52
|
-
title: "Default Author Email",
|
|
53
|
-
type: "string",
|
|
54
|
-
description: `Sets the default author email for the commit.`
|
|
55
|
-
},
|
|
56
|
-
signCommit: {
|
|
57
|
-
title: "Sign commit",
|
|
58
|
-
type: "boolean",
|
|
59
|
-
description: "Sign commit with configured PGP private key"
|
|
60
|
-
}
|
|
61
|
-
}
|
|
24
|
+
repoUrl: (z) => z.string({
|
|
25
|
+
description: "Repository Location"
|
|
26
|
+
}),
|
|
27
|
+
branch: (z) => z.string({
|
|
28
|
+
description: "Branch of the repository the review will be created on"
|
|
29
|
+
}).optional(),
|
|
30
|
+
sourcePath: (z) => z.string({
|
|
31
|
+
description: "Subdirectory of working directory containing the repository"
|
|
32
|
+
}).optional(),
|
|
33
|
+
gitCommitMessage: (z) => z.string({
|
|
34
|
+
description: `Sets the commit message on the repository.`
|
|
35
|
+
}).optional(),
|
|
36
|
+
gitAuthorName: (z) => z.string({
|
|
37
|
+
description: `Sets the default author name for the commit. The default value is 'Scaffolder'`
|
|
38
|
+
}).optional(),
|
|
39
|
+
gitAuthorEmail: (z) => z.string({
|
|
40
|
+
description: `Sets the default author email for the commit.`
|
|
41
|
+
}).optional(),
|
|
42
|
+
signCommit: (z) => z.boolean({
|
|
43
|
+
description: "Sign commit with configured PGP private key"
|
|
44
|
+
}).optional()
|
|
62
45
|
},
|
|
63
46
|
output: {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
repoContentsUrl: {
|
|
71
|
-
title: "A URL to the root of the repository",
|
|
72
|
-
type: "string"
|
|
73
|
-
}
|
|
74
|
-
}
|
|
47
|
+
reviewUrl: (z) => z.string({
|
|
48
|
+
description: "A URL to the review"
|
|
49
|
+
}).optional(),
|
|
50
|
+
repoContentsUrl: (z) => z.string({
|
|
51
|
+
description: "A URL to the root of the repository"
|
|
52
|
+
}).optional()
|
|
75
53
|
}
|
|
76
54
|
},
|
|
77
55
|
async handler(ctx) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gerritReview.cjs.js","sources":["../../src/actions/gerritReview.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport crypto from 'crypto';\nimport { InputError } from '@backstage/errors';\nimport { Config } from '@backstage/config';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport {\n commitAndPushRepo,\n createTemplateAction,\n getRepoSourceDirectory,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { examples } from './gerritReview.examples';\n\nconst generateGerritChangeId = (): string => {\n const changeId = crypto.randomBytes(20).toString('hex');\n return `I${changeId}`;\n};\n\n/**\n * Creates a new action that creates a Gerrit review\n * @public\n */\nexport function createPublishGerritReviewAction(options: {\n integrations: ScmIntegrationRegistry;\n config: Config;\n}) {\n const { integrations, config } = options;\n\n return createTemplateAction
|
|
1
|
+
{"version":3,"file":"gerritReview.cjs.js","sources":["../../src/actions/gerritReview.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport crypto from 'crypto';\nimport { InputError } from '@backstage/errors';\nimport { Config } from '@backstage/config';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport {\n commitAndPushRepo,\n createTemplateAction,\n getRepoSourceDirectory,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { examples } from './gerritReview.examples';\n\nconst generateGerritChangeId = (): string => {\n const changeId = crypto.randomBytes(20).toString('hex');\n return `I${changeId}`;\n};\n\n/**\n * Creates a new action that creates a Gerrit review\n * @public\n */\nexport function createPublishGerritReviewAction(options: {\n integrations: ScmIntegrationRegistry;\n config: Config;\n}) {\n const { integrations, config } = options;\n\n return createTemplateAction({\n id: 'publish:gerrit:review',\n description: 'Creates a new Gerrit review.',\n examples,\n schema: {\n input: {\n repoUrl: z =>\n z.string({\n description: 'Repository Location',\n }),\n branch: z =>\n z\n .string({\n description:\n 'Branch of the repository the review will be created on',\n })\n .optional(),\n sourcePath: z =>\n z\n .string({\n description:\n 'Subdirectory of working directory containing the repository',\n })\n .optional(),\n gitCommitMessage: z =>\n z\n .string({\n description: `Sets the commit message on the repository.`,\n })\n .optional(),\n gitAuthorName: z =>\n z\n .string({\n description: `Sets the default author name for the commit. The default value is 'Scaffolder'`,\n })\n .optional(),\n gitAuthorEmail: z =>\n z\n .string({\n description: `Sets the default 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 reviewUrl: z =>\n z\n .string({\n description: 'A URL to the review',\n })\n .optional(),\n repoContentsUrl: z =>\n z\n .string({\n description: 'A URL to the root of the repository',\n })\n .optional(),\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n branch = 'master',\n sourcePath,\n gitAuthorName,\n gitAuthorEmail,\n gitCommitMessage,\n signCommit,\n } = ctx.input;\n const { host, repo } = parseRepoUrl(repoUrl, integrations);\n\n if (!gitCommitMessage) {\n throw new InputError(`Missing gitCommitMessage input`);\n }\n\n const integrationConfig = integrations.gerrit.byHost(host);\n\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 auth = {\n username: integrationConfig.config.username!,\n password: integrationConfig.config.password!,\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 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 const changeId = generateGerritChangeId();\n const commitMessage = `${gitCommitMessage}\\n\\nChange-Id: ${changeId}`;\n\n await commitAndPushRepo({\n dir: getRepoSourceDirectory(ctx.workspacePath, sourcePath),\n auth,\n logger: ctx.logger,\n commitMessage,\n gitAuthorInfo,\n branch,\n remoteRef: `refs/for/${branch}`,\n signingKey: signCommit ? signingKey : undefined,\n });\n\n const repoContentsUrl = `${integrationConfig.config.gitilesBaseUrl}/${repo}/+/refs/heads/${branch}`;\n const reviewUrl = `${integrationConfig.config.baseUrl}/#/q/${changeId}`;\n ctx.logger?.info(`Review available on ${reviewUrl}`);\n ctx.output('repoContentsUrl', repoContentsUrl);\n ctx.output('reviewUrl', reviewUrl);\n },\n });\n}\n"],"names":["crypto","createTemplateAction","examples","parseRepoUrl","InputError","commitAndPushRepo","getRepoSourceDirectory"],"mappings":";;;;;;;;;;;AA4BA,MAAM,yBAAyB,MAAc;AAC3C,EAAA,MAAM,WAAWA,uBAAO,CAAA,WAAA,CAAY,EAAE,CAAA,CAAE,SAAS,KAAK,CAAA;AACtD,EAAA,OAAO,IAAI,QAAQ,CAAA,CAAA;AACrB,CAAA;AAMO,SAAS,gCAAgC,OAG7C,EAAA;AACD,EAAM,MAAA,EAAE,YAAc,EAAA,MAAA,EAAW,GAAA,OAAA;AAEjC,EAAA,OAAOC,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,uBAAA;AAAA,IACJ,WAAa,EAAA,8BAAA;AAAA,cACbC,8BAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,OAAA,EAAS,CACP,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,UACP,WAAa,EAAA;AAAA,SACd,CAAA;AAAA,QACH,MAAA,EAAQ,CACN,CAAA,KAAA,CAAA,CACG,MAAO,CAAA;AAAA,UACN,WACE,EAAA;AAAA,SACH,EACA,QAAS,EAAA;AAAA,QACd,UAAA,EAAY,CACV,CAAA,KAAA,CAAA,CACG,MAAO,CAAA;AAAA,UACN,WACE,EAAA;AAAA,SACH,EACA,QAAS,EAAA;AAAA,QACd,gBAAA,EAAkB,CAChB,CAAA,KAAA,CAAA,CACG,MAAO,CAAA;AAAA,UACN,WAAa,EAAA,CAAA,0CAAA;AAAA,SACd,EACA,QAAS,EAAA;AAAA,QACd,aAAA,EAAe,CACb,CAAA,KAAA,CAAA,C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B,oBAAA,EAAA,SAAS,CAAE,CAAA,CAAA;AACnD,MAAI,GAAA,CAAA,MAAA,CAAO,mBAAmB,eAAe,CAAA;AAC7C,MAAI,GAAA,CAAA,MAAA,CAAO,aAAa,SAAS,CAAA;AAAA;AACnC,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 { Config } from '@backstage/config';
|
|
4
3
|
import { ScmIntegrationRegistry } from '@backstage/integration';
|
|
5
4
|
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
@@ -15,13 +14,17 @@ declare function createPublishGerritAction(options: {
|
|
|
15
14
|
}): _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
16
15
|
repoUrl: string;
|
|
17
16
|
description: string;
|
|
18
|
-
defaultBranch?: string;
|
|
19
|
-
gitCommitMessage?: string;
|
|
20
|
-
gitAuthorName?: string;
|
|
21
|
-
gitAuthorEmail?: string;
|
|
22
|
-
sourcePath?: string;
|
|
23
|
-
signCommit?: boolean;
|
|
24
|
-
},
|
|
17
|
+
defaultBranch?: string | undefined;
|
|
18
|
+
gitCommitMessage?: string | undefined;
|
|
19
|
+
gitAuthorName?: string | undefined;
|
|
20
|
+
gitAuthorEmail?: string | undefined;
|
|
21
|
+
sourcePath?: 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 creates a Gerrit review
|
|
@@ -32,13 +35,16 @@ declare function createPublishGerritReviewAction(options: {
|
|
|
32
35
|
config: Config;
|
|
33
36
|
}): _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
34
37
|
repoUrl: string;
|
|
35
|
-
branch?: string;
|
|
36
|
-
sourcePath?: string;
|
|
37
|
-
gitCommitMessage?: string;
|
|
38
|
-
gitAuthorName?: string;
|
|
39
|
-
gitAuthorEmail?: string;
|
|
40
|
-
signCommit?: boolean;
|
|
41
|
-
},
|
|
38
|
+
branch?: string | undefined;
|
|
39
|
+
sourcePath?: string | undefined;
|
|
40
|
+
gitCommitMessage?: string | undefined;
|
|
41
|
+
gitAuthorName?: string | undefined;
|
|
42
|
+
gitAuthorEmail?: string | undefined;
|
|
43
|
+
signCommit?: boolean | undefined;
|
|
44
|
+
}, {
|
|
45
|
+
reviewUrl?: string | undefined;
|
|
46
|
+
repoContentsUrl?: string | undefined;
|
|
47
|
+
}, "v2">;
|
|
42
48
|
|
|
43
49
|
/**
|
|
44
50
|
* @public
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-scaffolder-backend-module-gerrit",
|
|
3
|
-
"version": "0.2.10-next.
|
|
3
|
+
"version": "0.2.10-next.2",
|
|
4
4
|
"description": "The gerrit module for @backstage/plugin-scaffolder-backend",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "backend-plugin-module",
|
|
@@ -50,17 +50,17 @@
|
|
|
50
50
|
"test": "backstage-cli package test"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@backstage/backend-plugin-api": "1.4.0-next.
|
|
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.
|
|
57
|
+
"@backstage/plugin-scaffolder-node": "0.9.0-next.2",
|
|
58
58
|
"yaml": "^2.0.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@backstage/backend-test-utils": "1.6.0-next.
|
|
62
|
-
"@backstage/cli": "0.
|
|
63
|
-
"@backstage/plugin-scaffolder-node-test-utils": "0.
|
|
61
|
+
"@backstage/backend-test-utils": "1.6.0-next.2",
|
|
62
|
+
"@backstage/cli": "0.33.0-next.1",
|
|
63
|
+
"@backstage/plugin-scaffolder-node-test-utils": "0.3.0-next.2",
|
|
64
64
|
"msw": "^1.0.0"
|
|
65
65
|
}
|
|
66
66
|
}
|