@backstage/plugin-scaffolder-backend 0.0.0-nightly-20220719025614 → 0.0.0-nightly-20220721025105

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,6 +1,21 @@
1
1
  # @backstage/plugin-scaffolder-backend
2
2
 
3
- ## 0.0.0-nightly-20220719025614
3
+ ## 0.0.0-nightly-20220721025105
4
+
5
+ ### Minor Changes
6
+
7
+ - eeff5046ae: Updated `publish:gitlab:merge-request` action to allow commit updates and deletes
8
+
9
+ ### Patch Changes
10
+
11
+ - fc8a5f797b: Add a `publish:gerrit:review` scaffolder action
12
+ - Updated dependencies
13
+ - @backstage/backend-common@0.0.0-nightly-20220721025105
14
+ - @backstage/integration@0.0.0-nightly-20220721025105
15
+ - @backstage/backend-plugin-api@0.0.0-nightly-20220721025105
16
+ - @backstage/plugin-catalog-backend@0.0.0-nightly-20220721025105
17
+
18
+ ## 1.4.0
4
19
 
5
20
  ### Minor Changes
6
21
 
@@ -43,15 +58,15 @@
43
58
  - 945a27fa6a: Add sourcePath option to publish:gerrit action
44
59
  - 1764296a68: Allow to create Gerrit project using default owner
45
60
  - Updated dependencies
46
- - @backstage/backend-plugin-api@0.0.0-nightly-20220719025614
47
- - @backstage/plugin-catalog-backend@0.0.0-nightly-20220719025614
48
- - @backstage/backend-common@0.0.0-nightly-20220719025614
49
- - @backstage/catalog-model@0.0.0-nightly-20220719025614
50
- - @backstage/plugin-catalog-node@0.0.0-nightly-20220719025614
51
- - @backstage/integration@0.0.0-nightly-20220719025614
52
- - @backstage/catalog-client@0.0.0-nightly-20220719025614
53
- - @backstage/errors@0.0.0-nightly-20220719025614
54
- - @backstage/plugin-scaffolder-common@0.0.0-nightly-20220719025614
61
+ - @backstage/backend-plugin-api@0.1.0
62
+ - @backstage/plugin-catalog-backend@1.3.0
63
+ - @backstage/backend-common@0.14.1
64
+ - @backstage/catalog-model@1.1.0
65
+ - @backstage/plugin-catalog-node@1.0.0
66
+ - @backstage/integration@1.2.2
67
+ - @backstage/catalog-client@1.0.4
68
+ - @backstage/errors@1.1.0
69
+ - @backstage/plugin-scaffolder-common@1.1.2
55
70
 
56
71
  ## 1.4.0-next.3
57
72
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-scaffolder-backend",
3
- "version": "0.0.0-nightly-20220719025614",
3
+ "version": "0.0.0-nightly-20220721025105",
4
4
  "main": "../dist/index.cjs.js",
5
5
  "types": "../dist/index.alpha.d.ts"
6
6
  }
@@ -441,6 +441,22 @@ gitAuthorEmail?: string | undefined;
441
441
  sourcePath?: string | undefined;
442
442
  }>;
443
443
 
444
+ /**
445
+ * Creates a new action that creates a Gerrit review
446
+ * @public
447
+ */
448
+ export declare function createPublishGerritReviewAction(options: {
449
+ integrations: ScmIntegrationRegistry;
450
+ config: Config;
451
+ }): TemplateAction< {
452
+ repoUrl: string;
453
+ branch?: string | undefined;
454
+ sourcePath?: string | undefined;
455
+ gitCommitMessage?: string | undefined;
456
+ gitAuthorName?: string | undefined;
457
+ gitAuthorEmail?: string | undefined;
458
+ }>;
459
+
444
460
  /**
445
461
  * Creates a new action that initializes a git repository of the content in the workspace
446
462
  * and publishes it to GitHub.
@@ -534,6 +550,7 @@ description: string;
534
550
  branchName: string;
535
551
  targetPath: string;
536
552
  token?: string | undefined;
553
+ commitAction?: "create" | "update" | "delete" | undefined;
537
554
  /** @deprecated Use projectPath instead */
538
555
  projectid?: string | undefined;
539
556
  removeSourceBranch?: boolean | undefined;
@@ -441,6 +441,22 @@ gitAuthorEmail?: string | undefined;
441
441
  sourcePath?: string | undefined;
442
442
  }>;
443
443
 
