-
Notifications
You must be signed in to change notification settings - Fork 0
/
dangerfile.js
121 lines (98 loc) · 3.06 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
121
import { danger, fail, markdown, message, warn } from 'danger'
const fs = require('fs')
const path = require('path')
const istanbulCoverage = require('danger-plugin-istanbul-coverage')
.istanbulCoverage
const jiraIssue = require('danger-plugin-jira-issue').default
const getEslintMarkdown = (eslintOutput, files) => {
let eslintMarkdown =
'## Eslint Issues:\n<details>\n <summary>Issues</summary>\n\n'
let warnings = false
eslintOutput.map((record) => {
const file = path.parse(record.filePath).base
if (files.includes(file)) {
if (record.messages.length > 0) {
warnings = true
eslintMarkdown = eslintMarkdown.concat(' ').concat(file).concat('\n')
record.messages.map((error) => {
eslintMarkdown = eslintMarkdown.concat(
` * ${error.ruleId} - ${error.message} Line ${error.line} \n`
)
})
}
eslintMarkdown = eslintMarkdown.concat('\n')
}
})
eslintMarkdown = eslintMarkdown.concat('</details>')
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/)'
)
}
}
// Checking tests
let areThereNewTest = false
danger.git.modified_files.map((file) => {
if (file.includes('spec') || file.includes('test')) {
areThereNewTest = true
}
})
danger.git.created_files.map((file) => {
if (file.includes('spec') || file.includes('test')) {
areThereNewTest = true
}
})
if (!areThereNewTest) {
warn('Create some tests :rocket:')
}
if (fs.existsSync('coverage/coverage-summary.json')) {
istanbulCoverage({
customSuccessMessage: 'Congrats, coverage is good',
customFailureMessage: 'Coverage is a little low, take a look',
coveragePath: 'coverage/coverage-summary.json',
reportFileSet: 'createdOrModified',
reportMode: 'warn'
})
}
jiraIssue({
key: '[PROJECT-JIRA-CODE]',
url: 'https://wealize.atlassian.net/browse',
emoji: ':paperclip:',
location: 'title'
})
if (fs.existsSync('eslint.json')) {
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 files = newFiles.concat(modifiedFiles)
const messageToSend = getEslintMarkdown(eslintOutput, files)
if (messageToSend !== '') {
markdown(messageToSend)
} else {
message("There aren't eslint errors in your code :rocket:")
}
}
}