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

Infra/dx #24

Merged
merged 4 commits into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file tells Travis what's up
language: node_js
node_js:
- 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

# When Travis gets notified of a new build, do this
script:
- yarn ci
- yarn danger ci
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# RESTful React

[![Build Status](https://travis-ci.org/contiamo/restful-react.svg?branch=master)](https://travis-ci.org/contiamo/restful-react)

Building React apps that interact with a backend API presents a set of questions, challenges and potential gotchas. This project aims to remove such pitfalls, and provide a pleasant developer experience when crafting such applications. It can be considered a thin wrapper around the [fetch API](https://developer.mozilla.org/en/docs/Web/API/Fetch_API) in the form of a React component.

As an abstraction, this tool allows for greater consistency and maintainability of dynamic codebases.
Expand Down
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();
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
"build": "rollup -c",
"precommit": "lint-staged",
"preversion": "npm run build",
"version": "auto-changelog -p && git add CHANGELOG.md"
"version": "auto-changelog -p && git add CHANGELOG.md",
"lint": "tslint src/**/*{ts,tsx} --project .",
"ci": "npm run jest && npm run lint",
"jest": "jest --outputFile test-results.json --json"
},
"lint-staged": {
"*.md": [
Expand All @@ -58,9 +61,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 @@ -80,6 +86,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