Skip to content

Commit 3f85597

Browse files
umireongr2m
authored andcommitted
fix(post): Create a tag before makeing a release
1 parent f148a61 commit 3f85597

3 files changed

Lines changed: 27 additions & 19 deletions

File tree

src/post.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,18 @@ module.exports = function (config, cb) {
2424
if (err) return cb(err)
2525

2626
var ghRepo = parseSlug(pkg.repository.url)
27+
var tag = {
28+
owner: ghRepo[0],
29+
repo: ghRepo[1],
30+
ref: 'refs/heads/v' + pkg.version,
31+
sha: hash
32+
}
2733
var release = {
2834
owner: ghRepo[0],
2935
repo: ghRepo[1],
30-
name: 'v' + pkg.version,
3136
tag_name: 'v' + pkg.version,
32-
target_commitish: hash,
37+
name: 'v' + pkg.version,
38+
target_commitish: options.branch,
3339
draft: !!options.debug,
3440
body: log
3541
}
@@ -43,18 +49,18 @@ module.exports = function (config, cb) {
4349
token: options.githubToken
4450
})
4551

46-
github.repos.createRelease(release, function (err, res) {
47-
if (err) return cb(err)
48-
if (options.debug) return cb(null, true, release)
52+
if (options.debug) {
53+
return github.repos.createRelease(release, function (err) {
54+
if (err) return cb(err)
55+
56+
cb(null, true, release)
57+
})
58+
}
4959

50-
var editingRelease = {
51-
owner: ghRepo[0],
52-
repo: ghRepo[1],
53-
id: res.id,
54-
target_commitish: options.branch
55-
}
60+
github.gitdata.createReference(tag, function (err) {
61+
if (err) return cb(err)
5662

57-
github.repos.editRelease(editingRelease, function (err) {
63+
github.repos.createRelease(release, function (err) {
5864
if (err) return cb(err)
5965

6066
cb(null, true, release)

test/mocks/github.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ module.exports = function () {
33
authenticate: function () {
44
return true
55
},
6+
gitdata: {
7+
createReference: function (release, cb) {
8+
cb(null)
9+
}
10+
},
611
repos: {
712
createRelease: function (release, cb) {
8-
cb(null, {id: 1})
9-
},
10-
editRelease: function (release, cb) {
1113
cb(null)
1214
}
1315
}

test/specs/post.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ var defaultRelease = {
2323
repo: 'up',
2424
name: 'v1.0.0',
2525
tag_name: 'v1.0.0',
26-
target_commitish: 'bar',
26+
target_commitish: 'master',
2727
body: 'the log'
2828
}
2929

3030
test('full post run', function (t) {
3131
t.test('in debug mode w/o token', function (tt) {
3232
post({
33-
options: {debug: true},
33+
options: {debug: true, branch: 'master'},
3434
pkg: pkg,
3535
plugins: plugins
3636
}, function (err, published, release) {
@@ -44,7 +44,7 @@ test('full post run', function (t) {
4444

4545
t.test('in debug mode w/token', function (tt) {
4646
post({
47-
options: {debug: true, githubToken: 'yo'},
47+
options: {debug: true, githubToken: 'yo', branch: 'master'},
4848
pkg: pkg,
4949
plugins: plugins
5050
}, function (err, published, release) {
@@ -58,7 +58,7 @@ test('full post run', function (t) {
5858

5959
t.test('production', function (tt) {
6060
post({
61-
options: {githubToken: 'yo'},
61+
options: {githubToken: 'yo', branch: 'master'},
6262
pkg: pkg,
6363
plugins: plugins
6464
}, function (err, published, release) {

0 commit comments

Comments
 (0)