Skip to content

Commit 265f405

Browse files
committed
Allow configuration of the separator character (+) in git-tag-commit and version-commit
1 parent 7df8947 commit 265f405

File tree

7 files changed

+78
-18
lines changed

7 files changed

+78
-18
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,20 @@ Constructs a revision key based on the most recent git tag and the currently che
120120

121121
##### revisionKey
122122

123-
The unique identifier of this build based on the git tag, followed by a `+` symbol, followed by the first 8 characters of the current commit hash.
123+
The unique identifier of this build based on the git tag, followed by a the separator symbol (`+` by default), followed by the first 8 characters of the current commit hash.
124124

125125
For example, if your most recent git tag is `v2.0.3`, and the current commit is `0993043d49f9e0[...]`, this generator will return a revision of `v2.0.3+0993043d`.
126126

127127
##### timestamp
128128

129129
The timestamp of the current deploy
130130

131+
#### Configuration Options
132+
133+
##### separator
134+
135+
The text used to separate the tag name from the commit sha. By default, `+` is used.
136+
131137
### Git Commit generator
132138

133139
Constructs a revision key based on the most recent git commit.
@@ -152,7 +158,7 @@ Similar to the Git Tag Commit generator but uses the `package.json` version stri
152158

153159
##### revisionKey
154160

155-
The unique identifier of this build based on the version in the `package.json`, followed by a `+` symbol, followed by the first 8 characters of the current commit hash.
161+
The unique identifier of this build based on the version in the `package.json`, followed by a the separator symbol (`+` by default), followed by the first 8 characters of the current commit hash.
156162

