Skip to content

Commit 301d904

Browse files
authored
Merge pull request #10 from JonasPBovin/add-se-functions
Extracted poms
2 parents dd2f730 + b17e880 commit 301d904

File tree

2 files changed

+74
-41
lines changed

2 files changed

+74
-41
lines changed

dist/index.js

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13607,13 +13607,8 @@ class se_Helper {
1360713607
this.currentBuild = currentBuild;
1360813608
this.github = github;
1360913609
}
13610-
createMetaJson(root) {
13610+
listPoms(root) {
1361113611
const execSync = external_child_process_.execSync;
13612-
console.log('Run number: ' + this.currentBuild.runNumber);
13613-
const xmllint = execSync('sudo apt install libxml2-utils', {
13614-
shell: '/bin/bash'
13615-
});
13616-
console.log(xmllint.toString());
1361713612
const command = `#!/bin/bash
1361813613
cd ` +
1361913614
root +
@@ -13626,20 +13621,39 @@ class se_Helper {
1362613621
console.log(output.toString());
1362713622
const ret = [];
1362813623
const poms = Object(external_fs_.readFileSync)(root + 'poms.txt', 'utf8').toString();
13629-
const ownersFile = Object(external_fs_.readFileSync)(root + '.github/CODEOWNERS', 'utf8')
13630-
.toString();
1363113624
for (const pomRaw of poms.split('\n')) {
1363213625
const pom = pomRaw.replace('./', '/');
13633-
const name = pom.split('/')[2];
13634-
if (pom.startsWith('/components') &&
13635-
pom.indexOf(name + '-deployment/') > -1) {
13626+
const pomEntity = {};
13627+
pomEntity['path'] = pom.replace('/pom.xml', '').substring(1);
13628+
pomEntity['raw'] = pomRaw;
13629+
pomEntity['pom'] = pom;
13630+
pomEntity['name'] = pom.split('/')[2];
13631+
pomEntity['fullPath'] = root + pomRaw.substring(1);
13632+
ret.push(pomEntity);
13633+
}
13634+
return ret;
13635+
}
13636+
createMetaJson(root) {
13637+
const execSync = external_child_process_.execSync;
13638+
console.log('Run number: ' + this.currentBuild.runNumber);
13639+
const xmllint = execSync('sudo apt install libxml2-utils', {
13640+
shell: '/bin/bash'
13641+
});
13642+
console.log(xmllint.toString());
13643+
const ret = [];
13644+
const poms = this.listPoms(root);
13645+
const ownersFile = Object(external_fs_.readFileSync)(root + '.github/CODEOWNERS', 'utf8')
13646+
.toString();
13647+
for (const pomEntity of poms) {
13648+
if (pomEntity['pom'].startsWith('/components') &&
13649+
pomEntity['pom'].indexOf(name + '-deployment/') > -1) {
1363613650
const owners = [];
1363713651
const reviewers = [];
1363813652
for (const ownerRaw of ownersFile.split('\n')) {
1363913653
const path = ownerRaw.split(' ')[0];
1364013654
if (path.length > 3 &&
1364113655
ownerRaw.indexOf(' @') > -1 &&
13642-
pom.startsWith(path)) {
13656+
pomEntity['pom'].startsWith(path)) {
1364313657
owners.push(ownerRaw.split(' ')[1]);
1364413658
reviewers.push(ownerRaw.split(' ')[1]);
1364513659
}
@@ -13649,37 +13663,38 @@ class se_Helper {
1364913663
root +
1365013664
`
1365113665
xmllint --xpath "/*[local-name()='project']/*[local-name()='groupId']/text()" .` +
13652-
pom +
13666+
pomEntity['pom'] +
1365313667
`
1365413668
`;
1365513669
const aid = `#!/bin/bash
1365613670
cd ` +
1365713671
root +
1365813672
`
1365913673
xmllint --xpath "/*[local-name()='project']/*[local-name()='artifactId']/text()" .` +
13660-
pom +
13674+
pomEntity['pom'] +
1366113675
`
1366213676
`;
1366313677
const groupId = execSync(gid, { shell: '/bin/bash' }).toString();
1366413678
console.log(groupId);
1366513679
const artifactId = execSync(aid, { shell: '/bin/bash' }).toString();
1366613680
console.log(artifactId);
1366713681
const meta = {};
13668-
meta['manifestSource'] = pom.replace('/pom.xml', '').substring(1);
13682+
meta['manifestSource'] = pomEntity['path'];
1366913683
meta['manifestTarget'] =
1367013684
'helm-chart/components/charts/' +
13671-
name +
13685+
pomEntity['name'] +
1367213686
'/' +
13673-
name +
13687+
pomEntity['name'] +
1367413688
'-deployment/templates/';
1367513689
meta['owners'] = owners;
1367613690
meta['reviewers'] = reviewers;
13677-
meta['branchName'] = name + '-deployment';
13691+
meta['branchName'] = pomEntity['name'] + '-deployment';
1367813692
meta['mavenGroupId'] = groupId.trim();
1367913693
meta['mavenArtifactId'] = artifactId.trim();
1368013694
console.log(JSON.stringify(meta));
13681-
ret.push(pomRaw.replace('/pom.xml', '/meta.json').substring(1));
13682-
Object(external_fs_.writeFileSync)(root + pomRaw.replace('/pom.xml', '/meta.json').substring(1), JSON.stringify(meta));
13695+
ret.push(pomEntity['pomRaw'].replace('/pom.xml', '/meta.json').substring(1));
13696+
Object(external_fs_.writeFileSync)(root +
13697+
pomEntity['pomRaw'].replace('/pom.xml', '/meta.json').substring(1), JSON.stringify(meta));
1368313698
}
1368413699
}
1368513700
return ret;

src/se.ts

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,8 @@ export class Helper {
1515
this.github = github
1616
}
1717

18-
public createMetaJson(root: string) {
18+
public listPoms(root: string): {[key: string]: string}[] {
1919
const execSync = child.execSync
20-
console.log('Run number: ' + this.currentBuild.runNumber)
21-
const xmllint = execSync('sudo apt install libxml2-utils', {
22-
shell: '/bin/bash'
23-
})
24-
console.log(xmllint.toString())
2520
const command =
2621
`#!/bin/bash
2722
cd ` +
@@ -33,17 +28,37 @@ export class Helper {
3328
`
3429
const output = execSync(command, {shell: '/bin/bash'})
3530
console.log(output.toString())
36-
const ret: string[] = []
31+
const ret: {[key: string]: any}[] = []
3732
const poms = fs.readFileSync(root + 'poms.txt', 'utf8').toString()
33+
for (const pomRaw of poms.split('\n')) {
34+
const pom = pomRaw.replace('./', '/')
35+
const pomEntity: {[key: string]: any} = {}
36+
pomEntity['path'] = pom.replace('/pom.xml', '').substring(1)
37+
pomEntity['raw'] = pomRaw
38+
pomEntity['pom'] = pom
39+
pomEntity['name'] = pom.split('/')[2]
40+
pomEntity['fullPath'] = root + pomRaw.substring(1)
41+
ret.push(pomEntity)
42+
}
43+
return ret
44+
}
45+
46+
public createMetaJson(root: string) {
47+
const execSync = child.execSync
48+
console.log('Run number: ' + this.currentBuild.runNumber)
49+
const xmllint = execSync('sudo apt install libxml2-utils', {
50+
shell: '/bin/bash'
51+
})
52+
console.log(xmllint.toString())
53+
const ret: string[] = []
54+
const poms = this.listPoms(root)
3855
const ownersFile = fs
3956
.readFileSync(root + '.github/CODEOWNERS', 'utf8')
4057
.toString()
41-
for (const pomRaw of poms.split('\n')) {
42-
const pom = pomRaw.replace('./', '/')
43-
const name = pom.split('/')[2]
58+
for (const pomEntity of poms) {
4459
if (
45-
pom.startsWith('/components') &&
46-
pom.indexOf(name + '-deployment/') > -1
60+
pomEntity['pom'].startsWith('/components') &&
61+
pomEntity['pom'].indexOf(name + '-deployment/') > -1
4762
) {
4863
const owners = []
4964
const reviewers = []
@@ -53,7 +68,7 @@ export class Helper {
5368
if (
5469
path.length > 3 &&
5570
ownerRaw.indexOf(' @') > -1 &&
56-
pom.startsWith(path)
71+
pomEntity['pom'].startsWith(path)
5772
) {
5873
owners.push(ownerRaw.split(' ')[1])
5974
reviewers.push(ownerRaw.split(' ')[1])
@@ -65,7 +80,7 @@ export class Helper {
6580
root +
6681
`
6782
xmllint --xpath "/*[local-name()='project']/*[local-name()='groupId']/text()" .` +
68-
pom +
83+
pomEntity['pom'] +
6984
`
7085
`
7186
const aid =
@@ -74,30 +89,33 @@ export class Helper {
7489
root +
7590
`
7691
xmllint --xpath "/*[local-name()='project']/*[local-name()='artifactId']/text()" .` +
77-
pom +
92+
pomEntity['pom'] +
7893
`
7994
`
8095
const groupId = execSync(gid, {shell: '/bin/bash'}).toString()
8196
console.log(groupId)
8297
const artifactId = execSync(aid, {shell: '/bin/bash'}).toString()
8398
console.log(artifactId)
8499
const meta: {[key: string]: any} = {}
85-
meta['manifestSource'] = pom.replace('/pom.xml', '').substring(1)
100+
meta['manifestSource'] = pomEntity['path']
86101
meta['manifestTarget'] =
87102
'helm-chart/components/charts/' +
88-
name +
103+
pomEntity['name'] +
89104
'/' +
90-
name +
105+
pomEntity['name'] +
91106
'-deployment/templates/'
92107
meta['owners'] = owners
93108
meta['reviewers'] = reviewers
94-
meta['branchName'] = name + '-deployment'
109+
meta['branchName'] = pomEntity['name'] + '-deployment'
95110
meta['mavenGroupId'] = groupId.trim()
96111
meta['mavenArtifactId'] = artifactId.trim()
97112
console.log(JSON.stringify(meta))
98-
ret.push(pomRaw.replace('/pom.xml', '/meta.json').substring(1))
113+
ret.push(
114+
pomEntity['pomRaw'].replace('/pom.xml', '/meta.json').substring(1)
115+
)
99116
fs.writeFileSync(
100-
root + pomRaw.replace('/pom.xml', '/meta.json').substring(1),
117+
root +
118+
pomEntity['pomRaw'].replace('/pom.xml', '/meta.json').substring(1),
101119
JSON.stringify(meta)
102120
)
103121
}

0 commit comments

Comments
 (0)