chore: Implement danger for PRs (#1905)
This commit is contained in:
parent
49e52c6c00
commit
a7849a67ca
4 changed files with 2615 additions and 67 deletions
56
dangerfile.js
Normal file
56
dangerfile.js
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/* global danger warn fail */
|
||||
"use strict";
|
||||
|
||||
var fs = require("fs"),
|
||||
path = require("path"),
|
||||
|
||||
locater = require("locater"),
|
||||
pinpoint = require("pinpoint"),
|
||||
dedent = require("dedent");
|
||||
|
||||
// Various views of changed/added files
|
||||
var jsfiles = danger.git.created_files
|
||||
.concat(danger.git.modified_files)
|
||||
.filter((file) => path.extname(file) === ".js"),
|
||||
|
||||
changelog = danger.git.modified_files.find((file) =>
|
||||
file === "docs/change-log.md"
|
||||
),
|
||||
|
||||
appfiles = jsfiles.filter((file) =>
|
||||
file.indexOf("tests/") === -1
|
||||
);
|
||||
|
||||
function link(file, anchor, text) {
|
||||
var repo = danger.github.pr.head.repo.html_url,
|
||||
ref = danger.github.pr.head.ref;
|
||||
|
||||
return danger.utils.href(`${repo}/blob/${ref}/${file}${anchor || ""}`, file || text);
|
||||
}
|
||||
|
||||
// All PRs should be targeted against `next`
|
||||
if(danger.github.pr.base.ref !== "next") {
|
||||
warn("PRs should be based on `next`, rebase before submitting please");
|
||||
}
|
||||
|
||||
// Any non-test JS changes should probably have a change-log entry
|
||||
if(appfiles.length && !changelog) {
|
||||
warn(`Please include a ${link("docs/change-log.md", "changelog")} entry.`)
|
||||
}
|
||||
|
||||
// Call out if `o.only(...)` was left in
|
||||
jsfiles
|
||||
.filter((file) => file.indexOf("tests/") > -1)
|
||||
.forEach((file) => {
|
||||
var code = fs.readFileSync(file, "utf8"),
|
||||
locs = locater.find("o.only", code);
|
||||
|
||||
locs.forEach((loc) =>
|
||||
fail(dedent(`
|
||||
${link(file, `#L${loc.line}`)} is preventing tests from running.
|
||||
<pre lang="javascript">
|
||||
${pinpoint(code, {line: loc.line, column : loc.cursor})}
|
||||
</pre>
|
||||
`))
|
||||
)
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue