-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
168 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
exports['commit-info returns information 1'] = { | ||
"branch": "test-branch", | ||
"message": "important commit", | ||
"email": "me@foo.com", | ||
"author": "John Doe", | ||
"sha": "abc123", | ||
"remote": "git@github.com/repo" | ||
} | ||
|
||
exports['commit-info returns empty strings for missing info 1'] = { | ||
"branch": "test-branch", | ||
"message": "", | ||
"email": "me@foo.com", | ||
"author": "", | ||
"sha": "abc123", | ||
"remote": "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
exports['utils getting commit info works 1'] = { | ||
"message": "important commit", | ||
"email": "me@foo.com", | ||
"author": "John Doe", | ||
"sha": "abc123", | ||
"remote": "git@github.com/repo" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,44 @@ | ||
'use strict' | ||
|
||
/* eslint-env mocha */ | ||
const commitInfo = require('.') | ||
const { commitInfo } = require('.') | ||
const { stubSpawnShellOnce } = require('stub-spawn-once') | ||
const snapshot = require('snap-shot-it') | ||
const { gitCommands } = require('./utils') | ||
|
||
describe('commit-info', () => { | ||
it('write this test', () => { | ||
console.assert(commitInfo, 'should export something') | ||
const env = process.env | ||
|
||
beforeEach(() => { | ||
process.env = {} | ||
}) | ||
|
||
afterEach(() => { | ||
process.env = env | ||
}) | ||
|
||
it('returns information', () => { | ||
stubSpawnShellOnce(gitCommands.branch, 0, 'test-branch', '') | ||
stubSpawnShellOnce(gitCommands.message, 0, 'important commit', '') | ||
stubSpawnShellOnce(gitCommands.email, 0, 'me@foo.com', '') | ||
stubSpawnShellOnce(gitCommands.author, 0, 'John Doe', '') | ||
stubSpawnShellOnce(gitCommands.sha, 0, 'abc123', '') | ||
stubSpawnShellOnce( | ||
gitCommands.remoteOriginUrl, | ||
0, | ||
'git@github.com/repo', | ||
'' | ||
) | ||
return commitInfo().then(snapshot) | ||
}) | ||
|
||
it('returns empty strings for missing info', () => { | ||
stubSpawnShellOnce(gitCommands.branch, 0, 'test-branch', '') | ||
stubSpawnShellOnce(gitCommands.message, 1, '', 'no message') | ||
stubSpawnShellOnce(gitCommands.email, 0, 'me@foo.com', '') | ||
stubSpawnShellOnce(gitCommands.author, 1, '', 'missing author') | ||
stubSpawnShellOnce(gitCommands.sha, 0, 'abc123', '') | ||
stubSpawnShellOnce(gitCommands.remoteOriginUrl, 1, '', 'no remote origin') | ||
return commitInfo().then(snapshot) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,29 @@ | ||
'use strict' | ||
|
||
const debug = require('debug')('commit-info') | ||
const { | ||
getBranch, | ||
getMessage, | ||
getEmail, | ||
getAuthor, | ||
getSha, | ||
getRemoteOrigin | ||
} = require('./utils') | ||
|
||
const Promise = require('bluebird') | ||
|
||
function commitInfo (folder) { | ||
folder = folder || process.cwd() | ||
debug('commit-info in folder', folder) | ||
|
||
return Promise.props({ | ||
branch: getBranch(folder), | ||
message: getMessage(folder), | ||
email: getEmail(folder), | ||
author: getAuthor(folder), | ||
sha: getSha(folder), | ||
remote: getRemoteOrigin(folder) | ||
}) | ||
} | ||
|
||
module.exports = { commitInfo } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters