@backstage/plugin-scaffolder-backend 1.8.0-next.0 → 1.8.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,36 @@
1
1
  # @backstage/plugin-scaffolder-backend
2
2
 
3
+ ## 1.8.0-next.2
4
+
5
+ ### Minor Changes
6
+
7
+ - 5025d2e8b6: Adds the ability to pass (an optional) array of strings that will be applied to the newly scaffolded repository as topic labels.
8
+
9
+ ### Patch Changes
10
+
11
+ - 969a8444ea: Updated dependency `esbuild` to `^0.15.0`.
12
+ - 9ff4ff3745: Implement "Branch protection rules" support for "publish:github" action
13
+ - Updated dependencies
14
+ - @backstage/backend-common@0.16.0-next.1
15
+ - @backstage/backend-plugin-api@0.1.4-next.1
16
+ - @backstage/backend-tasks@0.3.7-next.1
17
+ - @backstage/plugin-auth-node@0.2.7-next.1
18
+ - @backstage/plugin-catalog-backend@1.5.1-next.1
19
+ - @backstage/plugin-catalog-node@1.2.1-next.1
20
+ - @backstage/catalog-client@1.1.2-next.0
21
+ - @backstage/catalog-model@1.1.3-next.0
22
+ - @backstage/config@1.0.4-next.0
23
+ - @backstage/errors@1.1.3-next.0
24
+ - @backstage/integration@1.4.0-next.0
25
+ - @backstage/types@1.0.1-next.0
26
+ - @backstage/plugin-scaffolder-common@1.2.2-next.0
27
+
28
+ ## 1.8.0-next.1
29
+
30
+ ### Minor Changes
31
+
32
+ - 5921b5ce49: - The GitLab Project ID for the `publish:gitlab:merge-request` action is now passed through the query parameter `project` in the `repoUrl`. It still allows people to not use the `projectid` and use the `repoUrl` with the `owner` and `repo` query parameters instead. This makes it easier to publish to repositories instead of writing the full path to the project.
33
+
3
34
  ## 1.8.0-next.0
4
35
 
5
36
  ### Minor Changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-scaffolder-backend",
3
- "version": "1.8.0-next.0",
3
+ "version": "1.8.0-next.2",
4
4
  "main": "../dist/index.cjs.js",
5
5
  "types": "../dist/index.alpha.d.ts"
6
6
  }
@@ -292,6 +292,11 @@ allowSquashMerge?: boolean | undefined;
292
292
  allowMergeCommit?: boolean | undefined;
293
293
  allowAutoMerge?: boolean | undefined;
294
294
  requireCodeOwnerReviews?: boolean | undefined;
295
+ bypassPullRequestAllowances?: {
296
+ users?: string[] | undefined;
297
+ teams?: string[] | undefined;
298
+ apps?: string[] | undefined;
299
+ } | undefined;
295
300
  requiredStatusCheckContexts?: string[] | undefined;
296
301
  requireBranchesToBeUpToDate?: boolean | undefined;
297
302
  repoVisibility?: "internal" | "private" | "public" | undefined;
@@ -330,6 +335,11 @@ gitCommitMessage?: string | undefined;
330
335
  gitAuthorName?: string | undefined;
331
336
  gitAuthorEmail?: string | undefined;
332
337
  requireCodeOwnerReviews?: boolean | undefined;
338
+ bypassPullRequestAllowances?: {
339
+ users?: string[];
340
+ teams?: string[];
341
+ apps?: string[];
342
+ } | undefined;
333
343
  requiredStatusCheckContexts?: string[] | undefined;
334
344
  requireBranchesToBeUpToDate?: boolean | undefined;
335
345
  sourcePath?: string | undefined;
@@ -492,6 +502,11 @@ allowSquashMerge?: boolean | undefined;
492
502
  allowMergeCommit?: boolean | undefined;
493
503
  allowAutoMerge?: boolean | undefined;
494
504
  sourcePath?: string | undefined;
505
+ bypassPullRequestAllowances?: {
506
+ users?: string[];
507
+ teams?: string[];
508
+ apps?: string[];
509
+ } | undefined;
495
510
  requireCodeOwnerReviews?: boolean | undefined;
496
511
  requiredStatusCheckContexts?: string[] | undefined;
497
512
  requireBranchesToBeUpToDate?: boolean | undefined;
@@ -547,6 +562,7 @@ gitCommitMessage?: string | undefined;
547
562
  gitAuthorName?: string | undefined;
