forked from DeKal/portfolio-next-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dangerfile.js
68 lines (57 loc) · 1.86 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
import { danger, fail, markdown } from 'danger'
// No PR is too small to include a description of why you made a change
if (danger.github.pr.body.length < 8) {
fail('Please include a description of your PR changes.')
}
// Check that someone has been assigned to this PR
if (danger.github.pr.assignee === null) {
fail(
'Please assign someone to merge this PR, and optionally include people who should review.'
)
}
const lernaConfigs = require('./lerna.json')
const { labels } = lernaConfigs.changelog
const { issue, pr, commits } = danger.github
// check sentence case
const firstChar = pr.title[0]
if (firstChar.toUpperCase() !== firstChar) {
fail('PR name should begin with a capital letter')
}
// should have a specified tag to be referenced in CHANGELOG.md
const availableLabels = Object.keys(labels)
const assignedLabels = issue.labels
.map(label => label.name)
.filter(name => availableLabels.filter(label => label.includes(name)).length)
if (!assignedLabels.length) {
fail(
`Requires one of these labels: [\`${availableLabels.join(
'`, `'
)}\`] to be referenced in CHANGELOG.md`
)
}
const uncapitalizedCommits = commits
.map(commit => commit.commit.message)
.filter(message => message[0].toUpperCase() !== message[0])
if (uncapitalizedCommits.length) {
fail(
`Commit messages should begin with a capital letter: [\`${uncapitalizedCommits.join(
'`, `'
)}\`]`
)
}
// commit message should be specific
const badCommitMessageExamples = [
'Fix test',
'Fix eslint',
'Fix bugs',
'Fix comments',
'Bug fixes'
]
const badCommitMessages = commits
.map(commit => commit.commit.message)
.filter(message => badCommitMessageExamples.indexOf(message) !== -1)
if (badCommitMessages.length) {
markdown(
`Commit message should be specific. Checkout [How to Write a Git Commit Message](https://chris.beams.io/posts/git-commit/)`
)
}