forked from contiamo/restful-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdangerfile.ts
57 lines (48 loc) · 2.09 KB
/
dangerfile.ts
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
import * as child_process from "child_process";
import { danger, markdown, warn } from "danger";
import * as fs from "fs";
import { includes } from "lodash";
// Setup
const pr = danger.github.pr;
const modified = danger.git.modified_files;
const added = danger.git.created_files;
const packageChanged = includes(modified, "package.json");
const wrongLockfileChanged = includes([...modified, ...added], "package-lock.json");
if (packageChanged && wrongLockfileChanged) {
fail(
"This PR contains `package-lock.json`, but we expect a `yarn.lock` instead as yarn is the preferred package manager for this project. We should not have to maintain two lockfiles.",
);
}
// No PR is too small to warrant a paragraph or two of summary
if (pr.body.length === 0) {
fail("Please add a description to your PR.");
}
// Warn when there is a big PR
const bigPRThreshold = 500;
if (danger.github.pr.additions + danger.github.pr.deletions > bigPRThreshold) {
warn(":exclamation: Big PR");
}
// Always ensure we assign someone, so that our Slackbot can do its work correctly
if (pr.assignee === null) {
fail("Please assign someone to merge this PR, and optionally include people who should review.");
}
// Show TSLint errors inline
// Yes, this is a bit lossy, we run the linter twice now, but its still a short amount of time
// Perhaps we could indicate that tslint failed somehow the first time?
// This process should always fail, so needs the `|| true` so it won't raise.
child_process.execSync(`npm run lint -- -- --format json --out tslint-errors.json || true`);
if (fs.existsSync("tslint-errors.json")) {
const tslintErrors = JSON.parse(fs.readFileSync("tslint-errors.json", "utf8")) as any[];
if (tslintErrors.length) {
const errors = tslintErrors.map(error => {
const format = error.ruleSeverity === "ERROR" ? ":no_entry_sign:" : ":warning:";
const linkToFile = danger.github.utils.fileLinks([error.name]);
return `* ${format} ${linkToFile} - ${error.ruleName} - ${error.failure}`;
});
const tslintMarkdown = `
## TSLint Issues:
${errors.join("\n")}
`;
markdown(tslintMarkdown);
}
}