-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathgit-tag-commit.js
More file actions
41 lines (34 loc) · 1.11 KB
/
git-tag-commit.js
File metadata and controls
41 lines (34 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var CoreObject = require('core-object');
var gitRepoInfo = require('git-repo-info');
var RSVP = require('rsvp');
module.exports = CoreObject.extend({
init: function(options) {
this._super();
this._plugin = options.plugin;
},
generate: function() {
var providedTag = this._plugin.readConfig('tag');
if (providedTag) {
return RSVP.resolve({
revisionKey: providedTag,
timestamp: new Date().toISOString()
});
} else {
var commitHashLength = this._plugin.readConfig('commitHashLength');
var separator = this._plugin.readConfig('separator');
var info = gitRepoInfo();
if (info === null || info.root === null) {
return RSVP.reject('Could not find git repository');
}
var tag = info.lastTag;
var sha = info.sha.slice(0, commitHashLength);
if (!tag || !sha) {
return RSVP.reject('Could not build revision with tag `' + tag + '` and commit hash `' + sha + '`');
}
return RSVP.resolve({
revisionKey: tag + separator + sha,
timestamp: new Date().toISOString()
});
}
}
});