Select Git revision
dangerfile.js
dangerfile.js 4.96 KiB
'use strict'
// Have you identified a contributing guideline that should be included here?
// Please open a pull request!
//
// To test changes to this file, pick a PR to test against, then run
// `./node_modules/.bin/danger pr pr-url`
// Note that the line numbers in the runtime errors are incorrect.
// To test changes locally:
// DANGER_GITHUB_API_TOKEN=your-github-api-token npm run danger -- pr https://github.com/badges/shields/pull/2665
const { danger, fail, message, warn } = require('danger')
const { fileMatch } = danger.git
const documentation = fileMatch(
'**/*.md',
'frontend/docs/**',
'frontend/src/**',
)
const server = fileMatch('core/server/**.js', '!*.spec.js')
const serverTests = fileMatch('core/server/**.spec.js')
const legacyHelpers = fileMatch('lib/**/*.js', '!*.spec.js')
const legacyHelperTests = fileMatch('lib/**/*.spec.js')
const logos = fileMatch('logo/*.svg')
const packageJson = fileMatch('package.json')
const packageLock = fileMatch('package-lock.json')
const secretsDocs = fileMatch('doc/server-secrets.md')
const capitals = fileMatch('**/*[A-Z]*.js')
const underscores = fileMatch('**/*_*.js')
message(
[
':sparkles: Thanks for your contribution to Shields, ',
`@${danger.github.pr.user.login}!`,
].join(''),
)
const targetBranch = danger.github.pr.base.ref
if (targetBranch !== 'master') {
const message = `This PR targets \`${targetBranch}\``
const idea = 'It is likely that the target branch should be `master`'
warn(`${message} - <i>${idea}</i>`)
}
if (documentation.edited) {
message(
[
'Thanks for contributing to our documentation. ',
'We :heart: our [documentarians](http://www.writethedocs.org/)!',
].join(''),
)
}
if (packageJson.modified && !packageLock.modified) {
const message = 'This PR modified `package.json`, but not `package-lock.json`'
const idea = 'Perhaps you need to run `npm install`?'
warn(`${message} - <i>${idea}</i>`)
}
if (server.modified && !serverTests.modified) {
warn(
[
'This PR modified the server but none of its tests. <br>',
"That's okay so long as it's refactoring existing code.",
].join(''),
)
}
if (legacyHelpers.created) {