Skip to content

Commit

Permalink
feat: Add predictable git author
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Krems committed Feb 24, 2017
1 parent 68ae9e5 commit e941fda
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 23 deletions.
7 changes: 1 addition & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
language: node_js
node_js:
- '0.10'
- '4'
before_install:
- npm install -g npm@latest-2
before_deploy:
- 'git config --global user.email "opensource@groupon.com"'
- 'git config --global user.name "Groupon"'
- '6'
deploy:
provider: script
script: ./bin/nlm.js release
Expand Down
13 changes: 12 additions & 1 deletion lib/steps/version-commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,23 @@ var _ = require('lodash');

var run = require('../run');

var NLM_GIT_NAME = 'nlm';
var NLM_GIT_EMAIL = 'opensource@groupon.com';

function addFiles(cwd) {
return run('git', ['add', 'CHANGELOG.md', 'package.json'], { cwd: cwd });
}

function commit(cwd, message) {
return run('git', ['commit', '-m', message], { cwd: cwd });
return run('git', ['commit', '-m', message], {
cwd: cwd,
env: _.assign({}, process.env, {
GIT_AUTHOR_NAME: NLM_GIT_NAME,
GIT_AUTHOR_EMAIL: NLM_GIT_EMAIL,
GIT_COMMITTER_NAME: NLM_GIT_NAME,
GIT_COMMITTER_EMAIL: NLM_GIT_EMAIL,
}),
});
}

function getHEAD(cwd) {
Expand Down
14 changes: 10 additions & 4 deletions test/fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ function withFixture(name) {
before('running fixture setup', function runFixture(done) {
execFile(script, [script], {
cwd: dirname,
env: { HOME: '/does/not/exist' },
env: {
HOME: '/does/not/exist',
GIT_AUTHOR_NAME: 'Robin Developer',
GIT_AUTHOR_EMAIL: 'rdev@example.com',
GIT_COMMITTER_NAME: 'Robin Developer',
GIT_COMMITTER_EMAIL: 'rdev@example.com',
},
}, function logErrorDetails(error, stdout, stderr) {
if (error) {
process.stdout.write(stdout + '\n');
Expand All @@ -59,9 +65,9 @@ function withFixture(name) {
});
});

// after('remove fixture directory', function removeFixture(done) {
// execFile('rm', ['-rf', dirname], done);
// });
after('remove fixture directory', function removeFixture(done) {
execFile('rm', ['-rf', dirname], done);
});

return dirname;
}
Expand Down
2 changes: 0 additions & 2 deletions test/fixtures/dirty-checkout
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env bash
set -e
git init
git config user.name "nlm"
git config user.email "nlm@example.com"

bash $(dirname $0)/fix-commit

Expand Down
2 changes: 0 additions & 2 deletions test/fixtures/empty-project
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env bash
set -e
git init
git config user.name "nlm"
git config user.email "nlm@example.com"
2 changes: 0 additions & 2 deletions test/fixtures/fix-commit
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env bash
set -e
git init
git config user.name "nlm"
git config user.email "nlm@example.com"

echo "console.log('do stuff');" > index.js
git add index.js
Expand Down
2 changes: 0 additions & 2 deletions test/fixtures/invalid-commit
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env bash
set -e
git init
git config user.name "nlm"
git config user.email "nlm@example.com"

echo "console.log('no type prefix');" > index.js
git add index.js
Expand Down
2 changes: 0 additions & 2 deletions test/fixtures/multiple-commits
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env bash
set -e
git init
git config user.name "nlm"
git config user.email "nlm@example.com"

bash $(dirname $0)/fix-commit

Expand Down
2 changes: 0 additions & 2 deletions test/fixtures/ticket-commits
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env bash
set -e
git init
git config user.name "nlm"
git config user.email "nlm@example.com"

echo "console.log('Short stuff');" > index.js
git add index.js
Expand Down
17 changes: 17 additions & 0 deletions test/steps/version-commit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
*/
'use strict';

var execFile = require('child_process').execFile;
var fs = require('fs');

var assert = require('assertive');
Expand All @@ -50,6 +51,14 @@ describe('createVersionCommit', function () {
changelog: '* New stuff\n* Interesting features',
};

before('commits with the original author', function (done) {
execFile('git', ['show'], { cwd: dirname }, function (err, stdout) {
if (err) return done(err);
assert.include('Author: Robin Developer <rdev@example.com>', stdout);
done();
});
});

before('create version commit', function () {
return createVersionCommit(dirname, pkg, options);
});
Expand All @@ -58,4 +67,12 @@ describe('createVersionCommit', function () {
var HEAD = fs.readFileSync(dirname + '/.git/refs/heads/master', 'utf8');
assert.equal(HEAD.trim(), options.versionCommitSha);
});

it('commits with the proper user', function (done) {
execFile('git', ['show'], { cwd: dirname }, function (err, stdout) {
if (err) return done(err);
assert.include('Author: nlm <opensource@groupon.com>', stdout);
done();
});
});
});

0 comments on commit e941fda

Please sign in to comment.