@backstage/plugin-scaffolder-backend 0.0.0-nightly-20220421024404 → 0.0.0-nightly-20220422024928

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,13 +1,36 @@
1
1
  # @backstage/plugin-scaffolder-backend
2
2
 
3
- ## 0.0.0-nightly-20220421024404
3
+ ## 0.0.0-nightly-20220422024928
4
+
5
+ ### Minor Changes
6
+
7
+ - 9818112d12: Update the `github:publish` action to allow passing required status check
8
+ contexts before merging to the main branch.
9
+ - 8d5a2238a9: Split `publish:bitbucket` into `publish:bitbucketCloud` and `publish:bitbucketServer`.
10
+
11
+ In order to migrate from the deprecated action, you need to replace the use of action
12
+ `publish:bitbucket` in your templates with the use of either `publish:bitbucketCloud`
13
+ or `publish:bitbucketServer` - depending on which destination SCM provider you use.
14
+
15
+ Additionally, these actions will not utilize `integrations.bitbucket` anymore,
16
+ but `integrations.bitbucketCloud` or `integrations.bitbucketServer` respectively.
17
+ You may or may not have migrated to these already.
18
+
19
+ As described in a previous changeset, using these two replacement integrations configs
20
+ will not compromise use cases which still rely on `integrations.bitbucket` as this was
21
+ set up in a backwards compatible way.
22
+
23
+ Additionally, please mind that the option `enableLFS` is only available (and always was)
24
+ for Bitbucket Server use cases and therefore, is not even part of the schema for
25
+ `publish:bitbucketCloud` anymore.
4
26
 
5
27
  ### Patch Changes
6
28
 
7
29
  - 0fc65cbf89: Override default commit message and author details in GitHub, Azure, bitbucket
8
30
  - Updated dependencies
9
- - @backstage/plugin-catalog-backend@0.0.0-nightly-20220421024404
10
- - @backstage/backend-common@0.0.0-nightly-20220421024404
31
+ - @backstage/backend-common@0.0.0-nightly-20220422024928
32
+ - @backstage/plugin-catalog-backend@0.0.0-nightly-20220422024928
33
+ - @backstage/integration@0.0.0-nightly-20220422024928
11
34
 
12
35
  ## 1.1.0
13
36
 
