-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircleci_export_jobs.js
89 lines (76 loc) · 2.15 KB
/
circleci_export_jobs.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
const jsonfile = require('jsonfile');
const MongoClient = require('mongodb').MongoClient;
const Timeout = require('await-timeout');
const csv = require('fast-csv')
const fs = require('fs')
const url = 'mongodb://localhost:27017';
const dbName = 'circleci';
const client = new MongoClient(url);
const csvStream = csv.format({ headers: [
'build_num',
'name',
'index',
'parallel',
'failed',
// 'bash_command',
'status',
'timedout',
'continue',
'end_time',
'type',
'allocation_id',
'output_url',
'start_time',
'background',
'exit_code',
'insignificant',
'canceled',
'step',
'run_time_millis',
'has_output',
]})
const writeStream = fs.createWriteStream('jobs.csv');
csvStream.pipe(writeStream).on('end', process.exit);
const { Transform } = require('stream');
const processor = new Transform({
readableObjectMode: true,
writableObjectMode: true,
transform(image, encoding, callback) {
for(const step of image.steps){
for(const action of step.actions){
action.build_num = image.build_num
action.bash_command = JSON.stringify(action.bash_command)
this.push(action);
}
}
callback();
}
});
async function retrieve_images_metadata() {
await client.connect();
console.log('Connected correctly to server');
const db = client.db(dbName);
const imagesStream = db.collection('builds').find().stream().pipe(processor).pipe(csvStream);
// imagesStream.on("data", async function(image) {
// imagesStream.pause()
// try {
// for(const step of image.steps){
// for(const action of step.actions){
// action.build_num = image.build_num
// action.bash_command = JSON.stringify(action.bash_command)
// await csvStream.write(action)
// }
// }
// imagesStream.resume()
// } catch (error) {
// console.log(error.path ? `error ${error.path}`: error)
// imagesStream.resume()
// }
// });
imagesStream.on("end", function() {
csvStream.end()
});
}
retrieve_images_metadata().catch(e => {
console.log(e);
});