Skip to content

Commit e8bd06a

Browse files
committed
feat: add branch name argument to API, close #3
1 parent 202cfe2 commit e8bd06a

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ You can pass repo in different format, it will be parsed using
3232
Optional arguments:
3333

3434
```
35-
--branch <master>
35+
--branch <master>
3636
```
3737

3838
Aliases: `--repo -r`, `--message -m`, `--branch -b`
@@ -49,7 +49,7 @@ emptyGitHubCommit({
4949
repo: 'repo name',
5050
token: process.env.TOKEN,
5151
message: 'my message',
52-
fullyQualifiedRef: 'heads/develop'
52+
branch: 'develop' // "master" is default
5353
}).then(console.log, e => {
5454
console.error(e)
5555
process.exit(1)
@@ -63,7 +63,7 @@ to make API calls.
6363

6464
### Testing
6565

66-
To test this project I created dummy repo
66+
To test this project I created dummy repo
6767
[test-make-empty-github-commit](https://github.com/bahmutov/test-make-empty-github-commit).
6868
See its [commit history](https://github.com/bahmutov/test-make-empty-github-commit/commits/master)
6969
to see empty commit messages created from this repository using

bin/empty.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ emptyGitHubCommit({
4545
repo: repo,
4646
token: token,
4747
message: options.message,
48-
fullyQualifiedRef: `heads/${options.branch}`
48+
branch: options.branch
4949
}).then(console.log, e => {
5050
console.error(e)
5151
process.exit(1)

src/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,14 @@ function emptyGitHubCommit (opts) {
103103
}
104104
data.owner = opts.owner
105105
data.repo = opts.repo
106-
data.fullyQualifiedRef = opts.fullyQualifiedRef || 'heads/master'
106+
107+
if (opts.branch) {
108+
data.fullyQualifiedRef = `heads/${opts.branch}`
109+
} else {
110+
const defaultRef = 'heads/master'
111+
data.fullyQualifiedRef = opts.fullyQualifiedRef || defaultRef
112+
}
113+
107114
data.forceUpdate = opts.forceUpdate || false
108115
data.commitMessage =
109116
opts.message ||
@@ -131,7 +138,7 @@ if (!module.parent) {
131138
owner: 'bahmutov',
132139
repo: 'commit-to-github',
133140
token: process.env.TOKEN,
134-
fullyQualifiedRef: 'heads/master'
141+
branch: 'master'
135142
}).then(console.log, e => {
136143
console.error(e)
137144
process.exit(1)

0 commit comments

Comments
 (0)