-
Notifications
You must be signed in to change notification settings - Fork 0
/
dangerfile.js
103 lines (82 loc) · 2.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
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
import { danger, fail, markdown, message } from 'danger'
const jiraIssue = require('danger-plugin-jira-issue').default
const fs = require('fs')
const path = require('path')
const filter = require('lodash').filter
const getPylintMarkdown = (pylintOutput, files) => {
let pylintMarkdown = '## Pylint Issues:\n<details>\n <summary>Issues</summary>\n\n'
let warnings = false
files.map(file => {
const records = filter(pylintOutput, function (record) {
if (record.path.includes(file)) {
return true
} else {
return false
}
})
if (records.length > 0) {
warnings = true
pylintMarkdown = pylintMarkdown.concat(' ').concat(file).concat('\n')
records.map(record => {
pylintMarkdown = pylintMarkdown.concat(
` * ${record.symbol} - ${record.message} Line ${record.line} \n`
)
})
pylintMarkdown = pylintMarkdown.concat('\n')
}
})
pylintMarkdown = pylintMarkdown.concat('</details>')
if (warnings) {
return pylintMarkdown
} 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('test')) {
areThereNewTest = true
}
})
danger.git.created_files.map(file => {
if (file.includes('test')) {
areThereNewTest = true
}
})
if (!areThereNewTest) {
warn('Create some tests :rocket:')
}
jiraIssue({
key: 'CQIO',
url: 'https://theneonproject.atlassian.net/browse',
emoji: ':paperclip:',
location: 'title'
})
if (fs.existsSync('pylint.json')) {
const pylintOutput = JSON.parse(fs.readFileSync('pylint.json', 'utf8'))
if (danger.git.modified_files.length > 0 || danger.git.created_files.length > 0) {
const modifiedFiles = danger.git.modified_files.map(pathname => {
return pathname
})
const newFiles = danger.git.created_files.map(pathname => {
return pathname
})
const files = newFiles.concat(modifiedFiles)
const messageToSend = getPylintMarkdown(pylintOutput, files)
if (messageToSend !== '') {
markdown(messageToSend)
} else {
message('There aren\'t pylint errors in your code :rocket:')
}
}
}