i18n: Upgrade translations from crowdin (5d3e42b3). (drive)
[ProtonMail-WebClient.git] / dangerfile.js
blob73d34aa5a77ca5bb453ace2a071055f90a26bf3b
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 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];
95 markdown(section);
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;
109 if (
110 danger.git.created_files.length + danger.git.modified_files.length + danger.git.deleted_files.length >
111 fileThresholdForLargePR
113 warn(
114 'Merge Request size is pretty large. Consider splitting into separate MRs to enable a faster and easier review.'