-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
53 lines (48 loc) · 2.18 KB
/
index.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
const config = require("../config.json"),
request = require('request'),
async = require('async'),
fs = require('fs'),
utils = require('../lib/utils'),
activespecs = require('../lib/active-specs'),
w3c = require('node-w3capi');
const selectedgroups = process.argv[2] ? process.argv[2].split(",").map(n => parseInt(n,10)) : false;
const restrictGroups = g => !selectedgroups || selectedgroups.includes(g.id);
let existingdata;
if (selectedgroups) {
var data = fs.readFileSync("./groups.json");
existingdata = JSON.parse(data);
}
const jsonify = o => JSON.stringify(o, null, 2);
w3c.groups().fetch({embed:true}, (err, groups) => {
if (err) return console.error(err);
const workinggroups = groups.filter(g => g.type === 'working group') ;
async.map(workinggroups, (wg,cb) => {
activespecs(wg.id, (err, unfinishedSpecs) => {
if (!unfinishedSpecs) return console.error("undefined result for " + wg.name);
if (err) console.error(err);
createOrUpdateSpreadSheet(wg, unfinishedSpecs.map(s=> s.shortlink), cb, restrictGroups(wg));
});
}, (err, results) => {
if (err) return console.error(err);
const groups = results.filter(g => g).reduce((a,b) => { a[b.id] = b; return a;}, {});
fs.writeFileSync("./groups.json", jsonify(groups, null, 2));
});
});
function createOrUpdateSpreadSheet(wg, specs, cb, create) {
if (create) {
const body = "TR shortlink,FPWD,Wide Review start, CR, Test Suite status, PR, Rec, Comments & notes\n" + specs.join("\n");
request({
method: 'POST',
url: config.ethercalc + '/_',
headers: {
'Content-Type': 'text/csv'
},
body: body
}, function (error, response, body) {
cb(null, {id: wg.id, name: wg.name, start: wg["start-date"], end: wg["end-date"], url: config.ethercalc + body});
});
} else {
if (!existingdata[wg.id]) throw new Error("Working Group " + wg.name + "(" + wg.id + ") is missing in the list");
cb(null, {id: wg.id, name: wg.name, start: wg["start-date"], end: wg["end-date"], url: existingdata[wg.id].url});
}
}