Skip to content

Commit

Permalink
fix: describe getBranch method
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Oct 29, 2017
1 parent d79d116 commit 19a9fd4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
33 changes: 23 additions & 10 deletions README.md
Expand Up @@ -22,15 +22,15 @@ npm install --save @cypress/commit-info
const {commitInfo} = require('@cypress/commit-info')
// default folder is current working directory
commitInfo(folder)
.then(info => {
// info object will have properties
// branch
// message
// email
// author
// sha
// remote
})
.then(info => {
// info object will have properties
// branch
// message
// email
// author
// sha
// remote
})
```

Notes:
Expand All @@ -50,9 +50,22 @@ For example
```js
const {getAuthor} = require('@cypress/commit-info')
getAuthor('path/to/repo')
.then(name => ...)
.then(name => ...)
```

### getBranch

Resolves with the current git branch name.

```js
const {getBranch} = require('@cypress/commit-info')
getBranch()
.then(branch => ...)
```

- First tries to get the branch from CI variables, otherwise runs a `git ...` command
- If this is detached commit (reporting `HEAD`), returns an empty string

### Small print

License: MIT - do anything with the code, but don't blame me if it does not work.
Expand Down
16 changes: 16 additions & 0 deletions src/commit-info-spec.js
Expand Up @@ -8,6 +8,22 @@ const { gitCommands } = require('./git-api')
const la = require('lazy-ass')
const is = require('check-more-types')

describe('getBranch', () => {
const { getBranch } = require('.')

it('is a function', () => {
la(is.fn(getBranch))
})

it('returns git branch', () => {
return getBranch().then(branch => {
// this will only fail if detached commit (HEAD)
// in which case it returns an empty string
la(is.unemptyString(branch), 'missing branch', branch)
})
})
})

describe('commit-info', () => {
const env = process.env

Expand Down

0 comments on commit 19a9fd4

Please sign in to comment.