generated from actions/javascript-action
-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
parse-entry.js
36 lines (29 loc) · 780 Bytes
/
parse-entry.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
const { prerelease } = require('semver')
exports.parseEntry = entry => {
const [title, ...other] = entry
.trim()
.split('\n')
const [versionPart, datePart] = title.split(' - ')
const [versionNumber] = versionPart.match(/[a-zA-Z0-9.\-+]+/)
const [versionDate] = datePart != null && datePart.match(/[0-9-]+/) || []
return {
id: versionNumber,
date: versionDate,
status: computeStatus(versionNumber, title),
text: other
.filter(item => !/\[.*\]: http/.test(item))
.join('\n')
}
}
function computeStatus(version, title) {
if (prerelease(version)) {
return 'prereleased'
}
if (title.match(/\[yanked\]/i)) {
return 'yanked'
}
if (title.match(/\[unreleased\]/i)) {
return 'unreleased'
}
return 'released'
}