forked from artsy/metaphysics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdangerfile.ts
40 lines (34 loc) · 1.28 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
import { danger, fail, markdown } from "danger"
import { printSchema } from "graphql/utilities/schemaPrinter"
import { readFileSync } from "fs"
import * as prettier from "prettier"
import * as jsdiff from "diff"
// Rule: encourage all new files to be TypeScript
const jsAppFiles = danger.git.created_files.filter(
f => f.startsWith("src/") && f.endsWith(".js")
)
if (jsAppFiles.length) {
const listed = danger.github.utils.fileLinks(jsAppFiles)
fail(`Please use <code>*.ts</code> for new files. Found: ${listed}.`)
}
// Grab the built schema to skip all the babel path faff
import schema from "./build/src/schema"
// Compare a printed copy of the schema
// with the file in the repo.
const schemaText = printSchema(schema as any, { commentDescriptions: true })
const prettySchema = prettier.format(schemaText, { parser: "graphql" })
const localGQL = readFileSync("_schema.graphql", "utf8")
if (prettySchema !== localGQL) {
fail(`Please update the schema in the root of the app via:
\`yarn dump-schema _schema.graphql\`
Note: This script uses your current \`.env\` variables.
`)
const diff = jsdiff.createPatch(
"_schema.graphql",
localGQL,
prettySchema,
"Version in Repo",
"Added in this PR"
)
markdown("The changes to the Schema:\n\n```diff\n" + diff + "```")
}