Skip to content
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ 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`, `messageonly` and `sha`. The default is to print a `simple` output suitable for stdout.
- `sequence`: hybrid format that can be pasted directly in the sequence editor of a `git rebase --interactive` session, without retaining info such as commit title, author, labels, PR URL.
- `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`.
Expand Down
15 changes: 11 additions & 4 deletions commit-to-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const formatType = {
SHA: 'sha',
PLAINTEXT: 'plaintext',
MARKDOWN: 'markdown',
SEQUENCE: 'sequence',
SIMPLE: 'simple',
MESSAGEONLY: 'messageonly'
}
Expand All @@ -58,18 +59,21 @@ function toStringPlaintext (data) {
return ` * ${s.trim()}`
}

function toStringSimple (data) {
function toStringSimple (data, withLabels = false) {
let s = ''
s += `* [${data.sha.substr(0, 10)}] - `
s += (data.semver || []).length ? `(${data.semver.join(', ').toUpperCase()}) ` : ''
s += data.revert ? 'Revert "' : ''
s += data.group ? `${data.group}: ` : ''
s += data.summary
s += data.revert ? '" ' : ' '
s += data.author ? `(${data.author}) ` : ''
s += data.pr ? data.prUrl : ''
s = s.trim()
if (withLabels) s += ' (' + data.labels.join(', ') + ')'
return s.trim()
}

function toStringSimpleWithListMarker (data) {
const s = `* [${data.sha.substr(0, 10)}] - ${toStringSimple(data)}`
return (data.semver && data.semver.length)
? chalk.green.bold(s)
: (data.group === 'doc'
Expand Down Expand Up @@ -110,6 +114,7 @@ export function commitToOutput (commit, format, ghId, commitUrl) {
data.sha = commit.sha
data.shaUrl = commitUrl.replace(/\{ghUser\}/g, ghId.user).replace(/\{ghRepo\}/g, ghId.repo).replace(/\{ref\}/g, ref)
data.semver = commit.labels && commit.labels.filter((l) => l.includes('semver'))
data.labels = commit.labels
data.revert = isRevert(commit.summary)
data.group = toGroups(commit.summary)
data.summary = cleanGroupSummary(cleanRevertSummary(commit.summary))
Expand All @@ -119,7 +124,9 @@ export function commitToOutput (commit, format, ghId, commitUrl) {
data.cveId = commit.cveId

if (format === formatType.SIMPLE) {
return toStringSimple(data)
return toStringSimpleWithListMarker(data)
} else if (format === formatType.SEQUENCE) {
return toStringSimple(data, true)
} else if (format === formatType.PLAINTEXT) {
return toStringPlaintext(data)
} else if (format === formatType.MESSAGEONLY) {
Expand Down
2 changes: 2 additions & 0 deletions process-commits.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export async function processCommits (argv, ghId, list) {

if (format === formatType.SHA) {
list = list.map((commit) => `${commit.sha.substr(0, 10)}`)
} else if (format === formatType.SEQUENCE) {
list = list.map((commit) => `pick ${commit.sha} # ${commitToOutput(commit, format, ghId, commitUrl)}`)
} else if (
format === formatType.PLAINTEXT ||
format === formatType.MESSAGEONLY
Expand Down
12 changes: 12 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ test('test simple', (t) => {
`)
t.end()
})
test('test sequence', (t) => {
t.equal(exec('--start-ref=v2.2.7 --end-ref=9c700d29 --group --filter-release --format=sequence'),
`pick cc442b65343cd1bb7cb4ecc3c6e729b4e4625f97 # (SEMVER-MINOR) minor nit (Rod Vagg) https://github.com/nodejs/node/pull/23715
pick 4f2b7f8136358bc3ecd720e33457fdeff9581733 # deps: use strip-ansi instead of chalk.stripColor (Rod Vagg)
pick 6898501e18f231db40a84b511d2a6a4b8f5f17f3 # deps: update deps, introduce test & lint deps (Rod Vagg)
pick 9c700d29104b5a22fcf79ba21f5f009d7f1cdfc5 # feature: refactor and improve --commit-url (Rod Vagg)
pick 50945246557b4a25133435b106d0e5dd5d88a9be # feature: make the commit url configurable via an additional argument (Jim Nielsen) https://github.com/nodejs/changelog-maker/pull/55
pick 42f248cf8904224a585e9f3834cc1283713c56cf # src: use \`standard\` for linting (Rod Vagg)
pick 64a8fdef3c35627ca50c48e9acb80c57a3f6d2a2 # test: basic test infrastructure (Rod Vagg)
`)
t.end()
})

test('test plaintext', (t) => {
t.equal(exec('--start-ref=9c700d2 --end-ref=dd937e9 --group --filter-release --plaintext'),
Expand Down
Loading