@backstage/plugin-scaffolder-backend 0.15.21 → 0.15.23

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,46 @@
1
1
  # @backstage/plugin-scaffolder-backend
2
2
 
3
+ ## 0.15.23
4
+
5
+ ### Patch Changes
6
+
7
+ - 2e0dbb0e50: Migrate from deprecated package @octokit/rest to octokit
8
+ - c95df1631e: Added support for templating secrets into actions input, and also added an extra `token` input argument to all publishers to provide a token that would override the `integrations.config`.
9
+ You can find more information over at [Writing Templates](https://backstage.io/docs/features/software-templates/writing-templates#using-the-users-oauth-token)
10
+ - Updated dependencies
11
+ - @backstage/plugin-catalog-backend@0.21.2
12
+ - @backstage/backend-common@0.10.6
13
+ - @backstage/plugin-scaffolder-backend-module-cookiecutter@0.1.10
14
+
15
+ ## 0.15.23-next.1
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies
20
+ - @backstage/backend-common@0.10.6-next.0
21
+ - @backstage/plugin-catalog-backend@0.21.2-next.1
22
+ - @backstage/plugin-scaffolder-backend-module-cookiecutter@0.1.10-next.1
23
+
24
+ ## 0.15.23-next.0
25
+
26
+ ### Patch Changes
27
+
28
+ - 2e0dbb0e50: Migrate from deprecated package @octokit/rest to octokit
29
+ - Updated dependencies
30
+ - @backstage/plugin-catalog-backend@0.21.2-next.0
31
+ - @backstage/plugin-scaffolder-backend-module-cookiecutter@0.1.10-next.0
32
+
33
+ ## 0.15.22
34
+
35
+ ### Patch Changes
36
+
37
+ - b09dd8f43b: chore(deps): bump `@gitbeaker/node` from 34.6.0 to 35.1.0
38
+ - ac2f1eeec0: This change is for adding the option of inputs on the `github:actions:dispatch` Backstage Action. This will allow users to pass data from Backstage to the GitHub Action.
39
+ - 0d5e846a78: Expose a new option to provide additional template filters via `@backstage/scaffolder-backend`'s `createRouter()` function.
40
+ - Updated dependencies
41
+ - @backstage/plugin-catalog-backend@0.21.1
42
+ - @backstage/backend-common@0.10.5
43
+
3
44
  ## 0.15.21
4
45
 
5
46
  ### Patch Changes
package/dist/index.cjs.js CHANGED
@@ -17,7 +17,7 @@ var child_process = require('child_process');
17
17
  var stream = require('stream');
18
18
  var azureDevopsNodeApi = require('azure-devops-node-api');
19
19
  var fetch = require('node-fetch');
20
- var rest = require('@octokit/rest');
20
+ var octokit = require('octokit');
21
21
  var lodash = require('lodash');
22
22
  var octokitPluginCreatePullRequest = require('octokit-plugin-create-pull-request');
23
23
  var node = require('@gitbeaker/node');
@@ -361,6 +361,12 @@ const { render, renderCompat } = (() => {
361
361
  });
362
362
  }
363
363
 
364
+ if (typeof additionalTemplateFilters !== 'undefined') {
365
+ for (const [filterName, filterFn] of Object.entries(additionalTemplateFilters)) {
366
+ env.addFilter(filterName, (...args) => JSON.parse(filterFn(...args)));
367
+ }
368
+ }
369
+
364
370
  let uninstallCompat = undefined;
365
371
 
