Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(conventional-recommended-bump) Specify base tag to analyze tags from #777

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/conventional-changelog-cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const cli = meow(`
-c, --context A filepath of a json that is used to define template variables
-l, --lerna-package Generate a changelog for a specific lerna package (:pkg-name@1.0.0)
-t, --tag-prefix Tag prefix to consider when reading the tags
--tag-from Tag to start reading from when reading the tags
--commit-path Generate a changelog scoped to a specific directory
`, {
booleanDefault: undefined,
Expand Down Expand Up @@ -171,7 +172,9 @@ try {
process.exit(1)
}

const gitRawCommitsOpts = _.merge({}, config.gitRawCommitsOpts || {})
const gitRawCommitsOpts = _.merge({
from: flags.tagFrom
}, config.gitRawCommitsOpts || {})
if (flags.commitPath) gitRawCommitsOpts.path = flags.commitPath

const changelogStream = conventionalChangelog(options, templateContext, gitRawCommitsOpts, config.parserOpts, config.writerOpts)
Expand Down
45 changes: 30 additions & 15 deletions packages/conventional-recommended-bump/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,27 @@ Got the idea from https://github.com/conventional-changelog/conventional-changel
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->


- [Install](#install)
- [Usage](#usage)
- [API](#api)
- [options](#options)
- [ignoreReverted](#ignorereverted)
- [preset](#preset)
- [config](#config)
- [whatBump](#whatbump)
- [tagPrefix](#tagprefix)
- [skipUnstable](#skipunstable)
- [lernaPackage](#lernapackage)
- [path](#path)
- [parserOpts](#parseropts)
- [callback](#callback)
- [License](#license)
- [conventional-recommended-bump](#conventional-recommended-bump)
- [Table of Contents](#table-of-contents)
- [Install](#install)
- [Usage](#usage)
- [API](#api)
- [options](#options)
- [ignoreReverted](#ignorereverted)
- [preset](#preset)
- [config](#config)
- [whatBump](#whatbump)
- [tagPrefix](#tagprefix)
- [skipUnstable](#skipunstable)
- [lernaPackage](#lernapackage)
- [path](#path)
- [tagFrom](#tagfrom)
- [parserOpts](#parseropts)
- [callback](#callback)
- [Debugging](#debugging)
- [Node Support Policy](#node-support-policy)
- [Contributing](#contributing)
- [License](#license)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Expand Down Expand Up @@ -68,6 +74,7 @@ In the case you don't want to provide `parserOpts`, then `callback` must be prov
* preset
* config
* whatBump
* tagFrom

##### ignoreReverted

Expand Down Expand Up @@ -133,6 +140,14 @@ For instance if your project contained a package named `conventional-changelog`,

Specify the path to only calculate with git commits related to the path. If you want to calculate recommended bumps of packages in a [Lerna](https://lernajs.io/)-managed repository, `path` should be use along with `lernaPackage` for each of the package.

##### tagFrom

**Type:** `string`

Specify the base tag to use as the base from which to analyze the commits. Can be any tag, not just a semver tag.

If not specified the most recent semver tag will be chosen.

#### parserOpts

**Type:** `object`
Expand Down
6 changes: 6 additions & 0 deletions packages/conventional-recommended-bump/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const cli = meow(`
-t, --tag-prefix Tag prefix to consider when reading the tags
--commit-path Recommend a bump scoped to a specific directory
--skip-unstable If given, unstable tags will be skipped, e.g., x.x.x-alpha.1, x.x.x-rc.2
--tag-from Tag to start reading from when reading the tags
`, {
flags: {
preset: {
Expand Down Expand Up @@ -83,6 +84,11 @@ if (preset) {
delete flags.config
}

if (flags.tagFrom) {
options.tagFrom = flags.tagFrom
delete flags.tagFrom
}

if (flags.verbose) {
options.warn = console.warn.bind(console)
}
Expand Down
8 changes: 6 additions & 2 deletions packages/conventional-recommended-bump/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,15 @@ function conventionalRecommendedBump (optionsArgument, parserOptsArgument, cbArg
return cb(err)
}

gitRawCommits({
const commitStream = gitRawCommits({
format: '%B%n-hash-%n%H',
from: tags[0] || '',
from: options.tagFrom || tags[0] || '',
path: options.path
})

commitStream.on('error', cb)

commitStream
.pipe(conventionalCommitsParser(parserOpts))
.pipe(concat(data => {
const commits = options.ignoreReverted ? conventionalCommitsFilter(data) : data
Expand Down
31 changes: 31 additions & 0 deletions packages/conventional-recommended-bump/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ betterThanBefore.setups([
() => { // 7
shell.exec('git tag my-package@1.0.0')
gitDummyCommit(['feat: this should have been working'])
},
() => { // 8
gitDummyCommit(['feat: should not be taken into account - at not-a-version', 'BREAKING CHANGE: I broke the API'])
shell.exec('git tag not-a-version')
gitDummyCommit(['feat: this should have been working - post not-a-version'])
}
])

Expand Down Expand Up @@ -336,4 +341,30 @@ describe('conventional-recommended-bump API', () => {
}, () => {})
})
})

describe('optional tagFrom', () => {
it('should return an error when tagFrom option references a non-existent tag', done => {
preparing(8)

conventionalRecommendedBump({
tagFrom: 'not-an-existing-tag'
}, {}, err => {
assert.ok(err)
done()
})
})

it('should recommend \'minor\' version bump when tagFrom option is set to an existing arbitrary tag', done => {
preparing(8)

conventionalRecommendedBump({
tagFrom: 'not-a-version',
whatBump: commits => {
assert.strictEqual(commits[0].type, 'feat')
assert.strictEqual(commits.length, 1)
done()
}
}, () => {})
})
})
})