@@ -3,6 +3,7 @@ import {context} from '@actions/github'
3
3
import { parseCoverageReport } from './coverage'
4
4
import { compareCommits } from './compareCommits'
5
5
import { messagePr } from './messagePr'
6
+ import { octokit } from './client'
6
7
7
8
import * as fs from 'fs'
8
9
@@ -18,13 +19,61 @@ async function run(): Promise<void> {
18
19
const base = context . payload . pull_request ?. base . sha
19
20
const head = context . payload . pull_request ?. head . sha
20
21
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
+
21
51
core . info ( `comparing commits: base ${ base } <> head ${ head } ` )
22
52
const files = await compareCommits ( base , head )
23
53
core . info ( `git new files: ${ JSON . stringify ( files . newFiles ) } modified files: ${ JSON . stringify ( files . modifiedFiles ) } ` )
24
54
25
55
const report = fs . readFileSync ( coverageFile , 'utf8' )
26
56
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
+ }
28
77
} catch ( error ) {
29
78
core . setFailed ( JSON . stringify ( error ) )
30
79
}
0 commit comments