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
|
const fs = require("fs");
const Ajv = require("ajv");
const ajv = new Ajv();
const schema = {
type: "array",
uniqueItems: true,
minItems: 1,
items: {
type: "object",
required: ["name", "title", "entries"],
properties: {
github: {type: "string"},
name: {type: "string"},
title: {type: "string"},
entries: {
type: "array",
uniqueItems: true,
minItems: 1,
items: {
type: "object",
required: ["name", "link"],
properties: {
name: {type: "string"},
link: {type: "string"},
},
additionalProperties: false,
},
},
},
additionalProperties: false,
},
};
const PEOPLE_PATH = "./people.json";
const [actor] = process.argv.slice(2);
console.log(`Triggered by ${actor}`);
if (!fs.existsSync(PEOPLE_PATH)) {
throw "No people file found";
}
let people;
try {
people = JSON.parse(fs.readFileSync(PEOPLE_PATH));
} catch (err) {
throw "Could not read people.json as JSON";
}
const person = people.find(person => person.github === actor);
if (!person) {
throw `${actor} isn't in people.json!`;
}
if (!(person.entries && person.entries.length > 0)) {
throw `${actor} is missing entries!`;
}
for (const entry of person.entries) {
const {link} = entry;
if (!(link.startsWith("http") || fs.existsSync(link))) {
throw `${link} not found!`;
}
}
const validate = ajv.compile(schema);
if (!validate(people)) {
console.error(validate.errors);
throw "people.json does not conform to json schema";
}
console.log("Checked!");
|