@@ -3,6 +3,7 @@ import {context} from '@actions/github'
33import { parseCoverageReport } from './coverage'
44import { compareCommits } from './compareCommits'
55import { messagePr } from './messagePr'
6+ import { octokit } from './client'
67
78import * as fs from 'fs'
89
@@ -18,13 +19,61 @@ async function run(): Promise<void> {
1819 const base = context . payload . pull_request ?. base . sha
1920 const head = context . payload . pull_request ?. head . sha
2021
22+ const checkName = 'Coverge Results'
23+ const checks = await octokit . rest . checks . listForRef ( {
24+ ...context . repo ,
25+ ref : head
26+ } )
27+
28+ const existingCheck = checks . data ?. check_runs ?. find ( check => check . name === checkName )
29+
30+ let checkId = - 1
31+
32+ if ( existingCheck ) {
33+ checkId = existingCheck . id
34+ core . info ( `existing checkId: ${ checkId } ` )
35+ await octokit . rest . checks . update ( {
36+ ...context . repo ,
37+ check_run_id : checkId ,
38+ status : 'in_progress'
39+ } )
40+ } else {
41+ const respond = await octokit . rest . checks . create ( {
42+ ...context . repo ,
43+ head_sha : head ,
44+ name : checkName ,
45+ status : 'in_progress'
46+ } )
47+ checkId = respond . data . id
48+ core . info ( `new checkId: ${ checkId } ` )
49+ }
50+
2151 core . info ( `comparing commits: base ${ base } <> head ${ head } ` )
2252 const files = await compareCommits ( base , head )
2353 core . info ( `git new files: ${ JSON . stringify ( files . newFiles ) } modified files: ${ JSON . stringify ( files . modifiedFiles ) } ` )
2454
2555 const report = fs . readFileSync ( coverageFile , 'utf8' )
2656 const filesCoverage = parseCoverageReport ( report , files )
27- messagePr ( filesCoverage )
57+ const { passOverall, message} = messagePr ( filesCoverage )
58+
59+ if ( passOverall ) {
60+ octokit . rest . checks . update ( {
61+ ...context . repo ,
62+ check_run_id : checkId ,
63+ status : 'completed' ,
64+ conclusion : 'success' ,
65+ output : { title : 'Coverage Results ✅' , summary : message }
66+ } )
67+ } else {
68+ octokit . rest . checks . update ( {
69+ ...context . repo ,
70+ check_run_id : checkId ,
71+ status : 'failure' ,
72+ conclusion : 'failed' ,
73+ output : { title : 'Coverage Results ❌' , summary : message }
74+ } )
75+ core . setFailed ( 'Coverage is lower then configured threshold 😭' )
76+ }
2877 } catch ( error ) {
2978 core . setFailed ( JSON . stringify ( error ) )
3079 }
0 commit comments