-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
69 lines (55 loc) · 1.47 KB
/
index.js
File metadata and controls
69 lines (55 loc) · 1.47 KB
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
const core = require('@actions/core');
const github = require('@actions/github');
const fs = require('fs');
const path = require('path');
const util = require('util');
const async = require('async');
const yaml = require('js-yaml');
const axios = require('axios');
const octokit = github.getOctokit(
process.env.GITHUB_TOKEN
);
const owner = github.context.payload.repository.owner.login;
const postBadgeData = async (badges) => {
// POST to badge data search
let data = await axios.post(
`${core.getInput('api-host')}/v1/badger/process/`,
{
data: badges
}
);
}
const getLatestAuthor = async () => {
let info = await octokit.rest.repos.listCommits({
owner: owner,
repo: github.context.payload.repository.name,
sha: process.env.GITHUB_REF_NAME
});
return info.data[0].author.login;
}
const run = async () => {
// Collect results from gatorgrader run
let outcome = JSON.parse(
fs.readFileSync(
core.getInput('grader-report'),
"utf-8"
)
);
// Filter only the checks with badges
let badges = outcome.checks.filter(
(check) => check.badges && check.status === true
).map(
(check) => check.badges
).reduce(
(badge)=>{badge}
);
badges = {
repository_name: github.context.payload.repository.name,
username: await getLatestAuthor(),
workflow_run_id: process.env.GITHUB_RUN_ID,
commit_hash: github.context.payload.commits[0].id,
grading_output: badges
}
postBadgeData(badges);
}
run();