-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion.js
More file actions
34 lines (32 loc) · 922 Bytes
/
version.js
File metadata and controls
34 lines (32 loc) · 922 Bytes
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
exports.get = function (ref, run, sha) {
if (ref.startsWith('refs/tags/')) {
return fromTag(ref.replace(/^refs\/tags\//, ''));
}
return fromRefRunSha(ref, run, sha);
};
function fromTag(tag) {
let versionWithoutV = tag.replace(/^v(\d)/, '$1');
let fields = versionWithoutV.split('.');
return {
version: tag,
versionWithoutV: versionWithoutV,
major: fields[0] || '',
minor: fields[1] || '',
patch: fields.slice(2).join('.') || '',
};
}
function fromRefRunSha(ref, run, sha) {
sha = sha.substr(0, 8);
if (ref.startsWith('refs/pull/')) {
ref = ref.replace(/^refs\/pull\/(\d+)\/.*/, 'pr$1');
} else {
ref = ref.replace(/^refs\/heads\//, '');
}
return {
version: `${ref}-${run}-${sha}`,
versionWithoutV: `${ref}-${run}-${sha}`,
major: ref,
minor: run,
patch: sha,
};
}