-
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 #13 from alisdair/git-and-version-commit-key-gener…
…ators Add git-tag-commit and version-commit key generators
- Loading branch information
Showing
29 changed files
with
279 additions
and
3 deletions.
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
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,23 @@ | ||
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 tag = info.tag; | ||
var sha = info.sha.slice(0, 8); | ||
|
||
if (!info.tag || !sha) { | ||
return Promise.reject('Could not build revision with tag `' + tag + '` and commit hash `' + sha + '`'); | ||
} | ||
|
||
return Promise.resolve(info.tag + '+' + sha); | ||
} | ||
}); |
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,3 +1,5 @@ | ||
module.exports = { | ||
"file-hash": require('./file-hash') | ||
"file-hash": require('./file-hash'), | ||
"git-tag-commit": require('./git-tag-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,37 @@ | ||
var CoreObject = require('core-object'); | ||
var gitRepoInfo = require('git-repo-info'); | ||
var fs = require('fs'); | ||
var Promise = require('ember-cli/lib/ext/promise'); | ||
|
||
var denodeify = require('rsvp').denodeify; | ||
var readFile = denodeify(fs.readFile); | ||
|
||
module.exports = CoreObject.extend({ | ||
init: function(options) { | ||
this._plugin = options.plugin; | ||
}, | ||
|
||
generate: function() { | ||
var versionFile = this._plugin.readConfig('versionFile'); | ||
|
||
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, 8); | ||
|
||
return readFile(versionFile) | ||
.then(function(contents) { | ||
var json = JSON.parse(contents); | ||
|
||
if (!json.version || !sha) { | ||
return Promise.reject('Could not build revision with version `' + json.version + '` and commit hash `' + sha + '`'); | ||
} | ||
|
||
return json.version + '+' + sha; | ||
}); | ||
} | ||
}); |
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,3 @@ | ||
{ | ||
"version": "3.2.1" | ||
} |
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 @@ | ||
ref: refs/heads/master |
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,7 @@ | ||
[core] | ||
repositoryformatversion = 0 | ||
filemode = true | ||
bare = false | ||
logallrefupdates = true | ||
ignorecase = true | ||
precomposeunicode = true |
Binary file not shown.
2 changes: 2 additions & 0 deletions
2
tests/fixtures/repo/dotgit/objects/41/d41f081b45ad50935c08b1203220737d9739b4
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,2 @@ | ||
x��A | ||
1@Q�=E��4�L����"Ӧ�Z��������������7H��g�0N�GN�샥A�'&&t9~�Gmp^��X��E�Mp�_;��ֶ��~\���ak�Z��.2��Ԯ����OB� | ||
|
Binary file added
BIN
+41 Bytes
tests/fixtures/repo/dotgit/objects/77/06f9e51d51a2f357b2c2078cdd04e4acf48f93
Binary file not shown.
Binary file added
BIN
+41 Bytes
tests/fixtures/repo/dotgit/objects/a5/10e8069cc7eaa8b8262a9c071a702fbd52dbea
Binary file not shown.
Binary file added
BIN
+89 Bytes
tests/fixtures/repo/dotgit/objects/d4/6bba1991f218165a93efe79024e16da2a213fc
Binary file not shown.
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 @@ | ||
41d41f081b45ad50935c08b1203220737d9739b4 |
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 @@ | ||
41d41f081b45ad50935c08b1203220737d9739b4 |
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,3 @@ | ||
{ | ||
"version": "3.2.1" | ||
} |
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,3 @@ | ||
{ | ||
"version": "1.2.3" | ||
} |
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 @@ | ||
ref: refs/heads/master |
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,7 @@ | ||
[core] | ||
repositoryformatversion = 0 | ||
filemode = true | ||
bare = false | ||
logallrefupdates = true | ||
ignorecase = true | ||
precomposeunicode = true |
Binary file not shown.
Binary file added
BIN
+57 Bytes
tests/fixtures/tagless-repo/dotgit/objects/5e/29d0ad64c0132a1fc27416a0af2c05511c3e99
Binary file not shown.
Binary file added
BIN
+41 Bytes
tests/fixtures/tagless-repo/dotgit/objects/77/06f9e51d51a2f357b2c2078cdd04e4acf48f93
Binary file not shown.
2 changes: 2 additions & 0 deletions
2
tests/fixtures/tagless-repo/dotgit/objects/91/38ef996f3c7680aedcba68b0371d828b6dbb0b
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,2 @@ | ||
x��A | ||
1@Q�=E��$i;RQp��C������Z�/8���_���V�H��K�X8e�<E�,4+�M�2�b�D�KJN���:�{e�7���j�k��ym���G��G�� ��w>ʟ��>m�,�z�n�BM |
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 @@ | ||
9138ef996f3c7680aedcba68b0371d828b6dbb0b |
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,3 @@ | ||
{ | ||
"version": "3.2.1" | ||
} |
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,57 @@ | ||
'use strict'; | ||
|
||
var assert = require('ember-cli/tests/helpers/assert'); | ||
var gitRepoInfo = require('git-repo-info'); | ||
|
||
describe('the git-tag-commit key generator', function() { | ||
var KeyGenerator; | ||
var cwd; | ||
|
||
before(function() { | ||
KeyGenerator = require('../../../../lib/key-generators/git-tag-commit'); | ||
gitRepoInfo._changeGitDir('dotgit'); | ||
}); | ||
|
||
beforeEach(function() { | ||
cwd = process.cwd(); | ||
}); | ||
|
||
afterEach(function() { | ||
process.chdir(cwd); | ||
}); | ||
|
||
describe('#generate', function() { | ||
it('concatenates the git tag and the git commit hash', function() { | ||
process.chdir('tests/fixtures/repo'); | ||
|
||
var subject = new KeyGenerator(); | ||
|
||
return assert.isFulfilled(subject.generate()) | ||
.then(function(revision) { | ||
assert.equal(revision, '2.3.4+41d41f08'); | ||
}); | ||
}); | ||
|
||
it('rejects if no repository found', function() { | ||
process.chdir('tests/fixtures/not-a-repo'); | ||
|
||
var subject = new KeyGenerator(); | ||
|
||
return assert.isRejected(subject.generate()) | ||
.then(function(error) { | ||
assert.equal(error, 'Could not find git repository'); | ||
}); | ||
}); | ||
|
||
it('rejects if no git tag found', function() { | ||
process.chdir('tests/fixtures/tagless-repo'); | ||
|
||
var subject = new KeyGenerator(); | ||
|
||
return assert.isRejected(subject.generate()) | ||
.then(function(error) { | ||
assert.equal(error, 'Could not build revision with tag `null` and commit hash `9138ef99`'); | ||
}); | ||
}); | ||
}); | ||
}); |
101 changes: 101 additions & 0 deletions
101
tests/unit/lib/key-generators/version-commit-nodetest.js
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,101 @@ | ||
'use strict'; | ||
|
||
var assert = require('ember-cli/tests/helpers/assert'); | ||
var gitRepoInfo = require('git-repo-info'); | ||
|
||
describe('the version-commit key generator', function() { | ||
var KeyGenerator; | ||
var cwd; | ||
|
||
before(function() { | ||
KeyGenerator = require('../../../../lib/key-generators/version-commit'); | ||
gitRepoInfo._changeGitDir('dotgit'); | ||
}); | ||
|
||
beforeEach(function() { | ||
cwd = process.cwd(); | ||
}); | ||
|
||
afterEach(function() { | ||
process.chdir(cwd); | ||
}); | ||
|
||
describe('#generate', function() { | ||
it('concatenates the package version and the git commit hash', function() { | ||
process.chdir('tests/fixtures/repo'); | ||
|
||
var plugin = { | ||
stubConfig: { | ||
versionFile: 'package.json' | ||
}, | ||
readConfig: function(key) { return this.stubConfig[key]; } | ||
}; | ||
|
||
var subject = new KeyGenerator({ | ||
plugin: plugin | ||
}); | ||
|
||
return assert.isFulfilled(subject.generate()) | ||
.then(function(revision) { | ||
assert.equal(revision, '3.2.1+41d41f08'); | ||
}); | ||
}); | ||
|
||
it('rejects if no repository found', function() { | ||
process.chdir('tests/fixtures/not-a-repo'); | ||
|
||
var plugin = { | ||
stubConfig: { | ||
versionFile: 'package.json' | ||
}, | ||
readConfig: function(key) { return this.stubConfig[key]; } | ||
}; | ||
|
||
var subject = new KeyGenerator({ | ||
plugin: plugin | ||
}); | ||
|
||
return assert.isRejected(subject.generate()) | ||
.then(function(error) { | ||
assert.equal(error, 'Could not find git repository'); | ||
}); | ||
}); | ||
|
||
it('has version source file option', function() { | ||
process.chdir('tests/fixtures/repo'); | ||
|
||
var plugin = { | ||
stubConfig: { | ||
versionFile: 'version.json' | ||
}, | ||
readConfig: function(key) { return this.stubConfig[key]; } | ||
}; | ||
|
||
var subject = new KeyGenerator({ | ||
plugin: plugin | ||
}); | ||
|
||
return assert.isFulfilled(subject.generate()) | ||
.then(function(revision) { | ||
assert.equal(revision, '1.2.3+41d41f08'); | ||
}); | ||
}); | ||
|
||
it('rejects when the version source file doesn\'t exist', function() { | ||
process.chdir('tests/fixtures/repo'); | ||
|
||
var plugin = { | ||
stubConfig: { | ||
versionFile: 'tests/fixtures/missing-version.json' | ||
}, | ||
readConfig: function(key) { return this.stubConfig[key]; } | ||
}; | ||
|
||
var subject = new KeyGenerator({ | ||
plugin: plugin | ||
}); | ||
|
||
return assert.isRejected(subject.generate()); | ||
}); | ||
}); | ||
}); |