Skip to content

Commit

Permalink
Merge pull request #19 from jrowlingson/master
Browse files Browse the repository at this point in the history
Add git-commit data generator
  • Loading branch information
Aaron Chambers committed Oct 12, 2015
2 parents d35c81c + 02121e2 commit 5cdf4be
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 1 deletion.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ For detailed information on how configuration of plugins works, please refer to
The type of [Data Generator](#data-generators) to be used.

*Default:* `'file-hash'`
*Alternatives:* `'git-tag-commit'`, `'version-commit'`
*Alternatives:* `'git-tag-commit'`, `'git-commit'`, `'version-commit'`

## Data Generators

Expand Down Expand Up @@ -111,6 +111,22 @@ For example, if your most recent git tag is `v2.0.3`, and the current commit is

The timestamp of the current deploy

### Git Commit generator

Constructs a revision key based on the most recent git commit.

#### Data fields returned

##### revisionKey

The unique identifier of this build based on the first 7 characters of the current commit hash.

For example, if the current commit is `0993043d49f9e0[...]`, this generator will return a revision of `0993043`.

##### timestamp

The timestamp of the current deploy

### Version Commit generator

Similar to the Git Tag Commit generator but uses the `package.json` version string to construct the revision key instead of the git tag.
Expand Down
25 changes: 25 additions & 0 deletions lib/data-generators/git-commit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var CoreObject = require('core-object');
var gitRepoInfo = require('git-repo-info');
var Promise = require('ember-cli/lib/ext/promise');

module.exports = CoreObject.extend({
generate: function() {
var path = gitRepoInfo._findRepo();

if (path === null) {
return Promise.reject('Could not find git repository');
}

var info = gitRepoInfo(path);
var sha = info.sha.slice(0, 7);

if (!sha) {
return Promise.reject('Could not build revision with commit hash `' + sha + '`');
}

return Promise.resolve({
revisionKey: sha,
timestamp: new Date().toISOString()
});
}
});
1 change: 1 addition & 0 deletions lib/data-generators/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
"file-hash": require('./file-hash'),
"git-tag-commit": require('./git-tag-commit'),
"git-commit": require('./git-commit'),
"version-commit": require('./version-commit')
};
57 changes: 57 additions & 0 deletions tests/unit/lib/data-generators/git-commit-nodetest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict';

var assert = require('ember-cli/tests/helpers/assert');
var gitRepoInfo = require('git-repo-info');

describe('the git-commit data generator', function() {
var DataGenerator;
var cwd;

before(function() {
DataGenerator = require('../../../../lib/data-generators/git-commit');
gitRepoInfo._changeGitDir('dotgit');
});

beforeEach(function() {
cwd = process.cwd();
});

afterEach(function() {
process.chdir(cwd);
});

describe('#generate', function() {
it('revision key contains first 7 characters of git commit hash', function() {
process.chdir('tests/fixtures/repo');

var subject = new DataGenerator();

return assert.isFulfilled(subject.generate())
.then(function(data) {
assert.equal(data.revisionKey, '41d41f0');
});
});

it('returns a timestamp', function() {
process.chdir('tests/fixtures/repo');

var subject = new DataGenerator();

return assert.isFulfilled(subject.generate())
.then(function(data) {
assert.isNotNull(data.timestamp);
});
});

it('rejects if no repository found', function() {
process.chdir('tests/fixtures/not-a-repo');

var subject = new DataGenerator();

return assert.isRejected(subject.generate())
.then(function(error) {
assert.equal(error, 'Could not find git repository');
});
});
});
});

0 comments on commit 5cdf4be

Please sign in to comment.