157163
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`.
158164

@@ -164,6 +170,10 @@ The timestamp of the current deploy
164170

165171
#### Configuration Options
166172

173+
##### separator
174+
175+
The text used to separate the tag name from the commit sha. By default, `+` is used.
176+
167177
##### versionFile
168178

169179
The file containing your project's version number. Must be a JSON file with a top-level `version` key.

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = {
1313
name: options.name,
1414
defaultConfig: {
1515
type: 'file-hash',
16+
separator: '+',
1617
filePattern: 'index.html',
1718
versionFile: 'package.json',
1819
distDir: function(context) {

lib/data-generators/git-tag-commit.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ var gitRepoInfo = require('git-repo-info');
33
var Promise = require('ember-cli/lib/ext/promise');
44

55
module.exports = CoreObject.extend({
6+
init: function(options) {
7+
this._super();
8+
this._plugin = options.plugin;
9+
},
10+
611
generate: function() {
12+
var separator = this._plugin.readConfig('separator');
713
var info = gitRepoInfo();
814

915
if (info === null || info.root === null) {
@@ -18,7 +24,7 @@ module.exports = CoreObject.extend({
1824
}
1925

2026
return Promise.resolve({
21-
revisionKey: info.tag + '+' + sha,
27+
revisionKey: info.tag + separator + sha,
2228
timestamp: new Date().toISOString()
2329
});
2430
}

lib/data-generators/version-commit.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = CoreObject.extend({
1313
},
1414

1515
generate: function() {
16+
var separator = this._plugin.readConfig('separator');
1617
var versionFile = this._plugin.readConfig('versionFile');
1718

1819
var info = gitRepoInfo();
@@ -34,7 +35,7 @@ module.exports = CoreObject.extend({
3435

3536
var versionString = json.version;
3637
if (sha) {
37-
versionString = versionString + '+' + sha;
38+
versionString = versionString + separator + sha;
3839
} else {
3940
plugin.log('Missing git commit sha, using package version as revisionKey', { color: 'yellow', verbose: true });
4041
}

tests/unit/index-nodetest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe('the index', function() {
7878
return previous;
7979
}, []);
8080

81-
assert.equal(messages.length, 6);
81+
assert.equal(messages.length, 7);
8282
});
8383

8484
it('adds default config to the config object', function() {

tests/unit/lib/data-generators/git-tag-commit-nodetest.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ describe('the git-tag-commit data generator', function() {
77
var DataGenerator;
88
var cwd;
99

10+
var plugin = {
11+
stubConfig: {
12+
separator: '+'
13+
},
14+
readConfig: function(key) { return this.stubConfig[key]; },
15+
};
16+
1017
before(function() {
1118
DataGenerator = require('../../../../lib/data-generators/git-tag-commit');
1219
gitRepoInfo._changeGitDir('dotgit');
@@ -24,29 +31,36 @@ describe('the git-tag-commit data generator', function() {
2431
it('concatenates the git tag and the git commit hash', function() {
2532
process.chdir('tests/fixtures/repo');
2633

27-
var subject = new DataGenerator();
34+
var subject = new DataGenerator({ plugin: plugin });
2835

2936
return assert.isFulfilled(subject.generate())
3037
.then(function(data) {
3138
assert.equal(data.revisionKey, '2.3.4+41d41f08');
3239
});
3340
});
3441

35-
it('returns a timestamp', function() {
42+
it('concatenates the git tag and the git commit hash with a custom separator', function() {
3643
process.chdir('tests/fixtures/repo');
3744

38-
var subject = new DataGenerator();
45+
var plugin = {
46+
stubConfig: {
47+
separator: '--'
48+
},
49+
readConfig: function(key) { return this.stubConfig[key]; },
50+
};
51+
52+
var subject = new DataGenerator({ plugin: plugin });
3953

4054
return assert.isFulfilled(subject.generate())
4155
.then(function(data) {
42-
assert.isNotNull(data.timestamp);
56+
assert.equal(data.revisionKey, '2.3.4--41d41f08');
4357
});
4458
});
4559

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

49-
var subject = new DataGenerator();
63+
var subject = new DataGenerator({ plugin: plugin });
5064

5165
return assert.isRejected(subject.generate())
5266
.then(function(error) {
@@ -57,7 +71,7 @@ describe('the git-tag-commit data generator', function() {
5771
it('rejects if no git tag found', function() {
5872
process.chdir('tests/fixtures/tagless-repo');
5973

60-
var subject = new DataGenerator();
74+
var subject = new DataGenerator({ plugin: plugin });
6175

6276
return assert.isRejected(subject.generate())
6377
.then(function(error) {

tests/unit/lib/data-generators/version-commit-nodetest.js

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ describe('the version-commit data generator', function() {
3535

3636
var plugin = {
3737
stubConfig: {
38-
versionFile: 'package.json'
38+
versionFile: 'package.json',
39+
separator: '+'
3940
},
4041
readConfig: function(key) { return this.stubConfig[key]; },
4142
log: function() {}
@@ -58,7 +59,8 @@ describe('the version-commit data generator', function() {
5859
var expectedMessage = /missing git commit sha/i;
5960
var plugin = {
6061
stubConfig: {
61-
versionFile: 'package.json'
62+
versionFile: 'package.json',
63+
separator: '+'
6264
},
6365
readConfig: function(key) { return this.stubConfig[key]; },
6466
log: function(message) {
@@ -79,7 +81,8 @@ describe('the version-commit data generator', function() {
7981

8082
var plugin = {
8183
stubConfig: {
82-
versionFile: 'package.json'
84+
versionFile: 'package.json',
85+
separator: '+'
8386
},
8487
readConfig: function(key) { return this.stubConfig[key]; }
8588
};
@@ -94,12 +97,34 @@ describe('the version-commit data generator', function() {
9497
});
9598
});
9699

100+
it('concatenates the package version and the git commit hash with a custom separator', function() {
101+
process.chdir('tests/fixtures/repo');
102+
103+
var plugin = {
104+
stubConfig: {
105+
versionFile: 'package.json',
106+
separator: '--'
107+
},
108+
readConfig: function(key) { return this.stubConfig[key]; }
109+
};
110+
111+
var subject = new DataGenerator({
112+
plugin: plugin
113+
});
114+
115+
return assert.isFulfilled(subject.generate())
116+
.then(function(data) {
117+
assert.equal(data.revisionKey, '3.2.1--41d41f08');
118+
});
119+
});
120+
97121
it('has version source file option', function() {
98122
process.chdir('tests/fixtures/repo');
99123

100124
var plugin = {
101125
stubConfig: {
102-
versionFile: 'version.json'
126+
versionFile: 'version.json',
127+
separator: '+'
103128
},
104129
readConfig: function(key) { return this.stubConfig[key]; }
105130
};
@@ -119,7 +144,8 @@ describe('the version-commit data generator', function() {
119144

120145
var plugin = {
121146
stubConfig: {
122-
versionFile: 'package.json'
147+
versionFile: 'package.json',
148+
separator: '+'
123149
},
124150
readConfig: function(key) { return this.stubConfig[key]; }
125151
};
@@ -139,7 +165,8 @@ describe('the version-commit data generator', function() {
139165

140166
var plugin = {
141167
stubConfig: {
142-
versionFile: 'package.json'
168+
versionFile: 'package.json',
169+
separator: '+'
143170
},
144171
readConfig: function(key) { return this.stubConfig[key]; }
145172
};
@@ -159,7 +186,8 @@ describe('the version-commit data generator', function() {
159186

160187
var plugin = {
161188
stubConfig: {
162-
versionFile: 'tests/fixtures/missing-version.json'
189+
versionFile: 'tests/fixtures/missing-version.json',
190+
separator: '+'
163191
},
164192
readConfig: function(key) { return this.stubConfig[key]; }
165193
};

0 commit comments

Comments
 (0)