366
372
  function render(str, values) {
@@ -393,12 +399,16 @@ const { render, renderCompat } = (() => {
393
399
  `;
394
400
  class SecureTemplater {
395
401
  static async loadRenderer(options = {}) {
396
- const { parseRepoUrl, cookiecutterCompat } = options;
397
- let sandbox = void 0;
402
+ const { parseRepoUrl, cookiecutterCompat, additionalTemplateFilters } = options;
403
+ const sandbox = {};
398
404
  if (parseRepoUrl) {
399
- sandbox = {
400
- parseRepoUrl: (url) => JSON.stringify(parseRepoUrl(url))
401
- };
405
+ sandbox.parseRepoUrl = (url) => JSON.stringify(parseRepoUrl(url));
406
+ }
407
+ if (additionalTemplateFilters) {
408
+ sandbox.additionalTemplateFilters = Object.fromEntries(Object.entries(additionalTemplateFilters).filter(([_, filterFunction]) => !!filterFunction).map(([filterName, filterFunction]) => [
409
+ filterName,
410
+ (...args) => JSON.stringify(filterFunction(...args))
411
+ ]));
402
412
  }
403
413
  const vm = new vm2.VM({ sandbox });
404
414
  const nunjucksSource = await fs__default["default"].readFile(backendCommon.resolvePackagePath("@backstage/plugin-scaffolder-backend", "assets/nunjucks.js.txt"), "utf-8");
@@ -419,7 +429,7 @@ class SecureTemplater {
419
429
  }
420
430
 
421
431
  function createFetchTemplateAction(options) {
422
- const { reader, integrations } = options;
432
+ const { reader, integrations, additionalTemplateFilters } = options;
423
433
  return createTemplateAction({
424
434
  id: "fetch:template",
425
435
  description: "Downloads a skeleton, templates variables into file and directory names and content, and places the result in the workspace, or optionally in a subdirectory specified by the 'targetPath' input option.",
@@ -510,7 +520,8 @@ function createFetchTemplateAction(options) {
510
520
  };
511
521
  ctx.logger.info(`Processing ${allEntriesInTemplate.length} template files/directories with input values`, ctx.input.values);
512
522
  const renderTemplate = await SecureTemplater.loadRenderer({
513
- cookiecutterCompat: ctx.input.cookiecutterCompat
523
+ cookiecutterCompat: ctx.input.cookiecutterCompat,
524
+ additionalTemplateFilters
514
525
  });
515
526
  for (const location of allEntriesInTemplate) {
516
527
  let renderFilename;
@@ -730,7 +741,7 @@ const enableBranchProtectionOnDefaultRepoBranch = async ({
730
741
  }) => {
731
742
  const tryOnce = async () => {
732
743
  try {
733
- await client.repos.updateBranchProtection({
744
+ await client.rest.repos.updateBranchProtection({
734
745
  mediaType: {
735
746
  previews: ["luke-cage-preview"]
736
747
  },
@@ -843,8 +854,14 @@ function createPublishAzureAction(options) {
843
854
  description: `Sets the default branch on the repository. The default value is 'master'`
844
855
  },
845
856
  sourcePath: {
846
- title: "Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.",
857
+ title: "Source Path",
858
+ description: "Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.",
847
859
  type: "string"
860
+ },
861
+ token: {
862
+ title: "Authentication Token",
863
+ type: "string",
864
+ description: "The token to use for authorization to Azure"
848
865
  }
849
866
  }
850
867
  },
@@ -863,6 +880,7 @@ function createPublishAzureAction(options) {
863
880
  }
864
881
  },
865
882
  async handler(ctx) {
883
+ var _a;
866
884
  const { repoUrl, defaultBranch = "master" } = ctx.input;
867
885
  const { owner, repo, host, organization } = parseRepoUrl(repoUrl, integrations);
868
886
  if (!organization) {
@@ -872,10 +890,11 @@ function createPublishAzureAction(options) {
872
890
  if (!integrationConfig) {
873
891
  throw new errors.InputError(`No matching integration configuration for host ${host}, please check your integrations config`);
874
892
  }
875
- if (!integrationConfig.config.token) {
893
+ if (!integrationConfig.config.token && !ctx.input.token) {
876
894
  throw new errors.InputError(`No token provided for Azure Integration ${host}`);
877
895
  }
878
- const authHandler = azureDevopsNodeApi.getPersonalAccessTokenHandler(integrationConfig.config.token);
896
+ const token = (_a = ctx.input.token) != null ? _a : integrationConfig.config.token;
897
+ const authHandler = azureDevopsNodeApi.getPersonalAccessTokenHandler(token);
879
898
  const webApi = new azureDevopsNodeApi.WebApi(`https://${host}/${organization}`, authHandler);
880
899
  const client = await webApi.getGitApi();
881
900
  const createOptions = { name: repo };
@@ -899,7 +918,7 @@ function createPublishAzureAction(options) {
899
918
  defaultBranch,
900
919
  auth: {
901
920
  username: "notempty",
902
- password: integrationConfig.config.token
921
+ password: token
903
922
  },
904
923
  logger: ctx.logger,
905
924
  commitMessage: config.getOptionalString("scaffolder.defaultCommitMessage"),
@@ -1045,12 +1064,19 @@ function createPublishBitbucketAction(options) {
1045
1064
  description: `Sets the default branch on the repository. The default value is 'master'`
1046
1065
  },
1047
1066
  sourcePath: {
1048
- title: "Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.",
1067
+ title: "Source Path",
1068
+ description: "Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.",
1049
1069
  type: "string"
1050
1070
  },
1051
1071
  enableLFS: {
1052
- title: "Enable LFS for the repository. Only available for hosted Bitbucket.",
1072
+ title: "Enable LFS?",
1073
+ description: "Enable LFS for the repository. Only available for hosted Bitbucket.",
1053
1074
  type: "boolean"
1075
+ },
1076
+ token: {
1077
+ title: "Authentication Token",
1078
+ type: "string",
1079
+ description: "The token to use for authorization to BitBucket"
1054
1080
  }
1055
1081
  }
1056
1082
  },
@@ -1090,7 +1116,7 @@ function createPublishBitbucketAction(options) {
1090
1116
  if (!integrationConfig) {
1091
1117
  throw new errors.InputError(`No matching integration configuration for host ${host}, please check your integrations config`);
1092
1118
  }
1093
- const authorization = getAuthorizationHeader(integrationConfig.config);
1119
+ const authorization = getAuthorizationHeader(ctx.input.token ? { host: integrationConfig.config.host, token: ctx.input.token } : integrationConfig.config);
1094
1120
  const apiBaseUrl = integrationConfig.config.apiBaseUrl;
1095
1121
  const createMethod = host === "bitbucket.org" ? createBitbucketCloudRepository : createBitbucketServerRepository;
1096
1122
  const { remoteUrl, repoContentsUrl } = await createMethod({
@@ -1107,13 +1133,22 @@ function createPublishBitbucketAction(options) {
1107
1133
  name: config.getOptionalString("scaffolder.defaultAuthor.name"),
1108
1134
  email: config.getOptionalString("scaffolder.defaultAuthor.email")
1109
1135
  };
1136
+ let auth;
1137
+ if (ctx.input.token) {
1138
+ auth = {
1139
+ username: "x-token-auth",
1140
+ password: ctx.input.token
1141
+ };
1142
+ } else {
1143
+ auth = {
1144
+ username: integrationConfig.config.username ? integrationConfig.config.username : "x-token-auth",
1145
+ password: integrationConfig.config.appPassword ? integrationConfig.config.appPassword : (_a = integrationConfig.config.token) != null ? _a : ""
1146
+ };
1147
+ }
1110
1148
  await initRepoAndPush({
1111
1149
  dir: getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath),
1112
1150
  remoteUrl,
1113
- auth: {
1114
- username: integrationConfig.config.username ? integrationConfig.config.username : "x-token-auth",
1115
- password: integrationConfig.config.appPassword ? integrationConfig.config.appPassword : (_a = integrationConfig.config.token) != null ? _a : ""
1116
- },
1151
+ auth,
1117
1152
  defaultBranch,
1118
1153
  logger: ctx.logger,
1119
1154
  commitMessage: config.getOptionalString("scaffolder.defaultCommitMessage"),
@@ -1161,7 +1196,7 @@ class OctokitProvider {
1161
1196
  this.integrations = integrations;
1162
1197
  this.githubCredentialsProvider = githubCredentialsProvider || integration.DefaultGithubCredentialsProvider.fromIntegrations(this.integrations);
1163
1198
  }
1164
- async getOctokit(repoUrl) {
1199
+ async getOctokit(repoUrl, options) {
1165
1200
  var _a;
1166
1201
  const { owner, repo, host } = parseRepoUrl(repoUrl, this.integrations);
1167
1202
  if (!owner) {
@@ -1171,13 +1206,21 @@ class OctokitProvider {
1171
1206
  if (!integrationConfig) {
1172
1207
  throw new errors.InputError(`No integration for host ${host}`);
1173
1208
  }
1209
+ if (options == null ? void 0 : options.token) {
1210
+ const client2 = new octokit.Octokit({
1211
+ auth: options.token,
1212
+ baseUrl: integrationConfig.apiBaseUrl,
1213
+ previews: ["nebula-preview"]
1214
+ });
1215
+ return { client: client2, token: options.token, owner, repo };
1216
+ }
1174
1217
  const { token } = await this.githubCredentialsProvider.getCredentials({
1175
1218
  url: `https://${host}/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}`
1176
1219
  });
1177
1220
  if (!token) {
1178
1221
  throw new errors.InputError(`No token available for host: ${host}, with owner ${owner}, and repo ${repo}`);
1179
1222
  }
1180
- const client = new rest.Octokit({
1223
+ const client = new octokit.Octokit({
1181
1224
  auth: token,
1182
1225
  baseUrl: integrationConfig.apiBaseUrl,
1183
1226
  previews: ["nebula-preview"]
@@ -1212,7 +1255,8 @@ function createPublishGithubAction(options) {
1212
1255
  type: "string"
1213
1256
  },
1214
1257
  requireCodeOwnerReviews: {
1215
- title: "Require an approved review in PR including files with a designated Code Owner",
1258
+ title: "Require CODEOWNER Reviews?",
1259
+ description: "Require an approved review in PR including files with a designated Code Owner",
1216
1260
  type: "boolean"
1217
1261
  },
1218
1262
  repoVisibility: {
@@ -1226,7 +1270,8 @@ function createPublishGithubAction(options) {
1226
1270
  description: `Sets the default branch on the repository. The default value is 'master'`
1227
1271
  },
1228
1272
  sourcePath: {
1229
- title: "Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.",
1273
+ title: "Source Path",
1274
+ description: "Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.",
1230
1275
  type: "string"
1231
1276
  },
1232
1277
  collaborators: {
@@ -1249,6 +1294,11 @@ function createPublishGithubAction(options) {
1249
1294
  }
1250
1295
  }
1251
1296
  },
1297
+ token: {
1298
+ title: "Authentication Token",
1299
+ type: "string",
1300
+ description: "The token to use for authorization to GitHub"
1301
+ },
1252
1302
  topics: {
1253
1303
  title: "Topics",
1254
1304
  type: "array",
@@ -1281,19 +1331,20 @@ function createPublishGithubAction(options) {
1281
1331
  repoVisibility = "private",
1282
1332
  defaultBranch = "master",
1283
1333
  collaborators,
1284
- topics
1334
+ topics,
1335
+ token: providedToken
1285
1336
  } = ctx.input;
1286
- const { client, token, owner, repo } = await octokitProvider.getOctokit(repoUrl);
1287
- const user = await client.users.getByUsername({
1337
+ const { client, token, owner, repo } = await octokitProvider.getOctokit(repoUrl, { token: providedToken });
1338
+ const user = await client.rest.users.getByUsername({
1288
1339
  username: owner
1289
1340
  });
1290
- const repoCreationPromise = user.data.type === "Organization" ? client.repos.createInOrg({
1341
+ const repoCreationPromise = user.data.type === "Organization" ? client.rest.repos.createInOrg({
1291
1342
  name: repo,
1292
1343
  org: owner,
1293
1344
  private: repoVisibility === "private",
1294
1345
  visibility: repoVisibility,
1295
1346
  description
1296
- }) : client.repos.createForAuthenticatedUser({
1347
+ }) : client.rest.repos.createForAuthenticatedUser({
1297
1348
  name: repo,
1298
1349
  private: repoVisibility === "private",
1299
1350
  description
@@ -1301,7 +1352,7 @@ function createPublishGithubAction(options) {
1301
1352
  const { data: newRepo } = await repoCreationPromise;
1302
1353
  if (access == null ? void 0 : access.startsWith(`${owner}/`)) {
1303
1354
  const [, team] = access.split("/");
1304
- await client.teams.addOrUpdateRepoPermissionsInOrg({
1355
+ await client.rest.teams.addOrUpdateRepoPermissionsInOrg({
1305
1356
  org: owner,
1306
1357
  team_slug: team,
1307
1358
  owner,
@@ -1309,7 +1360,7 @@ function createPublishGithubAction(options) {
1309
1360
  permission: "admin"
1310
1361
  });
1311
1362
  } else if (access && access !== owner) {
1312
- await client.repos.addCollaborator({
1363
+ await client.rest.repos.addCollaborator({
1313
1364
  owner,
1314
1365
  repo,
1315
1366
  username: access,
@@ -1322,7 +1373,7 @@ function createPublishGithubAction(options) {
1322
1373
  username: team_slug
1323
1374
  } of collaborators) {
1324
1375
  try {
1325
- await client.teams.addOrUpdateRepoPermissionsInOrg({
1376
+ await client.rest.teams.addOrUpdateRepoPermissionsInOrg({
1326
1377
  org: owner,
1327
1378
  team_slug,
1328
1379
  owner,
@@ -1337,7 +1388,7 @@ function createPublishGithubAction(options) {
1337
1388
  }
1338
1389
  if (topics) {
1339
1390
  try {
1340
- await client.repos.replaceAllTopics({
1391
+ await client.rest.repos.replaceAllTopics({
1341
1392
  owner,
1342
1393
  repo,
1343
1394
  names: topics.map((t) => t.toLowerCase())
@@ -1391,13 +1442,21 @@ const defaultClientFactory = async ({
1391
1442
  githubCredentialsProvider,
1392
1443
  owner,
1393
1444
  repo,
1394
- host = "github.com"
1445
+ host = "github.com",
1446
+ token: providedToken
1395
1447
  }) => {
1396
1448
  var _a;
1397
1449
  const integrationConfig = (_a = integrations.github.byHost(host)) == null ? void 0 : _a.config;
1450
+ const OctokitPR = octokit.Octokit.plugin(octokitPluginCreatePullRequest.createPullRequest);
1398
1451
  if (!integrationConfig) {
1399
1452
  throw new errors.InputError(`No integration for host ${host}`);
1400
1453
  }
1454
+ if (providedToken) {
1455
+ return new OctokitPR({
1456
+ auth: providedToken,
1457
+ baseUrl: integrationConfig.apiBaseUrl
1458
+ });
1459
+ }
1401
1460
  const credentialsProvider = githubCredentialsProvider || integration.SingleInstanceGithubCredentialsProvider.create(integrationConfig);
1402
1461
  const { token } = await credentialsProvider.getCredentials({
1403
1462
  url: `https://${host}/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}`
@@ -1405,7 +1464,6 @@ const defaultClientFactory = async ({
1405
1464
  if (!token) {
1406
1465
  throw new errors.InputError(`No token available for host: ${host}, with owner ${owner}, and repo ${repo}`);
1407
1466
  }
1408
- const OctokitPR = rest.Octokit.plugin(octokitPluginCreatePullRequest.createPullRequest);
1409
1467
  return new OctokitPR({
1410
1468
  auth: token,
1411
1469
  baseUrl: integrationConfig.apiBaseUrl
@@ -1452,6 +1510,11 @@ const createPublishGithubPullRequestAction = ({
1452
1510
  type: "string",
1453
1511
  title: "Repository Subdirectory",
1454
1512
  description: "Subdirectory of repository to apply changes to"
1513
+ },
1514
+ token: {
1515
+ title: "Authentication Token",
1516
+ type: "string",
1517
+ description: "The token to use for authorization to GitHub"
1455
1518
  }
1456
1519
  }
1457
1520
  },
@@ -1474,7 +1537,8 @@ const createPublishGithubPullRequestAction = ({
1474
1537
  title,
1475
1538
  description,
1476
1539
  targetPath,
1477
- sourcePath
1540
+ sourcePath,
1541
+ token: providedToken
1478
1542
  } = ctx.input;
1479
1543
  const { owner, repo, host } = parseRepoUrl(repoUrl, integrations);
1480
1544
  if (!owner) {
@@ -1485,7 +1549,8 @@ const createPublishGithubPullRequestAction = ({
1485
1549
  githubCredentialsProvider,
1486
1550
  host,
1487
1551
  owner,
1488
- repo
1552
+ repo,
1553
+ token: providedToken
1489
1554
  });
1490
1555
  const fileRoot = sourcePath ? backendCommon.resolveSafeChildPath(ctx.workspacePath, sourcePath) : ctx.workspacePath;
1491
1556
  const localFilePaths = await globby__default["default"](["./**", "./**/.*", "!.git"], {
@@ -1559,8 +1624,14 @@ function createPublishGitlabAction(options) {
1559
1624
  description: `Sets the default branch on the repository. The default value is 'master'`
1560
1625
  },
1561
1626
  sourcePath: {
1562
- title: "Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.",
1627
+ title: "Source Path",
1628
+ description: "Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.",
1563
1629
  type: "string"
1630
+ },
1631
+ token: {
1632
+ title: "Authentication Token",
1633
+ type: "string",
1634
+ description: "The token to use for authorization to GitLab"
1564
1635
  }
1565
1636
  }
1566
1637
  },
@@ -1592,12 +1663,13 @@ function createPublishGitlabAction(options) {
1592
1663
  if (!integrationConfig) {
1593
1664
  throw new errors.InputError(`No matching integration configuration for host ${host}, please check your integrations config`);
1594
1665
  }
1595
- if (!integrationConfig.config.token) {
1666
+ if (!integrationConfig.config.token && !ctx.input.token) {
1596
1667
  throw new errors.InputError(`No token available for host ${host}`);
1597
1668
  }
1669
+ const token = ctx.input.token || integrationConfig.config.token;
1598
1670
  const client = new node.Gitlab({
1599
1671
  host: integrationConfig.config.baseUrl,
1600
- token: integrationConfig.config.token
1672
+ token
1601
1673
  });
1602
1674
  let { id: targetNamespace } = await client.Namespaces.show(owner);
1603
1675
  if (!targetNamespace) {
@@ -1621,7 +1693,7 @@ function createPublishGitlabAction(options) {
1621
1693
  defaultBranch,
1622
1694
  auth: {
1623
1695
  username: "oauth2",
1624
- password: integrationConfig.config.token
1696
+ password: token
1625
1697
  },
1626
1698
  logger: ctx.logger,
1627
1699
  commitMessage: config.getOptionalString("scaffolder.defaultCommitMessage"),
@@ -1671,6 +1743,11 @@ const createPublishGitlabMergeRequestAction = (options) => {
1671
1743
  type: "string",
1672
1744
  title: "Repository Subdirectory",
1673
1745
  description: "Subdirectory of repository to apply changes to"
1746
+ },
1747
+ token: {
1748
+ title: "Authentication Token",
1749
+ type: "string",
1750
+ description: "The token to use for authorization to GitLab"
1674
1751
  }
1675
1752
  }
1676
1753
  },
@@ -1690,6 +1767,7 @@ const createPublishGitlabMergeRequestAction = (options) => {
1690
1767
  }
1691
1768
  },
1692
1769
  async handler(ctx) {
1770
+ var _a;
1693
1771
  const repoUrl = ctx.input.repoUrl;
1694
1772
  const { host } = parseRepoUrl(repoUrl, integrations);
1695
1773
  const integrationConfig = integrations.gitlab.byHost(host);
@@ -1698,12 +1776,13 @@ const createPublishGitlabMergeRequestAction = (options) => {
1698
1776
  if (!integrationConfig) {
1699
1777
  throw new errors.InputError(`No matching integration configuration for host ${host}, please check your integrations config`);
1700
1778
  }
1701
- if (!integrationConfig.config.token) {
1779
+ if (!integrationConfig.config.token && !ctx.input.token) {
1702
1780
  throw new errors.InputError(`No token available for host ${host}`);
1703
1781
  }
1782
+ const token = (_a = ctx.input.token) != null ? _a : integrationConfig.config.token;
1704
1783
  const api = new node.Gitlab({
1705
1784
  host: integrationConfig.config.baseUrl,
1706
- token: integrationConfig.config.token
1785
+ token
1707
1786
  });
1708
1787
  const fileRoot = ctx.workspacePath;
1709
1788
  const localFilePaths = await globby__default["default"]([`${ctx.input.targetPath}/**`], {
@@ -1772,19 +1851,36 @@ function createGithubActionsDispatchAction(options) {
1772
1851
  title: "Branch or Tag name",
1773
1852
  description: "The git branch or tag name used to dispatch the workflow",
1774
1853
  type: "string"
1854
+ },
1855
+ workflowInputs: {
1856
+ title: "Workflow Inputs",
1857
+ description: "Inputs keys and values to send to GitHub Action configured on the workflow file. The maximum number of properties is 10. ",
1858
+ type: "object"
1859
+ },
1860
+ token: {
1861
+ title: "Authentication Token",
1862
+ type: "string",
1863
+ description: "The GITHUB_TOKEN to use for authorization to GitHub"
1775
1864
  }
1776
1865
  }
1777
1866
  }
1778
1867
  },
1779
1868
  async handler(ctx) {
1780
- const { repoUrl, workflowId, branchOrTagName } = ctx.input;
1869
+ const {
1870
+ repoUrl,
1871
+ workflowId,
1872
+ branchOrTagName,
1873
+ workflowInputs,
1874
+ token: providedToken
1875
+ } = ctx.input;
1781
1876
  ctx.logger.info(`Dispatching workflow ${workflowId} for repo ${repoUrl} on ${branchOrTagName}`);
1782
- const { client, owner, repo } = await octokitProvider.getOctokit(repoUrl);
1877
+ const { client, owner, repo } = await octokitProvider.getOctokit(repoUrl, { token: providedToken });
1783
1878
  await client.rest.actions.createWorkflowDispatch({
1784
1879
  owner,
1785
1880
  repo,
1786
1881
  workflow_id: workflowId,
1787
- ref: branchOrTagName
1882
+ ref: branchOrTagName,
1883
+ inputs: workflowInputs
1788
1884
  });
1789
1885
  ctx.logger.info(`Workflow ${workflowId} dispatched successfully`);
1790
1886
  }
@@ -1852,6 +1948,11 @@ function createGithubWebhookAction(options) {
1852
1948
  title: "Insecure SSL",
1853
1949
  type: "boolean",
1854
1950
  description: `Determines whether the SSL certificate of the host for url will be verified when delivering payloads. Default 'false'`
1951
+ },
1952
+ token: {
1953
+ title: "Authentication Token",
1954
+ type: "string",
1955
+ description: "The GITHUB_TOKEN to use for authorization to GitHub"
1855
1956
  }
1856
1957
  }
1857
1958
  }
@@ -1864,13 +1965,14 @@ function createGithubWebhookAction(options) {
1864
1965
  events = ["push"],
1865
1966
  active = true,
1866
1967
  contentType = "form",
1867
- insecureSsl = false
1968
+ insecureSsl = false,
1969
+ token: providedToken
1868
1970
  } = ctx.input;
1869
1971
  ctx.logger.info(`Creating webhook ${webhookUrl} for repo ${repoUrl}`);
1870
- const { client, owner, repo } = await octokitProvider.getOctokit(repoUrl);
1972
+ const { client, owner, repo } = await octokitProvider.getOctokit(repoUrl, { token: providedToken });
1871
1973
  try {
1872
1974
  const insecure_ssl = insecureSsl ? "1" : "0";
1873
- await client.repos.createWebhook({
1975
+ await client.rest.repos.createWebhook({
1874
1976
  owner,
1875
1977
  repo,
1876
1978
  config: {
@@ -1892,7 +1994,14 @@ function createGithubWebhookAction(options) {
1892
1994
  }
1893
1995
 
1894
1996
  const createBuiltinActions = (options) => {
1895
- const { reader, integrations, containerRunner, catalogClient, config } = options;
1997
+ const {
1998
+ reader,
1999
+ integrations,
2000
+ containerRunner,
2001
+ catalogClient,
2002
+ config,
2003
+ additionalTemplateFilters
2004
+ } = options;
1896
2005
  const githubCredentialsProvider = integration.DefaultGithubCredentialsProvider.fromIntegrations(integrations);
1897
2006
  const actions = [
1898
2007
  createFetchPlainAction({
@@ -1901,7 +2010,8 @@ const createBuiltinActions = (options) => {
1901
2010
  }),
1902
2011
  createFetchTemplateAction({
1903
2012
  integrations,
1904
- reader
2013
+ reader,
2014
+ additionalTemplateFilters
1905
2015
  }),
1906
2016
  createPublishGithubAction({
1907
2017
  integrations,
@@ -2532,7 +2642,7 @@ class NunjucksWorkflowRunner {
2532
2642
  });
2533
2643
  }
2534
2644
  async execute(task) {
2535
- var _a, _b, _c, _d;
2645
+ var _a, _b, _c, _d, _e;
2536
2646
  if (!isValidTaskSpec(task.spec)) {
2537
2647
  throw new errors.InputError("Wrong template version executed with the workflow engine");
2538
2648
  }
@@ -2541,7 +2651,8 @@ class NunjucksWorkflowRunner {
2541
2651
  const renderTemplate = await SecureTemplater.loadRenderer({
2542
2652
  parseRepoUrl(url) {
2543
2653
  return parseRepoUrl(url, integrations);
2544
- }
2654
+ },
2655
+ additionalTemplateFilters: this.options.additionalTemplateFilters
2545
2656
  });
2546
2657
  try {
2547
2658
  await fs__default["default"].ensureDir(workspacePath);
@@ -2565,8 +2676,8 @@ class NunjucksWorkflowRunner {
2565
2676
  });
2566
2677
  const action = this.options.actionRegistry.get(step.action);
2567
2678
  const { taskLogger, streamLogger } = createStepLogger({ task, step });
2568
- const input = (_a = step.input && this.render(step.input, context, renderTemplate)) != null ? _a : {};
2569
- if ((_b = action.schema) == null ? void 0 : _b.input) {
2679
+ const input = (_b = step.input && this.render(step.input, { ...context, secrets: (_a = task.secrets) != null ? _a : {} }, renderTemplate)) != null ? _b : {};
2680
+ if ((_c = action.schema) == null ? void 0 : _c.input) {
2570
2681
  const validateResult = jsonschema.validate(input, action.schema.input);
2571
2682
  if (!validateResult.valid) {
2572
2683
  const errors$1 = validateResult.errors.join(", ");
@@ -2581,8 +2692,8 @@ class NunjucksWorkflowRunner {
2581
2692
  await action.handler({
2582
2693
  baseUrl: task.spec.baseUrl,
2583
2694
  input,
2584
- token: (_c = task.secrets) == null ? void 0 : _c.token,
2585
- secrets: (_d = task.secrets) != null ? _d : {},
2695
+ token: (_d = task.secrets) == null ? void 0 : _d.token,
2696
+ secrets: (_e = task.secrets) != null ? _e : {},
2586
2697
  logger: taskLogger,
2587
2698
  logStream: streamLogger,
2588
2699
  workspacePath,
@@ -2632,7 +2743,8 @@ class TaskWorker {
2632
2743
  logger,
2633
2744
  actionRegistry,
2634
2745
  integrations,
2635
- workingDirectory
2746
+ workingDirectory,
2747
+ additionalTemplateFilters
2636
2748
  } = options;
2637
2749
  const legacyWorkflowRunner = new HandlebarsWorkflowRunner({
2638
2750
  logger,
@@ -2644,7 +2756,8 @@ class TaskWorker {
2644
2756
  actionRegistry,
2645
2757
  integrations,
2646
2758
  logger,
2647
- workingDirectory
2759
+ workingDirectory,
2760
+ additionalTemplateFilters
2648
2761
  });
2649
2762
  return new TaskWorker({
2650
2763
  taskBroker,
@@ -2741,7 +2854,8 @@ async function createRouter(options) {
2741
2854
  catalogClient,
2742
2855
  actions,
2743
2856
  containerRunner,
2744
- taskWorkers
2857
+ taskWorkers,
2858
+ additionalTemplateFilters
2745
2859
  } = options;
2746
2860
  const logger = parentLogger.child({ plugin: "scaffolder" });
2747
2861
  const workingDirectory = await getWorkingDirectory(config, logger);
@@ -2764,7 +2878,8 @@ async function createRouter(options) {
2764
2878
  actionRegistry,
2765
2879
  integrations,
2766
2880
  logger,
2767
- workingDirectory
2881
+ workingDirectory,
2882
+ additionalTemplateFilters
2768
2883
  });
2769
2884
  workers.push(worker);
2770
2885
  }
@@ -2773,7 +2888,8 @@ async function createRouter(options) {
2773
2888
  catalogClient,
2774
2889
  containerRunner,
2775
2890
  reader,
2776
- config
2891
+ config,
2892
+ additionalTemplateFilters
2777
2893
  });
2778
2894
  actionsToRegister.forEach((action) => actionRegistry.register(action));
2779
2895
  workers.forEach((worker) => worker.start());