Skip to content

Commit

Permalink
feat: add support for '--skip-unstable' option (#656) (#656)
Browse files Browse the repository at this point in the history
  • Loading branch information
dudekaa committed Jun 22, 2020
1 parent 3dedddc commit 0679d7a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/conventional-changelog-cli/cli.js
Expand Up @@ -37,6 +37,8 @@ var cli = meow(`
If 0, the whole changelog will be regenerated and the outfile will be overwritten
Default: 1
--skip-unstable If given, unstable tags will be skipped, e.g., x.x.x-alpha.1, x.x.x-rc.2
-u, --output-unreleased Output unreleased changelog
-v, --verbose Verbose output. Use this for debugging
Expand Down Expand Up @@ -80,6 +82,9 @@ var cli = meow(`
alias: 'r',
type: 'number'
},
'skip-unstable': {
type: 'boolean'
},
'output-unreleased': {
alias: 'u',
type: 'boolean'
Expand Down Expand Up @@ -114,6 +119,7 @@ var outfile = flags.outfile
var sameFile = flags.sameFile
var append = flags.append
var releaseCount = flags.releaseCount
var skipUnstable = flags.skipUnstable

if (infile && infile === outfile) {
sameFile = true
Expand All @@ -133,6 +139,7 @@ var options = _.omitBy({
},
append: append,
releaseCount: releaseCount,
skipUnstable: skipUnstable,
outputUnreleased: flags.outputUnreleased,
lernaPackage: flags.lernaPackage,
tagPrefix: flags.tagPrefix
Expand Down
6 changes: 6 additions & 0 deletions packages/conventional-changelog-core/README.md
Expand Up @@ -64,6 +64,12 @@ Type: `number` Default: `1`

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.

##### skipUnstable

Type: `boolean` Default: `false`

If set, unstable release tags will be skipped, e.g., x.x.x-rc.

##### debug

Type: `function` Default: `function() {}`
Expand Down
3 changes: 2 additions & 1 deletion packages/conventional-changelog-core/lib/merge-config.js
Expand Up @@ -21,7 +21,7 @@ var rhosts = /github|bitbucket|gitlab/i

function semverTagsPromise (options) {
return Q.Promise(function (resolve, reject) {
gitSemverTags({ lernaTags: !!options.lernaPackage, package: options.lernaPackage, tagPrefix: options.tagPrefix }, function (err, result) {
gitSemverTags({ lernaTags: !!options.lernaPackage, package: options.lernaPackage, tagPrefix: options.tagPrefix, skipUnstable: options.skipUnstable }, function (err, result) {
if (err) {
reject(err)
} else {
Expand Down Expand Up @@ -70,6 +70,7 @@ function mergeConfig (options, context, gitRawCommitsOpts, parserOpts, writerOpt
},
append: false,
releaseCount: 1,
skipUnstable: false,
debug: function () {},
transform: function (commit, cb) {
if (_.isString(commit.gitTags)) {
Expand Down
7 changes: 7 additions & 0 deletions packages/git-semver-tags/index.js
Expand Up @@ -5,6 +5,7 @@ var exec = require('child_process').exec
var semverValid = require('semver').valid
var regex = /tag:\s*(.+?)[,)]/gi
var cmd = 'git log --decorate --no-color'
var unstableTagTest = /.*-\w*\.\d$/

function lernaTag (tag, pkg) {
if (pkg && !(new RegExp('^' + pkg + '@')).test(tag)) {
Expand Down Expand Up @@ -41,6 +42,12 @@ module.exports = function gitSemverTags (opts, callback) {
var match
while ((match = regex.exec(decorations))) {
var tag = match[1]

if (options.skipUnstable && unstableTagTest.test(tag)) {
// skip unstable tag
continue
}

if (options.lernaTags) {
if (lernaTag(tag, options.package)) {
tags.push(tag)
Expand Down
21 changes: 21 additions & 0 deletions packages/git-semver-tags/test.js
Expand Up @@ -196,6 +196,27 @@ describe('git-semver-tags', function () {
done()
})
})

it('should skip unstable tags', function (done) {
writeFileSync('test7', '')
shell.exec('git add --all && git commit -m"twelfth commit"')
shell.exec('git tag skip/8.0.0')
writeFileSync('test8', '')
shell.exec('git add --all && git commit -m"thirteenth commit"')
shell.exec('git tag skip/9.0.0-alpha.1')
writeFileSync('test9', '')
shell.exec('git add --all && git commit -m"fourteenth commit"')
shell.exec('git tag skip/9.0.0-rc.1')
writeFileSync('test10', '')
shell.exec('git add --all && git commit -m"fifteenth commit"')
shell.exec('git tag skip/9.0.0')

gitSemverTags({ tagPrefix: 'skip/', skipUnstable: true }, function (err, tags) {
if (err) done(err)
assert.deepStrictEqual(tags, ['skip/9.0.0', 'skip/8.0.0'])
done()
})
})
})

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

1 comment on commit 0679d7a

@Wxh16144
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really need this function. When can I go to NPM store to download it

Please sign in to comment.