@backstage/plugin-scaffolder-backend 1.7.0-next.1 → 1.7.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @backstage/plugin-scaffolder-backend
2
2
 
3
+ ## 1.7.0-next.2
4
+
5
+ ### Minor Changes
6
+
7
+ - 17ff77154c: Update the `github:publish` action to allow passing whether pull
8
+ requests must be up to date with the default branch before merging.
9
+ - a8e9848479: Added optional `sourcePath` parameter to `publish:gitlab:merge-request` action, `targetPath` is now optional and falls back to current workspace path.
10
+
11
+ ### Patch Changes
12
+
13
+ - 4880d43e25: Fixed setting default branch for Bitbucket Server
14
+ - Updated dependencies
15
+ - @backstage/plugin-catalog-node@1.2.0-next.2
16
+ - @backstage/plugin-catalog-backend@1.5.0-next.2
17
+ - @backstage/backend-tasks@0.3.6-next.2
18
+ - @backstage/backend-common@0.15.2-next.2
19
+ - @backstage/backend-plugin-api@0.1.3-next.2
20
+ - @backstage/plugin-auth-node@0.2.6-next.2
21
+ - @backstage/catalog-client@1.1.1-next.2
22
+ - @backstage/catalog-model@1.1.2-next.2
23
+ - @backstage/config@1.0.3-next.2
24
+ - @backstage/errors@1.1.2-next.2
25
+ - @backstage/integration@1.3.2-next.2
26
+ - @backstage/types@1.0.0
27
+ - @backstage/plugin-scaffolder-common@1.2.1-next.2
28
+
3
29
  ## 1.7.0-next.1
4
30
 
5
31
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-scaffolder-backend",
3
- "version": "1.7.0-next.1",
3
+ "version": "1.7.0-next.2",
4
4
  "main": "../dist/index.cjs.js",
5
5
  "types": "../dist/index.alpha.d.ts"
6
6
  }
@@ -293,6 +293,7 @@ allowMergeCommit?: boolean | undefined;
293
293
  allowAutoMerge?: boolean | undefined;
294
294
  requireCodeOwnerReviews?: boolean | undefined;
295
295
  requiredStatusCheckContexts?: string[] | undefined;
296
+ requireBranchesToBeUpToDate?: boolean | undefined;
296
297
  repoVisibility?: "internal" | "private" | "public" | undefined;
