Skip to content

Commit e899dce

Browse files
committed
feature: make the commit url configurable via an additional argument
`--commit-url` can be passed in for repositories not hosted on Github, allowing the commit URLs to be properly referenced in the output. `{sha}` serves as the part of the string which will be replaced/ PR-URL: nodejs/changelog-maker#55
1 parent 703316d commit e899dce

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ $ npm i changelog-maker -g
4444

4545
## Usage
4646

47-
**`changelog-maker [--simple] [--group] [--start-ref=<ref>] [--end-ref=<ref>] [github-user[, github-project]]`**
47+
**`changelog-maker [--simple] [--group] [--commit-url=<url/with/{ref}>] [--start-ref=<ref>] [--end-ref=<ref>] [github-user[, github-project]]`**
4848

4949
`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
5050

5151
* `--simple`: print a simple form, without additional Markdown cruft
5252
* `--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.
53+
* `--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}`
5354
* `--start-ref=<ref>`: use the given git `<ref>` as a starting point rather than the _last tag_. The `<ref>` can be anything commit-ish including a commit sha, tag, branch name. If you specify a `--start-ref` argument the commit log will not be pruned so that version commits and `working on <version>` commits are left in the list.
5455
* `--end-ref=<ref>`: use the given git `<ref>` as a end-point rather than the _now_. The `<ref>` can be anything commit-ish including a commit sha, tag, branch name.
5556
* `--filter-release`: exclude Node-style release commits from the list. e.g. "Working on v1.0.0" or "2015-10-21 Version 2.0.0" and also "npm version X" style commits containing _only_ an `x.y.z` semver designator.

changelog-maker.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const bl = require('bl')
1919
, quiet = argv.quiet || argv.q
2020
, simple = argv.simple || argv.s
2121
, help = argv.h || argv.help
22+
, commitUrl = argv["commit-url"]
2223

2324
, pkg = require('./package.json')
2425
, debug = require('debug')(pkg.name)
@@ -115,7 +116,7 @@ function onCommitList (err, list) {
115116
list = groupCommits(list)
116117

117118
list = list.map(function (commit) {
118-
return commitToOutput(commit, simple, ghId)
119+
return commitToOutput(commit, simple, ghId, commitUrl)
119120
})
120121

121122
if (!quiet)

commit-to-output.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,15 @@ function toStringMarkdown (data) {
4747
}
4848

4949

50-
function commitToOutput (commit, simple, ghId) {
50+
function commitToOutput (commit, simple, ghId, commitUrl) {
5151
var data = {}
5252
, prUrlMatch = commit.prUrl && commit.prUrl.match(/^https?:\/\/.+\/([^\/]+\/[^\/]+)\/\w+\/\d+$/i)
5353
, urlHash = '#'+commit.ghIssue || commit.prUrl
5454
, ghUrl = ghId.user + '/' + ghId.name
55+
, ref = commit.sha.substr(0, 10)
5556

5657
data.sha = commit.sha
57-
data.shaUrl = 'https://github.com/' + ghUrl + '/commit/' + commit.sha.substr(0,10)
58+
data.shaUrl = commitUrl ? commitUrl.replace("{ref}", ref) : 'https://github.com/' + ghUrl + '/commit/' + ref
5859
data.semver = commit.labels && commit.labels.filter(function (l) { return l.indexOf('semver') > -1 }) || false
5960
data.revert = reverts.isRevert(commit.summary)
6061
data.group = groups.toGroups(commit.summary)

0 commit comments

Comments
 (0)