@backstage/plugin-scaffolder-backend-module-gerrit 0.2.7-next.1 → 0.2.7
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,29 @@
|
|
|
1
1
|
# @backstage/plugin-scaffolder-backend-module-gerrit
|
|
2
2
|
|
|
3
|
+
## 0.2.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4f8b5b6: Allow signing git commits using configured private PGP key in scaffolder
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @backstage/integration@1.16.2
|
|
10
|
+
- @backstage/plugin-scaffolder-node@0.8.0
|
|
11
|
+
- @backstage/backend-plugin-api@1.2.1
|
|
12
|
+
- @backstage/config@1.3.2
|
|
13
|
+
- @backstage/errors@1.2.7
|
|
14
|
+
|
|
15
|
+
## 0.2.7-next.2
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 4f8b5b6: Allow signing git commits using configured private PGP key in scaffolder
|
|
20
|
+
- Updated dependencies
|
|
21
|
+
- @backstage/plugin-scaffolder-node@0.8.0-next.2
|
|
22
|
+
- @backstage/integration@1.16.2-next.0
|
|
23
|
+
- @backstage/backend-plugin-api@1.2.1-next.1
|
|
24
|
+
- @backstage/config@1.3.2
|
|
25
|
+
- @backstage/errors@1.2.7
|
|
26
|
+
|
|
3
27
|
## 0.2.7-next.1
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
|
@@ -87,6 +87,11 @@ function createPublishGerritAction(options) {
|
|
|
87
87
|
title: "Source Path",
|
|
88
88
|
type: "string",
|
|
89
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"
|
|
90
95
|
}
|
|
91
96
|
}
|
|
92
97
|
},
|
|
@@ -116,7 +121,8 @@ function createPublishGerritAction(options) {
|
|
|
116
121
|
gitAuthorName,
|
|
117
122
|
gitAuthorEmail,
|
|
118
123
|
gitCommitMessage = "initial commit",
|
|
119
|
-
sourcePath
|
|
124
|
+
sourcePath,
|
|
125
|
+
signCommit
|
|
120
126
|
} = ctx.input;
|
|
121
127
|
const { repo, host, owner, workspace } = pluginScaffolderNode.parseRepoUrl(
|
|
122
128
|
repoUrl,
|
|
@@ -167,6 +173,12 @@ function createPublishGerritAction(options) {
|
|
|
167
173
|
name: gitName,
|
|
168
174
|
email: gitEmail
|
|
169
175
|
};
|
|
176
|
+
const signingKey = integrationConfig.config.commitSigningKey ?? config.getOptionalString("scaffolder.defaultCommitSigningKey");
|
|
177
|
+
if (signCommit && !signingKey) {
|
|
178
|
+
throw new Error(
|
|
179
|
+
"Signing commits is enabled but no signing key is provided in the configuration"
|
|
180
|
+
);
|
|
181
|
+
}
|
|
170
182
|
const commitResult = await pluginScaffolderNode.initRepoAndPush({
|
|
171
183
|
dir: pluginScaffolderNode.getRepoSourceDirectory(ctx.workspacePath, sourcePath),
|
|
172
184
|
remoteUrl,
|
|
@@ -174,7 +186,8 @@ function createPublishGerritAction(options) {
|
|
|
174
186
|
defaultBranch,
|
|
175
187
|
logger: ctx.logger,
|
|
176
188
|
commitMessage: generateCommitMessage(config, gitCommitMessage),
|
|
177
|
-
gitAuthorInfo
|
|
189
|
+
gitAuthorInfo,
|
|
190
|
+
signingKey: signCommit ? signingKey : void 0
|
|
178
191
|
});
|
|
179
192
|
ctx.output("remoteUrl", remoteUrl);
|
|
180
193
|
ctx.output("commitHash", commitResult?.commitHash);
|
|
@@ -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 initRepoAndPush,\n getRepoSourceDirectory,\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 }>({\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 },\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 } = 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 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 });\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,KA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AA,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 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,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,CAAmB,WAAW,CAAC,CAAA,CAAA;AAAA,IAC/D;AAAA,GACF;AACA,EAAI,IAAA,QAAA,CAAS,WAAW,GAAK,EAAA;AAC3B,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,6BAAA,EAAgC,QAAS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 function createPublishGerritReviewAction(options) {
|
|
|
52
52
|
title: "Default Author Email",
|
|
53
53
|
type: "string",
|
|
54
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"
|
|
55
60
|
}
|
|
56
61
|
}
|
|
57
62
|
},
|
|
@@ -76,7 +81,8 @@ function createPublishGerritReviewAction(options) {
|
|
|
76
81
|
sourcePath,
|
|
77
82
|
gitAuthorName,
|
|
78
83
|
gitAuthorEmail,
|
|
79
|
-
gitCommitMessage
|
|
84
|
+
gitCommitMessage,
|
|
85
|
+
signCommit
|
|
80
86
|
} = ctx.input;
|
|
81
87
|
const { host, repo } = pluginScaffolderNode.parseRepoUrl(repoUrl, integrations);
|
|
82
88
|
if (!gitCommitMessage) {
|
|
@@ -96,6 +102,12 @@ function createPublishGerritReviewAction(options) {
|
|
|
96
102
|
name: gitAuthorName ? gitAuthorName : config.getOptionalString("scaffolder.defaultAuthor.name"),
|
|
97
103
|
email: gitAuthorEmail ? gitAuthorEmail : config.getOptionalString("scaffolder.defaultAuthor.email")
|
|
98
104
|
};
|
|
105
|
+
const signingKey = integrationConfig.config.commitSigningKey ?? config.getOptionalString("scaffolder.defaultCommitSigningKey");
|
|
106
|
+
if (signCommit && !signingKey) {
|
|
107
|
+
throw new Error(
|
|
108
|
+
"Signing commits is enabled but no signing key is provided in the configuration"
|
|
109
|
+
);
|
|
110
|
+
}
|
|
99
111
|
const changeId = generateGerritChangeId();
|
|
100
112
|
const commitMessage = `${gitCommitMessage}
|
|
101
113
|
|
|
@@ -107,7 +119,8 @@ Change-Id: ${changeId}`;
|
|
|
107
119
|
commitMessage,
|
|
108
120
|
gitAuthorInfo,
|
|
109
121
|
branch,
|
|
110
|
-
remoteRef: `refs/for/${branch}
|
|
122
|
+
remoteRef: `refs/for/${branch}`,
|
|
123
|
+
signingKey: signCommit ? signingKey : void 0
|
|
111
124
|
});
|
|
112
125
|
const repoContentsUrl = `${integrationConfig.config.gitilesBaseUrl}/${repo}/+/refs/heads/${branch}`;
|
|
113
126
|
const reviewUrl = `${integrationConfig.config.baseUrl}/#/q/${changeId}`;
|
|
@@ -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
|
|
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 repoUrl: string;\n branch?: string;\n sourcePath?: string;\n gitCommitMessage?: string;\n gitAuthorName?: string;\n gitAuthorEmail?: string;\n signCommit?: boolean;\n }>({\n id: 'publish:gerrit:review',\n description: 'Creates a new Gerrit review.',\n examples,\n schema: {\n input: {\n type: 'object',\n required: ['repoUrl', 'gitCommitMessage'],\n properties: {\n repoUrl: {\n title: 'Repository Location',\n type: 'string',\n },\n branch: {\n title: 'Repository branch',\n type: 'string',\n description:\n 'Branch of the repository the review will be created on',\n },\n sourcePath: {\n type: 'string',\n title: 'Working Subdirectory',\n description:\n 'Subdirectory of working directory containing the repository',\n },\n gitCommitMessage: {\n title: 'Git Commit Message',\n type: 'string',\n description: `Sets the commit message on the repository.`,\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 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 reviewUrl: {\n title: 'A URL to the review',\n type: 'string',\n },\n repoContentsUrl: {\n title: 'A URL to the root of the repository',\n type: 'string',\n },\n },\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,yCAQJ,CAAA;AAAA,IACD,EAAI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AAAA;AAEF,MAAA,MAAM,WAAW,sBAAuB,EAAA;AACxC,MAAM,MAAA,aAAA,GAAgB,GAAG,gBAAgB;;AAAA,WAAA,EAAkB,QAAQ,CAAA,CAAA;AAEnE,MAAA,MAAMC,sCAAkB,CAAA;AAAA,QACtB,GAAK,EAAAC,2CAAA,CAAuB,GAAI,CAAA,aAAA,EAAe,UAAU,CAAA;AAAA,QACzD,IAAA;AAAA,QACA,QAAQ,GAAI,CAAA,MAAA;AAAA,QACZ,aAAA;AAAA,QACA,aAAA;AAAA,QACA,MAAA;AAAA,QACA,SAAA,EAAW,YAAY,MAAM,CAAA,CAAA;AAAA,QAC7B,UAAA,EAAY,aAAa,UAAa,GAAA,KAAA;AAAA,OACvC,CAAA;AAED,MAAM,MAAA,eAAA,GAAkB,GAAG,iBAAkB,CAAA,MAAA,CAAO,cAAc,CAAI,CAAA,EAAA,IAAI,iBAAiB,MAAM,CAAA,CAAA;AACjG,MAAA,MAAM,YAAY,CAAG,EAAA,iBAAA,CAAkB,MAAO,CAAA,OAAO,QAAQ,QAAQ,CAAA,CAAA;AACrE,MAAA,GAAA,CAAI,MAAQ,EAAA,IAAA,CAAK,CAAuB,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
|
@@ -15,12 +15,13 @@ declare function createPublishGerritAction(options: {
|
|
|
15
15
|
}): _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
16
16
|
repoUrl: string;
|
|
17
17
|
description: string;
|
|
18
|
-
defaultBranch?: string
|
|
19
|
-
gitCommitMessage?: string
|
|
20
|
-
gitAuthorName?: string
|
|
21
|
-
gitAuthorEmail?: string
|
|
22
|
-
sourcePath?: string
|
|
23
|
-
|
|
18
|
+
defaultBranch?: string;
|
|
19
|
+
gitCommitMessage?: string;
|
|
20
|
+
gitAuthorName?: string;
|
|
21
|
+
gitAuthorEmail?: string;
|
|
22
|
+
sourcePath?: string;
|
|
23
|
+
signCommit?: boolean;
|
|
24
|
+
}, _backstage_types.JsonObject, "v1">;
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
27
|
* Creates a new action that creates a Gerrit review
|
|
@@ -31,12 +32,13 @@ declare function createPublishGerritReviewAction(options: {
|
|
|
31
32
|
config: Config;
|
|
32
33
|
}): _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
33
34
|
repoUrl: string;
|
|
34
|
-
branch?: string
|
|
35
|
-
sourcePath?: string
|
|
36
|
-
gitCommitMessage?: string
|
|
37
|
-
gitAuthorName?: string
|
|
38
|
-
gitAuthorEmail?: string
|
|
39
|
-
|
|
35
|
+
branch?: string;
|
|
36
|
+
sourcePath?: string;
|
|
37
|
+
gitCommitMessage?: string;
|
|
38
|
+
gitAuthorName?: string;
|
|
39
|
+
gitAuthorEmail?: string;
|
|
40
|
+
signCommit?: boolean;
|
|
41
|
+
}, _backstage_types.JsonObject, "v1">;
|
|
40
42
|
|
|
41
43
|
/**
|
|
42
44
|
* @public
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-scaffolder-backend-module-gerrit",
|
|
3
|
-
"version": "0.2.7
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "The gerrit module for @backstage/plugin-scaffolder-backend",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "backend-plugin-module",
|
|
@@ -30,13 +30,6 @@
|
|
|
30
30
|
},
|
|
31
31
|
"main": "./dist/index.cjs.js",
|
|
32
32
|
"types": "./dist/index.d.ts",
|
|
33
|
-
"typesVersions": {
|
|
34
|
-
"*": {
|
|
35
|
-
"index": [
|
|
36
|
-
"dist/index.d.ts"
|
|
37
|
-
]
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
33
|
"files": [
|
|
41
34
|
"dist"
|
|
42
35
|
],
|
|
@@ -50,17 +43,17 @@
|
|
|
50
43
|
"test": "backstage-cli package test"
|
|
51
44
|
},
|
|
52
45
|
"dependencies": {
|
|
53
|
-
"@backstage/backend-plugin-api": "1.2.1
|
|
54
|
-
"@backstage/config": "1.3.2",
|
|
55
|
-
"@backstage/errors": "1.2.7",
|
|
56
|
-
"@backstage/integration": "1.16.
|
|
57
|
-
"@backstage/plugin-scaffolder-node": "0.
|
|
46
|
+
"@backstage/backend-plugin-api": "^1.2.1",
|
|
47
|
+
"@backstage/config": "^1.3.2",
|
|
48
|
+
"@backstage/errors": "^1.2.7",
|
|
49
|
+
"@backstage/integration": "^1.16.2",
|
|
50
|
+
"@backstage/plugin-scaffolder-node": "^0.8.0",
|
|
58
51
|
"yaml": "^2.0.0"
|
|
59
52
|
},
|
|
60
53
|
"devDependencies": {
|
|
61
|
-
"@backstage/backend-test-utils": "1.3.1
|
|
62
|
-
"@backstage/cli": "0.
|
|
63
|
-
"@backstage/plugin-scaffolder-node-test-utils": "0.
|
|
54
|
+
"@backstage/backend-test-utils": "^1.3.1",
|
|
55
|
+
"@backstage/cli": "^0.31.0",
|
|
56
|
+
"@backstage/plugin-scaffolder-node-test-utils": "^0.2.0",
|
|
64
57
|
"msw": "^1.0.0"
|
|
65
58
|
}
|
|
66
59
|
}
|