548
563
  gitAuthorEmail?: string | undefined;
549
564
  setUserAsOwner?: boolean | undefined;
565
+ topics?: string[] | undefined;
550
566
  }>;
551
567
 
552
568
  /**
@@ -565,7 +581,7 @@ sourcePath?: string | undefined;
565
581
  targetPath?: string | undefined;
566
582
  token?: string | undefined;
567
583
  commitAction?: "update" | "create" | "delete" | undefined;
568
- /** @deprecated Use projectPath instead */
584
+ /** @deprecated projectID passed as query parameters in the repoUrl */
569
585
  projectid?: string | undefined;
570
586
  removeSourceBranch?: boolean | undefined;
571
587
  assignee?: string | undefined;
@@ -292,6 +292,11 @@ allowSquashMerge?: boolean | undefined;
292
292
  allowMergeCommit?: boolean | undefined;
293
293
  allowAutoMerge?: boolean | undefined;
294
294
  requireCodeOwnerReviews?: boolean | undefined;
295
+ bypassPullRequestAllowances?: {
296
+ users?: string[] | undefined;
297
+ teams?: string[] | undefined;
298
+ apps?: string[] | undefined;
299
+ } | undefined;
295
300
  requiredStatusCheckContexts?: string[] | undefined;
296
301
  requireBranchesToBeUpToDate?: boolean | undefined;
297
302
  repoVisibility?: "internal" | "private" | "public" | undefined;
@@ -330,6 +335,11 @@ gitCommitMessage?: string | undefined;
330
335
  gitAuthorName?: string | undefined;
331
336
  gitAuthorEmail?: string | undefined;
332
337
  requireCodeOwnerReviews?: boolean | undefined;
338
+ bypassPullRequestAllowances?: {
339
+ users?: string[];
340
+ teams?: string[];
341
+ apps?: string[];
342
+ } | undefined;
333
343
  requiredStatusCheckContexts?: string[] | undefined;
334
344
  requireBranchesToBeUpToDate?: boolean | undefined;
335
345
  sourcePath?: string | undefined;
@@ -492,6 +502,11 @@ allowSquashMerge?: boolean | undefined;
492
502
  allowMergeCommit?: boolean | undefined;
493
503
  allowAutoMerge?: boolean | undefined;
494
504
  sourcePath?: string | undefined;
505
+ bypassPullRequestAllowances?: {
506
+ users?: string[];
507
+ teams?: string[];
508
+ apps?: string[];
509
+ } | undefined;
495
510
  requireCodeOwnerReviews?: boolean | undefined;
496
511
  requiredStatusCheckContexts?: string[] | undefined;
497
512
  requireBranchesToBeUpToDate?: boolean | undefined;
@@ -547,6 +562,7 @@ gitCommitMessage?: string | undefined;
547
562
  gitAuthorName?: string | undefined;
548
563
  gitAuthorEmail?: string | undefined;
549
564
  setUserAsOwner?: boolean | undefined;
565
+ topics?: string[] | undefined;
550
566
  }>;
551
567
 
552
568
  /**
@@ -565,7 +581,7 @@ sourcePath?: string | undefined;
565
581
  targetPath?: string | undefined;
566
582
  token?: string | undefined;
567
583
  commitAction?: "update" | "create" | "delete" | undefined;
568
- /** @deprecated Use projectPath instead */
584
+ /** @deprecated projectID passed as query parameters in the repoUrl */
569
585
  projectid?: string | undefined;
570
586
  removeSourceBranch?: boolean | undefined;
571
587
  assignee?: string | undefined;
package/dist/index.cjs.js CHANGED
@@ -851,34 +851,41 @@ const parseRepoUrl = (repoUrl, integrations) => {
851
851
  `No matching integration configuration for host ${host}, please check your integrations config`
852
852
  );
853
853
  }
