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: Allow commit message ONLY with --messageonly #156

Merged
merged 4 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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 .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.DS_Store
.nyc_output/
.tap
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down
11 changes: 10 additions & 1 deletion commit-to-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export const formatType = {
SHA: 'sha',
PLAINTEXT: 'plaintext',
MARKDOWN: 'markdown',
SIMPLE: 'simple'
SIMPLE: 'simple',
MESSAGEONLY: 'messageonly'
}

function toStringPlaintext (data) {
Expand Down Expand Up @@ -90,6 +91,12 @@ function toStringMarkdown (data) {
: s)
}

function toStringMessageOnly (data) {
let s = ''
s += data.summary
return ` * ${s.trim()}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let s = ''
s += data.summary
return ` * ${s.trim()}`
return ` * ${data.summary.trim()}`

}

export function commitToOutput (commit, format, ghId, commitUrl) {
const data = {}
const prUrlMatch = commit.prUrl && commit.prUrl.match(/^https?:\/\/.+\/([^/]+\/[^/]+)\/\w+\/\d+$/i)
Expand All @@ -110,6 +117,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)
Expand Down
13 changes: 9 additions & 4 deletions process-commits.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')}
Expand Down