diff --git a/.gitignore b/.gitignore index 7f7c5cb..7609ad9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules .DS_Store .nyc_output/ +.tap diff --git a/README.md b/README.md index 5b585f4..acd5225 100644 --- a/README.md +++ b/README.md @@ -48,14 +48,16 @@ npm i changelog-maker -g `github-user` and `github-project` should point to the GitHub repository that can be used to find the `PR-URL` data if just an issue number is provided and will also impact how the PR-URL issue numbers are displayed -* `--format`: dictates what formatting the output will have. Possible options are: `simple`, `markdown`, `plaintext`, and `sha`. The default is to print a `simple` output suitable for stdout. +* `--format`: dictates what formatting the output will have. Possible options are: `simple`, `markdown`, `plaintext`, `messageonly` and `sha`. The default is to print a `simple` output suitable for stdout. - `simple`: don't print full markdown output, good for console printing without the additional fluff. - `sha`: print only the 10-character truncated commit hashes. - `plaintext`: a very simple form, without commit details, implies `--group`. - `markdown`: a Markdown formatted from, with links and proper escaping. + - `messageonly`: displays the commit message only, implies `--group` * `--sha`: same as `--format=sha`. * `--plaintext`: same as `--format=plaintext`. * `--markdown`: same as `--format=markdown`. +* `--messageonly`: same as `--format=messageonly`. * `--group`: reorder commits so that they are listed in groups where the `xyz:` prefix of the commit message defines the group. Commits are listed in original order _within_ group. * `--reverse`: reverse the order of commits when printed, does not work with `--reverse` * `--commit-url`: pass in a url template which will be used to generate commit URLs for a repository not hosted in Github. `{ref}` is the placeholder that will be replaced with the commit, i.e. `--commit-url=https://gitlab.com/myUser/myRepo/commit/{ref}` diff --git a/commit-to-output.js b/commit-to-output.js index 8acd536..7023ada 100644 --- a/commit-to-output.js +++ b/commit-to-output.js @@ -33,7 +33,8 @@ export const formatType = { SHA: 'sha', PLAINTEXT: 'plaintext', MARKDOWN: 'markdown', - SIMPLE: 'simple' + SIMPLE: 'simple', + MESSAGEONLY: 'messageonly' } function toStringPlaintext (data) { @@ -90,6 +91,10 @@ function toStringMarkdown (data) { : s) } +function toStringMessageOnly (data) { + return ` * ${data.summary.trim()}` +} + export function commitToOutput (commit, format, ghId, commitUrl) { const data = {} const prUrlMatch = commit.prUrl && commit.prUrl.match(/^https?:\/\/.+\/([^/]+\/[^/]+)\/\w+\/\d+$/i) @@ -110,6 +115,8 @@ export function commitToOutput (commit, format, ghId, commitUrl) { return toStringSimple(data) } else if (format === formatType.PLAINTEXT) { return toStringPlaintext(data) + } else if (format === formatType.MESSAGEONLY) { + return toStringMessageOnly(data) } return toStringMarkdown(data) diff --git a/process-commits.js b/process-commits.js index 450ff43..f3fa685 100644 --- a/process-commits.js +++ b/process-commits.js @@ -16,6 +16,8 @@ function getFormat (argv) { return formatType.PLAINTEXT } else if (argv.markdown || argv.md) { return formatType.MARKDOWN + } else if (argv.messageonly || argv.mo) { + return formatType.MESSAGEONLY } return formatType.SIMPLE } @@ -42,23 +44,26 @@ export async function processCommits (argv, ghId, list) { const format = getFormat(argv) - if (argv.group || argv.g || format === formatType.PLAINTEXT) { + if (argv.group || argv.g || format === formatType.PLAINTEXT || format === formatType.MESSAGEONLY) { list = groupCommits(list) } if (format === formatType.SHA) { list = list.map((commit) => `${commit.sha.substr(0, 10)}`) - } else if (format === formatType.PLAINTEXT) { + } else if ( + format === formatType.PLAINTEXT || + format === formatType.MESSAGEONLY + ) { const formatted = [] let currentGroup for (const commit of list) { const commitGroup = toGroups(commit.summary) if (currentGroup !== commitGroup) { - formatted.push(`${commitGroup}:`) + formatted.push(commitGroup ? `${commitGroup}:` : '') currentGroup = commitGroup } - formatted.push(commitToOutput(commit, formatType.PLAINTEXT, ghId, commitUrl)) + formatted.push(commitToOutput(commit, format, ghId, commitUrl)) } list = formatted } else { diff --git a/test.js b/test.js index c984436..27fe14e 100644 --- a/test.js +++ b/test.js @@ -55,6 +55,16 @@ test: t.end() }) +test('test messageonly', (t) => { + t.equal(exec('--start-ref=9c700d2 --end-ref=dd937e9 --group --filter-release --messageonly'), + `feature: + * refactor and improve --commit-url +test: + * update refs for testing +`) + t.end() +}) + test('test group, semver labels, PR-URL', (t) => { t.equal(exec('--start-ref=v2.2.7 --end-ref=9c700d29 --group --filter-release'), `${chalk.green.bold('* [cc442b6534] - (SEMVER-MINOR) minor nit (Rod Vagg) https://github.com/nodejs/node/pull/23715')}