-
Notifications
You must be signed in to change notification settings - Fork 19
/
dangerfile.js
79 lines (71 loc) · 2.48 KB
/
dangerfile.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
const {danger, fail, warn} = require('danger');
const yaml = require('js-yaml');
const Ajv = require('ajv');
const {readFileSync} = require('fs');
// JSON Schema for changelog entries.
// @see https://json-schema.org/
const CHANGELOG_SCHEMA = {
"definitions": {
"ChangelogLine": {
"description": "A single line in a changelog",
"type": "object",
"required": ["description", "issue"],
"properties": {
"description": {
"type": "string"
}
}
},
"ChangelogGroup": {
"description": "A grouping of changelog items",
"type": "array",
"items": {
"$ref": "#/definitions/ChangelogLine"
}
}
},
"title": "ChangelogFile",
"type": "object",
"additionalProperties": false,
"properties": {
"Added": {"$ref": "#/definitions/ChangelogGroup" },
"Changed": { "$ref": "#/definitions/ChangelogGroup" },
"Deprecated": { "$ref": "#/definitions/ChangelogGroup" },
"Removed": { "$ref": "#/definitions/ChangelogGroup" },
"Fixed": { "$ref": "#/definitions/ChangelogGroup" },
"Security": { "$ref": "#/definitions/ChangelogGroup" }
},
"anyOf": [
{"required": ["Added"]},
{"required": ["Changed"]},
{"required": ["Deprecated"]},
{"required": ["Removed"]},
{"required": ["Fixed"]},
{"required": ["Security"]}
]
}
// A list of all the changelog files that were touched during this change.
const changelogs = danger.git.fileMatch('changelogs/*.yml', '!**/template.yml');
// Fail if no changelog was created.
if(!changelogs || !changelogs.created) {
fail("Add a changelog YAML file to this PR");
}
else {
// Validate the schema of each added changelog.
const validator = new Ajv();
changelogs.getKeyedPaths().created.forEach(function(file) {
const contents = yaml.load(readFileSync(file));
const valid = validator.validate(CHANGELOG_SCHEMA, contents);
if(!valid) {
fail(`Changelog is not valid the following item(s) needs to be fixed (${validator.errorsText()})`, file);
}
})
}
// Check for a specific label "Awaiting Mayflower" can't merge until removed from the PR.
// if (github.pr_labels = "Awaiting Mayflower Release") {
// fail( "This PR needs to have a new Mayflower release (tag) before being merged into develop branch.");
// }
// Check for a specific label "Config Backport" and remind this PR needs to be merged before next release.
// if (github.pr_labels = "Config Backport") {
// warn("This PR needs to be merged before the next release.");
// }