forked from Uniswap/wallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdangerfile.ts
135 lines (115 loc) · 4.58 KB
/
dangerfile.ts
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import { danger, fail, markdown, message, warn } from 'danger'
// Other ideas:
// - verify TODO have work items linked
/* Warn about storing credentials in GH and uploading env.local to 1Password */
const envChanged = danger.git.modified_files.includes('.env.defaults')
if (envChanged) {
warn(
'Changes were made to .env.defaults. Confirm that no sensitive data is in the .env.defaults file. Sensitive data must go in .env (web) or .env.defaults.local (mobile) and then run `yarn upload-env-local` to store it in 1Password.'
)
}
// Checks for any logging and reminds the developer not to log sensitive data
const updatedTsFiles = danger.git.modified_files
.concat(danger.git.created_files)
.filter((file) => file.endsWith('.ts') || file.endsWith('.tsx'))
for (const file of updatedTsFiles) {
danger.git.structuredDiffForFile(file).then((diff) => {
for (const chunk of diff?.chunks || []) {
for (const change of chunk.changes) {
if (change.type !== 'add') {
return
}
if (change.content.includes('logMessage') || change.content.includes('logger.')) {
warn('You are logging data. Please confirm that nothing sensitive is being logged!')
}
}
}
})
}
// Stories for new components
const createdComponents = danger.git.created_files.filter(
(f) =>
f.includes('components/buttons') ||
f.includes('components/input') ||
f.includes('components/layout/') ||
f.includes('components/text')
)
const hasCreatedComponent = createdComponents.length > 0
const createdStories = createdComponents.filter((filepath) => filepath.includes('stories/'))
const hasCreatedStories = createdStories.length > 0
if (hasCreatedComponent && !hasCreatedStories) {
warn(
'There are new primitive components, but not stories. Consider documenting the new component with Storybook'
)
}
// Warn when there is a big PR
const bigPRThreshold = 500
if (danger.github.pr.additions + danger.github.pr.deletions > bigPRThreshold) {
warn(':exclamation: Big PR')
markdown(
'> Pull Request size seems relatively large. If PR contains multiple changes, split each into separate PRs for faster, easier reviews.'
)
}
// No PR is too small to warrant a paragraph or two of summary
if (danger.github.pr.body.length < 50) {
warn(
'The PR description is looking sparse. Please consider explaining more about this PRs goal and implementation decisions.'
)
}
// Congratulate when code was deleted
if (danger.github.pr.additions < danger.github.pr.deletions) {
message(
`✂️ Thanks for removing ${danger.github.pr.deletions - danger.github.pr.additions} lines!`
)
}
const stories = danger.git.fileMatch('**/*stories*')
if (stories.edited) {
message('🙌 Thanks for keeping stories up to date!')
}
// Migrations + schema warnings
const updatedSchemaFile = danger.git.modified_files.find((file) =>
file.includes('src/app/schema.ts')
)
const updatedMigrationsFile = danger.git.modified_files.find((file) =>
file.includes('src/app/migrations.ts')
)
const updatedMigrationsTestFile = danger.git.modified_files.find((file) =>
file.includes('src/app/migrations.test.ts')
)
const createdSliceFile = danger.git.created_files.find((file) =>
file.toLowerCase().includes('slice')
)
const modifiedSliceFile = danger.git.modified_files.find((file) =>
file.toLowerCase().includes('slice')
)
const deletedSliceFile = danger.git.deleted_files.find((file) =>
file.toLowerCase().includes('slice')
)
if (modifiedSliceFile && (!updatedSchemaFile || !updatedMigrationsFile)) {
warn(
'You modified a slice file. If you added, renamed, or deleted required properties from state, then make sure to define a new schema and a create a migration.'
)
}
if (updatedSchemaFile && !updatedMigrationsFile) {
warn(
'You updated the schema file but not the migrations file. Make sure to also define a migration.'
)
}
if (!updatedSchemaFile && updatedMigrationsFile) {
warn(
'You updated the migrations file but not the schema. Schema always needs to be updated when a new migration is defined.'
)
}
if (createdSliceFile && (!updatedMigrationsFile || !updatedSchemaFile)) {
fail(
'You created a new slice file. Please write a migration, update initialState in the `migrations.test.ts` file, and create a new schema.'
)
}
if (deletedSliceFile && (!updatedSchemaFile || !updatedMigrationsFile)) {
fail('You deleted a slice file. Make sure to define a new schema and and create a migration.')
}
if (updatedMigrationsFile && !updatedMigrationsTestFile) {
fail(
'You updated the migrations file but did not write any new tests. Each migration must have a test!'
)
}