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

Feat add parser opts #821

Open
wants to merge 6 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,26 @@ If you do not want to have any tag prefix you can use the `-t` flag and provide

> Note: simply -t or --tag-prefix without any value will fallback to the default 'v'

### Parser Options

If you need to include custom parser options to read your commits, you can use the `--parser-opts` to indicate the path to a .js file that exports the options.

```sh
standard-version --parser-opts ./parser-opts.js
```

This can be useful in cases like Azure DevOps that uses custom merge pull request titles. The `parser-opts.js` could look like this:

```js
/** @type {import("conventional-commits-parser").Options} */
module.exports = {
mergePattern: /^Merged PR (\d+): (\w*)(?:\(([\w\$\.\-\* ]*)\))?\: (.*)$/,
mergeCorrespondence: ['id', 'type', 'scope', 'subject']
}
```

For more informantion on what parser options are available, reference to [documentation](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-commits-parser).

### CLI Help

```sh
Expand Down
4 changes: 4 additions & 0 deletions command.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ const yargs = require('yargs')
default: defaults.preset,
describe: 'Commit message guideline preset'
})
.option('parser-opts', {
type: 'string',
describe: 'Path to file with Conventional Commits Parser Options'
})
.option('lerna-package', {
type: 'string',
describe: 'Name of the package from which the tags will be extracted'
Expand Down
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ module.exports = async function standardVersion (argv) {
throw Error(`custom changelog header must not match ${changelog.START_OF_LAST_RELEASE_PATTERN}`)
}

if (typeof argv.parserOpts === 'string') {
const parserOptsPath = path.resolve(argv.parserOpts)
try {
argv.parserOpts = require(parserOptsPath)
} catch(err) {
argv.parserOpts = null
}
}

/**
* If an argument for `packageFiles` provided, we include it as a "default" `bumpFile`.
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/lifecycles/bump.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function bumpVersion (releaseAs, currentVersion, args) {
path: args.path,
tagPrefix: args.tagPrefix,
lernaPackage: args.lernaPackage
}, function (err, release) {
}, args.parserOpts, function (err, release) {
if (err) return reject(err)
else return resolve(release)
})
Expand Down
2 changes: 1 addition & 1 deletion lib/lifecycles/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function outputChangelog (args, newVersion) {
debug: args.verbose && console.info.bind(console, 'conventional-changelog'),
preset: presetLoader(args),
tagPrefix: args.tagPrefix
}, context, { merges: null, path: args.path })
}, context, { merges: null, path: args.path }, args.parserOpts)
.on('error', function (err) {
return reject(err)
})
Expand Down