feat(post): initial

This commit is contained in:
Stephan Bönnemann 2015-07-16 17:30:23 +02:00
parent ed05101a61
commit 59d852d6fb
3 changed files with 61 additions and 0 deletions

View File

@ -18,11 +18,14 @@
"@semantic-release/condition-travis": "^1.0.0",
"@semantic-release/error": "^1.0.0",
"@semantic-release/release-notes-generator": "^1.0.0",
"git-head": "^1.2.1",
"github": "^0.2.4",
"lodash": "^3.9.3",
"nopt": "^3.0.3",
"npm-registry-client": "^6.4.0",
"npmconf": "^2.1.2",
"npmlog": "^1.2.1",
"parse-github-repo-url": "^1.0.0",
"require-relative": "^0.8.7",
"run-auto": "^1.1.2",
"semver": "^5.0.1"

View File

@ -111,6 +111,14 @@ npmconf.load({}, (err, conf) => {
} else if (options.argv.cooked[0] === 'post') {
log.verbose(PREFIX, 'Running post-script.')
require('./post')(pkg, options, plugins, (err, published, release) => {
if (err) {
log.error(PREFIX, 'Failed to publish release notes.', err)
process.exit(1)
}
log.verbose(PREFIX, `${published ? 'Published' : 'Generated'} release notes.`, release)
})
} else {
log.error(PREFIX, `Command "${options.argv.cooked[0]}" not recognized. User either "pre" or "post"`)
}

50
src/post.js Normal file
View File

@ -0,0 +1,50 @@
const url = require('url')
const gitHead = require('git-head')
const GitHubApi = require('github')
const parseSlug = require('parse-github-repo-url')
module.exports = function (pkg, argv, plugins, cb) {
const config = argv['github-url'] ? url.parse(argv['github-url']) : {}
const github = new GitHubApi({
version: '3.0.0',
port: config.port,
protocol: (config.protocol || '').split(':')[0] || null,
host: config.hostname
})
plugins.generateNotes(pkg, (err, log) => {
if (err) return cb(err)
gitHead((err, hash) => {
if (err) return cb(err)
const ghRepo = parseSlug(pkg.repository.url)
const release = {
owner: ghRepo[0],
repo: ghRepo[1],
name: `v${pkg.version}`,
tag_name: `v${pkg.version}`,
target_commitish: hash,
draft: !!argv.debug,
body: log
}
if (argv.debug && !argv['github-token']) {
return cb(null, false, release)
}
github.authenticate({
type: 'oauth',
token: argv['github-token']
})
github.releases.createRelease(release, (err) => {
if (err) return cb(err)
cb(null, true, release)
})
})
})
}