Skip to content

Commit 0679d7a

Browse files
authored
feat: add support for '--skip-unstable' option (conventional-changelog#656) (conventional-changelog#656)
1 parent 3dedddc commit 0679d7a

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

packages/conventional-changelog-cli/cli.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ var cli = meow(`
3737
If 0, the whole changelog will be regenerated and the outfile will be overwritten
3838
Default: 1
3939
40+
--skip-unstable If given, unstable tags will be skipped, e.g., x.x.x-alpha.1, x.x.x-rc.2
41+
4042
-u, --output-unreleased Output unreleased changelog
4143
4244
-v, --verbose Verbose output. Use this for debugging
@@ -80,6 +82,9 @@ var cli = meow(`
8082
alias: 'r',
8183
type: 'number'
8284
},
85+
'skip-unstable': {
86+
type: 'boolean'
87+
},
8388
'output-unreleased': {
8489
alias: 'u',
8590
type: 'boolean'
@@ -114,6 +119,7 @@ var outfile = flags.outfile
114119
var sameFile = flags.sameFile
115120
var append = flags.append
116121
var releaseCount = flags.releaseCount
122+
var skipUnstable = flags.skipUnstable
117123

118124
if (infile && infile === outfile) {
119125
sameFile = true
@@ -133,6 +139,7 @@ var options = _.omitBy({
133139
},
134140
append: append,
135141
releaseCount: releaseCount,
142+
skipUnstable: skipUnstable,
136143
outputUnreleased: flags.outputUnreleased,
137144
lernaPackage: flags.lernaPackage,
138145
tagPrefix: flags.tagPrefix

packages/conventional-changelog-core/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ Type: `number` Default: `1`
6464

6565
How many releases of changelog you want to generate. It counts from the upcoming release. Useful when you forgot to generate any previous changelog. Set to `0` to regenerate all.
6666

67+
##### skipUnstable
68+
69+
Type: `boolean` Default: `false`
70+
71+
If set, unstable release tags will be skipped, e.g., x.x.x-rc.
72+
6773
##### debug
6874

6975
Type: `function` Default: `function() {}`

packages/conventional-changelog-core/lib/merge-config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var rhosts = /github|bitbucket|gitlab/i
2121

2222
function semverTagsPromise (options) {
2323
return Q.Promise(function (resolve, reject) {
24-
gitSemverTags({ lernaTags: !!options.lernaPackage, package: options.lernaPackage, tagPrefix: options.tagPrefix }, function (err, result) {
24+
gitSemverTags({ lernaTags: !!options.lernaPackage, package: options.lernaPackage, tagPrefix: options.tagPrefix, skipUnstable: options.skipUnstable }, function (err, result) {
2525
if (err) {
2626
reject(err)
2727
} else {
@@ -70,6 +70,7 @@ function mergeConfig (options, context, gitRawCommitsOpts, parserOpts, writerOpt
7070
},
7171
append: false,
7272
releaseCount: 1,
73+
skipUnstable: false,
7374
debug: function () {},
7475
transform: function (commit, cb) {
7576
if (_.isString(commit.gitTags)) {

packages/git-semver-tags/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var exec = require('child_process').exec
55
var semverValid = require('semver').valid
66
var regex = /tag:\s*(.+?)[,)]/gi
77
var cmd = 'git log --decorate --no-color'
8+
var unstableTagTest = /.*-\w*\.\d$/
89

910
function lernaTag (tag, pkg) {
1011
if (pkg && !(new RegExp('^' + pkg + '@')).test(tag)) {
@@ -41,6 +42,12 @@ module.exports = function gitSemverTags (opts, callback) {
4142
var match
4243
while ((match = regex.exec(decorations))) {
4344
var tag = match[1]
45+
46+
if (options.skipUnstable && unstableTagTest.test(tag)) {
47+
// skip unstable tag
48+
continue
49+
}
50+
4451
if (options.lernaTags) {
4552
if (lernaTag(tag, options.package)) {
4653
tags.push(tag)

packages/git-semver-tags/test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,27 @@ describe('git-semver-tags', function () {
196196
done()
197197
})
198198
})
199+
200+
it('should skip unstable tags', function (done) {
201+
writeFileSync('test7', '')
202+
shell.exec('git add --all && git commit -m"twelfth commit"')
203+
shell.exec('git tag skip/8.0.0')
204+
writeFileSync('test8', '')
205+
shell.exec('git add --all && git commit -m"thirteenth commit"')
206+
shell.exec('git tag skip/9.0.0-alpha.1')
207+
writeFileSync('test9', '')
208+
shell.exec('git add --all && git commit -m"fourteenth commit"')
209+
shell.exec('git tag skip/9.0.0-rc.1')
210+
writeFileSync('test10', '')
211+
shell.exec('git add --all && git commit -m"fifteenth commit"')
212+
shell.exec('git tag skip/9.0.0')
213+
214+
gitSemverTags({ tagPrefix: 'skip/', skipUnstable: true }, function (err, tags) {
215+
if (err) done(err)
216+
assert.deepStrictEqual(tags, ['skip/9.0.0', 'skip/8.0.0'])
217+
done()
218+
})
219+
})
199220
})
200221

201222
describe('git semver tags on different cwd', function () {

0 commit comments

Comments
 (0)