dsa-connectors/status-checks/index.js
Ardhead 0ef4667258
Checker for solidity code (#32)
* raw logic

* rename and output update

* checks update

* name & comments checks update

* Updated comments for reflexer

* Updated comments

* colors and line numbers

* commit test

* commit test 2

* commit test 3

* commit test 4

* commit test 5

* commit test 6

* commit test 7

* reset branch

* commit test 1

* commit test 1

* test commit 1

* test commit

* test

* test

* test workflow

Co-authored-by: Thrilok Kumar <thrilok2000@gmail.com>
2021-05-07 22:06:52 +05:30

55 lines
1.3 KiB
JavaScript

const cp = require('child_process');
const fetch = require('node-fetch');
const checks = require('./checks');
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
function getCurrentCommitSha() {
return cp
.execSync(`git rev-parse HEAD`)
.toString()
.trim();
}
// The SHA provied by GITHUB_SHA is the merge (PR) commit.
// We need to get the current commit sha ourself.
const sha = getCurrentCommitSha();
async function setStatus(context, state, description) {
return fetch(`https://api.github.com/repos/${owner}/${repo}/statuses/${sha}`, {
method: 'POST',
body: JSON.stringify({
state,
description,
context,
}),
headers: {
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
'Content-Type': 'application/json',
},
});
}
(async () => {
console.log(`Starting status checks for commit ${sha}`);
// Run in parallel
await Promise.all(
checks.map(async check => {
const { name, callback } = check;
await setStatus(name, 'pending', 'Running check..');
try {
const response = await callback();
await setStatus(name, 'success', response);
} catch (err) {
const message = err ? err.message : 'Something went wrong';
await setStatus(name, 'failure', message);
}
}),
);
console.log('Finished status checks');
})();