From 0550b039634d260b659a990f263b82ded3dce908 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 8 Dec 2016 02:21:45 +0100 Subject: [PATCH] add `--require-label` option Add `--require-label` which is the exact opposite of `--exclude-label`. --- README.md | 1 + branch-diff.js | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 42d656d..cf7c9a8 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ But the comparison isn't quite as strict, generally leading to a shorter list of * `--version`: Only prints branch-diff's package.json version. * `--group` or `-g`: Group commits by prefix, this uses the part of the commit summary that is usually used in Node.js core to indicate subsystem for example. Groups are made up of numbers, letters, `,` and `-`, followed by a `:`. * `--exclude-label`: Exclude any commits from the list that come from a GitHub pull request with the given label. Multiple `--exclude-label` options may be provided, they will also be split by `,`. e.g. `--exclude-label=semver-major,meta`. +* `--require-label`: Only include commits in the list that come from a GitHub pull request with the given label. Multiple `--require-label` options may be provided, they will also be split by `,`. e.g. `--require-label=test,doc`. * `--patch-only`: An alias for `--exclude-label=semver-major,semver-minor`. * `--format`: Dictates what formatting the output will have. Possible options are: `simple`, `sha`. The default is to print markdown-formatted output. - `simple`: Don't print full markdown output, good for console printing without the additional fluff. diff --git a/branch-diff.js b/branch-diff.js index 6edbd95..95c239b 100755 --- a/branch-diff.js +++ b/branch-diff.js @@ -98,6 +98,14 @@ function diffCollected (options, branchCommits, callback) { }) } + if (options.requireLabels) { + list = list.filter((commit) => { + return commit.labels && commit.labels.some((label) => { + return options.requireLabels.indexOf(label) >= 0 + }) + }) + } + if (options.group) list = groupCommits(list) @@ -146,6 +154,7 @@ if (require.main === module) { , group = argv.group || argv.g , endRef = argv['end-ref'] , excludeLabels = [] + , requireLabels = [] , options @@ -164,7 +173,19 @@ if (require.main === module) { excludeLabels = excludeLabels.concat(argv['exclude-label']) } - options = { simple: format === 'simple', group, excludeLabels, endRef } + if (argv['require-label']) { + if (!Array.isArray(argv['require-label'])) + argv['require-label'] = argv['require-label'].split(',') + requireLabels = requireLabels.concat(argv['require-label']) + } + + options = { + simple: format === 'simple', + group, + excludeLabels, + requireLabels, + endRef + } branchDiff(branch1, branch2, options, (err, list) => { if (err)