@backstage/plugin-scaffolder-backend 1.15.0-next.2 → 1.15.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 +72 -0
- package/alpha/package.json +1 -1
- package/dist/alpha.cjs.js +2 -2
- package/dist/cjs/{ScaffolderEntitiesProcessor-70d9fced.cjs.js → ScaffolderEntitiesProcessor-d9bc7a90.cjs.js} +574 -54
- package/dist/cjs/ScaffolderEntitiesProcessor-d9bc7a90.cjs.js.map +1 -0
- package/dist/index.cjs.js +5 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +62 -1
- package/package.json +21 -21
- package/dist/cjs/ScaffolderEntitiesProcessor-70d9fced.cjs.js.map +0 -1
|
@@ -17,7 +17,7 @@ var path = require('path');
|
|
|
17
17
|
var luxon = require('luxon');
|
|
18
18
|
var globby = require('globby');
|
|
19
19
|
var isbinaryfile = require('isbinaryfile');
|
|
20
|
-
var
|
|
20
|
+
var isolatedVm = require('isolated-vm');
|
|
21
21
|
var get = require('lodash/get');
|
|
22
22
|
var octokit = require('octokit');
|
|
23
23
|
var child_process = require('child_process');
|
|
@@ -738,20 +738,14 @@ const { render, renderCompat } = (() => {
|
|
|
738
738
|
});
|
|
739
739
|
compatEnv.addFilter('jsonify', compatEnv.getFilter('dump'));
|
|
740
740
|
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
env.addFilter(filterName, (...args) => JSON.parse(filterFn(...args)));
|
|
744
|
-
}
|
|
741
|
+
for (const name of JSON.parse(availableTemplateFilters)) {
|
|
742
|
+
env.addFilter(name, (...args) => JSON.parse(callFilter(name, args)));
|
|
745
743
|
}
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
} else {
|
|
752
|
-
env.addGlobal(globalName, JSON.parse(global));
|
|
753
|
-
}
|
|
754
|
-
}
|
|
744
|
+
for (const [name, value] of Object.entries(JSON.parse(availableTemplateGlobals))) {
|
|
745
|
+
env.addGlobal(name, value);
|
|
746
|
+
}
|
|
747
|
+
for (const name of JSON.parse(availableTemplateCallbacks)) {
|
|
748
|
+
env.addGlobal(name, (...args) => JSON.parse(callGlobal(name, args)));
|
|
755
749
|
}
|
|
756
750
|
|
|
757
751
|
let uninstallCompat = undefined;
|
|
@@ -786,30 +780,14 @@ const { render, renderCompat } = (() => {
|
|
|
786
780
|
`;
|
|
787
781
|
class SecureTemplater {
|
|
788
782
|
static async loadRenderer(options = {}) {
|
|
789
|
-
const {
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
);
|
|
798
|
-
}
|
|
799
|
-
if (templateGlobals) {
|
|
800
|
-
sandbox.templateGlobals = Object.fromEntries(
|
|
801
|
-
Object.entries(templateGlobals).filter(([_, global]) => !!global).map(([globalName, global]) => {
|
|
802
|
-
if (typeof global === "function") {
|
|
803
|
-
return [
|
|
804
|
-
globalName,
|
|
805
|
-
(...args) => JSON.stringify(global(...args))
|
|
806
|
-
];
|
|
807
|
-
}
|
|
808
|
-
return [globalName, JSON.stringify(global)];
|
|
809
|
-
})
|
|
810
|
-
);
|
|
811
|
-
}
|
|
812
|
-
const vm = new vm2.VM({ sandbox });
|
|
783
|
+
const {
|
|
784
|
+
cookiecutterCompat,
|
|
785
|
+
templateFilters = {},
|
|
786
|
+
templateGlobals = {}
|
|
787
|
+
} = options;
|
|
788
|
+
const isolate = new isolatedVm.Isolate({ memoryLimit: 128 });
|
|
789
|
+
const context = await isolate.createContext();
|
|
790
|
+
const contextGlobal = context.global;
|
|
813
791
|
const nunjucksSource = await fs__default["default"].readFile(
|
|
814
792
|
backendCommon.resolvePackagePath(
|
|
815
793
|
"@backstage/plugin-scaffolder-backend",
|
|
@@ -817,17 +795,64 @@ class SecureTemplater {
|
|
|
817
795
|
),
|
|
818
796
|
"utf-8"
|
|
819
797
|
);
|
|
820
|
-
|
|
798
|
+
const nunjucksScript = await isolate.compileScript(
|
|
799
|
+
mkScript(nunjucksSource)
|
|
800
|
+
);
|
|
801
|
+
const availableFilters = Object.keys(templateFilters);
|
|
802
|
+
await contextGlobal.set(
|
|
803
|
+
"availableTemplateFilters",
|
|
804
|
+
JSON.stringify(availableFilters)
|
|
805
|
+
);
|
|
806
|
+
const globalCallbacks = [];
|
|
807
|
+
const globalValues = {};
|
|
808
|
+
for (const [name, value] of Object.entries(templateGlobals)) {
|
|
809
|
+
if (typeof value === "function") {
|
|
810
|
+
globalCallbacks.push(name);
|
|
811
|
+
} else {
|
|
812
|
+
globalValues[name] = value;
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
await contextGlobal.set(
|
|
816
|
+
"availableTemplateGlobals",
|
|
817
|
+
JSON.stringify(globalValues)
|
|
818
|
+
);
|
|
819
|
+
await contextGlobal.set(
|
|
820
|
+
"availableTemplateCallbacks",
|
|
821
|
+
JSON.stringify(globalCallbacks)
|
|
822
|
+
);
|
|
823
|
+
await contextGlobal.set(
|
|
824
|
+
"callFilter",
|
|
825
|
+
(filterName, args) => {
|
|
826
|
+
if (!Object.hasOwn(templateFilters, filterName)) {
|
|
827
|
+
return "";
|
|
828
|
+
}
|
|
829
|
+
return JSON.stringify(templateFilters[filterName](...args));
|
|
830
|
+
}
|
|
831
|
+
);
|
|
832
|
+
await contextGlobal.set(
|
|
833
|
+
"callGlobal",
|
|
834
|
+
(globalName, args) => {
|
|
835
|
+
if (!Object.hasOwn(templateGlobals, globalName)) {
|
|
836
|
+
return "";
|
|
837
|
+
}
|
|
838
|
+
const global = templateGlobals[globalName];
|
|
839
|
+
if (typeof global !== "function") {
|
|
840
|
+
return "";
|
|
841
|
+
}
|
|
842
|
+
return JSON.stringify(global(...args));
|
|
843
|
+
}
|
|
844
|
+
);
|
|
845
|
+
await nunjucksScript.run(context);
|
|
821
846
|
const render = (template, values) => {
|
|
822
|
-
if (!
|
|
847
|
+
if (!context) {
|
|
823
848
|
throw new Error("SecureTemplater has not been initialized");
|
|
824
849
|
}
|
|
825
|
-
|
|
826
|
-
|
|
850
|
+
contextGlobal.setSync("templateStr", String(template));
|
|
851
|
+
contextGlobal.setSync("templateValues", JSON.stringify(values));
|
|
827
852
|
if (cookiecutterCompat) {
|
|
828
|
-
return
|
|
853
|
+
return context.evalSync(`renderCompat(templateStr, templateValues)`);
|
|
829
854
|
}
|
|
830
|
-
return
|
|
855
|
+
return context.evalSync(`render(templateStr, templateValues)`);
|
|
831
856
|
};
|
|
832
857
|
return render;
|
|
833
858
|
}
|
|
@@ -1477,7 +1502,7 @@ async function createGithubRepoWithCollaboratorsAndTopics(client, repo, owner, r
|
|
|
1477
1502
|
name: repo,
|
|
1478
1503
|
org: owner,
|
|
1479
1504
|
private: repoVisibility === "private",
|
|
1480
|
-
// @ts-ignore
|
|
1505
|
+
// @ts-ignore https://github.com/octokit/types.ts/issues/522
|
|
1481
1506
|
visibility: repoVisibility,
|
|
1482
1507
|
description,
|
|
1483
1508
|
delete_branch_on_merge: deleteBranchOnMerge,
|
|
@@ -2421,6 +2446,260 @@ function createGithubWebhookAction(options) {
|
|
|
2421
2446
|
});
|
|
2422
2447
|
}
|
|
2423
2448
|
|
|
2449
|
+
function createGithubDeployKeyAction(options) {
|
|
2450
|
+
const { integrations } = options;
|
|
2451
|
+
return pluginScaffolderNode.createTemplateAction({
|
|
2452
|
+
id: "github:deployKey:create",
|
|
2453
|
+
description: "Creates and stores Deploy Keys",
|
|
2454
|
+
schema: {
|
|
2455
|
+
input: {
|
|
2456
|
+
type: "object",
|
|
2457
|
+
required: ["repoUrl", "publicKey", "privateKey", "deployKeyName"],
|
|
2458
|
+
properties: {
|
|
2459
|
+
repoUrl: {
|
|
2460
|
+
title: "Repository Location",
|
|
2461
|
+
description: `Accepts the format 'github.com?repo=reponame&owner=owner' where 'reponame' is the new repository name and 'owner' is an organization or username`,
|
|
2462
|
+
type: "string"
|
|
2463
|
+
},
|
|
2464
|
+
publicKey: {
|
|
2465
|
+
title: "SSH Public Key",
|
|
2466
|
+
description: `Generated from ssh-keygen. Begins with 'ssh-rsa', 'ecdsa-sha2-nistp256', 'ecdsa-sha2-nistp384', 'ecdsa-sha2-nistp521', 'ssh-ed25519', 'sk-ecdsa-sha2-nistp256@openssh.com', or 'sk-ssh-ed25519@openssh.com'.`,
|
|
2467
|
+
type: "string"
|
|
2468
|
+
},
|
|
2469
|
+
privateKey: {
|
|
2470
|
+
title: "SSH Private Key",
|
|
2471
|
+
description: `SSH Private Key generated from ssh-keygen`,
|
|
2472
|
+
type: "string"
|
|
2473
|
+
},
|
|
2474
|
+
deployKeyName: {
|
|
2475
|
+
title: "Deploy Key Name",
|
|
2476
|
+
description: `Name of the Deploy Key`,
|
|
2477
|
+
type: "string"
|
|
2478
|
+
},
|
|
2479
|
+
privateKeySecretName: {
|
|
2480
|
+
title: "Private Key GitHub Secret Name",
|
|
2481
|
+
description: `Name of the GitHub Secret to store the private key related to the Deploy Key. Defaults to: 'KEY_NAME_PRIVATE_KEY' where 'KEY_NAME' is the name of the Deploy Key`,
|
|
2482
|
+
type: "string"
|
|
2483
|
+
},
|
|
2484
|
+
token: {
|
|
2485
|
+
title: "Authentication Token",
|
|
2486
|
+
type: "string",
|
|
2487
|
+
description: "The token to use for authorization to GitHub"
|
|
2488
|
+
}
|
|
2489
|
+
}
|
|
2490
|
+
},
|
|
2491
|
+
output: {
|
|
2492
|
+
type: "object",
|
|
2493
|
+
properties: {
|
|
2494
|
+
privateKeySecretName: {
|
|
2495
|
+
title: "The GitHub Action Repo Secret Name for the Private Key",
|
|
2496
|
+
type: "string"
|
|
2497
|
+
}
|
|
2498
|
+
}
|
|
2499
|
+
}
|
|
2500
|
+
},
|
|
2501
|
+
async handler(ctx) {
|
|
2502
|
+
const {
|
|
2503
|
+
repoUrl,
|
|
2504
|
+
publicKey,
|
|
2505
|
+
privateKey,
|
|
2506
|
+
deployKeyName,
|
|
2507
|
+
privateKeySecretName = `${deployKeyName.split(" ").join("_").toLocaleUpperCase("en-US")}_PRIVATE_KEY`,
|
|
2508
|
+
token: providedToken
|
|
2509
|
+
} = ctx.input;
|
|
2510
|
+
const octokitOptions = await getOctokitOptions({
|
|
2511
|
+
integrations,
|
|
2512
|
+
token: providedToken,
|
|
2513
|
+
repoUrl
|
|
2514
|
+
});
|
|
2515
|
+
const { owner, repo } = parseRepoUrl(repoUrl, integrations);
|
|
2516
|
+
if (!owner) {
|
|
2517
|
+
throw new errors.InputError(`No owner provided for repo ${repoUrl}`);
|
|
2518
|
+
}
|
|
2519
|
+
const client = new octokit.Octokit(octokitOptions);
|
|
2520
|
+
await client.rest.repos.createDeployKey({
|
|
2521
|
+
owner,
|
|
2522
|
+
repo,
|
|
2523
|
+
title: deployKeyName,
|
|
2524
|
+
key: publicKey
|
|
2525
|
+
});
|
|
2526
|
+
const publicKeyResponse = await client.rest.actions.getRepoPublicKey({
|
|
2527
|
+
owner,
|
|
2528
|
+
repo
|
|
2529
|
+
});
|
|
2530
|
+
await Sodium__default["default"].ready;
|
|
2531
|
+
const binaryKey = Sodium__default["default"].from_base64(
|
|
2532
|
+
publicKeyResponse.data.key,
|
|
2533
|
+
Sodium__default["default"].base64_variants.ORIGINAL
|
|
2534
|
+
);
|
|
2535
|
+
const binarySecret = Sodium__default["default"].from_string(privateKey);
|
|
2536
|
+
const encryptedBinarySecret = Sodium__default["default"].crypto_box_seal(
|
|
2537
|
+
binarySecret,
|
|
2538
|
+
binaryKey
|
|
2539
|
+
);
|
|
2540
|
+
const encryptedBase64Secret = Sodium__default["default"].to_base64(
|
|
2541
|
+
encryptedBinarySecret,
|
|
2542
|
+
Sodium__default["default"].base64_variants.ORIGINAL
|
|
2543
|
+
);
|
|
2544
|
+
await client.rest.actions.createOrUpdateRepoSecret({
|
|
2545
|
+
owner,
|
|
2546
|
+
repo,
|
|
2547
|
+
secret_name: privateKeySecretName,
|
|
2548
|
+
encrypted_value: encryptedBase64Secret,
|
|
2549
|
+
key_id: publicKeyResponse.data.key_id
|
|
2550
|
+
});
|
|
2551
|
+
ctx.output("privateKeySecretName", privateKeySecretName);
|
|
2552
|
+
}
|
|
2553
|
+
});
|
|
2554
|
+
}
|
|
2555
|
+
|
|
2556
|
+
function createGithubEnvironmentAction(options) {
|
|
2557
|
+
const { integrations } = options;
|
|
2558
|
+
return pluginScaffolderNode.createTemplateAction({
|
|
2559
|
+
id: "github:environment:create",
|
|
2560
|
+
description: "Creates Deployment Environments",
|
|
2561
|
+
schema: {
|
|
2562
|
+
input: {
|
|
2563
|
+
type: "object",
|
|
2564
|
+
required: ["repoUrl", "name"],
|
|
2565
|
+
properties: {
|
|
2566
|
+
repoUrl: {
|
|
2567
|
+
title: "Repository Location",
|
|
2568
|
+
description: `Accepts the format 'github.com?repo=reponame&owner=owner' where 'reponame' is the new repository name and 'owner' is an organization or username`,
|
|
2569
|
+
type: "string"
|
|
2570
|
+
},
|
|
2571
|
+
name: {
|
|
2572
|
+
title: "Environment Name",
|
|
2573
|
+
description: `Name of the deployment environment to create`,
|
|
2574
|
+
type: "string"
|
|
2575
|
+
},
|
|
2576
|
+
deploymentBranchPolicy: {
|
|
2577
|
+
title: "Deployment Branch Policy",
|
|
2578
|
+
description: `The type of deployment branch policy for this environment. To allow all branches to deploy, set to null.`,
|
|
2579
|
+
type: "object",
|
|
2580
|
+
required: ["protected_branches", "custom_branch_policies"],
|
|
2581
|
+
properties: {
|
|
2582
|
+
protected_branches: {
|
|
2583
|
+
title: "Protected Branches",
|
|
2584
|
+
description: `Whether only branches with branch protection rules can deploy to this environment. If protected_branches is true, custom_branch_policies must be false; if protected_branches is false, custom_branch_policies must be true.`,
|
|
2585
|
+
type: "boolean"
|
|
2586
|
+
},
|
|
2587
|
+
custom_branch_policies: {
|
|
2588
|
+
title: "Custom Branch Policies",
|
|
2589
|
+
description: `Whether only branches that match the specified name patterns can deploy to this environment. If custom_branch_policies is true, protected_branches must be false; if custom_branch_policies is false, protected_branches must be true.`,
|
|
2590
|
+
type: "boolean"
|
|
2591
|
+
}
|
|
2592
|
+
}
|
|
2593
|
+
},
|
|
2594
|
+
customBranchPolicyNames: {
|
|
2595
|
+
title: "Custom Branch Policy Name",
|
|
2596
|
+
description: `The name pattern that branches must match in order to deploy to the environment.
|
|
2597
|
+
|
|
2598
|
+
Wildcard characters will not match /. For example, to match branches that begin with release/ and contain an additional single slash, use release/*/*. For more information about pattern matching syntax, see the Ruby File.fnmatch documentation.`,
|
|
2599
|
+
type: "array",
|
|
2600
|
+
items: {
|
|
2601
|
+
type: "string"
|
|
2602
|
+
}
|
|
2603
|
+
},
|
|
2604
|
+
environmentVariables: {
|
|
2605
|
+
title: "Environment Variables",
|
|
2606
|
+
description: `Environment variables attached to the deployment environment`,
|
|
2607
|
+
type: "object"
|
|
2608
|
+
},
|
|
2609
|
+
secrets: {
|
|
2610
|
+
title: "Deployment Secrets",
|
|
2611
|
+
description: `Secrets attached to the deployment environment`,
|
|
2612
|
+
type: "object"
|
|
2613
|
+
},
|
|
2614
|
+
token: {
|
|
2615
|
+
title: "Authentication Token",
|
|
2616
|
+
type: "string",
|
|
2617
|
+
description: "The token to use for authorization to GitHub"
|
|
2618
|
+
}
|
|
2619
|
+
}
|
|
2620
|
+
}
|
|
2621
|
+
},
|
|
2622
|
+
async handler(ctx) {
|
|
2623
|
+
const {
|
|
2624
|
+
repoUrl,
|
|
2625
|
+
name,
|
|
2626
|
+
deploymentBranchPolicy,
|
|
2627
|
+
customBranchPolicyNames,
|
|
2628
|
+
environmentVariables,
|
|
2629
|
+
secrets,
|
|
2630
|
+
token: providedToken
|
|
2631
|
+
} = ctx.input;
|
|
2632
|
+
const octokitOptions = await getOctokitOptions({
|
|
2633
|
+
integrations,
|
|
2634
|
+
token: providedToken,
|
|
2635
|
+
repoUrl
|
|
2636
|
+
});
|
|
2637
|
+
const { owner, repo } = parseRepoUrl(repoUrl, integrations);
|
|
2638
|
+
if (!owner) {
|
|
2639
|
+
throw new errors.InputError(`No owner provided for repo ${repoUrl}`);
|
|
2640
|
+
}
|
|
2641
|
+
const client = new octokit.Octokit(octokitOptions);
|
|
2642
|
+
const repository = await client.rest.repos.get({
|
|
2643
|
+
owner,
|
|
2644
|
+
repo
|
|
2645
|
+
});
|
|
2646
|
+
await client.rest.repos.createOrUpdateEnvironment({
|
|
2647
|
+
owner,
|
|
2648
|
+
repo,
|
|
2649
|
+
environment_name: name,
|
|
2650
|
+
deployment_branch_policy: deploymentBranchPolicy != null ? deploymentBranchPolicy : null
|
|
2651
|
+
});
|
|
2652
|
+
if (customBranchPolicyNames) {
|
|
2653
|
+
for (const item of customBranchPolicyNames) {
|
|
2654
|
+
await client.rest.repos.createDeploymentBranchPolicy({
|
|
2655
|
+
owner,
|
|
2656
|
+
repo,
|
|
2657
|
+
environment_name: name,
|
|
2658
|
+
name: item
|
|
2659
|
+
});
|
|
2660
|
+
}
|
|
2661
|
+
}
|
|
2662
|
+
for (const [key, value] of Object.entries(environmentVariables != null ? environmentVariables : {})) {
|
|
2663
|
+
await client.rest.actions.createEnvironmentVariable({
|
|
2664
|
+
repository_id: repository.data.id,
|
|
2665
|
+
environment_name: name,
|
|
2666
|
+
name: key,
|
|
2667
|
+
value
|
|
2668
|
+
});
|
|
2669
|
+
}
|
|
2670
|
+
if (secrets) {
|
|
2671
|
+
const publicKeyResponse = await client.rest.actions.getRepoPublicKey({
|
|
2672
|
+
owner,
|
|
2673
|
+
repo
|
|
2674
|
+
});
|
|
2675
|
+
await Sodium__default["default"].ready;
|
|
2676
|
+
const binaryKey = Sodium__default["default"].from_base64(
|
|
2677
|
+
publicKeyResponse.data.key,
|
|
2678
|
+
Sodium__default["default"].base64_variants.ORIGINAL
|
|
2679
|
+
);
|
|
2680
|
+
for (const [key, value] of Object.entries(secrets)) {
|
|
2681
|
+
const binarySecret = Sodium__default["default"].from_string(value);
|
|
2682
|
+
const encryptedBinarySecret = Sodium__default["default"].crypto_box_seal(
|
|
2683
|
+
binarySecret,
|
|
2684
|
+
binaryKey
|
|
2685
|
+
);
|
|
2686
|
+
const encryptedBase64Secret = Sodium__default["default"].to_base64(
|
|
2687
|
+
encryptedBinarySecret,
|
|
2688
|
+
Sodium__default["default"].base64_variants.ORIGINAL
|
|
2689
|
+
);
|
|
2690
|
+
await client.rest.actions.createOrUpdateEnvironmentSecret({
|
|
2691
|
+
repository_id: repository.data.id,
|
|
2692
|
+
environment_name: name,
|
|
2693
|
+
secret_name: key,
|
|
2694
|
+
encrypted_value: encryptedBase64Secret,
|
|
2695
|
+
key_id: publicKeyResponse.data.key_id
|
|
2696
|
+
});
|
|
2697
|
+
}
|
|
2698
|
+
}
|
|
2699
|
+
}
|
|
2700
|
+
});
|
|
2701
|
+
}
|
|
2702
|
+
|
|
2424
2703
|
function createPublishAzureAction(options) {
|
|
2425
2704
|
const { integrations, config } = options;
|
|
2426
2705
|
return pluginScaffolderNode.createTemplateAction({
|
|
@@ -3273,6 +3552,203 @@ function createPublishBitbucketServerAction(options) {
|
|
|
3273
3552
|
});
|
|
3274
3553
|
}
|
|
3275
3554
|
|
|
3555
|
+
const createPullRequest = async (opts) => {
|
|
3556
|
+
const {
|
|
3557
|
+
project,
|
|
3558
|
+
repo,
|
|
3559
|
+
title,
|
|
3560
|
+
description,
|
|
3561
|
+
toRef,
|
|
3562
|
+
fromRef,
|
|
3563
|
+
authorization,
|
|
3564
|
+
apiBaseUrl
|
|
3565
|
+
} = opts;
|
|
3566
|
+
let response;
|
|
3567
|
+
const data = {
|
|
3568
|
+
method: "POST",
|
|
3569
|
+
body: JSON.stringify({
|
|
3570
|
+
title,
|
|
3571
|
+
description,
|
|
3572
|
+
state: "OPEN",
|
|
3573
|
+
open: true,
|
|
3574
|
+
closed: false,
|
|
3575
|
+
locked: true,
|
|
3576
|
+
toRef,
|
|
3577
|
+
fromRef
|
|
3578
|
+
}),
|
|
3579
|
+
headers: {
|
|
3580
|
+
Authorization: authorization,
|
|
3581
|
+
"Content-Type": "application/json"
|
|
3582
|
+
}
|
|
3583
|
+
};
|
|
3584
|
+
try {
|
|
3585
|
+
response = await fetch__default["default"](
|
|
3586
|
+
`${apiBaseUrl}/projects/${encodeURIComponent(
|
|
3587
|
+
project
|
|
3588
|
+
)}/repos/${encodeURIComponent(repo)}/pull-requests`,
|
|
3589
|
+
data
|
|
3590
|
+
);
|
|
3591
|
+
} catch (e) {
|
|
3592
|
+
throw new Error(`Unable to create pull-reqeusts, ${e}`);
|
|
3593
|
+
}
|
|
3594
|
+
if (response.status !== 201) {
|
|
3595
|
+
throw new Error(
|
|
3596
|
+
`Unable to create pull requests, ${response.status} ${response.statusText}, ${await response.text()}`
|
|
3597
|
+
);
|
|
3598
|
+
}
|
|
3599
|
+
const r = await response.json();
|
|
3600
|
+
return `${r.links.self[0].href}`;
|
|
3601
|
+
};
|
|
3602
|
+
const findBranches = async (opts) => {
|
|
3603
|
+
const { project, repo, branchName, authorization, apiBaseUrl } = opts;
|
|
3604
|
+
let response;
|
|
3605
|
+
const options = {
|
|
3606
|
+
method: "GET",
|
|
3607
|
+
headers: {
|
|
3608
|
+
Authorization: authorization,
|
|
3609
|
+
"Content-Type": "application/json"
|
|
3610
|
+
}
|
|
3611
|
+
};
|
|
3612
|
+
try {
|
|
3613
|
+
response = await fetch__default["default"](
|
|
3614
|
+
`${apiBaseUrl}/projects/${encodeURIComponent(
|
|
3615
|
+
project
|
|
3616
|
+
)}/repos/${encodeURIComponent(
|
|
3617
|
+
repo
|
|
3618
|
+
)}/branches?boostMatches=true&filterText=${encodeURIComponent(
|
|
3619
|
+
branchName
|
|
3620
|
+
)}`,
|
|
3621
|
+
options
|
|
3622
|
+
);
|
|
3623
|
+
} catch (e) {
|
|
3624
|
+
throw new Error(`Unable to get branches, ${e}`);
|
|
3625
|
+
}
|
|
3626
|
+
if (response.status !== 200) {
|
|
3627
|
+
throw new Error(
|
|
3628
|
+
`Unable to get branches, ${response.status} ${response.statusText}, ${await response.text()}`
|
|
3629
|
+
);
|
|
3630
|
+
}
|
|
3631
|
+
const r = await response.json();
|
|
3632
|
+
for (const object of r.values) {
|
|
3633
|
+
if (object.displayId === branchName) {
|
|
3634
|
+
return object;
|
|
3635
|
+
}
|
|
3636
|
+
}
|
|
3637
|
+
return void 0;
|
|
3638
|
+
};
|
|
3639
|
+
function createPublishBitbucketServerPullRequestAction(options) {
|
|
3640
|
+
const { integrations } = options;
|
|
3641
|
+
return pluginScaffolderNode.createTemplateAction({
|
|
3642
|
+
id: "publish:bitbucketServer:pull-request",
|
|
3643
|
+
schema: {
|
|
3644
|
+
input: {
|
|
3645
|
+
type: "object",
|
|
3646
|
+
required: ["repoUrl", "title", "sourceBranch"],
|
|
3647
|
+
properties: {
|
|
3648
|
+
repoUrl: {
|
|
3649
|
+
title: "Repository Location",
|
|
3650
|
+
type: "string"
|
|
3651
|
+
},
|
|
3652
|
+
title: {
|
|
3653
|
+
title: "Pull Request title",
|
|
3654
|
+
type: "string",
|
|
3655
|
+
description: "The title for the pull request"
|
|
3656
|
+
},
|
|
3657
|
+
description: {
|
|
3658
|
+
title: "Pull Request Description",
|
|
3659
|
+
type: "string",
|
|
3660
|
+
description: "The description of the pull request"
|
|
3661
|
+
},
|
|
3662
|
+
targetBranch: {
|
|
3663
|
+
title: "Target Branch",
|
|
3664
|
+
type: "string",
|
|
3665
|
+
description: `Branch of repository to apply changes to. The default value is 'master'`
|
|
3666
|
+
},
|
|
3667
|
+
sourceBranch: {
|
|
3668
|
+
title: "Source Branch",
|
|
3669
|
+
type: "string",
|
|
3670
|
+
description: "Branch of repository to copy changes from"
|
|
3671
|
+
},
|
|
3672
|
+
token: {
|
|
3673
|
+
title: "Authorization Token",
|
|
3674
|
+
type: "string",
|
|
3675
|
+
description: "The token to use for authorization to BitBucket Server"
|
|
3676
|
+
}
|
|
3677
|
+
}
|
|
3678
|
+
},
|
|
3679
|
+
output: {
|
|
3680
|
+
type: "object",
|
|
3681
|
+
properties: {
|
|
3682
|
+
pullRequestUrl: {
|
|
3683
|
+
title: "A URL to the pull request with the provider",
|
|
3684
|
+
type: "string"
|
|
3685
|
+
}
|
|
3686
|
+
}
|
|
3687
|
+
}
|
|
3688
|
+
},
|
|
3689
|
+
async handler(ctx) {
|
|
3690
|
+
var _a;
|
|
3691
|
+
const {
|
|
3692
|
+
repoUrl,
|
|
3693
|
+
title,
|
|
3694
|
+
description,
|
|
3695
|
+
targetBranch = "master",
|
|
3696
|
+
sourceBranch
|
|
3697
|
+
} = ctx.input;
|
|
3698
|
+
const { project, repo, host } = parseRepoUrl(repoUrl, integrations);
|
|
3699
|
+
if (!project) {
|
|
3700
|
+
throw new errors.InputError(
|
|
3701
|
+
`Invalid URL provider was included in the repo URL to create ${ctx.input.repoUrl}, missing project`
|
|
3702
|
+
);
|
|
3703
|
+
}
|
|
3704
|
+
const integrationConfig = integrations.bitbucketServer.byHost(host);
|
|
3705
|
+
if (!integrationConfig) {
|
|
3706
|
+
throw new errors.InputError(
|
|
3707
|
+
`No matching integration configuration for host ${host}, please check your integrations config`
|
|
3708
|
+
);
|
|
3709
|
+
}
|
|
3710
|
+
const token = (_a = ctx.input.token) != null ? _a : integrationConfig.config.token;
|
|
3711
|
+
const authConfig = {
|
|
3712
|
+
...integrationConfig.config,
|
|
3713
|
+
...{ token }
|
|
3714
|
+
};
|
|
3715
|
+
const reqOpts = integration.getBitbucketServerRequestOptions(authConfig);
|
|
3716
|
+
const authorization = reqOpts.headers.Authorization;
|
|
3717
|
+
if (!authorization) {
|
|
3718
|
+
throw new Error(
|
|
3719
|
+
`Authorization has not been provided for ${integrationConfig.config.host}. Please add either (a) a user login auth token, or (b) a token input from the template or (c) username + password to the integration config.`
|
|
3720
|
+
);
|
|
3721
|
+
}
|
|
3722
|
+
const apiBaseUrl = integrationConfig.config.apiBaseUrl;
|
|
3723
|
+
const toRef = await findBranches({
|
|
3724
|
+
project,
|
|
3725
|
+
repo,
|
|
3726
|
+
branchName: targetBranch,
|
|
3727
|
+
authorization,
|
|
3728
|
+
apiBaseUrl
|
|
3729
|
+
});
|
|
3730
|
+
const fromRef = await findBranches({
|
|
3731
|
+
project,
|
|
3732
|
+
repo,
|
|
3733
|
+
branchName: sourceBranch,
|
|
3734
|
+
authorization,
|
|
3735
|
+
apiBaseUrl
|
|
3736
|
+
});
|
|
3737
|
+
const pullRequestUrl = await createPullRequest({
|
|
3738
|
+
project,
|
|
3739
|
+
repo,
|
|
3740
|
+
title,
|
|
3741
|
+
description,
|
|
3742
|
+
toRef,
|
|
3743
|
+
fromRef,
|
|
3744
|
+
authorization,
|
|
3745
|
+
apiBaseUrl
|
|
3746
|
+
});
|
|
3747
|
+
ctx.output("pullRequestUrl", pullRequestUrl);
|
|
3748
|
+
}
|
|
3749
|
+
});
|
|
3750
|
+
}
|
|
3751
|
+
|
|
3276
3752
|
const createGerritProject = async (config, options) => {
|
|
3277
3753
|
const { projectName, parent, owner, description } = options;
|
|
3278
3754
|
const fetchOptions = {
|
|
@@ -3811,6 +4287,11 @@ const createPublishGithubPullRequestAction = (options) => {
|
|
|
3811
4287
|
title: "Branch Name",
|
|
3812
4288
|
description: "The name for the branch"
|
|
3813
4289
|
},
|
|
4290
|
+
targetBranchName: {
|
|
4291
|
+
type: "string",
|
|
4292
|
+
title: "Target Branch Name",
|
|
4293
|
+
description: "The target branch name of the merge request"
|
|
4294
|
+
},
|
|
3814
4295
|
title: {
|
|
3815
4296
|
type: "string",
|
|
3816
4297
|
title: "Pull Request Name",
|
|
@@ -3868,6 +4349,10 @@ const createPublishGithubPullRequestAction = (options) => {
|
|
|
3868
4349
|
required: ["remoteUrl"],
|
|
3869
4350
|
type: "object",
|
|
3870
4351
|
properties: {
|
|
4352
|
+
targetBranchName: {
|
|
4353
|
+
title: "Target branch name of the merge request",
|
|
4354
|
+
type: "string"
|
|
4355
|
+
},
|
|
3871
4356
|
remoteUrl: {
|
|
3872
4357
|
type: "string",
|
|
3873
4358
|
title: "Pull Request URL",
|
|
@@ -3885,6 +4370,7 @@ const createPublishGithubPullRequestAction = (options) => {
|
|
|
3885
4370
|
const {
|
|
3886
4371
|
repoUrl,
|
|
3887
4372
|
branchName,
|
|
4373
|
+
targetBranchName,
|
|
3888
4374
|
title,
|
|
3889
4375
|
description,
|
|
3890
4376
|
draft,
|
|
@@ -3941,7 +4427,7 @@ const createPublishGithubPullRequestAction = (options) => {
|
|
|
3941
4427
|
])
|
|
3942
4428
|
);
|
|
3943
4429
|
try {
|
|
3944
|
-
const
|
|
4430
|
+
const createOptions = {
|
|
3945
4431
|
owner,
|
|
3946
4432
|
repo,
|
|
3947
4433
|
title,
|
|
@@ -3954,7 +4440,11 @@ const createPublishGithubPullRequestAction = (options) => {
|
|
|
3954
4440
|
body: description,
|
|
3955
4441
|
head: branchName,
|
|
3956
4442
|
draft
|
|
3957
|
-
}
|
|
4443
|
+
};
|
|
4444
|
+
if (targetBranchName) {
|
|
4445
|
+
createOptions.base = targetBranchName;
|
|
4446
|
+
}
|
|
4447
|
+
const response = await client.createPullRequest(createOptions);
|
|
3958
4448
|
if (!response) {
|
|
3959
4449
|
throw new GithubResponseError("null response from Github");
|
|
3960
4450
|
}
|
|
@@ -3969,6 +4459,8 @@ const createPublishGithubPullRequestAction = (options) => {
|
|
|
3969
4459
|
ctx.logger
|
|
3970
4460
|
);
|
|
3971
4461
|
}
|
|
4462
|
+
const targetBranch = response.data.base.ref;
|
|
4463
|
+
ctx.output("targetBranchName", targetBranch);
|
|
3972
4464
|
ctx.output("remoteUrl", response.data.html_url);
|
|
3973
4465
|
ctx.output("pullRequestNumber", pullRequestNumber);
|
|
3974
4466
|
} catch (e) {
|
|
@@ -4195,8 +4687,13 @@ const createPublishGitlabMergeRequestAction = (options) => {
|
|
|
4195
4687
|
},
|
|
4196
4688
|
branchName: {
|
|
4197
4689
|
type: "string",
|
|
4198
|
-
title: "
|
|
4199
|
-
description: "The
|
|
4690
|
+
title: "Source Branch Name",
|
|
4691
|
+
description: "The source branch name of the merge request"
|
|
4692
|
+
},
|
|
4693
|
+
targetBranchName: {
|
|
4694
|
+
type: "string",
|
|
4695
|
+
title: "Target Branch Name",
|
|
4696
|
+
description: "The target branch name of the merge request"
|
|
4200
4697
|
},
|
|
4201
4698
|
sourcePath: {
|
|
4202
4699
|
type: "string",
|
|
@@ -4234,6 +4731,10 @@ const createPublishGitlabMergeRequestAction = (options) => {
|
|
|
4234
4731
|
output: {
|
|
4235
4732
|
type: "object",
|
|
4236
4733
|
properties: {
|
|
4734
|
+
targetBranchName: {
|
|
4735
|
+
title: "Target branch name of the merge request",
|
|
4736
|
+
type: "string"
|
|
4737
|
+
},
|
|
4237
4738
|
projectid: {
|
|
4238
4739
|
title: "Gitlab Project id/Name(slug)",
|
|
4239
4740
|
type: "string"
|
|
@@ -4254,6 +4755,7 @@ const createPublishGitlabMergeRequestAction = (options) => {
|
|
|
4254
4755
|
const {
|
|
4255
4756
|
assignee,
|
|
4256
4757
|
branchName,
|
|
4758
|
+
targetBranchName,
|
|
4257
4759
|
description,
|
|
4258
4760
|
repoUrl,
|
|
4259
4761
|
removeSourceBranch,
|
|
@@ -4314,10 +4816,14 @@ const createPublishGitlabMergeRequestAction = (options) => {
|
|
|
4314
4816
|
execute_filemode: file.executable
|
|
4315
4817
|
};
|
|
4316
4818
|
});
|
|
4317
|
-
|
|
4318
|
-
|
|
4819
|
+
let targetBranch = targetBranchName;
|
|
4820
|
+
if (!targetBranch) {
|
|
4821
|
+
const projects = await api.Projects.show(repoID);
|
|
4822
|
+
const { default_branch: defaultBranch } = projects;
|
|
4823
|
+
targetBranch = defaultBranch;
|
|
4824
|
+
}
|
|
4319
4825
|
try {
|
|
4320
|
-
await api.Branches.create(repoID, branchName, String(
|
|
4826
|
+
await api.Branches.create(repoID, branchName, String(targetBranch));
|
|
4321
4827
|
} catch (e) {
|
|
4322
4828
|
throw new errors.InputError(
|
|
4323
4829
|
`The branch creation failed. Please check that your repo does not already contain a branch named '${branchName}'. ${e}`
|
|
@@ -4334,7 +4840,7 @@ const createPublishGitlabMergeRequestAction = (options) => {
|
|
|
4334
4840
|
const mergeRequestUrl = await api.MergeRequests.create(
|
|
4335
4841
|
repoID,
|
|
4336
4842
|
branchName,
|
|
4337
|
-
String(
|
|
4843
|
+
String(targetBranch),
|
|
4338
4844
|
title,
|
|
4339
4845
|
{
|
|
4340
4846
|
description,
|
|
@@ -4345,6 +4851,7 @@ const createPublishGitlabMergeRequestAction = (options) => {
|
|
|
4345
4851
|
return mergeRequest.web_url;
|
|
4346
4852
|
});
|
|
4347
4853
|
ctx.output("projectid", repoID);
|
|
4854
|
+
ctx.output("targetBranchName", targetBranch);
|
|
4348
4855
|
ctx.output("projectPath", repoID);
|
|
4349
4856
|
ctx.output("mergeRequestUrl", mergeRequestUrl);
|
|
4350
4857
|
} catch (e) {
|
|
@@ -4415,6 +4922,10 @@ const createBuiltinActions = (options) => {
|
|
|
4415
4922
|
integrations,
|
|
4416
4923
|
config
|
|
4417
4924
|
}),
|
|
4925
|
+
createPublishBitbucketServerPullRequestAction({
|
|
4926
|
+
integrations,
|
|
4927
|
+
config
|
|
4928
|
+
}),
|
|
4418
4929
|
createPublishAzureAction({
|
|
4419
4930
|
integrations,
|
|
4420
4931
|
config
|
|
@@ -4446,6 +4957,12 @@ const createBuiltinActions = (options) => {
|
|
|
4446
4957
|
integrations,
|
|
4447
4958
|
config,
|
|
4448
4959
|
githubCredentialsProvider
|
|
4960
|
+
}),
|
|
4961
|
+
createGithubEnvironmentAction({
|
|
4962
|
+
integrations
|
|
4963
|
+
}),
|
|
4964
|
+
createGithubDeployKeyAction({
|
|
4965
|
+
integrations
|
|
4449
4966
|
})
|
|
4450
4967
|
];
|
|
4451
4968
|
return actions;
|
|
@@ -6225,6 +6742,8 @@ exports.createFetchTemplateAction = createFetchTemplateAction;
|
|
|
6225
6742
|
exports.createFilesystemDeleteAction = createFilesystemDeleteAction;
|
|
6226
6743
|
exports.createFilesystemRenameAction = createFilesystemRenameAction;
|
|
6227
6744
|
exports.createGithubActionsDispatchAction = createGithubActionsDispatchAction;
|
|
6745
|
+
exports.createGithubDeployKeyAction = createGithubDeployKeyAction;
|
|
6746
|
+
exports.createGithubEnvironmentAction = createGithubEnvironmentAction;
|
|
6228
6747
|
exports.createGithubIssuesLabelAction = createGithubIssuesLabelAction;
|
|
6229
6748
|
exports.createGithubRepoCreateAction = createGithubRepoCreateAction;
|
|
6230
6749
|
exports.createGithubRepoPushAction = createGithubRepoPushAction;
|
|
@@ -6233,6 +6752,7 @@ exports.createPublishAzureAction = createPublishAzureAction;
|
|
|
6233
6752
|
exports.createPublishBitbucketAction = createPublishBitbucketAction;
|
|
6234
6753
|
exports.createPublishBitbucketCloudAction = createPublishBitbucketCloudAction;
|
|
6235
6754
|
exports.createPublishBitbucketServerAction = createPublishBitbucketServerAction;
|
|
6755
|
+
exports.createPublishBitbucketServerPullRequestAction = createPublishBitbucketServerPullRequestAction;
|
|
6236
6756
|
exports.createPublishGerritAction = createPublishGerritAction;
|
|
6237
6757
|
exports.createPublishGerritReviewAction = createPublishGerritReviewAction;
|
|
6238
6758
|
exports.createPublishGithubAction = createPublishGithubAction;
|
|
@@ -6245,4 +6765,4 @@ exports.executeShellCommand = executeShellCommand;
|
|
|
6245
6765
|
exports.fetchContents = fetchContents;
|
|
6246
6766
|
exports.scaffolderActionRules = scaffolderActionRules;
|
|
6247
6767
|
exports.scaffolderTemplateRules = scaffolderTemplateRules;
|
|
6248
|
-
//# sourceMappingURL=ScaffolderEntitiesProcessor-
|
|
6768
|
+
//# sourceMappingURL=ScaffolderEntitiesProcessor-d9bc7a90.cjs.js.map
|