From f148a61339b7f7b9fc77599aaa8cf6d6eadfd0ad Mon Sep 17 00:00:00 2001 From: Kaito Udagawa Date: Wed, 30 Nov 2016 01:11:35 +0900 Subject: [PATCH] fix(post): fix target_commitish to be the default branch target_commitish in GitHub Releases has two different meanings: * Target commit that a new associated tag will be created on * Target branch to compute how many "commits to since this release" target_commitish is usually the default branch (aka master), because the distance between the release and the latest branch is the primary concern. Before this change, target_commitish was left to be a hash and the feature of GitHub Releases that shows how much time passed since the release is ruined, because no tracking branch is given. By this change, target_commitish is changed to be the default branch given in the configuration (options.branch) via edit a release API after the release and tag are created via crate a release API. --- src/post.js | 16 ++++++++++++++-- test/mocks/github.js | 3 +++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/post.js b/src/post.js index c2c478d1..47e6893b 100644 --- a/src/post.js +++ b/src/post.js @@ -43,10 +43,22 @@ module.exports = function (config, cb) { token: options.githubToken }) - github.repos.createRelease(release, function (err) { + github.repos.createRelease(release, function (err, res) { if (err) return cb(err) + if (options.debug) return cb(null, true, release) - cb(null, true, release) + var editingRelease = { + owner: ghRepo[0], + repo: ghRepo[1], + id: res.id, + target_commitish: options.branch + } + + github.repos.editRelease(editingRelease, function (err) { + if (err) return cb(err) + + cb(null, true, release) + }) }) }) }) diff --git a/test/mocks/github.js b/test/mocks/github.js index d5f772ed..b64d455d 100644 --- a/test/mocks/github.js +++ b/test/mocks/github.js @@ -5,6 +5,9 @@ module.exports = function () { }, repos: { createRelease: function (release, cb) { + cb(null, {id: 1}) + }, + editRelease: function (release, cb) { cb(null) } }