-
Notifications
You must be signed in to change notification settings - Fork 573
/
dangerfile.js
120 lines (100 loc) · 3.69 KB
/
dangerfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import { danger, fail, markdown, warn } from 'danger';
const matchWhitespaceAtStartOfLine = /^\s+/gm;
const inboxFilesTouched = danger.git.fileMatch(
'applications/mail',
'applications/calendar',
'packages/activation',
'packages/mail-store',
'packages/calendar-store',
'packages/ai-assistant',
'packages/llm'
);
const driveFilesMatch = danger.git.fileMatch('applications/drive');
const driveFilesTouched =
driveFilesMatch.created || driveFilesMatch.edited || driveFilesMatch.deleted || driveFilesMatch.modified;
const docsFilesMatch = danger.git.fileMatch(
'applications/docs',
'applications/docs-editor',
'packages/docs-core',
'packages/docs-shared'
);
const docsFilesTouched =
docsFilesMatch.created || docsFilesMatch.edited || docsFilesMatch.deleted || docsFilesMatch.modified;
/**
* Fails if no assignee is provided.
*
* @param {Object} options - The options object.
* @param {boolean} [options.disabled=false] - Indicates whether the check is disabled.
* @returns {void}
*/
const failIfNoAssignees = ({ disabled = false }) => {
if (disabled) return;
if (!danger.gitlab.mr.assignees?.length) {
fail('This pull request needs an assignee, and optionally include any reviewers.');
}
};
/**
* Fails if no description is provided.
*
* @param {Object} options - The options object.
* @param {boolean} [options.disabled=false] - Indicates whether the check is disabled.
* @returns {void}
*/
const failIfNoDescription = ({ disabled = false }) => {
if (disabled) return;
if (!danger.gitlab.mr.description) {
fail('Merge request description is missing');
markdown(
`
## 🟠 Add an MR description
Please consider adding a more [meaningful description](https://confluence.protontech.ch/display/~glinford/Writing+Meaningful+Merge+Request+Descriptions).
`.replace(matchWhitespaceAtStartOfLine, '')
);
}
};
const warnIfSquashing = ({ disabled = false }) => {
if (disabled) return;
if (danger.gitlab.mr.squash) {
warn('Commits will be squashed');
}
};
const warnIfWIP = ({ disabled = false }) => {
if (disabled) return;
if (danger.gitlab.mr.title.includes('WIP') || danger.gitlab.mr.title.startsWith('Draft:')) {
warn('PR is considered WIP');
}
};
if (driveFilesTouched) {
const expectedSection = [];
if (!danger.gitlab.mr.description.includes('# Notes')) {
expectedSection.push('`# Notes`');
}
if (!danger.gitlab.mr.description.includes('# Tests')) {
expectedSection.push('`# Tests`');
}
if (!danger.gitlab.mr.description.includes('# Screenshots')) {
expectedSection.push('`# Screenshots`');
}
if (expectedSection.length) {
fail('Merge request description is missing required sections');
markdown(`## 🔴 Merge request description is missing required sections`);
markdown(`When modifying files in a 'drive' folder, the description must include:`);
for (let i = 0; i < expectedSection.length; i++) {
const section = expectedSection[i];
markdown(section);
}
}
}
failIfNoDescription({ disabled: inboxFilesTouched || driveFilesTouched });
failIfNoAssignees({ disabled: inboxFilesTouched || docsFilesTouched });
warnIfSquashing({ disabled: docsFilesTouched || driveFilesMatch });
warnIfWIP({ disabled: driveFilesMatch });
const fileThresholdForLargePR = 200;
if (
danger.git.created_files.length + danger.git.modified_files.length + danger.git.deleted_files.length >
fileThresholdForLargePR
) {
warn(
'Merge Request size is pretty large. Consider splitting into separate MRs to enable a faster and easier review.'
);
}