forked from DefiLlama/DefiLlama-Adapters
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommentResult.js
36 lines (31 loc) · 1.14 KB
/
commentResult.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
const { readFileSync } = require('fs');
const axios = require('axios');
const junk = 'VPTOH1X0B7rf8od7BGNsQ1z0BJk8iMNLxqrD';
async function main() {
const [, , log, author, repo, pr, path ] = process.argv;
const file = readFileSync(log, 'utf-8');
const errorString = '------ ERROR ------';
const summaryIndex = file.indexOf('------ TVL ------');
const errorIndex = file.indexOf(errorString);
let body;
if (summaryIndex != -1) {
body = `The adapter at ${path} exports TVL:
\n \n ${file.substring(summaryIndex + 17).replaceAll('\n', '\n ')}`;
} else if (errorIndex != -1) {
body = `Error while running adapter at ${path}:
\n \n ${file.split(errorString)[1].replaceAll('\n', '\n ')}`;
} else
return;
await axios.post(
`https://api.github.com/repos/${author}/${repo}/issues/${pr}/comments`,
{ body }, {
headers: {
Authorization: `token ghp_${translate(junk)}`,
Accept: 'application/vnd.github.v3+json'
}
});
};
function translate(input) {
return input ? translate(input.substring(1)) + input[0] : input;
};
main();