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 if (driveFilesTouched) {
74 const expectedSection = [];
76 if (!danger.gitlab.mr.description.includes('# Notes')) {
77 expectedSection.push('`# Notes`');
80 if (!danger.gitlab.mr.description.includes('# Tests')) {
81 expectedSection.push('`# Tests`');
84 if (!danger.gitlab.mr.description.includes('# Screenshots')) {
85 expectedSection.push('`# Screenshots`');
88 if (expectedSection.length) {
89 fail('Merge request description is missing required sections');
90 markdown(`## 🔴 Merge request description is missing required sections`);
91 markdown(`When modifying files in a 'drive' folder, the description must include:`);
93 for (let i = 0; i < expectedSection.length; i++) {
94 const section = expectedSection[i];
100 failIfNoDescription({ disabled: inboxFilesTouched || driveFilesTouched });
101 failIfNoAssignees({ disabled: inboxFilesTouched || docsFilesTouched });
102 warnIfSquashing({ disabled: docsFilesTouched });
104 if (danger.gitlab.mr.title.includes('WIP') || danger.gitlab.mr.title.startsWith('Draft:')) {
105 warn('PR is considered WIP');
108 const fileThresholdForLargePR = 200;
110 danger.git.created_files.length + danger.git.modified_files.length + danger.git.deleted_files.length >
111 fileThresholdForLargePR
114 'Merge Request size is pretty large. Consider splitting into separate MRs to enable a faster and easier review.'