@backstage/plugin-scaffolder-backend-module-github 0.4.0-next.0 → 0.4.0

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,48 @@
1
1
  # @backstage/plugin-scaffolder-backend-module-github
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 70c4b36: Adds support for custom tag policies when creating GitHub environments.
8
+
9
+ ### Patch Changes
10
+
11
+ - ccfc9d1: Fixed bug resulting from missing required owner and repo arguments in `getEnvironmentPublicKey` in action `github:environment:create`.
12
+
13
+ Adding environment secrets now works as expected.
14
+
15
+ - 141f366: Added action to enable GitHub Pages on a repo
16
+ - 4410fed: Fixed issue with octokit call missing owner and repo when creating environment variables and secrets using github:environment:create action
17
+ - dfaa28d: Adds `requireLastPushApproval` input property to configure Branch Protection Settings in `github:publish` action
18
+
19
+ Adds `requireLastPushApproval` input property to configure Branch Protection Settings in `github:repo:push` action
20
+
21
+ - Updated dependencies
22
+ - @backstage/backend-plugin-api@0.7.0
23
+ - @backstage/backend-common@0.23.3
24
+ - @backstage/integration@1.13.0
25
+ - @backstage/plugin-scaffolder-node@0.4.8
26
+ - @backstage/config@1.2.0
27
+ - @backstage/errors@1.2.4
28
+
29
+ ## 0.4.0-next.1
30
+
31
+ ### Patch Changes
32
+
33
+ - 141f366: Added action to enable GitHub Pages on a repo
34
+ - dfaa28d: Adds `requireLastPushApproval` input property to configure Branch Protection Settings in `github:publish` action
35
+
36
+ Adds `requireLastPushApproval` input property to configure Branch Protection Settings in `github:repo:push` action
37
+
38
+ - Updated dependencies
39
+ - @backstage/backend-common@0.23.3-next.1
40
+ - @backstage/backend-plugin-api@0.6.22-next.1
41
+ - @backstage/config@1.2.0
42
+ - @backstage/errors@1.2.4
43
+ - @backstage/integration@1.13.0-next.0
44
+ - @backstage/plugin-scaffolder-node@0.4.8-next.1
45
+
3
46
  ## 0.4.0-next.0
4
47
 
5
48
  ### Minor Changes
package/dist/index.cjs.js CHANGED
@@ -12,6 +12,7 @@ var webhooks = require('@octokit/webhooks');
12
12
  var path = require('path');
13
13
  var octokitPluginCreatePullRequest = require('octokit-plugin-create-pull-request');
14
14
  var backendPluginApi = require('@backstage/backend-plugin-api');
15
+ var pluginScaffolderBackendModuleGithub = require('@backstage/plugin-scaffolder-backend-module-github');
15
16
  var alpha = require('@backstage/plugin-scaffolder-node/alpha');
16
17
 
17
18
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
@@ -32,6 +33,7 @@ const enableBranchProtectionOnDefaultRepoBranch = async ({
32
33
  requiredStatusCheckContexts = [],
33
34
  requireBranchesToBeUpToDate = true,
34
35
  requiredConversationResolution = false,
36
+ requireLastPushApproval = false,
35
37
  defaultBranch = "master",
36
38
  enforceAdmins = true,
37
39
  dismissStaleReviews = false,
@@ -63,7 +65,8 @@ const enableBranchProtectionOnDefaultRepoBranch = async ({
63
65
  required_approving_review_count: requiredApprovingReviewCount,
64
66
  require_code_owner_reviews: requireCodeOwnerReviews,
65
67
  bypass_pull_request_allowances: bypassPullRequestAllowances,
66
- dismiss_stale_reviews: dismissStaleReviews
68
+ dismiss_stale_reviews: dismissStaleReviews,
69
+ require_last_push_approval: requireLastPushApproval
67
70
  },
68
71
  required_conversation_resolution: requiredConversationResolution
69
72
  });
@@ -303,7 +306,7 @@ async function createGithubRepoWithCollaboratorsAndTopics(client, repo, owner, r
303
306
  }
304
307
  return newRepo;
305
308
  }
