Skip to content

Commit 21ab03d

Browse files
committed
feat: pass commit to json, close #15
1 parent b7ccfd8 commit 21ab03d

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,16 @@ the commit message using provided function
124124
```js
125125
const {getInstallJson} = require('commit-message-install')
126126
// package(s), env, platform, branch name (optional)
127-
const json = getInstallJson('foo', {foo: 42}, 'linux', 'test-branch')
127+
const json = getInstallJson('foo',
128+
{foo: 42}, 'linux', 'test-branch', 'b7ccfd8')
128129
// returns an object
129-
// {platform: "linux", env: {foo: 42}, packages: "foo", branch: "test-branch"}
130+
// {
131+
// platform: "linux",
132+
// env: {foo: 42},
133+
// packages: "foo",
134+
// branch: "test-branch",
135+
// commit: "b7ccfd8"
136+
// }
130137
```
131138

132139
You can pass individual package name like `debug` or several as a single string

__snapshots__/get-install-json-spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,10 @@ exports['getInstallJson sets branch 1'] = {
2626
"packages": "debug chalk",
2727
"branch": "test-branch"
2828
}
29+
30+
exports['getInstallJson sets commit 1'] = {
31+
"platform": "linux",
32+
"env": {},
33+
"packages": "debug chalk",
34+
"commit": "b7ccfd8"
35+
}

src/get-install-json-spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ describe('getInstallJson', () => {
2727
it('sets branch', () => {
2828
snapshot(getInstallJson(['debug', 'chalk'], {}, 'linux', 'test-branch'))
2929
})
30+
31+
it('sets commit', () => {
32+
snapshot(getInstallJson(['debug', 'chalk'], {}, 'linux', null, 'b7ccfd8'))
33+
})
3034
})

src/get-install-json.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const debug = require('debug')('commit-message-install')
55
const { isNpmInstall } = require('./utils')
66

77
// forms JSON object that can be parsed later
8-
function getInstallJson (packages, env, platform, branch) {
8+
function getInstallJson (packages, env, platform, branch, commit) {
99
if (!env) {
1010
env = {}
1111
}
@@ -33,6 +33,14 @@ function getInstallJson (packages, env, platform, branch) {
3333
debug('branch name', branch)
3434
json.branch = branch
3535
}
36+
if (commit) {
37+
la(
38+
is.commitId(commit) || is.shortCommitId(commit),
39+
'invalid commit',
40+
commit
41+
)
42+
json.commit = commit
43+
}
3644

3745
la(
3846
isNpmInstall(json),

0 commit comments

Comments
 (0)