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

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,11 +1,14 @@
1
1
  # @backstage/plugin-scaffolder-backend
2
2
 
3
- ## 0.0.0-nightly-20220718024938
3
+ ## 0.0.0-nightly-20220719025614
4
4
 
5
5
  ### Minor Changes
6
6
 
7
+ - e1a08d872c: Added optional assignee parameter for Gitlab Merge Request action
8
+ - dab9bcf2e7: Add `protectEnforceAdmins` as an option to GitHub publish actions
7
9
  - 4baf8a4ece: Update GitLab Merge Request Action to allow source branch to be deleted
8
10
  - 91c1d12123: Export experimental `scaffolderCatalogExtension` for the new backend system. This export is not considered stable and should not be used in production.
11
+ - d10ccc2ed1: Introduced audit log message when a new scaffolder task is created
9
12
  - 2db07887cb: Added two new scaffolder actions: `github:repo:create` and `github:repo:push`
10
13
 
11
14
  ### Patch Changes
@@ -40,15 +43,15 @@
40
43
  - 945a27fa6a: Add sourcePath option to publish:gerrit action
41
44
  - 1764296a68: Allow to create Gerrit project using default owner
42
45
  - Updated dependencies
43
- - @backstage/backend-plugin-api@0.0.0-nightly-20220718024938
44
- - @backstage/plugin-catalog-backend@0.0.0-nightly-20220718024938
45
- - @backstage/backend-common@0.0.0-nightly-20220718024938
46
- - @backstage/catalog-model@0.0.0-nightly-20220718024938
47
- - @backstage/plugin-catalog-node@0.0.0-nightly-20220718024938
48
- - @backstage/integration@0.0.0-nightly-20220718024938
49
- - @backstage/catalog-client@0.0.0-nightly-20220718024938
50
- - @backstage/errors@0.0.0-nightly-20220718024938
51
- - @backstage/plugin-scaffolder-common@0.0.0-nightly-20220718024938
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
52
55
 
53
56
  ## 1.4.0-next.3
54
57
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-scaffolder-backend",
3
- "version": "0.0.0-nightly-20220718024938",
3
+ "version": "0.0.0-nightly-20220719025614",
4
4
  "main": "../dist/index.cjs.js",
5
5
  "types": "../dist/index.alpha.d.ts"
6
6
  }
@@ -303,6 +303,7 @@ repoUrl: string;
303
303
  description?: string | undefined;
304
304
  defaultBranch?: string | undefined;
305
305
  protectDefaultBranch?: boolean | undefined;
306
+ protectEnforceAdmins?: boolean | undefined;
306
307
  gitCommitMessage?: string | undefined;
307
308
  gitAuthorName?: string | undefined;
308
309
  gitAuthorEmail?: string | undefined;
@@ -456,6 +457,7 @@ description?: string | undefined;
456
457
  access?: string | undefined;
457
458
  defaultBranch?: string | undefined;
458
459
  protectDefaultBranch?: boolean | undefined;
460
+ protectEnforceAdmins?: boolean | undefined;
459
461
  deleteBranchOnMerge?: boolean | undefined;
460
462
  gitCommitMessage?: string | undefined;
461
463
  gitAuthorName?: string | undefined;
@@ -535,6 +537,7 @@ token?: string | undefined;
535
537
  /** @deprecated Use projectPath instead */
536
538
  projectid?: string | undefined;
537
539
  removeSourceBranch?: boolean | undefined;
540
+ assignee?: string | undefined;
538
541
  }>;
539
542
 