package/dist/index.cjs.js CHANGED
@@ -734,6 +734,7 @@ const enableBranchProtectionOnDefaultRepoBranch = async ({
734
734
  owner,
735
735
  logger,
736
736
  requireCodeOwnerReviews,
737
+ requiredStatusCheckContexts = [],
737
738
  defaultBranch = "master"
738
739
  }) => {
739
740
  const tryOnce = async () => {
@@ -745,7 +746,10 @@ const enableBranchProtectionOnDefaultRepoBranch = async ({
745
746
  owner,
746
747
  repo: repoName,
747
748
  branch: defaultBranch,
748
- required_status_checks: { strict: true, contexts: [] },
749
+ required_status_checks: {
750
+ strict: true,
751
+ contexts: requiredStatusCheckContexts
752
+ },
749
753
  restrictions: null,
750
754
  enforce_admins: true,
751
755
  required_pull_request_reviews: {
@@ -1031,7 +1035,7 @@ const createBitbucketServerRepository = async (opts) => {
1031
1035
  const repoContentsUrl = `${r.links.self[0].href}`;
1032
1036
  return { remoteUrl, repoContentsUrl };
1033
1037
  };
1034
- const getAuthorizationHeader = (config) => {
1038
+ const getAuthorizationHeader$2 = (config) => {
1035
1039
  if (config.username && config.appPassword) {
1036
1040
  const buffer = Buffer.from(`${config.username}:${config.appPassword}`, "utf8");
1037
1041
  return `Basic ${buffer.toString("base64")}`;
@@ -1041,7 +1045,7 @@ const getAuthorizationHeader = (config) => {
1041
1045
  }
1042
1046
  throw new Error(`Authorization has not been provided for Bitbucket. Please add either username + appPassword or token to the Integrations config`);
1043
1047
  };
1044
- const performEnableLFS = async (opts) => {
1048
+ const performEnableLFS$1 = async (opts) => {
1045
1049
  const { authorization, host, project, repo } = opts;
1046
1050
  const options = {
1047
1051
  method: "PUT",
@@ -1129,6 +1133,7 @@ function createPublishBitbucketAction(options) {
1129
1133
  },
1130
1134
  async handler(ctx) {
1131
1135
  var _a;
1136
+ ctx.logger.warn(`[Deprecated] Please migrate the use of action "publish:bitbucket" to "publish:bitbucketCloud" or "publish:bitbucketServer".`);
1132
1137
  const {
1133
1138
  repoUrl,
1134
1139
  description,
@@ -1152,7 +1157,7 @@ function createPublishBitbucketAction(options) {
1152
1157
  if (!integrationConfig) {
1153
1158
  throw new errors.InputError(`No matching integration configuration for host ${host}, please check your integrations config`);
1154
1159
  }
1155
- const authorization = getAuthorizationHeader(ctx.input.token ? {
1160
+ const authorization = getAuthorizationHeader$2(ctx.input.token ? {
1156
1161
  host: integrationConfig.config.host,
1157
1162
  apiBaseUrl: integrationConfig.config.apiBaseUrl,
1158
1163
  token: ctx.input.token
@@ -1195,6 +1200,348 @@ function createPublishBitbucketAction(options) {
1195
1200
  gitAuthorInfo
1196
1201
  });
1197
1202
  if (enableLFS && host !== "bitbucket.org") {
1203
+ await performEnableLFS$1({ authorization, host, project, repo });
1204
+ }
1205
+ ctx.output("remoteUrl", remoteUrl);
1206
+ ctx.output("repoContentsUrl", repoContentsUrl);
1207
+ }
1208
+ });
1209
+ }
1210
+
1211
+ const createRepository$1 = async (opts) => {
1212
+ const {
1213
+ workspace,
1214
+ project,
1215
+ repo,
1216
+ description,
1217
+ repoVisibility,
1218
+ mainBranch,
1219
+ authorization,
1220
+ apiBaseUrl
1221
+ } = opts;
1222
+ const options = {
1223
+ method: "POST",
1224
+ body: JSON.stringify({
1225
+ scm: "git",
1226
+ description,
1227
+ is_private: repoVisibility === "private",
1228
+ project: { key: project }
1229
+ }),
1230
+ headers: {
1231
+ Authorization: authorization,
1232
+ "Content-Type": "application/json"
1233
+ }
1234
+ };
1235
+ let response;
1236
+ try {
1237
+ response = await fetch__default["default"](`${apiBaseUrl}/repositories/${workspace}/${repo}`, options);
1238
+ } catch (e) {
1239
+ throw new Error(`Unable to create repository, ${e}`);
1240
+ }
1241
+ if (response.status !== 200) {
1242
+ throw new Error(`Unable to create repository, ${response.status} ${response.statusText}, ${await response.text()}`);
1243
+ }
1244
+ const r = await response.json();
1245
+ let remoteUrl = "";
1246
+ for (const link of r.links.clone) {
1247
+ if (link.name === "https") {
1248
+ remoteUrl = link.href;
1249
+ }
1250
+ }
1251
+ const repoContentsUrl = `${r.links.html.href}/src/${mainBranch}`;
1252
+ return { remoteUrl, repoContentsUrl };
1253
+ };
1254
+ const getAuthorizationHeader$1 = (config) => {
1255
+ if (config.username && config.appPassword) {
1256
+ const buffer = Buffer.from(`${config.username}:${config.appPassword}`, "utf8");
1257
+ return `Basic ${buffer.toString("base64")}`;
1258
+ }
1259
+ if (config.token) {
1260
+ return `Bearer ${config.token}`;
1261
+ }
1262
+ throw new Error(`Authorization has not been provided for Bitbucket Cloud. Please add either username + appPassword to the Integrations config or a user login auth token`);
1263
+ };
1264
+ function createPublishBitbucketCloudAction(options) {
1265
+ const { integrations, config } = options;
1266
+ return createTemplateAction({
1267
+ id: "publish:bitbucketCloud",
1268
+ description: "Initializes a git repository of the content in the workspace, and publishes it to Bitbucket Cloud.",
1269
+ schema: {
1270
+ input: {
1271
+ type: "object",
1272
+ required: ["repoUrl"],
1273
+ properties: {
1274
+ repoUrl: {
1275
+ title: "Repository Location",
1276
+ type: "string"
1277
+ },
1278
+ description: {
1279
+ title: "Repository Description",
1280
+ type: "string"
1281
+ },
1282
+ repoVisibility: {
1283
+ title: "Repository Visibility",
1284
+ type: "string",
1285
+ enum: ["private", "public"]
1286
+ },
1287
+ defaultBranch: {
1288
+ title: "Default Branch",
1289
+ type: "string",
1290
+ description: `Sets the default branch on the repository. The default value is 'master'`
1291
+ },
1292
+ sourcePath: {
1293
+ title: "Source Path",
1294
+ description: "Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.",
1295
+ type: "string"
1296
+ },
1297
+ token: {
1298
+ title: "Authentication Token",
1299
+ type: "string",
1300
+ description: "The token to use for authorization to BitBucket Cloud"
1301
+ }
1302
+ }
1303
+ },
1304
+ output: {
1305
+ type: "object",
1306
+ properties: {
1307
+ remoteUrl: {
1308
+ title: "A URL to the repository with the provider",
1309
+ type: "string"
1310
+ },
1311
+ repoContentsUrl: {
1312
+ title: "A URL to the root of the repository",
1313
+ type: "string"
1314
+ }
1315
+ }
1316
+ }
1317
+ },
1318
+ async handler(ctx) {
1319
+ const {
1320
+ repoUrl,
1321
+ description,
1322
+ defaultBranch = "master",
1323
+ repoVisibility = "private"
1324
+ } = ctx.input;
1325
+ const { workspace, project, repo, host } = parseRepoUrl(repoUrl, integrations);
1326
+ if (!workspace) {
1327
+ throw new errors.InputError(`Invalid URL provider was included in the repo URL to create ${ctx.input.repoUrl}, missing workspace`);
1328
+ }
1329
+ if (!project) {
1330
+ throw new errors.InputError(`Invalid URL provider was included in the repo URL to create ${ctx.input.repoUrl}, missing project`);
1331
+ }
1332
+ const integrationConfig = integrations.bitbucketCloud.byHost(host);
1333
+ if (!integrationConfig) {
1334
+ throw new errors.InputError(`No matching integration configuration for host ${host}, please check your integrations config`);
1335
+ }
1336
+ const authorization = getAuthorizationHeader$1(ctx.input.token ? { token: ctx.input.token } : integrationConfig.config);
1337
+ const apiBaseUrl = integrationConfig.config.apiBaseUrl;
1338
+ const { remoteUrl, repoContentsUrl } = await createRepository$1({
1339
+ authorization,
1340
+ workspace: workspace || "",
1341
+ project,
1342
+ repo,
1343
+ repoVisibility,
1344
+ mainBranch: defaultBranch,
1345
+ description,
1346
+ apiBaseUrl
1347
+ });
1348
+ const gitAuthorInfo = {
1349
+ name: config.getOptionalString("scaffolder.defaultAuthor.name"),
1350
+ email: config.getOptionalString("scaffolder.defaultAuthor.email")
1351
+ };
1352
+ let auth;
1353
+ if (ctx.input.token) {
1354
+ auth = {
1355
+ username: "x-token-auth",
1356
+ password: ctx.input.token
1357
+ };
1358
+ } else {
1359
+ if (!integrationConfig.config.username || !integrationConfig.config.appPassword) {
1360
+ throw new Error("Credentials for Bitbucket Cloud integration required for this action.");
1361
+ }
1362
+ auth = {
1363
+ username: integrationConfig.config.username,
1364
+ password: integrationConfig.config.appPassword
1365
+ };
1366
+ }
1367
+ await initRepoAndPush({
1368
+ dir: getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath),
1369
+ remoteUrl,
1370
+ auth,
1371
+ defaultBranch,
1372
+ logger: ctx.logger,
1373
+ commitMessage: config.getOptionalString("scaffolder.defaultCommitMessage"),
1374
+ gitAuthorInfo
1375
+ });
1376
+ ctx.output("remoteUrl", remoteUrl);
1377
+ ctx.output("repoContentsUrl", repoContentsUrl);
1378
+ }
1379
+ });
1380
+ }
1381
+
1382
+ const createRepository = async (opts) => {
1383
+ const {
1384
+ project,
1385
+ repo,
1386
+ description,
1387
+ authorization,
1388
+ repoVisibility,
1389
+ apiBaseUrl
1390
+ } = opts;
1391
+ let response;
1392
+ const options = {
1393
+ method: "POST",
1394
+ body: JSON.stringify({
1395
+ name: repo,
1396
+ description,
1397
+ public: repoVisibility === "public"
1398
+ }),
1399
+ headers: {
1400
+ Authorization: authorization,
1401
+ "Content-Type": "application/json"
1402
+ }
1403
+ };
1404
+ try {
1405
+ response = await fetch__default["default"](`${apiBaseUrl}/projects/${project}/repos`, options);
1406
+ } catch (e) {
1407
+ throw new Error(`Unable to create repository, ${e}`);
1408
+ }
1409
+ if (response.status !== 201) {
1410
+ throw new Error(`Unable to create repository, ${response.status} ${response.statusText}, ${await response.text()}`);
1411
+ }
1412
+ const r = await response.json();
1413
+ let remoteUrl = "";
1414
+ for (const link of r.links.clone) {
1415
+ if (link.name === "http") {
1416
+ remoteUrl = link.href;
1417
+ }
1418
+ }
1419
+ const repoContentsUrl = `${r.links.self[0].href}`;
1420
+ return { remoteUrl, repoContentsUrl };
1421
+ };
1422
+ const getAuthorizationHeader = (config) => {
1423
+ return `Bearer ${config.token}`;
1424
+ };
1425
+ const performEnableLFS = async (opts) => {
1426
+ const { authorization, host, project, repo } = opts;
1427
+ const options = {
1428
+ method: "PUT",
1429
+ headers: {
1430
+ Authorization: authorization
1431
+ }
1432
+ };
1433
+ const { ok, status, statusText } = await fetch__default["default"](`https://${host}/rest/git-lfs/admin/projects/${project}/repos/${repo}/enabled`, options);
1434
+ if (!ok)
1435
+ throw new Error(`Failed to enable LFS in the repository, ${status}: ${statusText}`);
1436
+ };
1437
+ function createPublishBitbucketServerAction(options) {
1438
+ const { integrations, config } = options;
1439
+ return createTemplateAction({
1440
+ id: "publish:bitbucketServer",
1441
+ description: "Initializes a git repository of the content in the workspace, and publishes it to Bitbucket Server.",
1442
+ schema: {
1443
+ input: {
1444
+ type: "object",
1445
+ required: ["repoUrl"],
1446
+ properties: {
1447
+ repoUrl: {
1448
+ title: "Repository Location",
1449
+ type: "string"
1450
+ },
1451
+ description: {
1452
+ title: "Repository Description",
1453
+ type: "string"
1454
+ },
1455
+ repoVisibility: {
1456
+ title: "Repository Visibility",
1457
+ type: "string",
1458
+ enum: ["private", "public"]
1459
+ },
1460
+ defaultBranch: {
1461
+ title: "Default Branch",
1462
+ type: "string",
1463
+ description: `Sets the default branch on the repository. The default value is 'master'`
1464
+ },
1465
+ sourcePath: {
1466
+ title: "Source Path",
1467
+ description: "Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.",
1468
+ type: "string"
1469
+ },
1470
+ enableLFS: {
1471
+ title: "Enable LFS?",
1472
+ description: "Enable LFS for the repository.",
1473
+ type: "boolean"
1474
+ },
1475
+ token: {
1476
+ title: "Authentication Token",
1477
+ type: "string",
1478
+ description: "The token to use for authorization to BitBucket Server"
1479
+ }
1480
+ }
1481
+ },
1482
+ output: {
1483
+ type: "object",
1484
+ properties: {
1485
+ remoteUrl: {
1486
+ title: "A URL to the repository with the provider",
1487
+ type: "string"
1488
+ },
1489
+ repoContentsUrl: {
1490
+ title: "A URL to the root of the repository",
1491
+ type: "string"
1492
+ }
1493
+ }
1494
+ }
1495
+ },
1496
+ async handler(ctx) {
1497
+ var _a;
1498
+ const {
1499
+ repoUrl,
1500
+ description,
1501
+ defaultBranch = "master",
1502
+ repoVisibility = "private",
1503
+ enableLFS = false
1504
+ } = ctx.input;
1505
+ const { project, repo, host } = parseRepoUrl(repoUrl, integrations);
1506
+ if (!project) {
1507
+ throw new errors.InputError(`Invalid URL provider was included in the repo URL to create ${ctx.input.repoUrl}, missing project`);
1508
+ }
1509
+ const integrationConfig = integrations.bitbucketServer.byHost(host);
1510
+ if (!integrationConfig) {
1511
+ throw new errors.InputError(`No matching integration configuration for host ${host}, please check your integrations config`);
1512
+ }
1513
+ const token = (_a = ctx.input.token) != null ? _a : integrationConfig.config.token;
1514
+ if (!token) {
1515
+ throw new Error(`Authorization has not been provided for ${integrationConfig.config.host}. Please add either token to the Integrations config or a user login auth token`);
1516
+ }
1517
+ const authorization = getAuthorizationHeader({ token });
1518
+ const apiBaseUrl = integrationConfig.config.apiBaseUrl;
1519
+ const { remoteUrl, repoContentsUrl } = await createRepository({
1520
+ authorization,
1521
+ project,
1522
+ repo,
1523
+ repoVisibility,
1524
+ description,
1525
+ apiBaseUrl
1526
+ });
1527
+ const gitAuthorInfo = {
1528
+ name: config.getOptionalString("scaffolder.defaultAuthor.name"),
1529
+ email: config.getOptionalString("scaffolder.defaultAuthor.email")
1530
+ };
1531
+ const auth = {
1532
+ username: "x-token-auth",
1533
+ password: token
1534
+ };
1535
+ await initRepoAndPush({
1536
+ dir: getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath),
1537
+ remoteUrl,
1538
+ auth,
1539
+ defaultBranch,
1540
+ logger: ctx.logger,
1541
+ commitMessage: config.getOptionalString("scaffolder.defaultCommitMessage"),
1542
+ gitAuthorInfo
1543
+ });
1544
+ if (enableLFS) {
1198
1545
  await performEnableLFS({ authorization, host, project, repo });
1199
1546
  }
1200
1547
  ctx.output("remoteUrl", remoteUrl);
@@ -1297,6 +1644,14 @@ function createPublishGithubAction(options) {
1297
1644
  description: "Require an approved review in PR including files with a designated Code Owner",
1298
1645
  type: "boolean"
1299
1646
  },
1647
+ requiredStatusCheckContexts: {
1648
+ title: "Required Status Check Contexts",
1649
+ description: "The list of status checks to require in order to merge into this branch",
1650
+ type: "array",
1651
+ items: {
1652
+ type: "string"
1653
+ }
1654
+ },
1300
1655
  repoVisibility: {
1301
1656
  title: "Repository Visibility",
1302
1657
  type: "string",
@@ -1401,6 +1756,7 @@ function createPublishGithubAction(options) {
1401
1756
  description,
1402
1757
  access,
1403
1758
  requireCodeOwnerReviews = false,
1759
+ requiredStatusCheckContexts = [],
1404
1760
  repoVisibility = "private",
1405
1761
  defaultBranch = "master",
1406
1762
  deleteBranchOnMerge = false,
@@ -1521,7 +1877,8 @@ function createPublishGithubAction(options) {
1521
1877
  repoName: newRepo.name,
1522
1878
  logger: ctx.logger,
1523
1879
  defaultBranch,
1524
- requireCodeOwnerReviews
1880
+ requireCodeOwnerReviews,
1881
+ requiredStatusCheckContexts
1525
1882
  });
1526
1883
  } catch (e) {
1527
1884
  errors.assertError(e);
@@ -2229,6 +2586,14 @@ const createBuiltinActions = (options) => {
2229
2586
  integrations,
2230
2587
  config
2231
2588
  }),
2589
+ createPublishBitbucketCloudAction({
2590
+ integrations,
2591
+ config
2592
+ }),
2593
+ createPublishBitbucketServerAction({
2594
+ integrations,
2595
+ config
2596
+ }),
2232
2597
  createPublishAzureAction({
2233
2598
  integrations,
2234
2599
  config
@@ -3110,6 +3475,8 @@ exports.createGithubIssuesLabelAction = createGithubIssuesLabelAction;
3110
3475
  exports.createGithubWebhookAction = createGithubWebhookAction;
3111
3476
  exports.createPublishAzureAction = createPublishAzureAction;
3112
3477
  exports.createPublishBitbucketAction = createPublishBitbucketAction;
3478
+ exports.createPublishBitbucketCloudAction = createPublishBitbucketCloudAction;
3479
+ exports.createPublishBitbucketServerAction = createPublishBitbucketServerAction;
3113
3480
  exports.createPublishFileAction = createPublishFileAction;
3114
3481
  exports.createPublishGithubAction = createPublishGithubAction;
3115
3482
  exports.createPublishGithubPullRequestAction = createPublishGithubPullRequestAction;