Skip to content
This repository was archived by the owner on Nov 27, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions lib/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var fse = require('fs-extra');
var path = require('path');
var glob = require('glob');
var temp = require('temp').track();
var cli = require('cli');

function getCommitMessage() {
var spawn = childProcess.spawnSync('git', ['log', '--format=%B', '-n', '1']);
Expand All @@ -41,6 +42,16 @@ function getCommitMessage() {
return spawn.stdout.toString().trim();
}

var lastMessage;
function ghPagesLogger(message) {
if (lastMessage) {
cli.spinner(chalk.bold.green('✓ ') + lastMessage + '… done!', true);
}

cli.spinner(' ' + message);
lastMessage = message;
}

module.exports = function(config) {
return new Promise(function(resolve, reject) {
config = config || {};
Expand Down Expand Up @@ -72,7 +83,7 @@ module.exports = function(config) {
}
}

console.log('Deploying "' + commitMessage + '"');
console.log('Deploying "' + commitMessage.split('\n')[0] + '" to GitHub Pages…\n');

if (cloneDir) {
ghPagesConfig.clone = cloneDir;
Expand All @@ -94,7 +105,7 @@ module.exports = function(config) {
// We can't log on Travis because it would leak the GitHub token.
// We can't use the gh-pages silent option because it makes error messages
// less informative (https://github.com/mozilla/oghliner/pull/58#issuecomment-147550610).
ghPagesConfig.logger = ('GH_TOKEN' in process.env) ? function() {} : console.log;
ghPagesConfig.logger = ('GH_TOKEN' in process.env) ? function() {} : ghPagesLogger;

if ('GH_TOKEN' in process.env) {
// We're using a token to authenticate with GitHub, so we have to embed
Expand All @@ -115,6 +126,10 @@ module.exports = function(config) {
}

ghPages.publish(rootDir, ghPagesConfig, function(err) {
if (lastMessage) {
cli.spinner(chalk.bold.green('✓ ') + lastMessage + '… done!\n', true);
}

if (err) {
reject(err);
} else {
Expand Down
44 changes: 44 additions & 0 deletions test/testDeploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var path = require('path');
var temp = require('temp').track();
var ghPages = require('gh-pages');
var deploy = require('../lib/deploy');
var childProcess = require('child_process');

describe('Deploy', function() {
var oldWD = process.cwd();
Expand Down Expand Up @@ -254,4 +255,47 @@ describe('Deploy', function() {
});
});
});

function checkCommitMessage(message, expected) {
return new Promise(function(resolve, reject) {
var dir = temp.mkdirSync('oghliner');

process.chdir(dir);

childProcess.execSync('git init');
fs.writeFileSync('file', 'data');
childProcess.execSync('git add file');
childProcess.execSync('git commit -m "' + message + '"');

var output = '';
var write = process.stdout.write;
process.stdout.write = function(chunk, encoding, fd) {
write.apply(process.stdout, arguments);
output += chunk;

if (output.indexOf('Deploying "' + expected + '" to GitHub Pages…') !== -1) {
process.stdout.write = write;
resolve();
}
};
});
}

it('should print the commit message', function() {
return Promise.all([
checkCommitMessage('Do. Or do not.', 'Do. Or do not.'),
deploy({
cloneDir: '.gh-pages-cache',
}).catch(function() {}),
]);
});

it('should print only the first line of a multiline commit', function() {
return Promise.all([
checkCommitMessage('Do. Or do not.\nThere is no try.', 'Do. Or do not.'),
deploy({
cloneDir: '.gh-pages-cache',
}).catch(function() {}),
]);
});
});