feat(INDA-383): daily stats.
[ProtonMail-WebClient.git] / dangerfile.js
blob8425c31df203c31223aeeae54ea73a580d702a83
1 import { danger, fail, markdown, warn } from 'danger';
3 const matchWhitespaceAtStartOfLine = /^\s+/gm;
5 const inboxFilesTouched = danger.git.fileMatch(
6 'applications/mail',
7 'applications/calendar',
8 'packages/activation',
9 'packages/mail-store',
10 'packages/calendar-store',
11 'packages/ai-assistant',
12 'packages/llm'
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(
20 'applications/docs',
21 'applications/docs-editor',
22 'packages/docs-core',
23 'packages/docs-shared'
25 const docsFilesTouched =
26 docsFilesMatch.created || docsFilesMatch.edited || docsFilesMatch.deleted || docsFilesMatch.modified;
28 /**
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.
33 * @returns {void}
35 const failIfNoAssignees = ({ disabled = false }) => {
36 if (disabled) return;
38 if (!danger.gitlab.mr.assignees?.length) {
39 fail('This pull request needs an assignee, and optionally include any reviewers.');
43 /**
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.
48 * @returns {void}
50 const failIfNoDescription = ({ disabled = false }) => {
51 if (disabled) return;
53 if (!danger.gitlab.mr.description) {
54 fail('Merge request description is missing');
55 markdown(
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 }) => {
66 if (disabled) return;
68 if (danger.gitlab.mr.squash) {
69 warn('Commits will be squashed');
73 const warnIfWIP = ({ disabled = false }) => {
74 if (disabled) return;
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];
102 markdown(section);
107 failIfNoDescription({ disabled: inboxFilesTouched || driveFilesTouched });
108 failIfNoAssignees({ disabled: inboxFilesTouched || docsFilesTouched });
109 warnIfSquashing({ disabled: docsFilesTouched || driveFilesMatch });
110 warnIfWIP({ disabled: driveFilesMatch });
112 const fileThresholdForLargePR = 200;
113 if (
114 danger.git.created_files.length + danger.git.modified_files.length + danger.git.deleted_files.length >
115 fileThresholdForLargePR
117 warn(
118 'Merge Request size is pretty large. Consider splitting into separate MRs to enable a faster and easier review.'