854
- if (type === "bitbucket") {
855
- if (host === "bitbucket.org") {
856
- if (!workspace) {
857
- throw new errors.InputError(
858
- `Invalid repo URL passed to publisher: ${repoUrl}, missing workspace`
859
- );
854
+ const repo = parsed.searchParams.get("repo");
855
+ switch (type) {
856
+ case "bitbucket": {
857
+ if (host === "www.bitbucket.org") {
858
+ checkRequiredParams(parsed, "workspace");
860
859
  }
860
+ checkRequiredParams(parsed, "project", "repo");
861
+ break;
861
862
  }
862
- if (!project) {
863
- throw new errors.InputError(
864
- `Invalid repo URL passed to publisher: ${repoUrl}, missing project`
865
- );
863
+ case "gitlab": {
864
+ if (!project) {
865
+ checkRequiredParams(parsed, "owner", "repo");
866
+ }
867
+ break;
866
868
  }
867
- } else {
868
- if (!owner && type !== "gerrit") {
869
- throw new errors.InputError(
870
- `Invalid repo URL passed to publisher: ${repoUrl}, missing owner`
871
- );
869
+ case "gerrit": {
870
+ checkRequiredParams(parsed, "repo");
871
+ break;
872
+ }
873
+ default: {
874
+ checkRequiredParams(parsed, "repo", "owner");
875
+ break;
872
876
  }
873
- }
874
- const repo = parsed.searchParams.get("repo");
875
- if (!repo) {
876
- throw new errors.InputError(
877
- `Invalid repo URL passed to publisher: ${repoUrl}, missing repo`
878
- );
879
877
  }
880
878
  return { host, owner, repo, organization, workspace, project };
881
879
  };
880
+ function checkRequiredParams(repoUrl, ...params) {
881
+ for (let i = 0; i < params.length; i++) {
882
+ if (!repoUrl.searchParams.get(params[i])) {
883
+ throw new errors.InputError(
884
+ `Invalid repo URL passed to publisher: ${repoUrl.toString()}, missing ${params[i]}`
885
+ );
886
+ }
887
+ }
888
+ }
882
889
 
883
890
  const executeShellCommand = async (options) => {
884
891
  const {
@@ -986,6 +993,7 @@ const enableBranchProtectionOnDefaultRepoBranch = async ({
986
993
  owner,
987
994
  logger,
988
995
  requireCodeOwnerReviews,
996
+ bypassPullRequestAllowances,
989
997
  requiredStatusCheckContexts = [],
990
998
  requireBranchesToBeUpToDate = true,
991
999
  defaultBranch = "master",
@@ -1008,7 +1016,8 @@ const enableBranchProtectionOnDefaultRepoBranch = async ({
1008
1016
  enforce_admins: enforceAdmins,
1009
1017
  required_pull_request_reviews: {
1010
1018
  required_approving_review_count: 1,
1011
- require_code_owner_reviews: requireCodeOwnerReviews
1019
+ require_code_owner_reviews: requireCodeOwnerReviews,
1020
+ bypass_pull_request_allowances: bypassPullRequestAllowances
1012
1021
  }
1013
1022
  });
1014
1023
  } catch (e) {
@@ -1175,7 +1184,7 @@ async function createGithubRepoWithCollaboratorsAndTopics(client, repo, owner, r
1175
1184
  }
1176
1185
  return newRepo;
1177
1186
  }
1178
- async function initRepoPushAndProtect(remoteUrl, password, workspacePath, sourcePath, defaultBranch, protectDefaultBranch, protectEnforceAdmins, owner, client, repo, requireCodeOwnerReviews, requiredStatusCheckContexts, requireBranchesToBeUpToDate, config, logger, gitCommitMessage, gitAuthorName, gitAuthorEmail) {
1187
+ async function initRepoPushAndProtect(remoteUrl, password, workspacePath, sourcePath, defaultBranch, protectDefaultBranch, protectEnforceAdmins, owner, client, repo, requireCodeOwnerReviews, bypassPullRequestAllowances, requiredStatusCheckContexts, requireBranchesToBeUpToDate, config, logger, gitCommitMessage, gitAuthorName, gitAuthorEmail) {
1179
1188
  const gitAuthorInfo = {
1180
1189
  name: gitAuthorName ? gitAuthorName : config.getOptionalString("scaffolder.defaultAuthor.name"),
1181
1190
  email: gitAuthorEmail ? gitAuthorEmail : config.getOptionalString("scaffolder.defaultAuthor.email")
@@ -1201,6 +1210,7 @@ async function initRepoPushAndProtect(remoteUrl, password, workspacePath, source
1201
1210
  repoName: repo,
1202
1211
  logger,
1203
1212
  defaultBranch,
1213
+ bypassPullRequestAllowances,
1204
1214
  requireCodeOwnerReviews,
1205
1215
  requiredStatusCheckContexts,
1206
1216
  requireBranchesToBeUpToDate,
@@ -1492,6 +1502,32 @@ const protectEnforceAdmins = {
1492
1502
  type: "boolean",
1493
1503
  description: `Enforce admins to adhere to default branch protection. The default value is 'true'`
1494
1504
  };
1505
+ const bypassPullRequestAllowances = {
1506
+ title: "Bypass pull request requirements",
1507
+ description: "Allow specific users, teams, or apps to bypass pull request requirements.",
1508
+ type: "object",
1509
+ additionalProperties: false,
1510
+ properties: {
1511
+ apps: {
1512
+ type: "array",
1513
+ items: {
1514
+ type: "string"
1515
+ }
1516
+ },
1517
+ users: {
1518
+ type: "array",
1519
+ items: {
1520
+ type: "string"
1521
+ }
1522
+ },
1523
+ teams: {
1524
+ type: "array",
1525
+ items: {
1526
+ type: "string"
1527
+ }
1528
+ }
1529
+ }
1530
+ };
1495
1531
  const gitCommitMessage = {
1496
1532
  title: "Git Commit Message",
1497
1533
  type: "string",
@@ -1527,6 +1563,7 @@ function createGithubRepoCreateAction(options) {
1527
1563
  homepage: homepage,
1528
1564
  access: access,
1529
1565
  requireCodeOwnerReviews: requireCodeOwnerReviews,
1566
+ bypassPullRequestAllowances: bypassPullRequestAllowances,
1530
1567
  requiredStatusCheckContexts: requiredStatusCheckContexts,
1531
1568
  requireBranchesToBeUpToDate: requireBranchesToBeUpToDate,
1532
1569
  repoVisibility: repoVisibility,
@@ -1610,6 +1647,7 @@ function createGithubRepoPushAction(options) {
1610
1647
  repoUrl: repoUrl,
1611
1648
  requireCodeOwnerReviews: requireCodeOwnerReviews,
1612
1649
  requiredStatusCheckContexts: requiredStatusCheckContexts,
1650
+ bypassPullRequestAllowances: bypassPullRequestAllowances,
1613
1651
  requireBranchesToBeUpToDate: requireBranchesToBeUpToDate,
1614
1652
  defaultBranch: defaultBranch,
1615
1653
  protectDefaultBranch: protectDefaultBranch,
@@ -1639,6 +1677,7 @@ function createGithubRepoPushAction(options) {
1639
1677
  gitAuthorName,
1640
1678
  gitAuthorEmail,
1641
1679
  requireCodeOwnerReviews = false,
1680
+ bypassPullRequestAllowances,
1642
1681
  requiredStatusCheckContexts = [],
1643
1682
  requireBranchesToBeUpToDate = true,
1644
1683
  token: providedToken
@@ -1669,6 +1708,7 @@ function createGithubRepoPushAction(options) {
1669
1708
  client,
1670
1709
  repo,
1671
1710
  requireCodeOwnerReviews,
1711
+ bypassPullRequestAllowances,
1672
1712
  requiredStatusCheckContexts,
1673
1713
  requireBranchesToBeUpToDate,
1674
1714
  config,
@@ -2887,6 +2927,7 @@ function createPublishGithubAction(options) {
2887
2927
  description: description,
2888
2928
  homepage: homepage,
2889
2929
  access: access,
2930
+ bypassPullRequestAllowances: bypassPullRequestAllowances,
2890
2931
  requireCodeOwnerReviews: requireCodeOwnerReviews,
2891
2932
  requiredStatusCheckContexts: requiredStatusCheckContexts,
2892
2933
  requireBranchesToBeUpToDate: requireBranchesToBeUpToDate,
@@ -2923,6 +2964,7 @@ function createPublishGithubAction(options) {
2923
2964
  homepage,
2924
2965
  access,
2925
2966
  requireCodeOwnerReviews = false,
2967
+ bypassPullRequestAllowances,
2926
2968
  requiredStatusCheckContexts = [],
2927
2969
  requireBranchesToBeUpToDate = true,
2928
2970
  repoVisibility = "private",
@@ -2983,6 +3025,7 @@ function createPublishGithubAction(options) {
2983
3025
  client,
2984
3026
  repo,
2985
3027
  requireCodeOwnerReviews,
3028
+ bypassPullRequestAllowances,
2986
3029
  requiredStatusCheckContexts,
2987
3030
  requireBranchesToBeUpToDate,
2988
3031
  config,
@@ -3333,6 +3376,14 @@ function createPublishGitlabAction(options) {
3333
3376
  title: "Set User As Owner",
3334
3377
  type: "boolean",
3335
3378
  description: "Set the token user as owner of the newly created repository. Requires a token authorized to do the edit in the integration configuration for the matching host"
3379
+ },
3380
+ topics: {
3381
+ title: "Topic labels",
3382
+ description: "Topic labels to apply on the repository.",
3383
+ type: "array",
3384
+ items: {
3385
+ type: "string"
3386
+ }
3336
3387
  }
3337
3388
  }
3338
3389
  },
@@ -3362,7 +3413,8 @@ function createPublishGitlabAction(options) {
3362
3413
  gitCommitMessage = "initial commit",
3363
3414
  gitAuthorName,
3364
3415
  gitAuthorEmail,
3365
- setUserAsOwner = false
3416
+ setUserAsOwner = false,
3417
+ topics = []
3366
3418
  } = ctx.input;
3367
3419
  const { owner, repo, host } = parseRepoUrl(repoUrl, integrations);
3368
3420
  if (!owner) {
@@ -3393,7 +3445,8 @@ function createPublishGitlabAction(options) {
3393
3445
  const { id: projectId, http_url_to_repo } = await client.Projects.create({
3394
3446
  namespace_id: targetNamespace,
3395
3447
  name: repo,
3396
- visibility: repoVisibility
3448
+ visibility: repoVisibility,
3449
+ ...topics.length ? { topics } : {}
3397
3450
  });
3398
3451
  if (setUserAsOwner && integrationConfig.config.token) {
3399
3452
  const adminClient = new node.Gitlab({
@@ -3525,13 +3578,11 @@ const createPublishGitlabMergeRequestAction = (options) => {
3525
3578
  title,
3526
3579
  token: providedToken
3527
3580
  } = ctx.input;
3528
- const { host, owner, repo } = parseRepoUrl(repoUrl, integrations);
3529
- const projectPath = `${owner}/${repo}`;
3530
- if (ctx.input.projectid) {
3531
- const deprecationWarning = `Property "projectid" is deprecated and no longer to needed to create a MR`;
3532
- ctx.logger.warn(deprecationWarning);
3533
- console.warn(deprecationWarning);
3534
- }
3581
+ const { host, owner, repo, project } = parseRepoUrl(
3582
+ repoUrl,
3583
+ integrations
3584
+ );
3585
+ const repoID = project ? project : `${owner}/${repo}`;
3535
3586
  const integrationConfig = integrations.gitlab.byHost(host);
3536
3587
  if (!integrationConfig) {
3537
3588
  throw new errors.InputError(
@@ -3579,19 +3630,15 @@ const createPublishGitlabMergeRequestAction = (options) => {
3579
3630
  execute_filemode: file.executable
3580
3631
  };
3581
3632
  });
3582
- const projects = await api.Projects.show(projectPath);
3633
+ const projects = await api.Projects.show(repoID);
3583
3634
  const { default_branch: defaultBranch } = projects;
3584
3635
  try {
3585
- await api.Branches.create(
3586
- projectPath,
3587
- branchName,
3588
- String(defaultBranch)
3589
- );
3636
+ await api.Branches.create(repoID, branchName, String(defaultBranch));
3590
3637
  } catch (e) {
3591
3638
  throw new errors.InputError(`The branch creation failed ${e}`);
3592
3639
  }
3593
3640
  try {
3594
- await api.Commits.create(projectPath, branchName, title, actions);
3641
+ await api.Commits.create(repoID, branchName, ctx.input.title, actions);
3595
3642
  } catch (e) {
3596
3643
  throw new errors.InputError(
3597
3644
  `Committing the changes to ${branchName} failed ${e}`
@@ -3599,7 +3646,7 @@ const createPublishGitlabMergeRequestAction = (options) => {
3599
3646
  }
3600
3647
  try {
3601
3648
  const mergeRequestUrl = await api.MergeRequests.create(
3602
- projectPath,
3649
+ repoID,
3603
3650
  branchName,
3604
3651
  String(defaultBranch),
3605
3652
  title,
@@ -3611,8 +3658,8 @@ const createPublishGitlabMergeRequestAction = (options) => {
3611
3658
  ).then((mergeRequest) => {
3612
3659
  return mergeRequest.web_url;
3613
3660
  });
3614
- ctx.output("projectid", projectPath);
3615
- ctx.output("projectPath", projectPath);
3661
+ ctx.output("projectid", repoID);
3662
+ ctx.output("projectPath", repoID);
3616
3663
  ctx.output("mergeRequestUrl", mergeRequestUrl);
3617
3664
  } catch (e) {
3618
3665
  throw new errors.InputError(`Merge request creation failed${e}`);