Skip to content

Commit

Permalink
Convert project to use ES2015
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Schmidt committed Mar 13, 2016
1 parent 325ed1c commit a5a9df6
Show file tree
Hide file tree
Showing 23 changed files with 295 additions and 270 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": [ "es2015" ]
}
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/**
build/**
dist/**
node_modules/**
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "holidaycheck",
"extends": "holidaycheck/es2015",

"env": {
"node": true
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.iml
.idea
build
dist
node_modules
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
.gitignore
.idea/
.travis.yml
bin/
build/
lib/
test/
8 changes: 3 additions & 5 deletions bin/pr-log.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!/usr/bin/env node

'use strict';

var program = require('commander'),
config = require('../package.json'),
cli = require('../lib/cli');
import program from 'commander';
import config from '../../package.json';
import cli from '../cli';

program
.version(config.version)
Expand Down
26 changes: 13 additions & 13 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';
import path from 'path';
import prepend from 'prepend';
import Promise from 'bluebird';
import ensureCleanLocalGitState from './ensureCleanLocalGitState';
import getMergedPullRequests from './getMergedPullRequests';
import createChangelog from './createChangelog';
import getGithubRepo from './getGithubRepo';

var ensureCleanLocalGitState = require('./ensureCleanLocalGitState'),
getMergedPullRequests = require('./getMergedPullRequests'),
createChangelog = require('./createChangelog'),
Promise = require('bluebird'),
path = require('path'),
prependFile = Promise.promisify(require('prepend')),
getGithubRepo = require('./getGithubRepo');
const prependFile = Promise.promisify(prepend);

function stripTrailingEmptyLine(text) {
if (text.indexOf('\n\n') === text.length - 2) {
Expand All @@ -16,11 +16,11 @@ function stripTrailingEmptyLine(text) {
return text;
}

module.exports = {
run: function (newVersionNumber) {
var packageConfig = require(path.join(process.cwd(), 'package.json')),
githubRepo = getGithubRepo(packageConfig.repository.url),
changelogPath = path.join(process.cwd(), 'CHANGELOG.md');
export default {
run: (newVersionNumber) => {
const packageConfig = require(path.join(process.cwd(), 'package.json'));
const githubRepo = getGithubRepo(packageConfig.repository.url);
const changelogPath = path.join(process.cwd(), 'CHANGELOG.md');

if (!newVersionNumber) {
throw new Error('version-number not specified');
Expand Down
30 changes: 14 additions & 16 deletions lib/createChangelog.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
'use strict';
import moment from 'moment';
import R from 'ramda';
import validLabels from './validLabels';

var validLabels = require('./validLabels'),
R = require('ramda'),
util = require('util'),
moment = require('moment');
function createChangelog(newVersionNumber, mergedPullRequests) {
const groupedPullRequests = R.groupBy(R.prop('label'), mergedPullRequests);
const date = moment().locale('en').format('MMMM D, YYYY');
const title = `## ${newVersionNumber} (${date})`;

module.exports = function createChangelog(newVersionNumber, mergedPullRequests) {
var changelog,
groupedPullRequests = R.groupBy(R.prop('label'), mergedPullRequests),
date = moment().locale('en').format('MMMM D, YYYY'),
title = util.format('## %s (%s)', newVersionNumber, date);

changelog = title + '\n\n';
let changelog = `${title}\n\n`;

Object.keys(groupedPullRequests).forEach(function (label) {
var pullRequests = groupedPullRequests[label];
const pullRequests = groupedPullRequests[label];

changelog += '### ' + validLabels[label] + '\n\n';
changelog += `### ${validLabels[label]}\n\n`;

pullRequests.forEach(function (pullRequest) {
changelog += '* ' + pullRequest.title + ' (#' + pullRequest.id + ')\n';
changelog += `* ${pullRequest.title} (#${pullRequest.id})\n`;
});

changelog += '\n';
});

return changelog;
};
}

export default createChangelog;
40 changes: 21 additions & 19 deletions lib/ensureCleanLocalGitState.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
'use strict';

var git = require('git-promise'),
findRemoteAlias = require('./findRemoteAlias'),
Promise = require('bluebird'),
util = require('util');
import git from 'git-promise';
import Promise from 'bluebird';
import findRemoteAlias from './findRemoteAlias';

function ensureCleanLocalCopy() {
return git('status -s')
.then(function (status) {
.then((status) => {
if (status.trim() !== '') {
throw new Error('Local copy is not clean');
}
Expand All @@ -16,26 +13,26 @@ function ensureCleanLocalCopy() {

function ensureMasterBranch() {
return git('rev-parse --abbrev-ref HEAD')
.then(function (branchName) {
.then((branchName) => {
if (branchName.trim() !== 'master') {
throw new Error('Not on master branch');
}
});
}

function fetchRemote(remoteAlias) {
return git('fetch ' + remoteAlias);
return git(`fetch ${remoteAlias}`);
}

function ensureLocalIsEqualToRemote(remoteAlias) {
var remoteBranch = remoteAlias + '/master';
const remoteBranch = `${remoteAlias}/master`;

return git(`rev-list --left-right master...${remoteBranch}`)
.then((result) => {
const commits = result.split('\n');

return git('rev-list --left-right master...' + remoteBranch)
.then(function (result) {
var commits = result.split('\n'),
commitsAhead = 0,
commitsBehind = 0,
errorMessage = 'Local git master branch is %d commits ahead and %d commits behind of %s';
let commitsAhead = 0;
let commitsBehind = 0;

commits.forEach(function (commit) {
if (commit.trim().length > 0) {
Expand All @@ -48,15 +45,20 @@ function ensureLocalIsEqualToRemote(remoteAlias) {
});

if (commitsAhead > 0 || commitsBehind > 0) {
throw new Error(util.format(errorMessage, commitsAhead, commitsBehind, remoteBranch));
// eslint-disable-next-line max-len
const errorMessage = `Local git master branch is ${commitsAhead} commits ahead and ${commitsBehind} commits behind of ${remoteBranch}`;

throw new Error(errorMessage);
}
});
}

module.exports = function ensureCleanLocalGitState(githubRepo) {
function ensureCleanLocalGitState(githubRepo) {
return Promise.try(ensureCleanLocalCopy)
.then(ensureMasterBranch)
.then(findRemoteAlias.bind(null, githubRepo))
.tap(fetchRemote)
.then(ensureLocalIsEqualToRemote);
};
}

export default ensureCleanLocalGitState;
41 changes: 20 additions & 21 deletions lib/findRemoteAlias.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,46 @@
'use strict';

var git = require('git-promise'),
parseGitUrl = require('git-url-parse'),
R = require('ramda');
import git from 'git-promise';
import parseGitUrl from 'git-url-parse';
import R from 'ramda';

function isSameGitUrl(gitUrlA, gitUrlB) {
var parsedUrlA = parseGitUrl(gitUrlA),
parsedUrlB = parseGitUrl(gitUrlB),
pathA = parsedUrlA.pathname.replace(/\.git$/, ''),
pathB = parsedUrlB.pathname.replace(/\.git$/, '');
const parsedUrlA = parseGitUrl(gitUrlA);
const parsedUrlB = parseGitUrl(gitUrlB);
const pathA = parsedUrlA.pathname.replace(/\.git$/, '');
const pathB = parsedUrlB.pathname.replace(/\.git$/, '');

return parsedUrlA.resource === parsedUrlB.resource && pathA === pathB;
}

function getGitUrl(githubRepo) {
return 'git://github.com/' + githubRepo + '.git';
return `git://github.com/${githubRepo}.git`;
}

module.exports = function findRemoteAlias(githubRepo) {
var gitRemote = getGitUrl(githubRepo);
function findRemoteAlias(githubRepo) {
const gitRemote = getGitUrl(githubRepo);

return git('remote -v')
.then(function (output) {
var remotes = output
.then((output) => {
const remotes = output
.split('\n')
.map(function (remote) {
var tokens = remote.split(/\s/);
.map((remote) => {
const tokens = remote.split(/\s/);

return {
alias: tokens[0],
url: tokens[1]
};
}),
matchedRemote;
});

matchedRemote = R.find(function (remote) {
const matchedRemote = R.find((remote) => {
return remote.url && isSameGitUrl(gitRemote, remote.url);
}, remotes);

if (!matchedRemote) {
throw new Error('This local git repository doesn’t have a remote pointing to ' + gitRemote);
throw new Error(`This local git repository doesn’t have a remote pointing to ${gitRemote}`);
}

return matchedRemote.alias;
});
};
}

export default findRemoteAlias;
16 changes: 8 additions & 8 deletions lib/getGithubRepo.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict';
import parseGithubUrl from 'parse-github-repo-url';

var parseGithubUrl = require('parse-github-repo-url');

module.exports = function getGithubRepo(githubUrl) {
var result = parseGithubUrl(githubUrl);
function getGithubRepo(githubUrl) {
const result = parseGithubUrl(githubUrl);

if (!result) {
throw new Error('Invalid GitHub URI ' + githubUrl);
throw new Error(`Invalid GitHub URI ${githubUrl}`);
}

return result[0] + '/' + result[1];
};
return `${result[0]}/${result[1]}`;
}

export default getGithubRepo;
42 changes: 21 additions & 21 deletions lib/getMergedPullRequests.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
'use strict';

var git = require('git-promise'),
semver = require('semver'),
Promise = require('bluebird'),
getPullRequestLabel = require('./getPullRequestLabel');
import git from 'git-promise';
import Promise from 'bluebird';
import semver from 'semver';
import getPullRequestLabel from './getPullRequestLabel';

function getLatestVersionTag() {
return git('tag --list')
.then(function (result) {
var tags = result.split('\n'),
versionTags = tags.filter(semver.valid),
orderedVersionTags = versionTags.sort(semver.compare);
const tags = result.split('\n');
const versionTags = tags.filter(semver.valid);
const orderedVersionTags = versionTags.sort(semver.compare);

return orderedVersionTags[orderedVersionTags.length - 1];
});
}

function getPullRequests(fromTag) {
return git('log --no-color --pretty=format:"%s (%b)" --merges ' + fromTag + '..HEAD')
.then(function (result) {
var mergeCommits = result.replace(/[\r\n]+\)/g, ')').split('\n');
return git(`log --no-color --pretty=format:"%s (%b)" --merges ${fromTag}..HEAD`)
.then((result) => {
const mergeCommits = result.replace(/[\r\n]+\)/g, ')').split('\n');

return mergeCommits
.filter(function (commit) {
.filter((commit) => {
return commit.indexOf('Merge pull request') === 0;
})
.map(function (pullRequest) {
var pattern = /^Merge pull request #(\d+) from (.*) \((.*)\)/,
matches = pullRequest.match(pattern);
.map((pullRequest) => {
const pattern = /^Merge pull request #(\d+) from (.*) \((.*)\)/;
const matches = pullRequest.match(pattern);

return {
id: matches[1],
Expand All @@ -38,22 +36,24 @@ function getPullRequests(fromTag) {
}

function extendWithLabel(githubRepo, pullRequests) {
var promises = pullRequests.map(function (pullRequest) {
const promises = pullRequests.map((pullRequest) => {
return getPullRequestLabel(githubRepo, pullRequest.id)
.then(function (label) {
.then((label) => {
return {
id: pullRequest.id,
title: pullRequest.title,
label: label
label
};
});
});

return Promise.all(promises);
}

module.exports = function getMergedPullRequests(githubRepo) {
function getMergedPullRequests(githubRepo) {
return getLatestVersionTag()
.then(getPullRequests)
.then(extendWithLabel.bind(null, githubRepo));
};
}

export default getMergedPullRequests;
Loading

0 comments on commit a5a9df6

Please sign in to comment.