-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquery-partner-orbs-prod.js
143 lines (134 loc) · 4.42 KB
/
query-partner-orbs-prod.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
const fs = require('fs');
const { exec } = require('child_process');
function queryOrbs() {
// query production orbs from CircleCI registry
return new Promise(function(resolve, reject) {
// Do async job
exec('circleci orb list -u', function(error, stdout, stderr) {
if (error) {
reject(error);
} else {
console.log("Production orbs queried from registry...")
resolve(stdout);
}
});
})
}
function loadProdOrbs(result) {
// read and prepare list of orbs
const prodOrbsRaw = result;
// const dataFile = './data/partner-orbs/prod-orbs.txt'
return new Promise(function(resolve, reject) {
// Do async job
var prodOrbsRaw = result.split("\n")
var prodOrbs = prodOrbsRaw.slice(2,-1);
var prodOrbsSplit = [];
prodOrbs.forEach(function(orb) {
prodOrbsSplit.push(orb.split("/"));
})
console.log('Production orbs read from file...');
resolve(prodOrbsSplit);
});
}
function loadPartners(result) {
// load and prep list of partners >>filter production orbs by partners
const prodOrbsSplit = result;
const dataFile = './data/partner-orbs/partners.txt'
// Return new promise
return new Promise(function(resolve, reject) {
// Do async job
fs.readFile(dataFile, 'utf8', function(err, data) {
if (err) {
reject(err);
} else {
console.log('Partners read from file...');
// convert partners list to lowercase, remove spaces, and sort
var dataByLine = data.split("\n")
var partners = [];
dataByLine.slice(0,-1).forEach(function(item) {
partners.push(item.toLowerCase().replace(/ /g,''))
});
partners.sort();
console.log('\nPartners:');
console.log(partners);
// filter productionOrbs for partner-related orbs (produced by
// either CCI or partner)
var partnerOrbsSplit = [];
prodOrbsSplit.forEach(function(orb) {
partners.forEach(function(partner) {
if (orb[0].includes(partner) || (orb[1].includes(partner)
&& orb[0] == 'circleci')) {
partnerOrbsSplit.push(orb);
}
});
});
resolve(partnerOrbsSplit);
}
});
});
}
function filterPartnerOrbs(result) {
return new Promise(function(resolve, reject) {
// filter productionOrbs for partner-related orbs, produced by
// either CCI or partner
const partnerOrbsSplit = result;
var partnerOrbs = [];
partnerOrbsSplit.forEach(function(orb) {
partnerOrbs.push(orb[0] + "/" + orb[1])
});
resolve(partnerOrbs, partnerOrbsSplit);
});
}
function outputPartnerOrbs(result) {
return new Promise(function(resolve, reject) {
// output partner orbs to console and file
partnerOrbs = result;
console.log('\nPartner-related orbs:');
console.log(partnerOrbs);
fs.writeFile('data/partner-orbs/partner-orbs.csv', partnerOrbs.sort(), err => {
if (err) throw err;
});
resolve(partnerOrbs);
});
}
function summarizePartnerOrbs(result) {
// summary stats for partner-related orbs
const partnerOrbs = result;
console.log('\nSummary stats:');
const numPartnerRelatedOrbs = partnerOrbs.length;
const numCircleciPartnerOrbs = partnerOrbs.filter(orb => orb.startsWith('circleci'));
const numPartnerOrbs = numPartnerRelatedOrbs - numCircleciPartnerOrbs.length
const numPartnerNamespaces = Object.create(null);
// split partner orbs by namespace and orb
var partnerOrbsSplit = [];
partnerOrbs.forEach(function(orb) {
partnerOrbsSplit.push(orb.split("/"));
})
// determine unique namespaces based on first 7 characters
partnerOrbsSplit.forEach(orb => {
numPartnerNamespaces[orb[0]] = true;
});
const uniqueNamespaces = Object.keys(numPartnerNamespaces);
let unique = [...new Set(uniqueNamespaces)];
var unique7 = [];
unique.forEach(function(ns) {
unique7.push(ns.slice(0,7));
});
unique7 = [...new Set(unique7)];
// remove circleci from list of unique partner namespaces
const numUniqueNamespaces = unique7.length - 1;
// print summary stats to console
console.log('Number of partner-related orbs: ' + numPartnerRelatedOrbs);
console.log('Number of partner orbs: ' + numPartnerOrbs);
console.log('Number of CircleCI partner-related orbs: ' + numCircleciPartnerOrbs.length);
console.log('Number of unique partner namespaces: ' + numUniqueNamespaces);
}
var fnlist = [ queryOrbs, loadProdOrbs, loadPartners, filterPartnerOrbs,
outputPartnerOrbs, summarizePartnerOrbs ];
function main(list) {
var p = Promise.resolve();
return list.reduce(function(pacc, fn) {
return pacc = pacc.then(fn);
}, p);
}
main(fnlist);