File tree Expand file tree Collapse file tree 2 files changed +39
-10
lines changed
Expand file tree Collapse file tree 2 files changed +39
-10
lines changed Original file line number Diff line number Diff line change @@ -22,15 +22,15 @@ npm install --save @cypress/commit-info
2222const {commitInfo } = require (' @cypress/commit-info' )
2323// default folder is current working directory
2424commitInfo (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
3636Notes:
@@ -50,9 +50,22 @@ For example
5050``` js
5151const {getAuthor } = require (' @cypress/commit-info' )
5252getAuthor (' 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
5871License: MIT - do anything with the code, but don't blame me if it does not work.
Original file line number Diff line number Diff line change @@ -8,6 +8,22 @@ const { gitCommands } = require('./git-api')
88const la = require ( 'lazy-ass' )
99const 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+
1127describe ( 'commit-info' , ( ) => {
1228 const env = process . env
1329
You can’t perform that action at this time.
0 commit comments