Files
DefiLlama-yield-server/.github/workflows/commentResult.js
glebskr 6fb1c8b0b4 Use jest for tests #1 (#110)
* Use jest for tests #1

* Trigger tests

* Move jest to main dependencies

* install dev deps for tests

* Use node for pr comments

* Fix summary index string

* Change tests prompt

* Add error

* Throw error

* Fix comment output

* Fix error output

* Fix error index

* Fix

* Add error

* Fix test.yml

* Fix error

* Revert broken adapter for ci tests
2022-07-22 00:22:13 +02:00

40 lines
1.3 KiB
JavaScript

const { readFileSync } = require('fs');
const fetch = require('node-fetch');
const junk = 'VPTOH1X0B7rf8od7BGNsQ1z0BJk8iMNLxqrD';
async function main() {
const [, , log, author, repo, pr, adapter] = process.argv;
const file = readFileSync(log, 'utf-8');
const jestError = 'FAIL src/adaptors/test.js';
const jestSuccess = 'PASS src/adaptors/test.js';
const summaryIndex = file.indexOf('Test Suites:');
const jestSuccessIndex = file.indexOf(jestSuccess);
const jestErrorIndex = file.indexOf(jestError);
let body;
if (jestErrorIndex === -1 && jestSuccessIndex !== -1) {
body = `The ${adapter} adapter exports pools:
\n \n ${file.substring(summaryIndex).replaceAll('\n', '\n ')}`;
} else if (jestErrorIndex !== -1) {
body = `Error while running ${adapter} adapter:
\n \n ${file.substring(summaryIndex).replaceAll('\n', '\n ')}}`;
} else return;
await fetch(
`https://api.github.com/repos/${author}/${repo}/issues/${pr}/comments`,
{
body: JSON.stringify({ body }),
method: 'POST',
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();