conventional-commits-parser 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/README.md +6 -0
- package/cli.js +18 -18
- package/index.js +7 -7
- package/lib/parser.js +50 -52
- package/lib/regex.js +14 -8
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,23 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [3.2.0](https://github.com/conventional-changelog/conventional-changelog/compare/conventional-commits-parser@3.1.0...conventional-commits-parser@3.2.0) (2020-11-05)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* ignore gpg lines ([#685](https://github.com/conventional-changelog/conventional-changelog/issues/685)) ([f8fcbc2](https://github.com/conventional-changelog/conventional-changelog/commit/f8fcbc2e8b0834c29178ace6382b438a020ad828))
|
|
12
|
+
* **deps:** update dependency through2 to v4 ([#657](https://github.com/conventional-changelog/conventional-changelog/issues/657)) ([7ae618c](https://github.com/conventional-changelog/conventional-changelog/commit/7ae618c81491841e5b1d796d3933aac0c54bc312))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* allows notes pattern to be customized ([#586](https://github.com/conventional-changelog/conventional-changelog/issues/586)) ([9c00f32](https://github.com/conventional-changelog/conventional-changelog/commit/9c00f3242d916be1774a618d943f908f8d9699a6))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
6
23
|
# [3.1.0](https://github.com/conventional-changelog/conventional-changelog/compare/conventional-commits-parser@3.0.8...conventional-commits-parser@3.1.0) (2020-05-08)
|
|
7
24
|
|
|
8
25
|
|
package/README.md
CHANGED
|
@@ -205,6 +205,12 @@ Type: `array` of `string` or `string` Default: `['BREAKING CHANGE']`
|
|
|
205
205
|
|
|
206
206
|
Keywords for important notes. This value is case **insensitive**. If it's a `string` it will be converted to an `array` separated by a comma.
|
|
207
207
|
|
|
208
|
+
##### notesPattern
|
|
209
|
+
|
|
210
|
+
Type: `function` Default: `noteKeywordsSelection => ^[\\s|*]*(' + noteKeywordsSelection + ')[:\\s]+(.*)` where `noteKeywordsSelection` is `join(noteKeywords, '|')`
|
|
211
|
+
|
|
212
|
+
A function that takes `noteKeywordsSelection` and returns a `RegExp` to be matched against the notes.
|
|
213
|
+
|
|
208
214
|
##### fieldPattern
|
|
209
215
|
|
|
210
216
|
Type: `regex` or `string` Default: `/^-(.*?)-$/`
|
package/cli.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
const conventionalCommitsParser = require('./')
|
|
4
|
+
const forEach = require('lodash').forEach
|
|
5
|
+
const fs = require('fs')
|
|
6
|
+
const isTextPath = require('is-text-path')
|
|
7
|
+
const JSONStream = require('JSONStream')
|
|
8
|
+
const meow = require('meow')
|
|
9
|
+
const readline = require('readline')
|
|
10
|
+
const split = require('split2')
|
|
11
|
+
const through = require('through2')
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const filePaths = []
|
|
14
|
+
let separator = '\n\n\n'
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
const cli = meow(`
|
|
17
17
|
Practice writing commit messages or parse messages from files.
|
|
18
18
|
If used without specifying a text file path, you will enter an interactive shell.
|
|
19
19
|
Otherwise the commit messages in the files are parsed and printed
|
|
@@ -91,15 +91,15 @@ forEach(cli.input, function (arg) {
|
|
|
91
91
|
}
|
|
92
92
|
})
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
const length = filePaths.length
|
|
95
|
+
const options = cli.flags
|
|
96
96
|
|
|
97
97
|
if (options.verbose) {
|
|
98
98
|
options.warn = console.log.bind(console)
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
function processFile (fileIndex) {
|
|
102
|
-
|
|
102
|
+
const filePath = filePaths[fileIndex]
|
|
103
103
|
fs.createReadStream(filePath)
|
|
104
104
|
.on('error', function (err) {
|
|
105
105
|
console.warn('Failed to read file ' + filePath + '\n' + err)
|
|
@@ -122,9 +122,9 @@ if (process.stdin.isTTY) {
|
|
|
122
122
|
if (length > 0) {
|
|
123
123
|
processFile(0)
|
|
124
124
|
} else {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
125
|
+
let commit = ''
|
|
126
|
+
const stream = through()
|
|
127
|
+
const rl = readline.createInterface({
|
|
128
128
|
input: process.stdin,
|
|
129
129
|
output: process.stdout,
|
|
130
130
|
terminal: true
|
package/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
const parser = require('./lib/parser')
|
|
4
|
+
const regex = require('./lib/regex')
|
|
5
|
+
const through = require('through2')
|
|
6
|
+
const _ = require('lodash')
|
|
7
7
|
|
|
8
8
|
function assignOpts (options) {
|
|
9
9
|
options = _.extend({
|
|
@@ -71,10 +71,10 @@ function assignOpts (options) {
|
|
|
71
71
|
|
|
72
72
|
function conventionalCommitsParser (options) {
|
|
73
73
|
options = assignOpts(options)
|
|
74
|
-
|
|
74
|
+
const reg = regex(options)
|
|
75
75
|
|
|
76
76
|
return through.obj(function (data, enc, cb) {
|
|
77
|
-
|
|
77
|
+
let commit
|
|
78
78
|
|
|
79
79
|
try {
|
|
80
80
|
commit = parser(data.toString(), options, reg)
|
|
@@ -92,7 +92,7 @@ function conventionalCommitsParser (options) {
|
|
|
92
92
|
|
|
93
93
|
function sync (commit, options) {
|
|
94
94
|
options = assignOpts(options)
|
|
95
|
-
|
|
95
|
+
const reg = regex(options)
|
|
96
96
|
|
|
97
97
|
return parser(commit, options, reg)
|
|
98
98
|
}
|
package/lib/parser.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const trimOffNewlines = require('trim-off-newlines')
|
|
3
|
+
const _ = require('lodash')
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const CATCH_ALL = /()(.+)/gi
|
|
6
|
+
const SCISSOR = '# ------------------------ >8 ------------------------'
|
|
7
7
|
|
|
8
8
|
function append (src, line) {
|
|
9
9
|
if (src) {
|
|
@@ -22,7 +22,7 @@ function getCommentFilter (char) {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
function truncateToScissor (lines) {
|
|
25
|
-
|
|
25
|
+
const scissorIndex = lines.indexOf(SCISSOR)
|
|
26
26
|
|
|
27
27
|
if (scissorIndex === -1) {
|
|
28
28
|
return lines
|
|
@@ -32,29 +32,29 @@ function truncateToScissor (lines) {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
function getReferences (input, regex) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
const references = []
|
|
36
|
+
let referenceSentences
|
|
37
|
+
let referenceMatch
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
const reApplicable = input.match(regex.references) !== null
|
|
40
40
|
? regex.references
|
|
41
41
|
: CATCH_ALL
|
|
42
42
|
|
|
43
43
|
while ((referenceSentences = reApplicable.exec(input))) {
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
const action = referenceSentences[1] || null
|
|
45
|
+
const sentence = referenceSentences[2]
|
|
46
46
|
|
|
47
47
|
while ((referenceMatch = regex.referenceParts.exec(sentence))) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
let owner = null
|
|
49
|
+
let repository = referenceMatch[1] || ''
|
|
50
|
+
const ownerRepo = repository.split('/')
|
|
51
51
|
|
|
52
52
|
if (ownerRepo.length > 1) {
|
|
53
53
|
owner = ownerRepo.shift()
|
|
54
54
|
repository = ownerRepo.join('/')
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
const reference = {
|
|
58
58
|
action: action,
|
|
59
59
|
owner: owner,
|
|
60
60
|
repository: repository || null,
|
|
@@ -87,39 +87,37 @@ function parser (raw, options, regex) {
|
|
|
87
87
|
throw new TypeError('Expected regex')
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
var revertMatch
|
|
95
|
-
var otherFields = {}
|
|
96
|
-
var commentFilter = typeof options.commentChar === 'string'
|
|
90
|
+
let currentProcessedField
|
|
91
|
+
let mentionsMatch
|
|
92
|
+
const otherFields = {}
|
|
93
|
+
const commentFilter = typeof options.commentChar === 'string'
|
|
97
94
|
? getCommentFilter(options.commentChar)
|
|
98
95
|
: passTrough
|
|
96
|
+
const gpgFilter = line => !line.match(/^\s*gpg:/)
|
|
99
97
|
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
const rawLines = trimOffNewlines(raw).split(/\r?\n/)
|
|
99
|
+
const lines = truncateToScissor(rawLines).filter(commentFilter).filter(gpgFilter)
|
|
102
100
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
101
|
+
let continueNote = false
|
|
102
|
+
let isBody = true
|
|
103
|
+
const headerCorrespondence = _.map(options.headerCorrespondence, function (part) {
|
|
106
104
|
return part.trim()
|
|
107
105
|
})
|
|
108
|
-
|
|
106
|
+
const revertCorrespondence = _.map(options.revertCorrespondence, function (field) {
|
|
109
107
|
return field.trim()
|
|
110
108
|
})
|
|
111
|
-
|
|
109
|
+
const mergeCorrespondence = _.map(options.mergeCorrespondence, function (field) {
|
|
112
110
|
return field.trim()
|
|
113
111
|
})
|
|
114
112
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
113
|
+
let body = null
|
|
114
|
+
let footer = null
|
|
115
|
+
let header = null
|
|
116
|
+
const mentions = []
|
|
117
|
+
let merge = null
|
|
118
|
+
const notes = []
|
|
119
|
+
const references = []
|
|
120
|
+
let revert = null
|
|
123
121
|
|
|
124
122
|
if (lines.length === 0) {
|
|
125
123
|
return {
|
|
@@ -139,12 +137,12 @@ function parser (raw, options, regex) {
|
|
|
139
137
|
|
|
140
138
|
// msg parts
|
|
141
139
|
merge = lines.shift()
|
|
142
|
-
|
|
143
|
-
|
|
140
|
+
const mergeParts = {}
|
|
141
|
+
const headerParts = {}
|
|
144
142
|
body = ''
|
|
145
143
|
footer = ''
|
|
146
144
|
|
|
147
|
-
mergeMatch = merge.match(options.mergePattern)
|
|
145
|
+
const mergeMatch = merge.match(options.mergePattern)
|
|
148
146
|
if (mergeMatch && options.mergePattern) {
|
|
149
147
|
merge = mergeMatch[0]
|
|
150
148
|
|
|
@@ -154,7 +152,7 @@ function parser (raw, options, regex) {
|
|
|
154
152
|
}
|
|
155
153
|
|
|
156
154
|
_.forEach(mergeCorrespondence, function (partName, index) {
|
|
157
|
-
|
|
155
|
+
const partValue = mergeMatch[index + 1] || null
|
|
158
156
|
mergeParts[partName] = partValue
|
|
159
157
|
})
|
|
160
158
|
} else {
|
|
@@ -166,10 +164,10 @@ function parser (raw, options, regex) {
|
|
|
166
164
|
})
|
|
167
165
|
}
|
|
168
166
|
|
|
169
|
-
headerMatch = header.match(options.headerPattern)
|
|
167
|
+
const headerMatch = header.match(options.headerPattern)
|
|
170
168
|
if (headerMatch) {
|
|
171
169
|
_.forEach(headerCorrespondence, function (partName, index) {
|
|
172
|
-
|
|
170
|
+
const partValue = headerMatch[index + 1] || null
|
|
173
171
|
headerParts[partName] = partValue
|
|
174
172
|
})
|
|
175
173
|
} else {
|
|
@@ -186,7 +184,7 @@ function parser (raw, options, regex) {
|
|
|
186
184
|
// body or footer
|
|
187
185
|
_.forEach(lines, function (line) {
|
|
188
186
|
if (options.fieldPattern) {
|
|
189
|
-
|
|
187
|
+
const fieldMatch = options.fieldPattern.exec(line)
|
|
190
188
|
|
|
191
189
|
if (fieldMatch) {
|
|
192
190
|
currentProcessedField = fieldMatch[1]
|
|
@@ -201,16 +199,16 @@ function parser (raw, options, regex) {
|
|
|
201
199
|
}
|
|
202
200
|
}
|
|
203
201
|
|
|
204
|
-
|
|
202
|
+
let referenceMatched
|
|
205
203
|
|
|
206
204
|
// this is a new important note
|
|
207
|
-
|
|
205
|
+
const notesMatch = line.match(regex.notes)
|
|
208
206
|
if (notesMatch) {
|
|
209
207
|
continueNote = true
|
|
210
208
|
isBody = false
|
|
211
209
|
footer = append(footer, line)
|
|
212
210
|
|
|
213
|
-
|
|
211
|
+
const note = {
|
|
214
212
|
title: notesMatch[1],
|
|
215
213
|
text: notesMatch[2]
|
|
216
214
|
}
|
|
@@ -220,7 +218,7 @@ function parser (raw, options, regex) {
|
|
|
220
218
|
return
|
|
221
219
|
}
|
|
222
220
|
|
|
223
|
-
|
|
221
|
+
const lineReferences = getReferences(line, {
|
|
224
222
|
references: regex.references,
|
|
225
223
|
referenceParts: regex.referenceParts
|
|
226
224
|
})
|
|
@@ -254,7 +252,7 @@ function parser (raw, options, regex) {
|
|
|
254
252
|
})
|
|
255
253
|
|
|
256
254
|
if (options.breakingHeaderPattern && notes.length === 0) {
|
|
257
|
-
|
|
255
|
+
const breakingHeader = header.match(options.breakingHeaderPattern)
|
|
258
256
|
if (breakingHeader) {
|
|
259
257
|
const noteText = breakingHeader[3] // the description of the change.
|
|
260
258
|
notes.push({
|
|
@@ -269,11 +267,11 @@ function parser (raw, options, regex) {
|
|
|
269
267
|
}
|
|
270
268
|
|
|
271
269
|
// does this commit revert any other commit?
|
|
272
|
-
revertMatch = raw.match(options.revertPattern)
|
|
270
|
+
const revertMatch = raw.match(options.revertPattern)
|
|
273
271
|
if (revertMatch) {
|
|
274
272
|
revert = {}
|
|
275
273
|
_.forEach(revertCorrespondence, function (partName, index) {
|
|
276
|
-
|
|
274
|
+
const partValue = revertMatch[index + 1] || null
|
|
277
275
|
revert[partName] = partValue
|
|
278
276
|
})
|
|
279
277
|
} else {
|
|
@@ -286,7 +284,7 @@ function parser (raw, options, regex) {
|
|
|
286
284
|
return note
|
|
287
285
|
})
|
|
288
286
|
|
|
289
|
-
|
|
287
|
+
const msg = _.merge(headerParts, mergeParts, {
|
|
290
288
|
merge: merge,
|
|
291
289
|
header: header,
|
|
292
290
|
body: body ? trimOffNewlines(body) : null,
|
package/lib/regex.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const reNomatch = /(?!.*)/
|
|
4
4
|
|
|
5
5
|
function join (array, joiner) {
|
|
6
6
|
return array
|
|
@@ -13,12 +13,18 @@ function join (array, joiner) {
|
|
|
13
13
|
.join(joiner)
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
function getNotesRegex (noteKeywords) {
|
|
16
|
+
function getNotesRegex (noteKeywords, notesPattern) {
|
|
17
17
|
if (!noteKeywords) {
|
|
18
18
|
return reNomatch
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
const noteKeywordsSelection = join(noteKeywords, '|')
|
|
22
|
+
|
|
23
|
+
if (!notesPattern) {
|
|
24
|
+
return new RegExp('^[\\s|*]*(' + noteKeywordsSelection + ')[:\\s]+(.*)', 'i')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return notesPattern(noteKeywordsSelection)
|
|
22
28
|
}
|
|
23
29
|
|
|
24
30
|
function getReferencePartsRegex (issuePrefixes, issuePrefixesCaseSensitive) {
|
|
@@ -26,7 +32,7 @@ function getReferencePartsRegex (issuePrefixes, issuePrefixesCaseSensitive) {
|
|
|
26
32
|
return reNomatch
|
|
27
33
|
}
|
|
28
34
|
|
|
29
|
-
|
|
35
|
+
const flags = issuePrefixesCaseSensitive ? 'g' : 'gi'
|
|
30
36
|
return new RegExp('(?:.*?)??\\s*([\\w-\\.\\/]*?)??(' + join(issuePrefixes, '|') + ')([\\w-]*\\d+)', flags)
|
|
31
37
|
}
|
|
32
38
|
|
|
@@ -36,15 +42,15 @@ function getReferencesRegex (referenceActions) {
|
|
|
36
42
|
return /()(.+)/gi
|
|
37
43
|
}
|
|
38
44
|
|
|
39
|
-
|
|
45
|
+
const joinedKeywords = join(referenceActions, '|')
|
|
40
46
|
return new RegExp('(' + joinedKeywords + ')(?:\\s+(.*?))(?=(?:' + joinedKeywords + ')|$)', 'gi')
|
|
41
47
|
}
|
|
42
48
|
|
|
43
49
|
module.exports = function (options) {
|
|
44
50
|
options = options || {}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
51
|
+
const reNotes = getNotesRegex(options.noteKeywords, options.notesPattern)
|
|
52
|
+
const reReferenceParts = getReferencePartsRegex(options.issuePrefixes, options.issuePrefixesCaseSensitive)
|
|
53
|
+
const reReferences = getReferencesRegex(options.referenceActions)
|
|
48
54
|
|
|
49
55
|
return {
|
|
50
56
|
notes: reNotes,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "conventional-commits-parser",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Parse raw conventional commits",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/conventional-changelog/conventional-changelog/issues"
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"JSONStream": "^1.0.4",
|
|
37
37
|
"is-text-path": "^1.0.1",
|
|
38
38
|
"lodash": "^4.17.15",
|
|
39
|
-
"meow": "^
|
|
39
|
+
"meow": "^8.0.0",
|
|
40
40
|
"split2": "^2.0.0",
|
|
41
|
-
"through2": "^
|
|
41
|
+
"through2": "^4.0.0",
|
|
42
42
|
"trim-off-newlines": "^1.0.0"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"forceable-tty": "^0.1.0"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "cc567b98facf71315f4b1620d81ce01d155efaca"
|
|
54
54
|
}
|