Skip to content

Commit

Permalink
Comment stats
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-8 committed Dec 17, 2019
1 parent 4946c05 commit f58cef4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
19 changes: 8 additions & 11 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,27 +392,24 @@ async function run() {
const sha = process.env.GITHUB_SHA;
core.debug(`SHA: ${sha}`);

console.log(`about to read: ${inputs.path}`)
console.log(`about to read: ${process.env.GITHUB_WORKSPACE}/${inputs.path}`)
const data = fs.readFileSync(`${process.env.GITHUB_WORKSPACE}/coverage/coverage-summary.json`, 'utf8');
console.log(`about to read: ${process.env.GITHUB_WORKSPACE}/`)
const data = fs.readFileSync(`${process.env.GITHUB_WORKSPACE}/${inputs.path}`, 'utf8');
const json = JSON.parse(data);
console.log(json);

fs.readdir(process.env.GITHUB_WORKSPACE, function (err, items) {
console.log(items);

for (var i = 0; i < items.length; i++) {
console.log(items[i]);
}
});
const coverage = `==== **Test Coverage** ====
Statements: ${json.total.statements.pct}% ( ${json.total.statements.covered}/${json.total.statements.total} )
Branches : ${json.total.branches.pct}% ( ${json.total.branches.covered}/${json.total.branches.total} )
Functions : ${json.total.functions.pct}% ( ${json.total.functions.covered}/${json.total.functions.total} )
Lines : ${json.total.lines.pct}% ( ${json.total.lines.covered}/${json.total.lines.total} )`

await request(
`POST /repos/${process.env.GITHUB_REPOSITORY}/commits/${sha}/comments`,
{
headers: {
authorization: `token ${inputs.token}`
},
body: eval('`' + inputs.path + '`')
body: eval('`' + coverage + '`')
}
);
} catch (error) {
Expand Down
19 changes: 8 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,24 @@ async function run() {
const sha = process.env.GITHUB_SHA;
core.debug(`SHA: ${sha}`);

console.log(`about to read: ${inputs.path}`)
console.log(`about to read: ${process.env.GITHUB_WORKSPACE}/${inputs.path}`)
const data = fs.readFileSync(`${process.env.GITHUB_WORKSPACE}/coverage/coverage-summary.json`, 'utf8');
console.log(`about to read: ${process.env.GITHUB_WORKSPACE}/`)
const data = fs.readFileSync(`${process.env.GITHUB_WORKSPACE}/${inputs.path}`, 'utf8');
const json = JSON.parse(data);
console.log(json);

fs.readdir(process.env.GITHUB_WORKSPACE, function (err, items) {
console.log(items);

for (var i = 0; i < items.length; i++) {
console.log(items[i]);
}
});
const coverage = `==== **Test Coverage** ====
Statements: ${json.total.statements.pct}% ( ${json.total.statements.covered}/${json.total.statements.total} )
Branches : ${json.total.branches.pct}% ( ${json.total.branches.covered}/${json.total.branches.total} )
Functions : ${json.total.functions.pct}% ( ${json.total.functions.covered}/${json.total.functions.total} )
Lines : ${json.total.lines.pct}% ( ${json.total.lines.covered}/${json.total.lines.total} )`

await request(
`POST /repos/${process.env.GITHUB_REPOSITORY}/commits/${sha}/comments`,
{
headers: {
authorization: `token ${inputs.token}`
},
body: eval('`' + inputs.path + '`')
body: eval('`' + coverage + '`')
}
);
} catch (error) {
Expand Down

0 comments on commit f58cef4

Please sign in to comment.