-
Notifications
You must be signed in to change notification settings - Fork 5
/
release.utils.js
216 lines (203 loc) · 5.1 KB
/
release.utils.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
const types = {
maxSubjectLength: 72,
bodyLineLength: 100,
typesOrder: [
'feat',
'fix',
'perf',
'build',
'refactor',
'docs',
'test',
'ci',
'chore',
'style',
'revert',
'initial',
'dependencies',
'peerDependencies',
'devDependencies',
'metadata',
],
types: {
feat: {
description: 'A new feature',
title: 'Features',
emoji: '✨',
changelog: true,
release: 'minor',
aliases: {
initial: {
description: 'Initial commit',
title: 'Initial',
emoji: '🎉',
},
},
},
fix: {
description: 'A bug fix',
title: 'Bug Fixes',
emoji: '🐛',
changelog: true,
release: 'patch',
aliases: {
dependencies: {
description: 'Update dependency',
title: 'Dependencies',
emoji: '⬆️',
scope: 'package',
},
peerDependencies: {
description: 'Update peer dependency',
title: 'Peer dependencies',
emoji: '⬆️',
scope: 'package',
},
metadata: {
description: 'Update metadata (package.json)',
title: 'Metadata',
emoji: '📦',
scope: 'package',
},
},
},
docs: {
description: 'Documentation only changes',
title: 'Documentation',
emoji: '📚',
changelog: true,
release: { scope: 'readme', release: 'patch' },
},
style: {
description:
'Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)',
title: 'Styles',
emoji: '💎',
changelog: true,
release: false,
},
refactor: {
description: 'A code change that neither fixes a bug nor adds a feature',
title: 'Code Refactoring',
emoji: '📦',
changelog: true,
release: false,
},
perf: {
description: 'A code change that improves performance',
title: 'Performance Improvements',
emoji: '🚀',
changelog: true,
release: 'patch',
},
test: {
description: 'Adding missing tests or correcting existing tests',
title: 'Tests',
emoji: '🚨',
changelog: true,
release: false,
},
build: {
description:
'Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)',
title: 'Builds',
emoji: '🛠',
changelog: true,
release: 'patch',
},
ci: {
description:
'Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)',
title: 'Continuous Integrations',
emoji: '⚙️',
changelog: true,
release: false,
},
chore: {
description: 'Other changes that dont modify src or test files',
title: 'Chores',
emoji: '♻️',
changelog: true,
release: false,
aliases: {
devDependencies: {
description: 'Update dev dependencies',
title: 'Dev dependencies',
emoji: '⬆️',
scope: 'package',
},
},
},
revert: {
description: 'Reverts a previous commit',
title: 'Reverts',
emoji: '🗑',
changelog: true,
release: false,
},
},
}
const COMMIT_HASH_LENGTH = 7
/**
* Transform a parsed commit to render the changelog.
*
* @param {Object} commit commit parsed with `conventional-changelog-parser`.
* @param {Object} context `conventional-changelog` context.
* @return {Object} the transformed commit.
*/
const customTransform = (commit, context) => {
if (commit.notes) {
commit.notes.forEach((note) => {
note.title = 'Breaking changes'
})
}
if (
types.types[commit.type] &&
(types.types[commit.type].changelog ||
(commit.notes && commit.notes.length > 0))
) {
commit.type = `${
types.types[commit.type].emoji ? types.types[commit.type].emoji : ''
} \t ${types.types[commit.type].title}`
} else {
return null
}
if (commit.scope === '*') {
commit.scope = ''
}
if (typeof commit.hash === 'string') {
commit.shortHash = commit.hash.slice(0, COMMIT_HASH_LENGTH)
}
const references = []
if (typeof commit.subject === 'string') {
let url = context.repository
? `${context.host}/${context.owner}/${context.repository}`
: context.repoUrl
if (url) {
url += '/issues/'
// Issue URLs.
commit.subject = commit.subject.replace(/#(\d+)/g, (_, issue) => {
references.push(issue)
return `[#${issue}](${url}${issue})`
})
}
if (context.host) {
// User URLs.
commit.subject = commit.subject.replace(
/\B@([a-z0-9](?:-?[a-z0-9]){0,38})/g,
`[@$1](${context.host}/$1)`,
)
}
}
if (commit.references) {
// Remove references that already appear in the subject
commit.references = commit.references.filter((reference) => {
if (!references.includes(reference.issue)) {
return true
}
return false
})
}
return commit
}
module.exports = customTransform