Skip to content

Commit 19a9fd4

Browse files
committed
fix: describe getBranch method
1 parent d79d116 commit 19a9fd4

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

README.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ npm install --save @cypress/commit-info
2222
const {commitInfo} = require('@cypress/commit-info')
2323
// default folder is current working directory
2424
commitInfo(folder)
25-
.then(info => {
26-
// info object will have properties
27-
// branch
28-
// message
29-
// email
30-
// author
31-
// sha
32-
// remote
33-
})
25+
.then(info => {
26+
// info object will have properties
27+
// branch
28+
// message
29+
// email
30+
// author
31+
// sha
32+
// remote
33+
})
3434
```
3535

3636
Notes:
@@ -50,9 +50,22 @@ For example
5050
```js
5151
const {getAuthor} = require('@cypress/commit-info')
5252
getAuthor('path/to/repo')
53-
.then(name => ...)
53+
.then(name => ...)
5454
```
5555

56+
### getBranch
57+
58+
Resolves with the current git branch name.
59+
60+
```js
61+
const {getBranch} = require('@cypress/commit-info')
62+
getBranch()
63+
.then(branch => ...)
64+
```
65+
66+
- First tries to get the branch from CI variables, otherwise runs a `git ...` command
67+
- If this is detached commit (reporting `HEAD`), returns an empty string
68+
5669
### Small print
5770

5871
License: MIT - do anything with the code, but don't blame me if it does not work.

src/commit-info-spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ const { gitCommands } = require('./git-api')
88
const la = require('lazy-ass')
99
const is = require('check-more-types')
1010

11+
describe('getBranch', () => {
12+
const { getBranch } = require('.')
13+
14+
it('is a function', () => {
15+
la(is.fn(getBranch))
16+
})
17+
18+
it('returns git branch', () => {
19+
return getBranch().then(branch => {
20+
// this will only fail if detached commit (HEAD)
21+
// in which case it returns an empty string
22+
la(is.unemptyString(branch), 'missing branch', branch)
23+
})
24+
})
25+
})
26+
1127
describe('commit-info', () => {
1228
const env = process.env
1329

0 commit comments

Comments
 (0)