444
+ /**
445
+ * Creates a new action that creates a Gerrit review
446
+ * @public
447
+ */
448
+ export declare function createPublishGerritReviewAction(options: {
449
+ integrations: ScmIntegrationRegistry;
450
+ config: Config;
451
+ }): TemplateAction< {
452
+ repoUrl: string;
453
+ branch?: string | undefined;
454
+ sourcePath?: string | undefined;
455
+ gitCommitMessage?: string | undefined;
456
+ gitAuthorName?: string | undefined;
457
+ gitAuthorEmail?: string | undefined;
458
+ }>;
459
+
444
460
  /**
445
461
  * Creates a new action that initializes a git repository of the content in the workspace
446
462
  * and publishes it to GitHub.
@@ -534,6 +550,7 @@ description: string;
534
550
  branchName: string;
535
551
  targetPath: string;
536
552
  token?: string | undefined;
553
+ commitAction?: "create" | "update" | "delete" | undefined;
537
554
  /** @deprecated Use projectPath instead */
538
555
  projectid?: string | undefined;
539
556
  removeSourceBranch?: boolean | undefined;
package/dist/index.cjs.js CHANGED
@@ -834,6 +834,40 @@ async function initRepoAndPush({
834
834
  remote: "origin"
835
835
  });
836
836
  }
837
+ async function commitAndPushRepo({
838
+ dir,
839
+ auth,
840
+ logger,
841
+ commitMessage,
842
+ gitAuthorInfo,
843
+ branch = "master",
844
+ remoteRef
845
+ }) {
846
+ var _a, _b;
847
+ const git = backendCommon.Git.fromAuth({
848
+ username: auth.username,
849
+ password: auth.password,
850
+ logger
851
+ });
852
+ await git.fetch({ dir });
853
+ await git.checkout({ dir, ref: branch });
854
+ await git.add({ dir, filepath: "." });
855
+ const authorInfo = {
856
+ name: (_a = gitAuthorInfo == null ? void 0 : gitAuthorInfo.name) != null ? _a : "Scaffolder",
857
+ email: (_b = gitAuthorInfo == null ? void 0 : gitAuthorInfo.email) != null ? _b : "scaffolder@backstage.io"
858
+ };
859
+ await git.commit({
860
+ dir,
861
+ message: commitMessage,
862
+ author: authorInfo,
863
+ committer: authorInfo
864
+ });
865
+ await git.push({
866
+ dir,
867
+ remote: "origin",
868
+ remoteRef: remoteRef != null ? remoteRef : `refs/heads/${branch}`
869
+ });
870
+ }
837
871
  const enableBranchProtectionOnDefaultRepoBranch = async ({
838
872
  repoName,
839
873
  client,
@@ -2447,6 +2481,113 @@ function createPublishGerritAction(options) {
2447
2481
  });
2448
2482
  }
2449
2483
 
