Skip to content

Commit d79d116

Browse files
committed
feat: add getSubject and getBody functions, close #2
1 parent 55044c8 commit d79d116

File tree

6 files changed

+49
-1
lines changed

6 files changed

+49
-1
lines changed

__snapshots__/commit-info-spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,15 @@ exports['commit-info returns empty strings for missing info 1'] = {
1515
"sha": "abc123",
1616
"remote": ""
1717
}
18+
19+
exports['commit-info has certain api 1'] = [
20+
"commitInfo",
21+
"getBranch",
22+
"getMessage",
23+
"getEmail",
24+
"getAuthor",
25+
"getSha",
26+
"getRemoteOrigin",
27+
"getSubject",
28+
"getBody"
29+
]

__snapshots__/git-api-spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@ exports['git-api getting commit info works 1'] = {
55
"sha": "abc123",
66
"remote": "[email protected]/repo"
77
}
8+
9+
exports['git-api subject and body gets subject and body 1'] = {
10+
"subject": "commit does this",
11+
"body": "more details"
12+
}

src/commit-info-spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ describe('commit-info', () => {
1919
process.env = env
2020
})
2121

22+
it('has certain api', () => {
23+
const api = require('.')
24+
snapshot(Object.keys(api))
25+
})
26+
2227
it('returns information', () => {
2328
stubSpawnShellOnce(gitCommands.branch, 0, 'test-branch', '')
2429
stubSpawnShellOnce(gitCommands.message, 0, 'important commit', '')

src/git-api-spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ const snapshot = require('snap-shot-it')
1010
describe('git-api', () => {
1111
const { gitCommands } = require('./git-api')
1212

13+
describe('subject and body', () => {
14+
const { getSubject, getBody } = require('./git-api')
15+
16+
it('gets subject and body', () => {
17+
stubSpawnShellOnce(gitCommands.subject, 0, 'commit does this', '')
18+
stubSpawnShellOnce(gitCommands.body, 0, 'more details', '')
19+
return Promise.props({
20+
subject: getSubject(),
21+
body: getBody()
22+
}).then(snapshot)
23+
})
24+
})
25+
1326
describe('getting commit info', () => {
1427
const {
1528
getMessage,

src/git-api.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ const la = require('lazy-ass')
55
const is = require('check-more-types')
66

77
// common git commands for getting basic info
8+
// https://git-scm.com/docs/git-show
89
const gitCommands = {
910
branch: 'git rev-parse --abbrev-ref HEAD',
1011
message: 'git show -s --pretty=%B',
12+
subject: 'git show -s --pretty=%s',
13+
body: 'git show -s --pretty=%b',
1114
email: 'git show -s --pretty=%ae',
1215
author: 'git show -s --pretty=%an',
1316
sha: 'git show -s --pretty=%H',
@@ -53,6 +56,10 @@ function getGitBranch (pathToRepo) {
5356

5457
const getMessage = runGitCommand.bind(null, gitCommands.message)
5558

59+
const getSubject = runGitCommand.bind(null, gitCommands.subject)
60+
61+
const getBody = runGitCommand.bind(null, gitCommands.body)
62+
5663
const getEmail = runGitCommand.bind(null, gitCommands.email)
5764

5865
const getAuthor = runGitCommand.bind(null, gitCommands.author)
@@ -64,6 +71,8 @@ const getRemoteOrigin = runGitCommand.bind(null, gitCommands.remoteOriginUrl)
6471
module.exports = {
6572
runGitCommand,
6673
getGitBranch,
74+
getSubject,
75+
getBody,
6776
getMessage,
6877
getEmail,
6978
getAuthor,

src/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
const debug = require('debug')('commit-info')
44
const {
5+
getSubject,
6+
getBody,
57
getMessage,
68
getEmail,
79
getAuthor,
@@ -33,5 +35,7 @@ module.exports = {
3335
getEmail,
3436
getAuthor,
3537
getSha,
36-
getRemoteOrigin
38+
getRemoteOrigin,
39+
getSubject,
40+
getBody
3741
}

0 commit comments

Comments
 (0)