1 import { danger, fail, markdown, warn } from 'danger';
3 const matchWhitespaceAtStartOfLine = /^\s+/gm;
5 const inboxFilesTouched = danger.git.fileMatch(
7 'applications/calendar',
10 'packages/calendar-store',
11 'packages/ai-assistant',
15 const driveFilesMatch = danger.git.fileMatch('applications/drive');
16 const driveFilesTouched =
17 driveFilesMatch.created || driveFilesMatch.edited || driveFilesMatch.deleted || driveFilesMatch.modified;
19 const docsFilesMatch = danger.git.fileMatch(
21 'applications/docs-editor',
23 'packages/docs-shared'
25 const docsFilesTouched =
26 docsFilesMatch.created || docsFilesMatch.edited || docsFilesMatch.deleted || docsFilesMatch.modified;
29 * Fails if no assignee is provided.
31 * @param {Object} options - The options object.
32 * @param {boolean} [options.disabled=false] - Indicates whether the check is disabled.
35 const failIfNoAssignees = ({ disabled = false }) => {
38 if (!danger.gitlab.mr.assignees?.length) {
39 fail('This pull request needs an assignee, and optionally include any reviewers.');
44 * Fails if no description is provided.
46 * @param {Object} options - The options object.
47 * @param {boolean} [options.disabled=false] - Indicates whether the check is disabled.
50 const failIfNoDescription = ({ disabled = false }) => {
53 if (!danger.gitlab.mr.description) {
54 fail('Merge request description is missing');
57 ## 🟠Add an MR description
59 Please consider adding a more [meaningful description](https://confluence.protontech.ch/display/~glinford/Writing+Meaningful+Merge+Request+Descriptions).
60 `.replace(matchWhitespaceAtStartOfLine, '')
65 const warnIfSquashing = ({ disabled = false }) => {
68 if (danger.gitlab.mr.squash) {
69 warn('Commits will be squashed');
73 const warnIfWIP = ({ disabled = false }) => {
75 if (danger.gitlab.mr.title.includes('WIP') || danger.gitlab.mr.title.startsWith('Draft:')) {
76 warn('PR is considered WIP');
80 if (driveFilesTouched) {
81 const expectedSection = [];
83 if (!danger.gitlab.mr.description.includes('# Notes')) {
84 expectedSection.push('`# Notes`');
87 if (!danger.gitlab.mr.description.includes('# Tests')) {
88 expectedSection.push('`# Tests`');
91 if (!danger.gitlab.mr.description.includes('# Screenshots')) {
92 expectedSection.push('`# Screenshots`');
95 if (expectedSection.length) {
96 fail('Merge request description is missing required sections');
97 markdown(`## 🔴 Merge request description is missing required sections`);
98 markdown(`When modifying files in a 'drive' folder, the description must include:`);
100 for (let i = 0; i < expectedSection.length; i++) {
101 const section = expectedSection[i];
107 failIfNoDescription({ disabled: inboxFilesTouched || driveFilesTouched });
108 failIfNoAssignees({ disabled: inboxFilesTouched || docsFilesTouched });
109 warnIfSquashing({ disabled: docsFilesTouched || driveFilesMatch });
110 warnIfWIP({ disabled: driveFilesMatch });
112 const fileThresholdForLargePR = 200;
114 danger.git.created_files.length + danger.git.modified_files.length + danger.git.deleted_files.length >
115 fileThresholdForLargePR
118 'Merge Request size is pretty large. Consider splitting into separate MRs to enable a faster and easier review.'