306
- async function initRepoPushAndProtect(remoteUrl, password, workspacePath, sourcePath, defaultBranch, protectDefaultBranch, protectEnforceAdmins, owner, client, repo, requireCodeOwnerReviews, bypassPullRequestAllowances, requiredApprovingReviewCount, restrictions, requiredStatusCheckContexts, requireBranchesToBeUpToDate, requiredConversationResolution, config, logger, gitCommitMessage, gitAuthorName, gitAuthorEmail, dismissStaleReviews, requiredCommitSigning) {
309
+ async function initRepoPushAndProtect(remoteUrl, password, workspacePath, sourcePath, defaultBranch, protectDefaultBranch, protectEnforceAdmins, owner, client, repo, requireCodeOwnerReviews, bypassPullRequestAllowances, requiredApprovingReviewCount, restrictions, requiredStatusCheckContexts, requireBranchesToBeUpToDate, requiredConversationResolution, requireLastPushApproval, config, logger, gitCommitMessage, gitAuthorName, gitAuthorEmail, dismissStaleReviews, requiredCommitSigning) {
307
310
  const gitAuthorInfo = {
308
311
  name: gitAuthorName ? gitAuthorName : config.getOptionalString("scaffolder.defaultAuthor.name"),
309
312
  email: gitAuthorEmail ? gitAuthorEmail : config.getOptionalString("scaffolder.defaultAuthor.email")
@@ -336,6 +339,7 @@ async function initRepoPushAndProtect(remoteUrl, password, workspacePath, source
336
339
  requiredStatusCheckContexts,
337
340
  requireBranchesToBeUpToDate,
338
341
  requiredConversationResolution,
342
+ requireLastPushApproval,
339
343
  enforceAdmins: protectEnforceAdmins,
340
344
  dismissStaleReviews,
341
345
  requiredCommitSigning
@@ -373,7 +377,7 @@ function getGitCommitMessage(gitCommitMessage, config) {
373
377
  return gitCommitMessage ? gitCommitMessage : config.getOptionalString("scaffolder.defaultCommitMessage");
374
378
  }
375
379
 
376
- const examples$9 = [
380
+ const examples$a = [
377
381
  {
378
382
  description: "GitHub Action Workflow Without Inputs.",
379
383
  example: yaml__default.default.stringify({
@@ -434,7 +438,7 @@ function createGithubActionsDispatchAction(options) {
434
438
  return pluginScaffolderNode.createTemplateAction({
435
439
  id: "github:actions:dispatch",
436
440
  description: "Dispatches a GitHub Action workflow for a given branch or tag",
437
- examples: examples$9,
441
+ examples: examples$a,
438
442
  schema: {
439
443
  input: {
440
444
  type: "object",
@@ -503,7 +507,7 @@ function createGithubActionsDispatchAction(options) {
503
507
  });
504
508
  }
505
509
 
506
- const examples$8 = [
510
+ const examples$9 = [
507
511
  {
508
512
  description: "Add labels to pull request or issue",
509
513
  example: yaml__default.default.stringify({
@@ -544,7 +548,7 @@ function createGithubIssuesLabelAction(options) {
544
548
  return pluginScaffolderNode.createTemplateAction({
545
549
  id: "github:issues:label",
546
550
  description: "Adds labels to a pull request or issue on GitHub.",
547
- examples: examples$8,
551
+ examples: examples$9,
548
552
  schema: {
549
553
  input: {
550
554
  type: "object",
@@ -654,6 +658,11 @@ const requiredConversationResolution = {
654
658
  description: "Requires all conversations on code to be resolved before a pull request can be merged into this branch",
655
659
  type: "boolean"
656
660
  };
661
+ const requireLastPushApproval = {
662
+ title: "Require last push approval",
663
+ type: "boolean",
664
+ description: `Whether the most recent push to a PR must be approved by someone other than the person who pushed it. The default value is 'false'`
665
+ };
657
666
  const repoVisibility = {
658
667
  title: "Repository Visibility",
659
668
  type: "string",
@@ -888,7 +897,7 @@ const commitHash = {
888
897
  type: "string"
889
898
  };
890
899
 
891
- const examples$7 = [
900
+ const examples$8 = [
892
901
  {
893
902
  description: "Creates a GitHub repository with default configuration.",
894
903
  example: yaml__default.default.stringify({
@@ -941,7 +950,7 @@ function createGithubRepoCreateAction(options) {
941
950
  return pluginScaffolderNode.createTemplateAction({
942
951
  id: "github:repo:create",
943
952
  description: "Creates a GitHub repository.",
944
- examples: examples$7,
953
+ examples: examples$8,
945
954
  schema: {
946
955
  input: {
947
956
  type: "object",
@@ -1051,7 +1060,7 @@ function createGithubRepoCreateAction(options) {
1051
1060
  });
1052
1061
  }
1053
1062
 
1054
- const examples$6 = [
1063
+ const examples$7 = [
1055
1064
  {
1056
1065
  description: "Setup repo with no modifications to branch protection rules",
1057
1066
  example: yaml__default.default.stringify({
@@ -1103,7 +1112,7 @@ function createGithubRepoPushAction(options) {
1103
1112
  return pluginScaffolderNode.createTemplateAction({
1104
1113
  id: "github:repo:push",
1105
1114
  description: "Initializes a git repository of contents in workspace and publishes it to GitHub.",
1106
- examples: examples$6,
1115
+ examples: examples$7,
1107
1116
  schema: {
1108
1117
  input: {
1109
1118
  type: "object",
@@ -1118,6 +1127,7 @@ function createGithubRepoPushAction(options) {
1118
1127
  restrictions: restrictions,
1119
1128
  requireBranchesToBeUpToDate: requireBranchesToBeUpToDate,
1120
1129
  requiredConversationResolution: requiredConversationResolution,
1130
+ requireLastPushApproval: requireLastPushApproval,
1121
1131
  defaultBranch: defaultBranch,
1122
1132
  protectDefaultBranch: protectDefaultBranch,
1123
1133
  protectEnforceAdmins: protectEnforceAdmins,
@@ -1155,6 +1165,7 @@ function createGithubRepoPushAction(options) {
1155
1165
  requiredStatusCheckContexts = [],
1156
1166
  requireBranchesToBeUpToDate = true,
1157
1167
  requiredConversationResolution = false,
1168
+ requireLastPushApproval = false,
1158
1169
  token: providedToken,
1159
1170
  requiredCommitSigning = false
1160
1171
  } = ctx.input;
@@ -1190,6 +1201,7 @@ function createGithubRepoPushAction(options) {
1190
1201
  requiredStatusCheckContexts,
1191
1202
  requireBranchesToBeUpToDate,
1192
1203
  requiredConversationResolution,
1204
+ requireLastPushApproval,
1193
1205
  config,
1194
1206
  ctx.logger,
1195
1207
  gitCommitMessage,
@@ -1205,7 +1217,7 @@ function createGithubRepoPushAction(options) {
1205
1217
  });
1206
1218
  }
1207
1219
 
1208
- const examples$5 = [
1220
+ const examples$6 = [
1209
1221
  {
1210
1222
  description: "Create a GitHub webhook for a repository",
1211
1223
  example: yaml__default.default.stringify({
@@ -1314,7 +1326,7 @@ function createGithubWebhookAction(options) {
1314
1326
  return pluginScaffolderNode.createTemplateAction({
1315
1327
  id: "github:webhook",
1316
1328
  description: "Creates webhook for a repository on GitHub.",
1317
- examples: examples$5,
1329
+ examples: examples$6,
1318
1330
  supportsDryRun: true,
1319
1331
  schema: {
1320
1332
  input: {
@@ -1432,7 +1444,7 @@ function createGithubWebhookAction(options) {
1432
1444
  });
1433
1445
  }
1434
1446
 
1435
- const examples$4 = [
1447
+ const examples$5 = [
1436
1448
  {
1437
1449
  description: "Example 1: Create and store a Deploy Key",
1438
1450
  example: yaml__default.default.stringify({
@@ -1457,7 +1469,7 @@ function createGithubDeployKeyAction(options) {
1457
1469
  return pluginScaffolderNode.createTemplateAction({
1458
1470
  id: "github:deployKey:create",
1459
1471
  description: "Creates and stores Deploy Keys",
1460
- examples: examples$4,
1472
+ examples: examples$5,
1461
1473
  schema: {
1462
1474
  input: {
1463
1475
  type: "object",
@@ -1560,7 +1572,7 @@ function createGithubDeployKeyAction(options) {
1560
1572
  });
1561
1573
  }
1562
1574
 
1563
- const examples$3 = [
1575
+ const examples$4 = [
1564
1576
  {
1565
1577
  description: "Create a GitHub Environment (No Policies, No Variables, No Secrets)",
1566
1578
  example: yaml__default.default.stringify({
@@ -1645,7 +1657,7 @@ function createGithubEnvironmentAction(options) {
1645
1657
  return pluginScaffolderNode.createTemplateAction({
1646
1658
  id: "github:environment:create",
1647
1659
  description: "Creates Deployment Environments",
1648
- examples: examples$3,
1660
+ examples: examples$4,
1649
1661
  schema: {
1650
1662
  input: {
1651
1663
  type: "object",
@@ -1783,6 +1795,8 @@ function createGithubEnvironmentAction(options) {
1783
1795
  if (secrets) {
1784
1796
  const publicKeyResponse = await client.rest.actions.getEnvironmentPublicKey({
1785
1797
  repository_id: repository.data.id,
1798
+ owner,
1799
+ repo,
1786
1800
  environment_name: name
1787
1801
  });
1788
1802
  await Sodium__default.default.ready;
@@ -1815,7 +1829,7 @@ function createGithubEnvironmentAction(options) {
1815
1829
  });
1816
1830
  }
1817
1831
 
1818
- const examples$2 = [
1832
+ const examples$3 = [
1819
1833
  {
1820
1834
  description: "Create a pull request",
1821
1835
  example: yaml__default.default.stringify({
@@ -2099,7 +2113,7 @@ const createPublishGithubPullRequestAction = (options) => {
2099
2113
  } = options;
2100
2114
  return pluginScaffolderNode.createTemplateAction({
2101
2115
  id: "publish:github:pull-request",
2102
- examples: examples$2,
2116
+ examples: examples$3,
2103
2117
  supportsDryRun: true,
2104
2118
  schema: {
2105
2119
  input: {
@@ -2383,7 +2397,7 @@ const createPublishGithubPullRequestAction = (options) => {
2383
2397
  }
2384
2398
  };
2385
2399
 
2386
- const examples$1 = [
2400
+ const examples$2 = [
2387
2401
  {
2388
2402
  description: "Initializes a git repository with the content in the workspace, and publishes it to GitHub with the default configuration.",
2389
2403
  example: yaml__default.default.stringify({
@@ -2438,7 +2452,7 @@ function createPublishGithubAction(options) {
2438
2452
  return pluginScaffolderNode.createTemplateAction({
2439
2453
  id: "publish:github",
2440
2454
  description: "Initializes a git repository of contents in workspace and publishes it to GitHub.",
2441
- examples: examples$1,
2455
+ examples: examples$2,
2442
2456
  schema: {
2443
2457
  input: {
2444
2458
  type: "object",
@@ -2456,6 +2470,7 @@ function createPublishGithubAction(options) {
2456
2470
  requiredStatusCheckContexts: requiredStatusCheckContexts,
2457
2471
  requireBranchesToBeUpToDate: requireBranchesToBeUpToDate,
2458
2472
  requiredConversationResolution: requiredConversationResolution,
2473
+ requireLastPushApproval: requireLastPushApproval,
2459
2474
  repoVisibility: repoVisibility,
2460
2475
  defaultBranch: defaultBranch,
2461
2476
  protectDefaultBranch: protectDefaultBranch,
@@ -2506,6 +2521,7 @@ function createPublishGithubAction(options) {
2506
2521
  requiredStatusCheckContexts = [],
2507
2522
  requireBranchesToBeUpToDate = true,
2508
2523
  requiredConversationResolution = false,
2524
+ requireLastPushApproval = false,
2509
2525
  repoVisibility = "private",
2510
2526
  defaultBranch = "master",
2511
2527
  protectDefaultBranch = true,
@@ -2587,6 +2603,7 @@ function createPublishGithubAction(options) {
2587
2603
  requiredStatusCheckContexts,
2588
2604
  requireBranchesToBeUpToDate,
2589
2605
  requiredConversationResolution,
2606
+ requireLastPushApproval,
2590
2607
  config,
2591
2608
  ctx.logger,
2592
2609
  gitCommitMessage,
@@ -2602,7 +2619,7 @@ function createPublishGithubAction(options) {
2602
2619
  });
2603
2620
  }
2604
2621
 
2605
- const examples = [
2622
+ const examples$1 = [
2606
2623
  {
2607
2624
  description: "GitHub alphanumric autolink reference",
2608
2625
  example: yaml__default.default.stringify({
@@ -2627,7 +2644,7 @@ function createGithubAutolinksAction(options) {
2627
2644
  return pluginScaffolderNode.createTemplateAction({
2628
2645
  id: "github:autolinks:create",
2629
2646
  description: "Create an autolink reference for a repository",
2630
- examples,
2647
+ examples: examples$1,
2631
2648
  schema: {
2632
2649
  input: {
2633
2650
  type: "object",
@@ -2688,6 +2705,106 @@ function createGithubAutolinksAction(options) {
2688
2705
  });
2689
2706
  }
2690
2707
 
2708
+ const examples = [
2709
+ {
2710
+ description: "Enables GitHub Pages for a repository.",
2711
+ example: yaml__default.default.stringify({
2712
+ steps: [
2713
+ {
2714
+ action: "github:pages",
2715
+ id: "github-pages",
2716
+ name: "Enable GitHub Pages",
2717
+ input: {
2718
+ repoUrl: "github.com?repo=repo&owner=owner",
2719
+ buildType: "workflow",
2720
+ sourceBranch: "main",
2721
+ sourcePath: "/",
2722
+ token: "gph_YourGitHubToken"
2723
+ }
2724
+ }
2725
+ ]
2726
+ })
2727
+ }
2728
+ ];
2729
+
2730
+ function createGithubPagesEnableAction(options) {
2731
+ const { integrations, githubCredentialsProvider } = options;
2732
+ return pluginScaffolderNode.createTemplateAction({
2733
+ id: "github:pages:enable",
2734
+ examples,
2735
+ description: "Enables GitHub Pages for a repository.",
2736
+ schema: {
2737
+ input: {
2738
+ type: "object",
2739
+ required: ["repoUrl"],
2740
+ properties: {
2741
+ repoUrl: {
2742
+ title: "Repository Location",
2743
+ description: `Accepts the format 'github.com?repo=reponame&owner=owner' where 'reponame' is the new repository name and 'owner' is an organization or username`,
2744
+ type: "string"
2745
+ },
2746
+ buildType: {
2747
+ title: "Build Type",
2748
+ type: "string",
2749
+ description: 'The GitHub Pages build type - "legacy" or "workflow". Default is "workflow'
2750
+ },
2751
+ sourceBranch: {
2752
+ title: "Source Branch",
2753
+ type: "string",
2754
+ description: 'The the GitHub Pages source branch. Default is "main"'
2755
+ },
2756
+ sourcePath: {
2757
+ title: "Source Path",
2758
+ type: "string",
2759
+ description: 'The the GitHub Pages source path - "/" or "/docs". Default is "/"'
2760
+ },
2761
+ token: {
2762
+ title: "Authorization Token",
2763
+ type: "string",
2764
+ description: "The token to use for authorization to GitHub"
2765
+ }
2766
+ }
2767
+ }
2768
+ },
2769
+ async handler(ctx) {
2770
+ const {
2771
+ repoUrl,
2772
+ buildType = "workflow",
2773
+ sourceBranch = "main",
2774
+ sourcePath = "/",
2775
+ token: providedToken
2776
+ } = ctx.input;
2777
+ const octokitOptions = await pluginScaffolderBackendModuleGithub.getOctokitOptions({
2778
+ integrations,
2779
+ credentialsProvider: githubCredentialsProvider,
2780
+ token: providedToken,
2781
+ repoUrl
2782
+ });
2783
+ const client = new octokit.Octokit(octokitOptions);
2784
+ const { owner, repo } = pluginScaffolderNode.parseRepoUrl(repoUrl, integrations);
2785
+ if (!owner) {
2786
+ throw new errors.InputError("Invalid repository owner provided in repoUrl");
2787
+ }
2788
+ ctx.logger.info(
2789
+ `Attempting to enable GitHub Pages for ${owner}/${repo} with "${buildType}" build type, on source branch "${sourceBranch}" and source path "${sourcePath}"`
2790
+ );
2791
+ await client.request("POST /repos/{owner}/{repo}/pages", {
2792
+ owner,
2793
+ repo,
2794
+ build_type: buildType,
2795
+ source: {
2796
+ branch: sourceBranch,
2797
+ path: sourcePath
2798
+ },
2799
+ headers: {
2800
+ "X-GitHub-Api-Version": "2022-11-28"
2801
+ }
2802
+ });
2803
+ ctx.logger.info("Completed enabling GitHub Pages");
2804
+ }
2805
+ });
2806
+ }
2807
+
2691
2808
  const githubModule = backendPluginApi.createBackendModule({
2692
2809
  pluginId: "scaffolder",
2693
2810
  moduleId: "github",
@@ -2737,6 +2854,10 @@ const githubModule = backendPluginApi.createBackendModule({
2737
2854
  integrations,
2738
2855
  githubCredentialsProvider,
2739
2856
  config
2857
+ }),
2858
+ createGithubPagesEnableAction({
2859
+ integrations,
2860
+ githubCredentialsProvider
2740
2861
  })
2741
2862
  );
2742
2863
  }
@@ -2749,6 +2870,7 @@ exports.createGithubAutolinksAction = createGithubAutolinksAction;
2749
2870
  exports.createGithubDeployKeyAction = createGithubDeployKeyAction;
2750
2871
  exports.createGithubEnvironmentAction = createGithubEnvironmentAction;
2751
2872
  exports.createGithubIssuesLabelAction = createGithubIssuesLabelAction;
2873
+ exports.createGithubPagesEnableAction = createGithubPagesEnableAction;
2752
2874
  exports.createGithubRepoCreateAction = createGithubRepoCreateAction;
2753
2875
  exports.createGithubRepoPushAction = createGithubRepoPushAction;
2754
2876
  exports.createGithubWebhookAction = createGithubWebhookAction;