Skip to content

Commit

Permalink
feat: add getSubject and getBody functions, close #2
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Oct 28, 2017
1 parent 55044c8 commit d79d116
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 1 deletion.
12 changes: 12 additions & 0 deletions __snapshots__/commit-info-spec.js
Expand Up @@ -15,3 +15,15 @@ exports['commit-info returns empty strings for missing info 1'] = {
"sha": "abc123",
"remote": ""
}

exports['commit-info has certain api 1'] = [
"commitInfo",
"getBranch",
"getMessage",
"getEmail",
"getAuthor",
"getSha",
"getRemoteOrigin",
"getSubject",
"getBody"
]
5 changes: 5 additions & 0 deletions __snapshots__/git-api-spec.js
Expand Up @@ -5,3 +5,8 @@ exports['git-api getting commit info works 1'] = {
"sha": "abc123",
"remote": "git@github.com/repo"
}

exports['git-api subject and body gets subject and body 1'] = {
"subject": "commit does this",
"body": "more details"
}
5 changes: 5 additions & 0 deletions src/commit-info-spec.js
Expand Up @@ -19,6 +19,11 @@ describe('commit-info', () => {
process.env = env
})

it('has certain api', () => {
const api = require('.')
snapshot(Object.keys(api))
})

it('returns information', () => {
stubSpawnShellOnce(gitCommands.branch, 0, 'test-branch', '')
stubSpawnShellOnce(gitCommands.message, 0, 'important commit', '')
Expand Down
13 changes: 13 additions & 0 deletions src/git-api-spec.js
Expand Up @@ -10,6 +10,19 @@ const snapshot = require('snap-shot-it')
describe('git-api', () => {
const { gitCommands } = require('./git-api')

describe('subject and body', () => {
const { getSubject, getBody } = require('./git-api')

it('gets subject and body', () => {
stubSpawnShellOnce(gitCommands.subject, 0, 'commit does this', '')
stubSpawnShellOnce(gitCommands.body, 0, 'more details', '')
return Promise.props({
subject: getSubject(),
body: getBody()
}).then(snapshot)
})
})

describe('getting commit info', () => {
const {
getMessage,
Expand Down
9 changes: 9 additions & 0 deletions src/git-api.js
Expand Up @@ -5,9 +5,12 @@ const la = require('lazy-ass')
const is = require('check-more-types')

// common git commands for getting basic info
// https://git-scm.com/docs/git-show
const gitCommands = {
branch: 'git rev-parse --abbrev-ref HEAD',
message: 'git show -s --pretty=%B',
subject: 'git show -s --pretty=%s',
body: 'git show -s --pretty=%b',
email: 'git show -s --pretty=%ae',
author: 'git show -s --pretty=%an',
sha: 'git show -s --pretty=%H',
Expand Down Expand Up @@ -53,6 +56,10 @@ function getGitBranch (pathToRepo) {

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

const getSubject = runGitCommand.bind(null, gitCommands.subject)

const getBody = runGitCommand.bind(null, gitCommands.body)

const getEmail = runGitCommand.bind(null, gitCommands.email)

const getAuthor = runGitCommand.bind(null, gitCommands.author)
Expand All @@ -64,6 +71,8 @@ const getRemoteOrigin = runGitCommand.bind(null, gitCommands.remoteOriginUrl)
module.exports = {
runGitCommand,
getGitBranch,
getSubject,
getBody,
getMessage,
getEmail,
getAuthor,
Expand Down
6 changes: 5 additions & 1 deletion src/index.js
Expand Up @@ -2,6 +2,8 @@

const debug = require('debug')('commit-info')
const {
getSubject,
getBody,
getMessage,
getEmail,
getAuthor,
Expand Down Expand Up @@ -33,5 +35,7 @@ module.exports = {
getEmail,
getAuthor,
getSha,
getRemoteOrigin
getRemoteOrigin,
getSubject,
getBody
}

0 comments on commit d79d116

Please sign in to comment.