-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdangerfile.js
56 lines (46 loc) · 1.59 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
import { danger, markdown } from 'danger'
import _ from 'lodash'
import fs from 'fs'
let errorsAndWarnings = 0
checkLinterErrors()
checkSkippedTests()
isABigPR()
congrats()
function checkSkippedTests() {
const modifiedSpecFiles = danger.git.modified_files.filter(filePath => filePath.match(/.test.(js|jsx)$/gi))
const testFilesIncludeExclusion = modifiedSpecFiles.reduce((acc, value) => {
const content = fs.readFileSync(value).toString()
const invalid = _.includes(content, 'it.only') || _.includes(content, 'describe.only') || _.includes(content, 'fdescribe') || _.includes(content, 'fit(')
if (invalid) { acc.push(value) }
return acc
}, [])
if (testFilesIncludeExclusion.length > 0) {
errorsAndWarnings++
fail(`skipped test was left in tests (${testFilesIncludeExclusion})`)
}
}
function checkLinterErrors() {
const linterOutput = fs.readFileSync('prepush.log').toString()
const thereWarningOrErrors = _.includes(linterOutput, 'error') || _.includes(linterOutput, 'warning')
if (thereWarningOrErrors) {
errorsAndWarnings++
markdown('O linter está reclamando sobre: ')
_.each(linterOutput.split('\n'), (line) => {
if (!_.startsWith(line, '>')) {
markdown(line)
}
})
}
}
function isABigPR() {
const bigPRThreshold = 1000
if (danger.github.pr.additions + danger.github.pr.deletions > bigPRThreshold) {
errorsAndWarnings++
warn(':exclamation: Pull request grande, encorajamos PR menores')
}
}
function congrats() {
if (!errorsAndWarnings) {
message(`Nenhum error ou warning @${danger.github.pr.user.login} :tada:`)
}
}