-
Notifications
You must be signed in to change notification settings - Fork 0
/
dangerfile.js
89 lines (72 loc) · 2.54 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
import { danger, fail, markdown, message } from 'danger'
const istanbulCoverage = require('danger-plugin-istanbul-coverage').istanbulCoverage
import jiraIssue from 'danger-plugin-jira-issue'
import * as fs from 'fs'
import * as path from 'path'
const getEslintMarkdown = (eslintOutput, newFiles, modifiedFiles) => {
let eslintMarkdown = '## ESlint Issues:\n'
let warnings = false
eslintOutput.map(record => {
const file = path.parse(record.filePath).base
if (modifiedFiles.includes(file) || newFiles.includes(file)) {
if (record.messages.length > 0) {
warnings = true
eslintMarkdown = eslintMarkdown.concat(file).concat('\n')
record.messages.map(error => {
eslintMarkdown = eslintMarkdown.concat(
`* ${error.ruleId} - ${error.message} Line ${error.line} \n`
)
})
}
eslintMarkdown = eslintMarkdown.concat('\n')
}
})
if (warnings) {
return eslintMarkdown
} else {
return ''
}
}
const existsChangelog = fs.existsSync('CHANGELOG.md')
if (!existsChangelog) {
fail('Create a changelog file following the instructions of [KeepaChangelog](https://keepachangelog.com/en/1.0.0/)')
} else {
const hasChangelogModified = danger.git.modified_files.includes('CHANGELOG.md')
if (!hasChangelogModified) {
fail('Please add a changelog entry for your changes and follow the instructions of [KeepaChangelog](https://keepachangelog.com/en/1.0.0/)')
}
}
if (process.env['COVERAGE']) {
istanbulCoverage({
customSuccessMessage: 'Congrats, coverage is good',
customFailureMessage: 'Coverage is a little low, take a look',
coveragePath: 'coverage/coverage-summary.json',
reportFileSet: 'createdOrModified',
reportMode: 'warn'
})
}
if (process.env['JIRA_TAG'] !== '') {
jiraIssue({
key: process.env['JIRA_TAG'],
url: process.env['JIRA_URL'],
emoji: ':paperclip:',
location: 'title'
})
}
if (process.env['ESLINT']) {
const eslintOutput = JSON.parse(fs.readFileSync('eslint.json', 'utf8'))
if (danger.git.modified_files.length > 0 || danger.git.created_files.length > 0) {
const modifiedFiles = danger.git.modified_files.map(pathname => {
return path.parse(pathname).base
})
const newFiles = danger.git.created_files.map(pathname => {
return path.parse(pathname).base
})
const messageToSend = getEslintMarkdown(eslintOutput, newFiles, modifiedFiles)
if (messageToSend !== '') {
markdown(messageToSend)
} else {
message('There aren\'t eslint errors in your code :rocket:')
}
}
}