|
| 1 | +// @flow |
| 2 | +import path from 'path'; |
| 3 | +import { warn, fail, message, markdown, schedule, danger } from 'danger'; |
| 4 | +import yarn from 'danger-plugin-yarn'; |
| 5 | +import jest from 'danger-plugin-jest'; |
| 6 | +import noTestShortcuts from 'danger-plugin-no-test-shortcuts'; |
| 7 | + |
| 8 | +const APP_FOLDERS = [ |
| 9 | + 'admin', |
| 10 | + 'athena', |
| 11 | + 'chronos', |
| 12 | + 'hermes', |
| 13 | + 'hyperion', |
| 14 | + 'iris', |
| 15 | + 'mercury', |
| 16 | + 'shared', |
| 17 | + 'src', |
| 18 | + 'vulcan', |
| 19 | +]; |
| 20 | +const CHECKBOXES = /^- \[x\] *(.*)?$/gim; |
| 21 | +const possibleAutoLabels = { |
| 22 | + wip: 'WIP: Building', |
| 23 | + 'needs testing': 'WIP: Needs Testing', |
| 24 | + 'ready for review': 'WIP: Ready for Review', |
| 25 | +}; |
| 26 | + |
| 27 | +// Make sure people describe what their PR is about |
| 28 | +if (danger.github.pr.body.length < 10) { |
| 29 | + fail('Please add a description to your PR.'); |
| 30 | +} |
| 31 | + |
| 32 | +// Add automatic labels to the PR |
| 33 | +schedule(async () => { |
| 34 | + const pr = danger.github.pr; |
| 35 | + const api = danger.github.api; |
| 36 | + const checkedBoxes = pr.body.match(CHECKBOXES); |
| 37 | + if (!checkedBoxes || checkedBoxes.length === 0) return; |
| 38 | + |
| 39 | + const matches = checkedBoxes.map(result => result[1]); |
| 40 | + |
| 41 | + const matchingLabels = matches.filter(match => |
| 42 | + Object.keys(possibleAutoLabels).includes(match.toLowerCase()) |
| 43 | + ); |
| 44 | + |
| 45 | + if (!matchingLabels || matchingLabels.length === 0) return; |
| 46 | + |
| 47 | + await api.issues.addLabels({ |
| 48 | + owner: pr.owner, |
| 49 | + repo: pr.repo, |
| 50 | + number: pr.number, |
| 51 | + labels: matchingLabels, |
| 52 | + }); |
| 53 | +}); |
| 54 | + |
| 55 | +// Make sure the yarn.lock file is updated when dependencies get added and log any added dependencies |
| 56 | +APP_FOLDERS.forEach(folder => { |
| 57 | + schedule(yarn(path.join(__dirname, folder, 'package.json'))); |
| 58 | +}); |
| 59 | + |
| 60 | +// Log test failures if there are any |
| 61 | +jest(); |
| 62 | + |
| 63 | +// Make sure nobody does a it.only and blocks our entire test-suite from running |
| 64 | +noTestShortcuts({ |
| 65 | + testFilePredicate: filePath => filePath.endsWith('.test.js'), |
| 66 | +}); |
0 commit comments