Skip to content

Commit

Permalink
Merge pull request #49 from destroyerofbuilds/feat/github-enterprise
Browse files Browse the repository at this point in the history
feat: support GitHub Enterprise in CLI
  • Loading branch information
hutson committed Nov 1, 2017
2 parents 4d8260b + de6d812 commit 45ce4d9
Show file tree
Hide file tree
Showing 11 changed files with 1,789 additions and 930 deletions.
7 changes: 7 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "xo-space",
"rules": {
"camelcase": ["error", {"properties": "never"}],
"comma-dangle": ["error", "always-multiline"]
}
}
5 changes: 0 additions & 5 deletions .jscsrc

This file was deleted.

15 changes: 0 additions & 15 deletions .jshintrc

This file was deleted.

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ node_js:
before_install:
- npm install --global npm@${NPM_VERSION}
after_success:
- cat ./coverage/lcov.info | node $(npm bin)/coveralls
- $(npm bin)/codecov
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# conventional-github-releaser

[![Build Status](https://travis-ci.org/conventional-changelog/conventional-github-releaser.svg?branch=master)](https://travis-ci.org/conventional-changelog/conventional-github-releaser)
[![Coverage Status](https://coveralls.io/repos/github/conventional-changelog/conventional-github-releaser/badge.svg?branch=master)](https://coveralls.io/github/conventional-changelog/conventional-github-releaser?branch=master)
[![dependencies Status](https://david-dm.org/conventional-changelog/conventional-github-releaser/status.svg)](https://david-dm.org/conventional-changelog/conventional-github-releaser)
[![Join the chat at https://gitter.im/conventional-changelog/conventional-github-releaser](https://badges.gitter.im/conventional-changelog/conventional-github-releaser.svg)](https://gitter.im/conventional-changelog/conventional-github-releaser?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

> Make a new GitHub release from git metadata.
Expand Down Expand Up @@ -57,10 +55,10 @@ Please use this [gist](https://gist.github.com/stevemao/280ef22ee861323993a0) to

## Why

- Based on [conventional-changelog](https://github.com/ajoslin/conventional-changelog) but GitHub releases are more elegant.
- Based on [conventional-changelog](https://www.npmjs.com/package/conventional-changelog) but GitHub releases are more elegant.
- Easy fully automate changelog generation. You could still add more points on top of it.
- Detecting prerelease based on semver, ignoring reverted commits, templating with [handlebars.js](https://github.com/wycats/handlebars.js) and links to references, etc. Open an [issue](../../issues/new) if you want more reasonable features.
- Intelligently setup defaults but yet fully configurable with presets of [popular projects](https://github.com/ajoslin/conventional-changelog#preset).
- Detecting prerelease based on semver, ignoring reverted commits, templating with [handlebars.js](https://www.npmjs.com/package/handlebars) and links to references, etc. Open an [issue](../../issues/new) if you want more reasonable features.
- Intelligently setup defaults but yet fully configurable with presets of [popular projects](https://www.npmjs.com/package/conventional-changelog#preset).
- Everything internally or externally is pluggable.
- A lot of tests and actively maintained.

Expand Down Expand Up @@ -89,7 +87,21 @@ conventionalGithubReleaser(AUTH, {

#### auth

An auth object passed to [node-github](https://github.com/mikedeboer/node-github#authentication).
An object that may contain the following properties:

* token - A [GitHub Personal Token](https://github.com/blog/1509-personal-api-tokens) with `repo` [scope permissions](https://developer.github.com/enterprise/2.11/apps/building-integrations/setting-up-and-registering-oauth-apps/about-scopes-for-oauth-apps/).
* url - The fully qualified ___domain name for the GitHub instance (such as `https://api.github.com`).

For example:

```json
{
token: '0126af95c0e2d9b0a7c78738c4c00a860b04acc8',
url: 'https://api.github.com'
}
```

> Please read [`gh-got`](https://www.npmjs.com/package/gh-got#token) for default behavior when `token` and/or `url` aren't provided.
#### callback

Expand Down
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@
"url": "https://github.com/conventional-changelog/conventional-github-releaser.git"
},
"scripts": {
"test": "jshint src/ && jscs src/ && nyc --all --cache --include=src/ --exclude=src/**/*.spec.js --reporter=lcov --reporter=text mocha --check-leaks --full-trace --globals __core-js_shared__,__coverage__,YamlEscaper --inline-diffs --no-exit --recursive --reporter=progress --retries 1 src/**/*.spec.js"
"dev": "docker run --rm --user node -v \"$(pwd)\":/app -w /app -it node:4 sh -c \"yarn install; yarn test; bash\"",
"test": "eslint src/ && nyc --all --cache --include=src/ --exclude=src/cli.js --exclude=src/**/*.spec.js --exclude=src/**/*.mocks.js --reporter=lcov --reporter=text mocha --check-leaks --full-trace --globals __core-js_shared__,__coverage__,YamlEscaper --inline-diffs --no-exit --recursive --reporter=progress --retries 1 src/**/*.spec.js"
},
"version": "1.1.12",
"dependencies": {
"conventional-changelog": "^1.1.0",
"dateformat": "^1.0.11",
"dateformat": "^3.0.0",
"gh-got": "^6.0.0",
"git-semver-tags": "^1.0.0",
"github": "^0.2.4",
"lodash.merge": "^4.0.2",
"meow": "^3.3.0",
"object-assign": "^4.0.1",
Expand All @@ -50,12 +51,12 @@
"through2": "^2.0.0"
},
"devDependencies": {
"chai": "^3.0.0",
"concat-stream": "^1.5.1",
"coveralls": "^2.11.2",
"jscs": "^3.0.7",
"jshint": "^2.9.1",
"mocha": "^3.2.0",
"nyc": "^10.3.2"
"chai": "^4.1.2",
"codecov": "^3.0.0",
"eslint": "^4.10.0",
"eslint-config-xo-space": "^0.17.0",
"mocha": "^4.0.1",
"npm-publish-git-tag": "^1.1.14",
"nyc": "^11.2.1"
}
}
11 changes: 11 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"automerge": true,
"major": {
"automerge": false
},
"labels": ["refactor"],
"pinVersions": false,
"prCreation": "not-pending",
"rebaseStalePrs": true,
"semanticCommits": true
}
46 changes: 24 additions & 22 deletions src/cli.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/usr/bin/env node

'use strict';
var meow = require('meow');
var conventionalGithubReleaser = require('./index');
var resolve = require('path').resolve;

var cli = meow({
const meow = require('meow');
const conventionalGithubReleaser = require('./index');
const resolve = require('path').resolve;

const cli = meow({
help: [
'Usage',
' conventional-github-releaser',
Expand All @@ -13,6 +15,7 @@ var cli = meow({
' conventional-github-releaser -p angular',
'',
'Options',
' -u, --url URL of your GitHub provider. Defaults to `https://api.github.com`',
' -t, --token Your GitHub auth token',
'',
' -p, --preset Name of the preset you want to use. Must be one of the following:',
Expand All @@ -34,28 +37,29 @@ var cli = meow({
' -c, --context A filepath of a javascript that is used to define template variables',
'',
' -d, --draft Publishes a draft instead of a real release',
' Default: false'
]
' Default: false',
],
}, {
alias: {
u: 'url',
t: 'token',
p: 'preset',
k: 'pkg',
r: 'releaseCount',
v: 'verbose',
n: 'config',
c: 'context',
d: 'draft'
}
d: 'draft',
},
});

var config;
var flags = cli.flags;
let config = {};
const flags = cli.flags;

var templateContext;
var gitRawCommitsOpts;
var parserOpts;
var writerOpts;
let templateContext;
let gitRawCommitsOpts;
let parserOpts;
let writerOpts;

try {
if (flags.context) {
Expand All @@ -64,8 +68,6 @@ try {

if (flags.config) {
config = require(resolve(process.cwd(), flags.config));
} else {
config = {};
}

if (config.gitRawCommitsOpts) {
Expand All @@ -84,13 +86,13 @@ try {
process.exit(1);
}

var changelogOpts = {
const changelogOpts = {
preset: flags.preset,
pkg: {
path: flags.pkg
path: flags.pkg,
},
releaseCount: flags.releaseCount,
draft: flags.draft
draft: flags.draft,
};

if (flags.verbose) {
Expand All @@ -99,9 +101,9 @@ if (flags.verbose) {
}

conventionalGithubReleaser({
type: 'oauth',
token: flags.token || process.env.CONVENTIONAL_GITHUB_RELEASER_TOKEN
}, changelogOpts, templateContext, gitRawCommitsOpts, parserOpts, writerOpts, function(err, data) {
url: flags.url || process.env.CONVENTIONAL_GITHUB_URL,
token: flags.token || process.env.CONVENTIONAL_GITHUB_RELEASER_TOKEN,
}, changelogOpts, templateContext, gitRawCommitsOpts, parserOpts, writerOpts, function (err, data) {
if (err) {
console.error(err.toString());
process.exit(1);
Expand Down
91 changes: 46 additions & 45 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
'use strict';
var assign = require('object-assign');
var conventionalChangelog = require('conventional-changelog');
var Github = require('github');
var gitSemverTags = require('git-semver-tags');
var merge = require('lodash.merge');
var Q = require('q');
var semver = require('semver');
var through = require('through2');
var transform = require('./transform');

var github = new Github({
version: '3.0.0'
});

const assign = require('object-assign');
const conventionalChangelog = require('conventional-changelog');
const gitSemverTags = require('git-semver-tags');
const ghGot = require('gh-got');
const merge = require('lodash.merge');
const Q = require('q');
const semver = require('semver');
const through = require('through2');
const transform = require('./transform');

/* eslint max-params: ["error", 7] */
function conventionalGithubReleaser(auth, changelogOpts, context, gitRawCommitsOpts, parserOpts, writerOpts, userCb) {
if (!auth) {
throw new Error('Expected an auth object');
}

var promises = [];
const promises = [];

var changelogArgs = [changelogOpts, context, gitRawCommitsOpts, parserOpts, writerOpts].map(function(arg) {
const changelogArgs = [changelogOpts, context, gitRawCommitsOpts, parserOpts, writerOpts].map(function (arg) {
if (typeof arg === 'function') {
userCb = arg;
return {};
} else {
return arg || {};
}
return arg || {};
});

if (!userCb) {
Expand All @@ -41,75 +38,79 @@ function conventionalGithubReleaser(auth, changelogOpts, context, gitRawCommitsO

changelogOpts = merge({
transform: transform,
releaseCount: 1
releaseCount: 1,
}, changelogOpts);

writerOpts.includeDetails = true;

// ignore the default header partial
writerOpts.headerPartial = writerOpts.headerPartial || '';

github.authenticate(auth);

Q.nfcall(gitSemverTags)
.then(function(tags) {
.then(function (tags) {
if (!tags || !tags.length) {
setImmediate(userCb, new Error('No semver tags found'));
return;
}

var releaseCount = changelogOpts.releaseCount;
const releaseCount = changelogOpts.releaseCount;
if (releaseCount !== 0) {
gitRawCommitsOpts = assign({
from: tags[releaseCount]
from: tags[releaseCount],
}, gitRawCommitsOpts);
}

gitRawCommitsOpts.to = gitRawCommitsOpts.to || tags[0];

conventionalChangelog(changelogOpts, context, gitRawCommitsOpts, parserOpts, writerOpts)
.on('error', function(err) {
.on('error', function (err) {
userCb(err);
})
.pipe(through.obj(function(chunk, enc, cb) {
.pipe(through.obj(function (chunk, enc, cb) {
if (!chunk.keyCommit || !chunk.keyCommit.version) {
cb();
return;
}

var version = chunk.keyCommit.version;

var prerelease = semver.parse(version).prerelease.length > 0;
const version = chunk.keyCommit.version;
const prerelease = semver.parse(version).prerelease.length > 0;
const draft = changelogOpts.draft || false;

const options = {
body: {
body: chunk.log,
draft: draft,
name: changelogOpts.name || version,
prerelease: prerelease,
tag_name: version,
target_commitish: changelogOpts.targetCommitish,
},
};

if (auth.token) {
options.token = auth.token;
}

var draft = changelogOpts.draft || false;
if (auth.url) {
options.endpoint = auth.url;
}

var promise = Q.nfcall(github.releases.createRelease, {
// jscs:disable
owner: context.owner,
repo: context.repository,
tag_name: version,
body: chunk.log,
prerelease: prerelease,
draft: draft,
target_commitish: changelogOpts.targetCommitish,
name: changelogOpts.name || version
// jscs:enable
});
const promise = ghGot('repos/' + context.owner + '/' + context.repository + '/releases', options);

promises.push(promise);

cb();
}, function() {
}, function () {
Q.all(promises)
.then(function(responses) {
.then(function (responses) {
userCb(null, responses);
})
.catch(function(err) {
.catch(function (err) {
userCb(err);
});
}));
})
.catch(function(err) {
.catch(function (err) {
userCb(err);
});
}
Expand Down
Loading

0 comments on commit 45ce4d9

Please sign in to comment.