-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathpost-processing.js
77 lines (71 loc) · 1.98 KB
/
post-processing.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
75
76
77
const https = require('node:https');
const jsdom = require('jsdom');
module.exports = async function (data, callback) {
const rewritten = [];
for (const commit of data.commits) {
if (commit.title.indexOf('chore(release)') !== -1) {
continue;
}
const commitTitle = commit.title;
commit.title = commitTitle.substring(0, commitTitle.indexOf('#') - 1);
commit.messageLines = commit.messageLines.filter(message => {
if (message.indexOf('efs/') === -1) return message;
});
commit.messageLines.forEach(message => {
commit.issueno = message.includes('GH-')
? message.replace('GH-', '').trim()
: null;
});
const issueDesc = await getIssueDesc(commit.issueno).then(res => {
return res;
});
commit.issueTitle = issueDesc;
commit.committerDate = new Date(commit.committerDate).toLocaleDateString(
'en-us',
{
year: 'numeric',
month: 'long',
day: 'numeric',
},
);
rewritten.push(commit);
}
callback({
commits: rewritten.filter(Boolean),
range: data.range,
});
};
function getIssueDesc(issueNo) {
return new Promise((resolve, reject) => {
let result = '';
const req = https.get(
`https://github.com/sourcefuse/loopback4-notifications/issues/${encodeURIComponent(
issueNo,
)}`,
res => {
res.setEncoding('utf8');
res.on('data', chunk => {
result = result + chunk;
});
res.on('end', () => {
const {JSDOM} = jsdom;
const dom = new JSDOM(result);
const title = dom.window.document.getElementsByClassName(
'js-issue-title markdown-title',
);
let issueTitle = '';
for (const ele of title) {
if (ele.nodeName === 'BDI') {
issueTitle = ele.innerHTML;
}
}
resolve(issueTitle);
});
},
);
req.on('error', e => {
reject(e);
});
req.end();
});
}