feat(post): add initial version of command
This commit is contained in:
parent
0ee9cc31e9
commit
17ad82bfbc
51
src/post.js
Normal file
51
src/post.js
Normal file
@ -0,0 +1,51 @@
|
||||
'use strict'
|
||||
|
||||
var exec = require('child_process').exec
|
||||
var readFile = require('fs').readFileSync
|
||||
|
||||
var changelog = require('conventional-changelog')
|
||||
var GitHubApi = require('github')
|
||||
var parse = require('parse-github-repo-url')
|
||||
|
||||
var github = new GitHubApi({
|
||||
version: '3.0.0'
|
||||
})
|
||||
|
||||
module.exports = function (options, cb) {
|
||||
var pkg = JSON.parse(readFile('./package.json'))
|
||||
var repository = pkg.repository ? pkg.repository.url : null
|
||||
|
||||
if (!repository) return cb('Package must have a repository')
|
||||
|
||||
changelog({
|
||||
version: pkg.version,
|
||||
repository: repository,
|
||||
file: false
|
||||
}, function(err, log) {
|
||||
if (err) return cb(err)
|
||||
|
||||
exec('git rev-parse HEAD', function(err, hash) {
|
||||
if (err) return cb(err)
|
||||
|
||||
var ghRepo = parse(repository)
|
||||
var release = {
|
||||
owner: ghRepo[0],
|
||||
repo: ghRepo[1],
|
||||
tag_name: 'v' + pkg.version,
|
||||
target_commitish: hash,
|
||||
draft: options.debug,
|
||||
body: log
|
||||
}
|
||||
|
||||
github.authenticate({
|
||||
type: 'oauth',
|
||||
token: options.token
|
||||
})
|
||||
|
||||
github.releases.createRelease(release, function(err) {
|
||||
if (err) return cb(err)
|
||||
cb(null, true)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user