Skip to content
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ The unique identifier of this build based on the version in the `package.json`,

For example, if your package.json version is `v2.0.3`, and the current commit is `0993043d49f9e0[...]`, this generator will return a revision of `v2.0.3+0993043d`.

`Note:` Some environments (like CircleCI) may return partial git information. If the current commit hash cannot be determined, the generator will return only the package.json version (`v2.0.3`) as the `revisionKey`.

##### timestamp

The timestamp of the current deploy
Expand Down
14 changes: 11 additions & 3 deletions lib/data-generators/version-commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,26 @@ module.exports = CoreObject.extend({
}

var info = gitRepoInfo(path);
var sha = info.sha.slice(0, 8);
var sha = (info.sha || '').slice(0, 8);
var log = this._plugin.log;

return readFile(versionFile)
.then(function(contents) {
var json = JSON.parse(contents);

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

var versionString = json.version;
if (sha) {
versionString = versionString + '+' + sha;
} else {
log('Missing git commit sha, using package version as revisionKey', { color: 'yellow', verbose: true });
}

return {
revisionKey: json.version + '+' + sha,
revisionKey: versionString,
timestamp: new Date().toISOString()
};
});
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/repo/dotgit-branch-only/HEAD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ref: refs/heads/master
7 changes: 7 additions & 0 deletions tests/fixtures/repo/dotgit-branch-only/config
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 added tests/fixtures/repo/dotgit-branch-only/index
Binary file not shown.
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�
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
53 changes: 53 additions & 0 deletions tests/unit/lib/data-generators/version-commit-nodetest.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,59 @@ describe('the version-commit data generator', function() {
});

describe('#generate', function() {
describe('with partial commit data', function() {
before(function() {
gitRepoInfo._changeGitDir('dotgit-branch-only');
});

after(function() {
gitRepoInfo._changeGitDir('dotgit');
});

it('only adds `+revision` if it can be read', function() {
process.chdir('tests/fixtures/repo');

var plugin = {
stubConfig: {
versionFile: 'package.json'
},
readConfig: function(key) { return this.stubConfig[key]; },
log: function() {}
};

var subject = new DataGenerator({
plugin: plugin
});

return assert.isFulfilled(subject.generate())
.then(function(data) {
var path = gitRepoInfo._findRepo();
assert.equal(data.revisionKey, '3.2.1');
});
});

it('logs a warning if no git sha found', function() {
process.chdir('tests/fixtures/repo');

var expectedMessage = /missing git commit sha/i;
var plugin = {
stubConfig: {
versionFile: 'package.json'
},
readConfig: function(key) { return this.stubConfig[key]; },
log: function(message) {
assert.ok(message.match(expectedMessage));
}
};

var subject = new DataGenerator({
plugin: plugin
});

return assert.isFulfilled(subject.generate())
})
});

it('concatenates the package version and the git commit hash', function() {
process.chdir('tests/fixtures/repo');

Expand Down