Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
hutson committed May 27, 2017
2 parents 09c2045 + 0330f1b commit 0de3ddf
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 23 deletions.
5 changes: 3 additions & 2 deletions .gitignore
@@ -1,3 +1,4 @@
/.nyc_output/
/coverage/
/node_modules/
token
tmp
yarn-error.log
12 changes: 12 additions & 0 deletions README.md
Expand Up @@ -120,6 +120,18 @@ Default: `1`

How many releases of changelog you want to generate. It counts from the latest semver tag. Useful when you forgot to generate any previous releases. Set to `0` to regenerate all.

##### name

Default: same as version tag

Name that should be applied to the release on GitHub.

##### targetCommitish

Default: `undefined` (uses the tag to determine commit)

Specific `target_commitish` in GitHub release

#### gitRawCommitsOpts

##### from
Expand Down
8 changes: 8 additions & 0 deletions cli.js
Expand Up @@ -107,6 +107,14 @@ conventionalGithubReleaser({
process.exit(1);
}

if (0 === data.length) {
if (flags.verbose) {
console.log('No GitHub releases created because no git tags available to work with.');
}

process.exit(0);
}

var allRejected = true;

for (var i = data.length - 1; i >= 0 ; i--) {
Expand Down
21 changes: 5 additions & 16 deletions index.js
@@ -1,13 +1,13 @@
'use strict';
var assign = require('object-assign');
var conventionalChangelog = require('conventional-changelog');
var dateFormat = require('dateformat');
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('./lib/transform');

var github = new Github({
version: '3.0.0'
Expand Down Expand Up @@ -40,20 +40,7 @@ function conventionalGithubReleaser(auth, changelogOpts, context, gitRawCommitsO
writerOpts = changelogArgs[4];

changelogOpts = merge({
transform: function(chunk, cb) {
if (typeof chunk.gitTags === 'string') {
var match = /tag:\s*(.+?)[,\)]/gi.exec(chunk.gitTags);
if (match) {
chunk.version = match[1];
}
}

if (chunk.committerDate) {
chunk.committerDate = dateFormat(chunk.committerDate, 'yyyy-mm-dd', true);
}

cb(null, chunk);
},
transform: transform,
releaseCount: 1
}, changelogOpts);

Expand All @@ -75,7 +62,7 @@ function conventionalGithubReleaser(auth, changelogOpts, context, gitRawCommitsO
if (releaseCount !== 0) {
gitRawCommitsOpts = assign({
from: tags[releaseCount]
});
}, gitRawCommitsOpts);
}

gitRawCommitsOpts.to = gitRawCommitsOpts.to || tags[0];
Expand Down Expand Up @@ -104,6 +91,8 @@ function conventionalGithubReleaser(auth, changelogOpts, context, gitRawCommitsO
body: chunk.log,
prerelease: prerelease,
draft: draft
target_commitish: changelogOpts.targetCommitish,
name: changelogOpts.name || version
// jscs:enable
});

Expand Down
18 changes: 18 additions & 0 deletions lib/transform.js
@@ -0,0 +1,18 @@
'use strict';

var dateFormat = require('dateformat');
var findVersions = require('find-versions');

function transform(chunk, cb) {
if (typeof chunk.gitTags === 'string') {
chunk.version = findVersions(chunk.gitTags)[0];
}

if (chunk.committerDate) {
chunk.committerDate = dateFormat(chunk.committerDate, 'yyyy-mm-dd', true);
}

cb(null, chunk);
}

module.exports = transform;
50 changes: 50 additions & 0 deletions lib/transform.spec.js
@@ -0,0 +1,50 @@
'use strict';

// jshint expr: true

var chai = require('chai');
var transform = require('./transform');

var expect = chai.expect;

describe('transform', function() {
beforeEach(function() {
this.chunk = {
gitTags: '',
};
});

it('should skip semantic version matching when gitTags isn\'t a string', function(done) {
this.chunk.gitTags = undefined;

transform(this.chunk, function(err, chunk) {
expect(chunk.version).to.be.undefined;
done();
});
});

it('should have no version when there are no tags', function(done) {
transform(this.chunk, function(err, chunk) {
expect(chunk.version).to.be.undefined;
done();
});
});

it('should not match invalid semantic version tag', function(done) {
this.chunk.gitTags = ' tag: release-18';

transform(this.chunk, function(err, chunk) {
expect(chunk.version).to.be.undefined;
done();
});
});

it('should match valid semantic version tag', function(done) {
this.chunk.gitTags = ' tag: release-18, tag: 1.1.20';

transform(this.chunk, function(err, chunk) {
expect(chunk.version).to.equal('1.1.20');
done();
});
});
});
13 changes: 8 additions & 5 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "conventional-github-releaser",
"version": "1.1.3",
"version": "1.1.4",
"description": "Make a new GitHub release from git metadata",
"homepage": "https://github.com/conventional-changelog/conventional-github-releaser",
"author": {
Expand Down Expand Up @@ -28,8 +28,9 @@
"dependencies": {
"conventional-changelog": "^1.1.0",
"dateformat": "^1.0.11",
"find-versions": "^2.0.0",
"git-semver-tags": "^1.0.0",
"github": "^2.0.0",
"github": "^0.2.4",
"lodash.merge": "^4.0.2",
"meow": "^3.3.0",
"object-assign": "^4.0.1",
Expand All @@ -43,15 +44,17 @@
"coveralls": "^2.11.2",
"github-remove-all-releases": "^1.0.0",
"istanbul": "^0.4.1",
"jscs": "^3.0.5",
"jscs": "^2.0.0",
"jshint": "^2.9.1",
"mocha": "*",
"shelljs": "^0.7.0"
"nyc": "^10.3.2",
"shelljs": "^0.6.0"
},
"scripts": {
"coverage": "istanbul cover _mocha -- -R spec --timeout 50000 && rm -rf ./coverage",
"lint": "jshint *.js test --exclude node_modules && jscs *.js test",
"test": "npm run-script lint && mocha --timeout 50000"
"formertest": "npm run-script lint && mocha --timeout 50000",
"test": "jshint lib/ && jscs lib/ && nyc --all --cache --include=lib/ --exclude=lib/**/*.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 lib/**/*.spec.js"
},
"bin": {
"conventional-github-releaser": "cli.js"
Expand Down
35 changes: 35 additions & 0 deletions test/cli.js
@@ -1,6 +1,7 @@
'use strict';
var expect = require('chai').expect;
var fs = require('fs');
var Q = require('q');
var githubRemoveAllReleases = require('github-remove-all-releases');
var shell = require('shelljs');
var spawn = require('child_process').spawn;
Expand Down Expand Up @@ -64,6 +65,40 @@ describe('cli', function() {
});
});

it('should work with no releases', function(done) {
Q.Promise(function(resolve, reject) {
var cp = spawn(cliPath, ['--pkg', __dirname + '/fixtures/_package.json', '-t', AUTH.token, '-v'], {
stdio: [process.stdin, null, null]
});

cp.on('error', function(code) {
reject('Process exits with code ' + code);
});

cp.on('close', function(code) {
expect(code).to.equal(0);

resolve();
});
}).then(function() {
// we call it a second time, because there no tags are left to create a release from
var cp = spawn(cliPath, ['--pkg', __dirname + '/fixtures/_package.json', '-t', AUTH.token, '-v'], {
stdio: [process.stdin, null, null]
});

cp.on('error', function(code) {
done('Process exits with code ' + code);
});

cp.on('close', function(code) {
// this time we also expect the cli to exit with code 0 due to #17
expect(code).to.equal(0);

done();
});
});
});

it('should print out error message and exit with `1` if all results error', function(done) {
var cp = spawn(cliPath, ['--pkg', __dirname + '/fixtures/_package.json', '-t', AUTH.token], {
stdio: [process.stdin, null, null]
Expand Down

0 comments on commit 0de3ddf

Please sign in to comment.