540
543
  /**
@@ -303,6 +303,7 @@ repoUrl: string;
303
303
  description?: string | undefined;
304
304
  defaultBranch?: string | undefined;
305
305
  protectDefaultBranch?: boolean | undefined;
306
+ protectEnforceAdmins?: boolean | undefined;
306
307
  gitCommitMessage?: string | undefined;
307
308
  gitAuthorName?: string | undefined;
308
309
  gitAuthorEmail?: string | undefined;
@@ -456,6 +457,7 @@ description?: string | undefined;
456
457
  access?: string | undefined;
457
458
  defaultBranch?: string | undefined;
458
459
  protectDefaultBranch?: boolean | undefined;
460
+ protectEnforceAdmins?: boolean | undefined;
459
461
  deleteBranchOnMerge?: boolean | undefined;
460
462
  gitCommitMessage?: string | undefined;
461
463
  gitAuthorName?: string | undefined;
@@ -535,6 +537,7 @@ token?: string | undefined;
535
537
  /** @deprecated Use projectPath instead */
536
538
  projectid?: string | undefined;
537
539
  removeSourceBranch?: boolean | undefined;
540
+ assignee?: string | undefined;
538
541
  }>;
539
542
 
540
543
  /**
package/dist/index.cjs.js CHANGED
@@ -841,7 +841,8 @@ const enableBranchProtectionOnDefaultRepoBranch = async ({
841
841
  logger,
842
842
  requireCodeOwnerReviews,
843
843
  requiredStatusCheckContexts = [],
844
- defaultBranch = "master"
844
+ defaultBranch = "master",
845
+ enforceAdmins = true
845
846
  }) => {
846
847
  const tryOnce = async () => {
847
848
  try {
@@ -857,7 +858,7 @@ const enableBranchProtectionOnDefaultRepoBranch = async ({
857
858
  contexts: requiredStatusCheckContexts
858
859
  },
859
860
  restrictions: null,
860
- enforce_admins: true,
861
+ enforce_admins: enforceAdmins,
861
862
  required_pull_request_reviews: {
862
863
  required_approving_review_count: 1,
863
864
  require_code_owner_reviews: requireCodeOwnerReviews
@@ -1009,7 +1010,7 @@ async function createGithubRepoWithCollaboratorsAndTopics(client, repo, owner, r
1009
1010
  }
1010
1011
  return newRepo;
1011
1012
  }
1012
- async function initRepoPushAndProtect(remoteUrl, password, workspacePath, sourcePath, defaultBranch, protectDefaultBranch, owner, client, repo, requireCodeOwnerReviews, requiredStatusCheckContexts, config, logger, gitCommitMessage, gitAuthorName, gitAuthorEmail) {
1013
+ async function initRepoPushAndProtect(remoteUrl, password, workspacePath, sourcePath, defaultBranch, protectDefaultBranch, protectEnforceAdmins, owner, client, repo, requireCodeOwnerReviews, requiredStatusCheckContexts, config, logger, gitCommitMessage, gitAuthorName, gitAuthorEmail) {
1013
1014
  const gitAuthorInfo = {
1014
1015
  name: gitAuthorName ? gitAuthorName : config.getOptionalString("scaffolder.defaultAuthor.name"),
1015
1016
  email: gitAuthorEmail ? gitAuthorEmail : config.getOptionalString("scaffolder.defaultAuthor.email")
@@ -1036,7 +1037,8 @@ async function initRepoPushAndProtect(remoteUrl, password, workspacePath, source
1036
1037
  logger,
1037
1038
  defaultBranch,
1038
1039
  requireCodeOwnerReviews,
1039
- requiredStatusCheckContexts
1040
+ requiredStatusCheckContexts,
1041
+ enforceAdmins: protectEnforceAdmins
1040
1042
  });
1041
1043
  } catch (e) {
1042
1044
  errors.assertError(e);
@@ -1295,6 +1297,11 @@ const protectDefaultBranch = {
1295
1297
  type: "boolean",
1296
1298
  description: `Protect the default branch after creating the repository. The default value is 'true'`
1297
1299
  };
1300
+ const protectEnforceAdmins = {
1301
+ title: "Enforce Admins On Protected Branches",
1302
+ type: "boolean",
1303
+ description: `Enforce admins to adhere to default branch protection. The default value is 'true'`
1304
+ };
1298
1305
  const gitCommitMessage = {
1299
1306
  title: "Git Commit Message",
1300
1307
  type: "string",
@@ -1394,6 +1401,7 @@ function createGithubRepoPushAction(options) {
1394
1401
  requiredStatusCheckContexts: requiredStatusCheckContexts,
1395
1402
  defaultBranch: defaultBranch,
1396
1403
  protectDefaultBranch: protectDefaultBranch,
1404
+ protectEnforceAdmins: protectEnforceAdmins,
1397
1405
  gitCommitMessage: gitCommitMessage,
1398
1406
  gitAuthorName: gitAuthorName,
1399
1407
  gitAuthorEmail: gitAuthorEmail,
@@ -1414,6 +1422,7 @@ function createGithubRepoPushAction(options) {
1414
1422
  repoUrl,
1415
1423
  defaultBranch = "master",
1416
1424
  protectDefaultBranch = true,
1425
+ protectEnforceAdmins = true,
1417
1426
  gitCommitMessage = "initial commit",
1418
1427
  gitAuthorName,
1419
1428
  gitAuthorEmail,
@@ -1435,7 +1444,7 @@ function createGithubRepoPushAction(options) {
1435
1444
  const targetRepo = await client.rest.repos.get({ owner, repo });
1436
1445
  const remoteUrl = targetRepo.data.clone_url;
1437
1446
  const repoContentsUrl = `${targetRepo.data.html_url}/blob/${defaultBranch}`;
1438
- await initRepoPushAndProtect(remoteUrl, octokitOptions.auth, ctx.workspacePath, ctx.input.sourcePath, defaultBranch, protectDefaultBranch, owner, client, repo, requireCodeOwnerReviews, requiredStatusCheckContexts, config, ctx.logger, gitCommitMessage, gitAuthorName, gitAuthorEmail);
1447
+ await initRepoPushAndProtect(remoteUrl, octokitOptions.auth, ctx.workspacePath, ctx.input.sourcePath, defaultBranch, protectDefaultBranch, protectEnforceAdmins, owner, client, repo, requireCodeOwnerReviews, requiredStatusCheckContexts, config, ctx.logger, gitCommitMessage, gitAuthorName, gitAuthorEmail);
1439
1448
  ctx.output("remoteUrl", remoteUrl);
1440
1449
  ctx.output("repoContentsUrl", repoContentsUrl);
1441
1450
  }
@@ -2456,6 +2465,7 @@ function createPublishGithubAction(options) {
2456
2465
  repoVisibility: repoVisibility,
2457
2466
  defaultBranch: defaultBranch,
2458
2467
  protectDefaultBranch: protectDefaultBranch,
2468
+ protectEnforceAdmins: protectEnforceAdmins,
2459
2469
  deleteBranchOnMerge: deleteBranchOnMerge,
2460
2470
  gitCommitMessage: gitCommitMessage,
2461
2471
  gitAuthorName: gitAuthorName,
@@ -2487,6 +2497,7 @@ function createPublishGithubAction(options) {
2487
2497
  repoVisibility = "private",
2488
2498
  defaultBranch = "master",
2489
2499
  protectDefaultBranch = true,
2500
+ protectEnforceAdmins = true,
2490
2501
  deleteBranchOnMerge = false,
2491
2502
  gitCommitMessage = "initial commit",
2492
2503
  gitAuthorName,
@@ -2512,7 +2523,7 @@ function createPublishGithubAction(options) {
2512
2523
  const newRepo = await createGithubRepoWithCollaboratorsAndTopics(client, repo, owner, repoVisibility, description, deleteBranchOnMerge, allowMergeCommit, allowSquashMerge, allowRebaseMerge, access, collaborators, topics, ctx.logger);
2513
2524
  const remoteUrl = newRepo.clone_url;
2514
2525
  const repoContentsUrl = `${newRepo.html_url}/blob/${defaultBranch}`;
2515
- await initRepoPushAndProtect(remoteUrl, octokitOptions.auth, ctx.workspacePath, ctx.input.sourcePath, defaultBranch, protectDefaultBranch, owner, client, repo, requireCodeOwnerReviews, requiredStatusCheckContexts, config, ctx.logger, gitCommitMessage, gitAuthorName, gitAuthorEmail);
2526
+ await initRepoPushAndProtect(remoteUrl, octokitOptions.auth, ctx.workspacePath, ctx.input.sourcePath, defaultBranch, protectDefaultBranch, protectEnforceAdmins, owner, client, repo, requireCodeOwnerReviews, requiredStatusCheckContexts, config, ctx.logger, gitCommitMessage, gitAuthorName, gitAuthorEmail);
2516
2527
  ctx.output("remoteUrl", remoteUrl);
2517
2528
  ctx.output("repoContentsUrl", repoContentsUrl);
2518
2529
  }
@@ -2893,6 +2904,11 @@ const createPublishGitlabMergeRequestAction = (options) => {
2893
2904
  title: "Delete source branch",
2894
2905
  type: "boolean",
2895
2906
  description: "Option to delete source branch once the MR has been merged. Default: false"
2907
+ },
2908
+ assignee: {
2909
+ title: "Merge Request Assignee",
2910
+ type: "string",
2911
+ description: "User this merge request will be assigned to"
2896
2912
  }
2897
2913
  }
2898
2914
  },
@@ -2939,6 +2955,16 @@ const createPublishGitlabMergeRequestAction = (options) => {
2939
2955
  host: integrationConfig.config.baseUrl,
2940
2956
  [tokenType]: token
2941
2957
  });
2958
+ const assignee = ctx.input.assignee;
2959
+ let assigneeId = void 0;
2960
+ if (assignee !== void 0) {
2961
+ try {
2962
+ const assigneeUser = await api.Users.username(assignee);
2963
+ assigneeId = assigneeUser[0].id;
2964
+ } catch (e) {
2965
+ ctx.logger.warn(`Failed to find gitlab user id for ${assignee}: ${e}. Proceeding with MR creation without an assignee.`);
2966
+ }
2967
+ }
2942
2968
  const targetPath = backendCommon.resolveSafeChildPath(ctx.workspacePath, ctx.input.targetPath);
2943
2969
  const fileContents = await serializeDirectoryContents(targetPath, {
2944
2970
  gitignore: true
@@ -2965,7 +2991,8 @@ const createPublishGitlabMergeRequestAction = (options) => {
2965
2991
  try {
2966
2992
  const mergeRequestUrl = await api.MergeRequests.create(projectPath, destinationBranch, String(defaultBranch), ctx.input.title, {
2967
2993
  description: ctx.input.description,
2968
- removeSourceBranch: ctx.input.removeSourceBranch ? ctx.input.removeSourceBranch : false
2994
+ removeSourceBranch: ctx.input.removeSourceBranch ? ctx.input.removeSourceBranch : false,
2995
+ assigneeId
2969
2996
  }).then((mergeRequest) => {
2970
2997
  return mergeRequest.web_url;
2971
2998
  });
@@ -3914,6 +3941,11 @@ async function createRouter(options) {
3914
3941
  });
3915
3942
  const { token, entityRef: userEntityRef } = parseBearerToken(req.headers.authorization);
3916
3943
  const userEntity = userEntityRef ? await catalogClient.getEntityByRef(userEntityRef, { token }) : void 0;
3944
+ let auditLog = `Scaffolding task for ${templateRef}`;
3945
+ if (userEntityRef) {
3946
+ auditLog += ` created by ${userEntityRef}`;
3947
+ }
3948
+ logger.info(auditLog);
3917
3949
  const values = req.body.values;
3918
3950
  const template = await findTemplate({
3919
3951
  catalogApi: catalogClient,