Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Commit

Permalink
Add Danger
Browse files Browse the repository at this point in the history
  • Loading branch information
Tejas Kumar committed Aug 8, 2018
1 parent 5ab6f79 commit 3bc4a0a
Show file tree
Hide file tree
Showing 5 changed files with 1,326 additions and 145 deletions.
13 changes: 8 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# This file tells Travis what's up
language: node_js
node_js:
- stable
- stable

notifications:
email: false

# This allows tests to run more efficiently without leaking memory
# More info: https://facebook.github.io/jest/docs/en/troubleshooting.html#tests-are-extremely-slow-on-docker-and-or-continuous-integration-ci-server
env:
- JEST_MAX_WORKERS: 4
- JEST_MAX_WORKERS: 4

# When Travis gets notified of a new build, do this
script:
- yarn ci
before_script:
- yarn danger ci

# When Travis gets notified of a new build, do this
script:
- yarn ci
60 changes: 60 additions & 0 deletions dangerfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import * as child_process from "child_process";
import { danger, markdown, warn } from "danger";
import jest from "danger-plugin-jest";
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);
}
}

jest();
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@
},
"devDependencies": {
"@types/jest": "^23.3.1",
"@types/lodash": "^4.14.116",
"@types/nock": "^9.3.0",
"@types/react": "^16.4.1",
"auto-changelog": "^1.8.0",
"danger": "^3.8.4",
"danger-plugin-jest": "^1.1.0",
"doctoc": "^1.3.1",
"husky": "^0.14.3",
"isomorphic-fetch": "^2.2.1",
Expand All @@ -82,6 +85,7 @@
"typescript": "^2.9.2"
},
"dependencies": {
"lodash": "^4.17.10",
"react": "^16.4.1",
"react-fast-compare": "^2.0.1"
},
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"target":
"es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
// "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": ["es2015", "dom"] /* Specify library files to be included in the compilation. */,
"lib": ["es2015", "es2016.array.include", "dom"] /* Specify library files to be included in the compilation. */,
// "allowJs": true /* Allow javascript files to be compiled. */,
// "checkJs": true, /* Report errors in .js files. */
"jsx": "react" /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */,
Expand Down
Loading

0 comments on commit 3bc4a0a

Please sign in to comment.