-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchangelog-option.js
More file actions
87 lines (75 loc) · 2.44 KB
/
changelog-option.js
File metadata and controls
87 lines (75 loc) · 2.44 KB
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
import compareFunc from 'compare-func'
export default {
writerOpts: {
transform: (commit, context) => {
let discard = true
const issues = []
const newCommit = {
...commit,
notes: commit.notes.map(note => ({
...note,
title: 'BREAKING CHANGES',
})),
}
if (newCommit.notes.length > 0) {
discard = false
}
const typeMap = {
feat: '✨ Features | 新功能',
fix: '🐛 Bug Fixes | Bug 修复',
perf: '⚡ Performance Improvements | 性能优化',
revert: '⏪ Reverts | 回退',
refactor: '♻ Code Refactoring | 代码重构',
test: '✅ Tests | 测试',
build: '👷 Build System | 构建',
chore: '🎫 Chores | 其他更新',
style: '💄 Styles | 风格',
ci: '🔧 Continuous Integration | CI 配置',
docs: '📝 Documentation | 文档',
}
if (typeMap[newCommit.type]) {
newCommit.type = typeMap[newCommit.type]
} else if (newCommit.type === 'revert' || newCommit.revert) {
newCommit.type = typeMap['revert']
} else if (discard) {
return
}
if (newCommit.scope === '*') {
newCommit.scope = ''
}
if (typeof newCommit.hash === 'string') {
newCommit.shortHash = newCommit.hash.substring(0, 7)
}
if (typeof newCommit.subject === 'string') {
let url = context.repository ? `${context.host}/${context.owner}/${context.repository}` : context.repoUrl
if (url) {
url = `${url}/issues/`
newCommit.subject = newCommit.subject.replace(/#([0-9]+)/g, (_, issue) => {
issues.push(issue)
return `[#${issue}](${url}${issue})`
})
}
if (context.host) {
newCommit.subject = newCommit.subject.replace(/\B@([a-z0-9](?:-?[a-z0-9/]){0,38})/g, (_, username) => {
if (username.includes('/')) {
return `@${username}`
}
return `[@${username}](${context.host}/${username})`
})
}
}
newCommit.references = newCommit.references.filter(reference => {
if (issues.indexOf(reference.issue) === -1) {
return true
}
return false
})
return newCommit
},
groupBy: 'type',
commitGroupsSort: 'title',
commitsSort: ['scope', 'subject'],
noteGroupsSort: 'title',
notesSort: compareFunc,
},
}