@firestartr/cli 1.30.0 → 1.31.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/build/index.js +200 -5
- package/build/provisioner/dist-cdktf/index.js +82 -0
- package/build/provisioner/dist-cdktf/index.js.map +1 -1
- package/build/provisioner/dist-cdktf/src/resources/github_repository/helpers/AdditionalBranchesHelper.d.ts +1 -0
- package/build/provisioner/dist-cdktf/src/resources/github_repository/helpers/AdditionalBranchesHelper.js +62 -0
- package/build/provisioner/dist-cdktf/src/resources/github_repository/index.d.ts +1 -0
- package/build/provisioner/dist-cdktf/src/resources/github_repository/index.js +22 -0
- package/build/provisioner/dist-cdktf/src/resources/resource.d.ts +1 -0
- package/build/provisioner/dist-cdktf/src/resources/resource.js +2 -0
- package/build/provisioner/dist-cdktf/tsconfig.cdktf.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function provisionAdditionalBranches(cr: any): Promise<void>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.provisionAdditionalBranches = void 0;
|
|
7
|
+
const github_1 = __importDefault(require("github"));
|
|
8
|
+
// Main function to provision additional branches
|
|
9
|
+
async function provisionAdditionalBranches(cr) {
|
|
10
|
+
//Debug: Inspect the cr
|
|
11
|
+
//console.log('Received CR in provisionAdditionalBranches:', JSON.stringify(cr, null, 2));
|
|
12
|
+
// Verify that the cr and its properties exist
|
|
13
|
+
if (!cr || !cr.spec || !cr.spec.repo) {
|
|
14
|
+
console.log('Invalid cr object:', JSON.stringify(cr, null, 2));
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
// Obtain the additional branches from the repository configuration
|
|
18
|
+
const branches = cr.spec.repo.additionalBranches;
|
|
19
|
+
//console.log('Branches assigned:', JSON.stringify(branches, null, 2));
|
|
20
|
+
if (!Array.isArray(branches)) {
|
|
21
|
+
console.log('No additional branches found or branches is not an array');
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const repoName = cr.metadata.annotations['firestartr.dev/external-name'];
|
|
25
|
+
const org = cr.spec.org;
|
|
26
|
+
// Process each branch individually
|
|
27
|
+
for (const branch of branches) {
|
|
28
|
+
//console.log('Processing branch:', JSON.stringify(branch, null, 2));
|
|
29
|
+
try {
|
|
30
|
+
// Try to obtain the branch
|
|
31
|
+
await github_1.default.branches.getBranch(repoName, branch.name, org);
|
|
32
|
+
// If not error is thrown, the branch already exists
|
|
33
|
+
console.log(`Branch ${branch.name} already exists in ${org}/${repoName}, skipping...`);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
// If error is a 404, we can create the branch
|
|
37
|
+
if (error.status === 404) {
|
|
38
|
+
if (branch.orphan) {
|
|
39
|
+
await github_1.default.branches.createOrphanBranch(repoName, branch.name, org);
|
|
40
|
+
console.log(`Created orphan branch ${branch.name} in ${org}/${repoName}`);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
await provisionRegularBranch(repoName, branch.name, cr.spec.repo.defaultBranch, org);
|
|
44
|
+
console.log(`Created regular branch ${branch.name} in ${org}/${repoName}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// If error is not a 404, we throw it
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.provisionAdditionalBranches = provisionAdditionalBranches;
|
|
55
|
+
// function to provision a regular branch
|
|
56
|
+
async function provisionRegularBranch(repo, branchName, sourceBranch, org) {
|
|
57
|
+
// Obtaining the sha of the source branch
|
|
58
|
+
const sourceBranchData = await github_1.default.branches.getBranch(repo, sourceBranch, org);
|
|
59
|
+
const sha = sourceBranchData.commit.sha;
|
|
60
|
+
// Create the new branch
|
|
61
|
+
await github_1.default.branches.createBranch(repo, branchName, sha, org);
|
|
62
|
+
}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.FirestartrGithubRepository = void 0;
|
|
7
7
|
const resource_1 = require("../resource");
|
|
8
8
|
const debug_1 = __importDefault(require("debug"));
|
|
9
|
+
const AdditionalBranchesHelper_1 = require("./helpers/AdditionalBranchesHelper");
|
|
9
10
|
const log = (0, debug_1.default)('firestartr:provisioner:github_repository');
|
|
10
11
|
class FirestartrGithubRepository extends resource_1.Resource {
|
|
11
12
|
static kind() {
|
|
@@ -32,5 +33,26 @@ class FirestartrGithubRepository extends resource_1.Resource {
|
|
|
32
33
|
log('UNKNOWN');
|
|
33
34
|
}
|
|
34
35
|
}
|
|
36
|
+
async postprocess() {
|
|
37
|
+
const cr = this.get('main_artifact');
|
|
38
|
+
switch (this.get('operation')) {
|
|
39
|
+
case 'CREATE':
|
|
40
|
+
case 'UPDATE':
|
|
41
|
+
log('CREATE & UPDATE');
|
|
42
|
+
await (0, AdditionalBranchesHelper_1.provisionAdditionalBranches)(cr);
|
|
43
|
+
break;
|
|
44
|
+
case 'DELETE':
|
|
45
|
+
log('DELETED');
|
|
46
|
+
break;
|
|
47
|
+
case 'IMPORT':
|
|
48
|
+
log('IMPORT');
|
|
49
|
+
break;
|
|
50
|
+
case 'IMPORT_SKIP_PLAN':
|
|
51
|
+
log('IMPORT_SKIP_PLAN');
|
|
52
|
+
break;
|
|
53
|
+
default:
|
|
54
|
+
log('UNKNOWN');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
35
57
|
}
|
|
36
58
|
exports.FirestartrGithubRepository = FirestartrGithubRepository;
|
|
@@ -47,6 +47,7 @@ class Resource {
|
|
|
47
47
|
await this.preprocess();
|
|
48
48
|
await this.synth();
|
|
49
49
|
await this.runTerraform();
|
|
50
|
+
await this.postprocess();
|
|
50
51
|
}
|
|
51
52
|
artifact() {
|
|
52
53
|
return this.get('main_artifact');
|
|
@@ -84,6 +85,7 @@ class Resource {
|
|
|
84
85
|
this.set('output', output);
|
|
85
86
|
}
|
|
86
87
|
async preprocess() { }
|
|
88
|
+
async postprocess() { }
|
|
87
89
|
crs() { }
|
|
88
90
|
env() { }
|
|
89
91
|
set(k, v) {
|