-
Notifications
You must be signed in to change notification settings - Fork 10
/
validate.js
114 lines (103 loc) · 3.06 KB
/
validate.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
/* eslint-env node */
"use strict";
const github = require("./lib/github.js");
const validator = require("./lib/validator.js");
const w3cData = require("./lib/w3cData.js");
const orgs = ["w3c", "WebAudio", "immersive-web", "webassembly", "w3ctag", "WICG", "w3cping", "privacycg", "gpuweb", "webmachinelearning", "w3c-fedid"];
const errortypes = [
"inconsistentgroups",
"now3cjson",
"invalidw3cjson",
"illformedw3cjson",
"incompletew3cjson",
"nocontributing",
"invalidcontributing",
"nolicense",
"noautopublish",
"usetravisci",
"nocodeofconduct",
"invalidlicense",
"noreadme",
"noashnazg",
"inconsistentstatus",
"defaultbranchismaster",
"nodefaultbranch",
"unprotectedbranch",
"unprotectedbranchforadmin",
"norequiredreview",
"missingashnazghook",
"duplicateashnazghooks"
];
async function validate() {
const data = await w3cData();
const licenses = await github.w3cLicenses();
const allrepos = [];
for (const org of orgs) {
for await (const repo of github.listRepos(org)) {
if (!repo.isPrivate) {
allrepos.push(repo);
}
}
}
const fullName = r => r.owner.login + '/' + r.name;
allrepos.sort((r1, r2) => fullName(r1).localeCompare(fullName(r2)));
const allerrors = {};
for (const type of errortypes) {
allerrors[type] = [];
}
function pushErrors(repo, errors) {
for (const [type, details] of errors) {
if (!(type in allerrors)) {
throw new Error(`Unexpected error type: ${type}`);
}
// Push just the repo name string if there are no details, and otherwise
// add it as a `repo` property to the details object.
if (details === null) {
allerrors[type].push(fullName(repo));
} else {
allerrors[type].push({repo: fullName(repo), ...details});
}
}
}
const allgroups = new Set();
const groupRepos = {};
for (const r of allrepos) {
if (!r || r.isArchived) {
continue;
}
const repoData = data.get(r.owner.login, r.name);
const {errors, groups, hasRecTrack} = validator.validateRepo(r, repoData, licenses, data.w3cgroups);
pushErrors(r, errors);
for (const gid of groups) {
allgroups.add(gid);
if (!groupRepos[gid]) {
groupRepos[gid] = [];
}
groupRepos[gid].push({
name: r.name,
fullName: fullName(r),
// Only include `hasRecTrack` in report.json if it's true.
hasRecTrack: hasRecTrack ? true : undefined,
});
}
if (repoData.ashRepo) {
const hooks = await github.listRepoHooks(r.owner.login, r.name);
const errors = validator.validateAshHooks(hooks);
pushErrors(r, errors);
}
}
const {w3cgroups} = data;
const results = {};
results.errors = allerrors;
results.timestamp = new Date();
results.repos = allrepos;
results.groups = w3cgroups.filter(g => allgroups.has(g.id)).reduce((acc, group) => {
acc[group.id] = {...group, repos: groupRepos[group.id]};
return acc;
}, {});
console.log(JSON.stringify(results, null, 2));
}
validate().catch((reason) => {
console.error(reason);
process.exit(1);
});