297
298
  collaborators?: ({
298
299
  user: string;
@@ -330,6 +331,7 @@ gitAuthorName?: string | undefined;
330
331
  gitAuthorEmail?: string | undefined;
331
332
  requireCodeOwnerReviews?: boolean | undefined;
332
333
  requiredStatusCheckContexts?: string[] | undefined;
334
+ requireBranchesToBeUpToDate?: boolean | undefined;
333
335
  sourcePath?: string | undefined;
334
336
  token?: string | undefined;
335
337
  }>;
@@ -492,6 +494,7 @@ allowAutoMerge?: boolean | undefined;
492
494
  sourcePath?: string | undefined;
493
495
  requireCodeOwnerReviews?: boolean | undefined;
494
496
  requiredStatusCheckContexts?: string[] | undefined;
497
+ requireBranchesToBeUpToDate?: boolean | undefined;
495
498
  repoVisibility?: "internal" | "private" | "public" | undefined;
496
499
  collaborators?: ({
497
500
  user: string;
@@ -558,7 +561,8 @@ repoUrl: string;
558
561
  title: string;
559
562
  description: string;
560
563
  branchName: string;
561
- targetPath: string;
564
+ sourcePath?: string | undefined;
565
+ targetPath?: string | undefined;
562
566
  token?: string | undefined;
563
567
  commitAction?: "update" | "create" | "delete" | undefined;
564
568
  /** @deprecated Use projectPath instead */
@@ -293,6 +293,7 @@ allowMergeCommit?: boolean | undefined;
293
293
  allowAutoMerge?: boolean | undefined;
294
294
  requireCodeOwnerReviews?: boolean | undefined;
295
295
  requiredStatusCheckContexts?: string[] | undefined;
296
+ requireBranchesToBeUpToDate?: boolean | undefined;
296
297
  repoVisibility?: "internal" | "private" | "public" | undefined;
297
298
  collaborators?: ({
298
299
  user: string;
@@ -330,6 +331,7 @@ gitAuthorName?: string | undefined;
330
331
  gitAuthorEmail?: string | undefined;
331
332
  requireCodeOwnerReviews?: boolean | undefined;
332
333
  requiredStatusCheckContexts?: string[] | undefined;
334
+ requireBranchesToBeUpToDate?: boolean | undefined;
333
335
  sourcePath?: string | undefined;
334
336
  token?: string | undefined;
335
337
  }>;
@@ -492,6 +494,7 @@ allowAutoMerge?: boolean | undefined;
492
494
  sourcePath?: string | undefined;
493
495
  requireCodeOwnerReviews?: boolean | undefined;
494
496
  requiredStatusCheckContexts?: string[] | undefined;
497
+ requireBranchesToBeUpToDate?: boolean | undefined;
495
498
  repoVisibility?: "internal" | "private" | "public" | undefined;
496
499
  collaborators?: ({
497
500
  user: string;
@@ -558,7 +561,8 @@ repoUrl: string;
558
561
  title: string;
559
562
  description: string;
560
563
  branchName: string;
561
- targetPath: string;
564
+ sourcePath?: string | undefined;
565
+ targetPath?: string | undefined;
562
566
  token?: string | undefined;
563
567
  commitAction?: "update" | "create" | "delete" | undefined;
564
568
  /** @deprecated Use projectPath instead */
package/dist/index.cjs.js CHANGED
@@ -986,6 +986,7 @@ const enableBranchProtectionOnDefaultRepoBranch = async ({
986
986
  logger,
987
987
  requireCodeOwnerReviews,
988
988
  requiredStatusCheckContexts = [],
989
+ requireBranchesToBeUpToDate = true,
989
990
  defaultBranch = "master",
990
991
  enforceAdmins = true
991
992
  }) => {
@@ -999,7 +1000,7 @@ const enableBranchProtectionOnDefaultRepoBranch = async ({
999
1000
  repo: repoName,
1000
1001
  branch: defaultBranch,
1001
1002
  required_status_checks: {
1002
- strict: true,
1003
+ strict: requireBranchesToBeUpToDate,
1003
1004
  contexts: requiredStatusCheckContexts
1004
1005
  },
1005
1006
  restrictions: null,
@@ -1173,7 +1174,7 @@ async function createGithubRepoWithCollaboratorsAndTopics(client, repo, owner, r
1173
1174
  }
1174
1175
  return newRepo;
1175
1176
  }
1176
- async function initRepoPushAndProtect(remoteUrl, password, workspacePath, sourcePath, defaultBranch, protectDefaultBranch, protectEnforceAdmins, owner, client, repo, requireCodeOwnerReviews, requiredStatusCheckContexts, config, logger, gitCommitMessage, gitAuthorName, gitAuthorEmail) {
1177
+ async function initRepoPushAndProtect(remoteUrl, password, workspacePath, sourcePath, defaultBranch, protectDefaultBranch, protectEnforceAdmins, owner, client, repo, requireCodeOwnerReviews, requiredStatusCheckContexts, requireBranchesToBeUpToDate, config, logger, gitCommitMessage, gitAuthorName, gitAuthorEmail) {
1177
1178
  const gitAuthorInfo = {
1178
1179
  name: gitAuthorName ? gitAuthorName : config.getOptionalString("scaffolder.defaultAuthor.name"),
1179
1180
  email: gitAuthorEmail ? gitAuthorEmail : config.getOptionalString("scaffolder.defaultAuthor.email")
@@ -1201,6 +1202,7 @@ async function initRepoPushAndProtect(remoteUrl, password, workspacePath, source
1201
1202
  defaultBranch,
1202
1203
  requireCodeOwnerReviews,
1203
1204
  requiredStatusCheckContexts,
1205
+ requireBranchesToBeUpToDate,
1204
1206
  enforceAdmins: protectEnforceAdmins
1205
1207
  });
1206
1208
  } catch (e) {
@@ -1391,6 +1393,11 @@ const requiredStatusCheckContexts = {
1391
1393
  type: "string"
1392
1394
  }
1393
1395
  };
1396
+ const requireBranchesToBeUpToDate = {
1397
+ title: "Require Branches To Be Up To Date?",
1398
+ description: `Require branches to be up to date before merging. The default value is 'true'`,
1399
+ type: "boolean"
1400
+ };
1394
1401
  const repoVisibility = {
1395
1402
  title: "Repository Visibility",
1396
1403
  type: "string",
@@ -1520,6 +1527,7 @@ function createGithubRepoCreateAction(options) {
1520
1527
  access: access,
1521
1528
  requireCodeOwnerReviews: requireCodeOwnerReviews,
1522
1529
  requiredStatusCheckContexts: requiredStatusCheckContexts,
1530
+ requireBranchesToBeUpToDate: requireBranchesToBeUpToDate,
1523
1531
  repoVisibility: repoVisibility,
1524
1532
  deleteBranchOnMerge: deleteBranchOnMerge,
1525
1533
  allowMergeCommit: allowMergeCommit,
@@ -1601,6 +1609,7 @@ function createGithubRepoPushAction(options) {
1601
1609
  repoUrl: repoUrl,
1602
1610
  requireCodeOwnerReviews: requireCodeOwnerReviews,
1603
1611
  requiredStatusCheckContexts: requiredStatusCheckContexts,
1612
+ requireBranchesToBeUpToDate: requireBranchesToBeUpToDate,
1604
1613
  defaultBranch: defaultBranch,
1605
1614
  protectDefaultBranch: protectDefaultBranch,
1606
1615
  protectEnforceAdmins: protectEnforceAdmins,
@@ -1630,6 +1639,7 @@ function createGithubRepoPushAction(options) {
1630
1639
  gitAuthorEmail,
1631
1640
  requireCodeOwnerReviews = false,
1632
1641
  requiredStatusCheckContexts = [],
1642
+ requireBranchesToBeUpToDate = true,
1633
1643
  token: providedToken
1634
1644
  } = ctx.input;
1635
1645
  const { owner, repo } = parseRepoUrl(repoUrl, integrations);
@@ -1659,6 +1669,7 @@ function createGithubRepoPushAction(options) {
1659
1669
  repo,
1660
1670
  requireCodeOwnerReviews,
1661
1671
  requiredStatusCheckContexts,
1672
+ requireBranchesToBeUpToDate,
1662
1673
  config,
1663
1674
  ctx.logger,
1664
1675
  gitCommitMessage,
@@ -2419,6 +2430,7 @@ const createRepository = async (opts) => {
2419
2430
  description,
2420
2431
  authorization,
2421
2432
  repoVisibility,
2433
+ defaultBranch,
2422
2434
  apiBaseUrl
2423
2435
  } = opts;
2424
2436
  let response;
@@ -2427,6 +2439,7 @@ const createRepository = async (opts) => {
2427
2439
  body: JSON.stringify({
2428
2440
  name: repo,
2429
2441
  description,
2442
+ defaultBranch,
2430
2443
  public: repoVisibility === "public"
2431
2444
  }),
2432
2445
  headers: {
@@ -2569,6 +2582,7 @@ function createPublishBitbucketServerAction(options) {
2569
2582
  project,
2570
2583
  repo,
2571
2584
  repoVisibility,
2585
+ defaultBranch,
2572
2586
  description,
2573
2587
  apiBaseUrl
2574
2588
  });
@@ -2874,6 +2888,7 @@ function createPublishGithubAction(options) {
2874
2888
  access: access,
2875
2889
  requireCodeOwnerReviews: requireCodeOwnerReviews,
2876
2890
  requiredStatusCheckContexts: requiredStatusCheckContexts,
2891
+ requireBranchesToBeUpToDate: requireBranchesToBeUpToDate,
2877
2892
  repoVisibility: repoVisibility,
2878
2893
  defaultBranch: defaultBranch,
2879
2894
  protectDefaultBranch: protectDefaultBranch,
@@ -2908,6 +2923,7 @@ function createPublishGithubAction(options) {
2908
2923
  access,
2909
2924
  requireCodeOwnerReviews = false,
2910
2925
  requiredStatusCheckContexts = [],
2926
+ requireBranchesToBeUpToDate = true,
2911
2927
  repoVisibility = "private",
2912
2928
  defaultBranch = "master",
2913
2929
  protectDefaultBranch = true,
@@ -2967,6 +2983,7 @@ function createPublishGithubAction(options) {
2967
2983
  repo,
2968
2984
  requireCodeOwnerReviews,
2969
2985
  requiredStatusCheckContexts,
2986
+ requireBranchesToBeUpToDate,
2970
2987
  config,
2971
2988
  ctx.logger,
2972
2989
  gitCommitMessage,
@@ -3415,7 +3432,7 @@ const createPublishGitlabMergeRequestAction = (options) => {
3415
3432
  id: "publish:gitlab:merge-request",
3416
3433
  schema: {
3417
3434
  input: {
3418
- required: ["repoUrl", "targetPath", "branchName"],
3435
+ required: ["repoUrl", "branchName"],
3419
3436
  type: "object",
3420
3437
  properties: {
3421
3438
  repoUrl: {
@@ -3443,6 +3460,11 @@ const createPublishGitlabMergeRequestAction = (options) => {
3443
3460
  title: "Destination Branch name",
3444
3461
  description: "The description of the merge request"
3445
3462
  },
3463
+ sourcePath: {
3464
+ type: "string",
3465
+ title: "Working Subdirectory",
3466
+ description: "Subdirectory of working directory to copy changes from"
3467
+ },
3446
3468
  targetPath: {
3447
3469
  type: "string",
3448
3470
  title: "Repository Subdirectory",
@@ -3491,8 +3513,17 @@ const createPublishGitlabMergeRequestAction = (options) => {
3491
3513
  }
3492
3514
  },
3493
3515
  async handler(ctx) {
3494
- var _a;
3495
- const repoUrl = ctx.input.repoUrl;
3516
+ const {
3517
+ assignee,
3518
+ branchName,
3519
+ description,
3520
+ repoUrl,
3521
+ removeSourceBranch,
3522
+ targetPath,
3523
+ sourcePath,
3524
+ title,
3525
+ token: providedToken
3526
+ } = ctx.input;
3496
3527
  const { host, owner, repo } = parseRepoUrl(repoUrl, integrations);
3497
3528
  const projectPath = `${owner}/${repo}`;
3498
3529
  if (ctx.input.projectid) {
@@ -3501,22 +3532,20 @@ const createPublishGitlabMergeRequestAction = (options) => {
3501
3532
  console.warn(deprecationWarning);
3502
3533
  }
3503
3534
  const integrationConfig = integrations.gitlab.byHost(host);
3504
- const destinationBranch = ctx.input.branchName;
3505
3535
  if (!integrationConfig) {
3506
3536
  throw new errors.InputError(
3507
3537
  `No matching integration configuration for host ${host}, please check your integrations config`
3508
3538
  );
3509
3539
  }
3510
- if (!integrationConfig.config.token && !ctx.input.token) {
3540
+ if (!integrationConfig.config.token && !providedToken) {
3511
3541
  throw new errors.InputError(`No token available for host ${host}`);
3512
3542
  }
3513
- const token = (_a = ctx.input.token) != null ? _a : integrationConfig.config.token;
3514
- const tokenType = ctx.input.token ? "oauthToken" : "token";
3543
+ const token = providedToken != null ? providedToken : integrationConfig.config.token;
3544
+ const tokenType = providedToken ? "oauthToken" : "token";
3515
3545
  const api = new node.Gitlab({
3516
3546
  host: integrationConfig.config.baseUrl,
3517
3547
  [tokenType]: token
3518
3548
  });
3519
- const assignee = ctx.input.assignee;
3520
3549
  let assigneeId = void 0;
3521
3550
  if (assignee !== void 0) {
3522
3551
  try {
@@ -3528,18 +3557,22 @@ const createPublishGitlabMergeRequestAction = (options) => {
3528
3557
  );
3529
3558
  }
3530
3559
  }
3531
- const targetPath = backendCommon.resolveSafeChildPath(
3532
- ctx.workspacePath,
3533
- ctx.input.targetPath
3534
- );
3535
- const fileContents = await serializeDirectoryContents(targetPath, {
3560
+ let fileRoot;
3561
+ if (sourcePath) {
3562
+ fileRoot = backendCommon.resolveSafeChildPath(ctx.workspacePath, sourcePath);
3563
+ } else if (targetPath) {
3564
+ fileRoot = backendCommon.resolveSafeChildPath(ctx.workspacePath, targetPath);
3565
+ } else {
3566
+ fileRoot = ctx.workspacePath;
3567
+ }
3568
+ const fileContents = await serializeDirectoryContents(fileRoot, {
3536
3569
  gitignore: true
3537
3570
  });
3538
3571
  const actions = fileContents.map((file) => {
3539
- var _a2;
3572
+ var _a;
3540
3573
  return {
3541
- action: (_a2 = ctx.input.commitAction) != null ? _a2 : "create",
3542
- filePath: path__default["default"].posix.join(ctx.input.targetPath, file.path),
3574
+ action: (_a = ctx.input.commitAction) != null ? _a : "create",
3575
+ filePath: targetPath ? path__default["default"].posix.join(targetPath, file.path) : file.path,
3543
3576
  encoding: "base64",
3544
3577
  content: file.content.toString("base64"),
3545
3578
  execute_filemode: file.executable
@@ -3550,33 +3583,28 @@ const createPublishGitlabMergeRequestAction = (options) => {
3550
3583
  try {
3551
3584
  await api.Branches.create(
3552
3585
  projectPath,
3553
- destinationBranch,
3586
+ branchName,
3554
3587
  String(defaultBranch)
3555
3588
  );
3556
3589
  } catch (e) {
3557
3590
  throw new errors.InputError(`The branch creation failed ${e}`);
3558
3591
  }
3559
3592
  try {
3560
- await api.Commits.create(
3561
- projectPath,
3562
- destinationBranch,
3563
- ctx.input.title,
3564
- actions
3565
- );
3593
+ await api.Commits.create(projectPath, branchName, title, actions);
3566
3594
  } catch (e) {
3567
3595
  throw new errors.InputError(
3568
- `Committing the changes to ${destinationBranch} failed ${e}`
3596
+ `Committing the changes to ${branchName} failed ${e}`
3569
3597
  );
3570
3598
  }
3571
3599
  try {
3572
3600
  const mergeRequestUrl = await api.MergeRequests.create(
3573
3601
  projectPath,
3574
- destinationBranch,
3602
+ branchName,
3575
3603
  String(defaultBranch),
3576
- ctx.input.title,
3604
+ title,
3577
3605
  {
3578
- description: ctx.input.description,
3579
- removeSourceBranch: ctx.input.removeSourceBranch ? ctx.input.removeSourceBranch : false,
3606
+ description,
3607
+ removeSourceBranch: removeSourceBranch ? removeSourceBranch : false,
3580
3608
  assigneeId
3581
3609
  }
3582
3610
  ).then((mergeRequest) => {