Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add danger #1

Merged
merged 8 commits into from
Jan 23, 2019
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
Binary file added .DS_Store
Binary file not shown.
5 changes: 4 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ jobs:
- ./node_modules
- run:
name: Lint
command: yarn lint
command: yarn lint
- run:
name: Danger
command: yarn danger ci
88 changes: 88 additions & 0 deletions dangerfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* BEFORE EDITING THIS FILE, PLEASE READ http://danger.systems/js/usage/culture.html
*
* This file is split into two parts:
* 1) Rules that require or suggest changes to the code, the PR, etc.
* 2) Rules that celebrate achievements
*/
import { danger, fail, message, warn } from 'danger'

const includes = require('lodash.includes')

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* ~ Required or suggested changes ~ */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

/**
* Rule: Exactly 1 reviewer is required.
* Reason: No reviewer tends to leave a PR in a state where nobody is
* responsible. Similarly, more than 1 reviewer doesn't clearly state
* who is responsible for the review.
*/
const reviewersCount = danger.github.requested_reviewers.users.length
if (reviewersCount === 0) {
fail(`🕵 Whoops, I don't see any reviewers. Remember to add one.`)
} else if (reviewersCount > 1) {
warn(
`It's great to have ${reviewersCount} reviewers. Remember though that more than 1 reviewer may lead to uncertainty as to who is responsible for the review.`
)
}

// Warns if there are changes to package.json, and tags the team.
const packageChanged = includes(danger.git.modified_files, 'package.json')
if (packageChanged) {
const title = ':lock: package.json'
const idea =
'Changes were made to package.json. ' +
'This will require a manual import by a Facebook employee.'
warn(`${title} - <i>${idea}</i>`)
}

// Tags big PRs
var bigPRThreshold = 600
if (danger.github.pr.additions + danger.github.pr.deletions > bigPRThreshold) {
const title = ':exclamation: Big PR'
const idea = `This PR is extremely unlikely to get reviewed because it touches ${danger
.github.pr.additions + danger.github.pr.deletions} lines.`
warn(`${title} - <i>${idea}</i>`)
} else if (
danger.git.modified_files +
danger.git.added_files +
danger.git.deleted_files >
bigPRThreshold
) {
const title = ':exclamation: Big PR'
const idea = `This PR is extremely unlikely to get reviewed because it touches ${danger
.git.modified_files +
danger.git.added_files +
danger.git.deleted_files} files.`
warn(`${title} - <i>${idea}</i>`)
}

// 10個以上のファイルを編集している場合、警告を出す
if (danger.github.pr.changed_files > 10) {
warn(
'This PR changes too many files. You should divide this PR into smaller PRs.'
)
}

if (danger.github.body < 5) {
fail(`PlZ enter the description or goal for this PR`)
}

const modifiedMD = danger.git.modified_files.join('- ')
message('Changed Files in this PR: \n - ' + modifiedMD)

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* ~ Achievemnts ~ */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

/**
* Rule: Celebrate PRs that remove more code than they add.
* Reason: Less is more!
*/
if (danger.github.pr.deletions > danger.github.pr.additions) {
message(
`👏 Great job! I see more lines deleted than added. Thanks for keeping us lean!`
)
}
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"test": "jest"
},
"dependencies": {
"@types/node": "^10.12.18",
"ioredis": "^4.3.0",
"koa": "^2.6.2",
"koa-bodyparser": "^4.2.1",
Expand All @@ -20,16 +21,17 @@
"koa-ratelimit": "^4.1.2",
"koa-response-time": "^2.1.0",
"koa-router": "^7.4.0",
"@types/node": "^10.12.18"
"lodash.includes": "^4.3.0"
},
"devDependencies": {
"nodemon": "^1.18.9",
"ts-node": "^7.0.1",
"tslint": "^5.12.1",
"@types/jest": "^23.3.12",
"danger": "^7.0.2",
"jest": "^23.6.0",
"nodemon": "^1.18.9",
"supertest": "^3.3.0",
"ts-jest": "^23.10.5",
"ts-node": "^7.0.1",
"tslint": "^5.12.1",
"typescript": "^3.2.4"
}
}
Loading