Skip to content

Commit e67d612

Browse files
committed
fix(sha): return sha
1 parent b20ede1 commit e67d612

File tree

4 files changed

+50
-14
lines changed

4 files changed

+50
-14
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ emptyGitHubCommit({
5252
})
5353
```
5454

55+
Resolves with an object with at least `sha` property of the new commit.
56+
5557
Uses [http://mikedeboer.github.io/node-github](http://mikedeboer.github.io/node-github)
5658
to make API calls.
5759

package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"npm prune",
1212
"npm run deps",
1313
"npm test",
14-
"git add src/*.js",
14+
"git add src/*.js bin/*.js test/*.js",
1515
"npm run ban"
1616
],
1717
"pre-push": [
@@ -60,31 +60,33 @@
6060
"deps": "deps-ok && dependency-check --no-dev .",
6161
"issues": "git-issues",
6262
"license": "license-checker --production --onlyunknown --csv",
63-
"lint": "standard --verbose --fix src/*.js bin/*.js",
63+
"lint": "standard --verbose --fix src/*.js bin/*.js test/*.js",
6464
"prelint": "npm run pretty",
6565
"pretest": "npm run lint",
66-
"pretty": "prettier-standard 'src/*.js' 'bin/*.js'",
66+
"pretty": "prettier-standard 'src/*.js' 'bin/*.js' 'test/*.js'",
6767
"secure": "nsp check",
6868
"size": "t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";",
6969
"test": "npm run unit",
70-
"unit": "mocha src/*-spec.js",
70+
"unit": "mocha src/*-spec.js test/*spec.js",
7171
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
7272
},
7373
"release": {
7474
"analyzeCommits": "simple-commit-message"
7575
},
7676
"devDependencies": {
7777
"ban-sensitive-files": "1.9.0",
78+
"check-more-types": "2.24.0",
7879
"dependency-check": "2.9.1",
7980
"deps-ok": "1.2.1",
8081
"git-issues": "1.3.1",
82+
"lazy-ass": "1.6.0",
8183
"license-checker": "14.0.0",
8284
"mocha": "3.5.3",
8385
"nsp": "2.8.1",
8486
"pre-git": "3.15.3",
8587
"prettier-standard": "7.0.1",
86-
"standard": "10.0.3",
87-
"semantic-release": "^8.0.3"
88+
"semantic-release": "^8.0.3",
89+
"standard": "10.0.3"
8890
},
8991
"dependencies": {
9092
"debug": "3.1.0",

src/index.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ var createCommit = function (data) {
6565
})
6666
}
6767

68-
var updateRefrence = function (data) {
68+
var updateReference = function (data) {
6969
console.log('updating reference')
7070
return new Promise((resolve, reject) => {
7171
data.github.gitdata.updateReference(
@@ -76,12 +76,12 @@ var updateRefrence = function (data) {
7676
sha: data.newCommitSha,
7777
force: data.forceUpdate
7878
},
79-
(err, data) => {
79+
(err, res) => {
8080
if (err) {
81-
debug('updateRefrence', JSON.stringify(err, null, ' '))
81+
debug('updateReference', JSON.stringify(err, null, ' '))
8282
return reject(err)
8383
}
84-
return resolve(data)
84+
return resolve(res.data)
8585
}
8686
)
8787
})
@@ -90,8 +90,8 @@ var updateRefrence = function (data) {
9090
function emptyGitHubCommit (opts) {
9191
opts = opts || {}
9292
if (!opts.owner || !opts.repo) {
93-
console.error('missing owner or repo')
94-
return ''
93+
const e = new Error('missing owner or repo')
94+
return Promise.reject(e)
9595
}
9696
var data = {}
9797
data.github = new GitHubApi()
@@ -114,8 +114,11 @@ function emptyGitHubCommit (opts) {
114114
getReferenceCommit(data)
115115
.then(getCommitData)
116116
.then(createCommit)
117-
.then(updateRefrence)
118-
.then(resolve)
117+
.then(updateReference)
118+
.then(data => {
119+
console.log('new commit SHA', data.object.sha)
120+
resolve({ sha: data.object.sha })
121+
})
119122
.catch(error => reject(error))
120123
})
121124
}

test/spec.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict'
2+
3+
const la = require('lazy-ass')
4+
const is = require('check-more-types')
5+
const makeEmptyGithubCommit = require('..')
6+
7+
/* eslint-env mocha */
8+
describe('make-empty-github-commit', () => {
9+
const token =
10+
process.env.TOKEN || process.env.GITHUB_TOKEN || process.env.GH_TOKEN
11+
12+
if (token) {
13+
it('adds empty commit', function () {
14+
this.timeout(10000)
15+
if (!token) {
16+
throw new Error('Cannot find TOKEN or GITHUB_TOKEN or GH_TOKEN')
17+
}
18+
19+
return makeEmptyGithubCommit({
20+
owner: 'bahmutov',
21+
repo: 'test-make-empty-github-commit',
22+
message: 'this is a test',
23+
token: token
24+
}).then(result => {
25+
la(is.commitId(result.sha), 'expected to find sha in', result)
26+
})
27+
})
28+
}
29+
})

0 commit comments

Comments
 (0)