-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from jrowlingson/master
Add git-commit data generator
- Loading branch information
Showing
4 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); | ||
}); | ||
}); |