-
Notifications
You must be signed in to change notification settings - Fork 0
/
circleci.js
57 lines (47 loc) · 1.58 KB
/
circleci.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
const axios = require('axios');
const jsonfile = require('jsonfile');
const MongoClient = require('mongodb').MongoClient;
const url = 'mongodb://localhost:27017';
const dbName = 'circleci';
const client = new MongoClient(url);
async function insertMany(db, objects) {
objects.forEach(async object => {
try {
await db.collection('builds').insert(object);
} catch (error) {
// console.log(error);
console.log('skip already existing ' + object.slug);
}
});
}
function buildUrl(run){
return `https://circleci.com/api/v1.1/project/gh/pytorch/pytorch/${run}?circle-token=${process.env.CIRCLECI_TOKEN}`
};
async function retrieve_images_metadata() {
await client.connect();
console.log('Connected correctly to server');
flag = false;
const db = client.db(dbName);
db.collection('builds').ensureIndex({ build_num: 1 }, { unique: true });
response = await axios.get(`https://circleci.com/api/v1.1/project/gh/pytorch/pytorch?circle-token=${process.env.CIRCLECI_TOKEN}&limit=1&filter=completed`)
const LIMIT = response.data[0].build_num
console.log(LIMIT)
do {
console.log(`retrieving build ${num}`);
try {
const list = [...Array(100).keys()];
response = await Promise.all(list.map(index=>axios.get(buildUrl(num+index))));
await insertMany(db, response.map(el=>{
delete el.data.circle_yml
return el.data
}));
} catch (e) {
console.log('failed at ' + num);
console.error(e);
}
num = num + 1;
} while (num < LIMIT)
}
retrieve_images_metadata().catch(e => {
console.log(e);
});