-
Notifications
You must be signed in to change notification settings - Fork 19
/
releaseLog.js
74 lines (61 loc) · 1.96 KB
/
releaseLog.js
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { execFile } from 'child_process';
function invoke(file = '', args = [], options) {
return new Promise((res, rej) => {
execFile(file, args, options, (err, out, steerr) => {
if (err) {
rej(err);
}
if (steerr) {
rej(steerr);
}
res(out);
});
});
}
function collectPreviouTagAfterHead (repoUrls = []) {
const req = repoUrls.map(({url}) => {
return invoke(
'git',
['tag', '--sort=-taggerdate'],
{ cwd: url, windowsHide: true }
).then((list) => {
const tags = list.split('\n').filter(Boolean);
return tags[1] || tags[0];
});
});
return Promise.all(req);
}
function collectLastTags (repoUrls = []) {
const req = repoUrls.map(({url}) => {
return invoke(
'git',
['describe', '--abbrev=0', '--tags'],
{ cwd: url, windowsHide: true }
).then((e) => e.trim());
});
return Promise.all(req);
}
function collectCommits (repoUrls = [], endTags = []) {
const req = repoUrls.map(({url}, i) => {
return invoke(
'git',
['log', '--pretty=format:"%cd; %s"','--date=short', '--' ,`HEAD...${endTags[i].trim()}`],
{ cwd: url, windowsHide: true }
).then(h => h.split('\n').filter(Boolean).map((l) => l.substring(1, l.length - 1)));
});
return Promise.all(req);
}
export async function releaseLog (reposList = [], endTags = []) {
if (!endTags || endTags.length === 0) {
endTags = await collectPreviouTagAfterHead(reposList);
}
const currentTags = await collectLastTags(reposList);
const history = await collectCommits(reposList, endTags);
return reposList.map((e, i) => ({
currentTag: currentTags[i],
endTag: endTags[i].trim(),
commits: history[i],
url: e.url,
name: e.name
}));
}