2484
+ const generateGerritChangeId = () => {
2485
+ const changeId = crypto__default["default"].randomBytes(20).toString("hex");
2486
+ return `I${changeId}`;
2487
+ };
2488
+ function createPublishGerritReviewAction(options) {
2489
+ const { integrations, config } = options;
2490
+ return createTemplateAction({
2491
+ id: "publish:gerrit:review",
2492
+ description: "Creates a new Gerrit review.",
2493
+ schema: {
2494
+ input: {
2495
+ type: "object",
2496
+ required: ["repoUrl", "gitCommitMessage"],
2497
+ properties: {
2498
+ repoUrl: {
2499
+ title: "Repository Location",
2500
+ type: "string"
2501
+ },
2502
+ branch: {
2503
+ title: "Repository branch",
2504
+ type: "string",
2505
+ description: "Branch of the repository the review will be created on"
2506
+ },
2507
+ sourcePath: {
2508
+ type: "string",
2509
+ title: "Working Subdirectory",
2510
+ description: "Subdirectory of working directory containing the repository"
2511
+ },
2512
+ gitCommitMessage: {
2513
+ title: "Git Commit Message",
2514
+ type: "string",
2515
+ description: `Sets the commit message on the repository.`
2516
+ },
2517
+ gitAuthorName: {
2518
+ title: "Default Author Name",
2519
+ type: "string",
2520
+ description: `Sets the default author name for the commit. The default value is 'Scaffolder'`
2521
+ },
2522
+ gitAuthorEmail: {
2523
+ title: "Default Author Email",
2524
+ type: "string",
2525
+ description: `Sets the default author email for the commit.`
2526
+ }
2527
+ }
2528
+ },
2529
+ output: {
2530
+ type: "object",
2531
+ properties: {
2532
+ reviewUrl: {
2533
+ title: "A URL to the review",
2534
+ type: "string"
2535
+ },
2536
+ repoContentsUrl: {
2537
+ title: "A URL to the root of the repository",
2538
+ type: "string"
2539
+ }
2540
+ }
2541
+ }
2542
+ },
2543
+ async handler(ctx) {
2544
+ var _a;
2545
+ const {
2546
+ repoUrl,
2547
+ branch = "master",
2548
+ sourcePath,
2549
+ gitAuthorName,
2550
+ gitAuthorEmail,
2551
+ gitCommitMessage
2552
+ } = ctx.input;
2553
+ const { host, repo } = parseRepoUrl(repoUrl, integrations);
2554
+ if (!gitCommitMessage) {
2555
+ throw new errors.InputError(`Missing gitCommitMessage input`);
2556
+ }
2557
+ const integrationConfig = integrations.gerrit.byHost(host);
2558
+ if (!integrationConfig) {
2559
+ throw new errors.InputError(`No matching integration configuration for host ${host}, please check your integrations config`);
2560
+ }
2561
+ const auth = {
2562
+ username: integrationConfig.config.username,
2563
+ password: integrationConfig.config.password
2564
+ };
2565
+ const gitAuthorInfo = {
2566
+ name: gitAuthorName ? gitAuthorName : config.getOptionalString("scaffolder.defaultAuthor.name"),
2567
+ email: gitAuthorEmail ? gitAuthorEmail : config.getOptionalString("scaffolder.defaultAuthor.email")
2568
+ };
2569
+ const changeId = generateGerritChangeId();
2570
+ const commitMessage = `${gitCommitMessage}
2571
+
2572
+ Change-Id: ${changeId}`;
2573
+ await commitAndPushRepo({
2574
+ dir: getRepoSourceDirectory(ctx.workspacePath, sourcePath),
2575
+ auth,
2576
+ logger: ctx.logger,
2577
+ commitMessage,
2578
+ gitAuthorInfo,
2579
+ branch,
2580
+ remoteRef: `refs/for/${branch}`
2581
+ });
2582
+ const repoContentsUrl = `${integrationConfig.config.gitilesBaseUrl}/${repo}/+/refs/heads/${branch}`;
2583
+ const reviewUrl = `${integrationConfig.config.baseUrl}/#/q/${changeId}`;
2584
+ (_a = ctx.logger) == null ? void 0 : _a.info(`Review available on ${reviewUrl}`);
2585
+ ctx.output("repoContentsUrl", repoContentsUrl);
2586
+ ctx.output("reviewUrl", reviewUrl);
2587
+ }
2588
+ });
2589
+ }
2590
+
2450
2591
  function createPublishGithubAction(options) {
2451
2592
  const { integrations, config, githubCredentialsProvider } = options;
2452
2593
  return createTemplateAction({
@@ -2900,6 +3041,12 @@ const createPublishGitlabMergeRequestAction = (options) => {
2900
3041
  type: "string",
2901
3042
  description: "The token to use for authorization to GitLab"
2902
3043
  },
3044
+ commitAction: {
3045
+ title: "Commit action",
3046
+ type: "string",
3047
+ enum: ["create", "update", "delete"],
3048
+ description: "The action to be used for git commit. Defaults to create."
3049
+ },
2903
3050
  removeSourceBranch: {
2904
3051
  title: "Delete source branch",
2905
3052
  type: "boolean",
@@ -2969,13 +3116,16 @@ const createPublishGitlabMergeRequestAction = (options) => {
2969
3116
  const fileContents = await serializeDirectoryContents(targetPath, {
2970
3117
  gitignore: true
2971
3118
  });
2972
- const actions = fileContents.map((file) => ({
2973
- action: "create",
2974
- filePath: path__default["default"].posix.join(ctx.input.targetPath, file.path),
2975
- encoding: "base64",
2976
- content: file.content.toString("base64"),
2977
- execute_filemode: file.executable
2978
- }));
3119
+ const actions = fileContents.map((file) => {
3120
+ var _a2;
3121
+ return {
3122
+ action: (_a2 = ctx.input.commitAction) != null ? _a2 : "create",
3123
+ filePath: path__default["default"].posix.join(ctx.input.targetPath, file.path),
3124
+ encoding: "base64",
3125
+ content: file.content.toString("base64"),
3126
+ execute_filemode: file.executable
3127
+ };
3128
+ });
2979
3129
  const projects = await api.Projects.show(projectPath);
2980
3130
  const { default_branch: defaultBranch } = projects;
2981
3131
  try {
@@ -3029,6 +3179,10 @@ const createBuiltinActions = (options) => {
3029
3179
  integrations,
3030
3180
  config
3031
3181
  }),
3182
+ createPublishGerritReviewAction({
3183
+ integrations,
3184
+ config
3185
+ }),
3032
3186
  createPublishGithubAction({
3033
3187
  integrations,
3034
3188
  config,
@@ -4246,6 +4400,7 @@ exports.createPublishBitbucketCloudAction = createPublishBitbucketCloudAction;
4246
4400
  exports.createPublishBitbucketServerAction = createPublishBitbucketServerAction;
4247
4401
  exports.createPublishFileAction = createPublishFileAction;
4248
4402
  exports.createPublishGerritAction = createPublishGerritAction;
4403
+ exports.createPublishGerritReviewAction = createPublishGerritReviewAction;
4249
4404
  exports.createPublishGithubAction = createPublishGithubAction;
4250
4405
  exports.createPublishGithubPullRequestAction = createPublishGithubPullRequestAction;
4251
4406
  exports.createPublishGitlabAction = createPublishGitlabAction;