1 import { danger, fail, markdown, warn } from 'danger';
3 const matchWhitespaceAtStartOfLine = /^\s+/gm;
5 const driveFilesMatch = danger.git.fileMatch('applications/drive', 'packages/drive-store');
6 const driveFilesTouched =
7 driveFilesMatch.created || driveFilesMatch.edited || driveFilesMatch.deleted || driveFilesMatch.modified;
9 if (driveFilesTouched) {
10 const expectedSection = [];
12 if (!danger.gitlab.mr.description.includes('# Notes')) {
13 expectedSection.push('`# Notes`');
16 if (!danger.gitlab.mr.description.includes('# Tests')) {
17 expectedSection.push('`# Tests`');
20 if (!danger.gitlab.mr.description.includes('# Screenshots')) {
21 expectedSection.push('`# Screenshots`');
24 if (expectedSection.length) {
25 fail('Merge request description is missing required sections');
26 markdown(`## 🔴 Merge request description is missing required sections`);
27 markdown(`When modifying files in a 'drive' folder, the description must include:`);
29 for (let i = 0; i < expectedSection.length; i++) {
30 const section = expectedSection[i];
34 } else if (!danger.gitlab.mr.description) {
35 fail('Merge request description is missing');
38 ## 🟠Add an MR description
40 Please consider adding a more [meaningful description](https://confluence.protontech.ch/display/~glinford/Writing+Meaningful+Merge+Request+Descriptions).
41 `.replace(matchWhitespaceAtStartOfLine, '')
45 if (danger.gitlab.mr.title.includes('WIP') || danger.gitlab.mr.title.startsWith('Draft:')) {
46 warn('PR is considered WIP');
49 if (danger.gitlab.mr.squash) {
50 warn('Commits will be squashed');
53 if (!danger.gitlab.mr.assignees?.length) {
54 fail('This pull request needs an assignee, and optionally include any reviewers.');
57 const fileThresholdForLargePR = 200;
59 danger.git.created_files.length + danger.git.modified_files.length + danger.git.deleted_files.length >
60 fileThresholdForLargePR
63 'Merge Request size is pretty large. Consider splitting into separate MRs to enable a faster and easier review.'