@@ -3,6 +3,7 @@ import { context, getOctokit } from '@actions/github'
3
3
import type { GitHub } from '@actions/github/lib/utils'
4
4
import * as exec from '@actions/exec'
5
5
6
+ import type { ProjectStatus } from './sonarqube'
6
7
import Sonarqube from './sonarqube'
7
8
import type { Annotation } from './utils'
8
9
import { issuesToAnnotations } from './utils'
@@ -13,12 +14,12 @@ const MAX_ANNOTATIONS_PER_REQUEST = 50
13
14
const createCheckRun = async ( {
14
15
octokit,
15
16
repo,
16
- SQDetailsURL ,
17
+ summary ,
17
18
annotations,
18
19
} : {
19
20
octokit : InstanceType < typeof GitHub >
20
21
repo : { owner : string ; repo : string }
21
- SQDetailsURL : string
22
+ summary : string
22
23
annotations ?: Annotation [ ]
23
24
} ) => {
24
25
info ( 'Creating check' )
@@ -34,10 +35,9 @@ const createCheckRun = async ({
34
35
head_sha : ref ,
35
36
status : 'completed' ,
36
37
conclusion : 'neutral' ,
37
- details_url : SQDetailsURL ,
38
38
output : {
39
39
title : 'SonarQube' ,
40
- summary : `See more details in [SonarQube]( ${ SQDetailsURL } )` ,
40
+ summary,
41
41
annotations,
42
42
} ,
43
43
} )
@@ -48,21 +48,60 @@ const createCheckRun = async ({
48
48
}
49
49
}
50
50
51
+ const generateSummary = ( status : ProjectStatus , url : string ) => {
52
+ const conditions = status . conditions . reduce < string > ( ( acc , current ) => {
53
+ switch ( current . metricKey ) {
54
+ case 'reliability_rating' :
55
+ return `${ acc } Reability ${
56
+ current . status === 'ERROR' ? ':x:' : ':white_check_mark:'
57
+ } \n`
58
+
59
+ case 'security_rating' :
60
+ return `${ acc } Security ${
61
+ current . status === 'ERROR' ? ':x:' : ':white_check_mark:'
62
+ } \n`
63
+
64
+ case 'sqale_rating' :
65
+ return `${ acc } Security review ${
66
+ current . status === 'ERROR' ? ':x:' : ':white_check_mark:'
67
+ } \n`
68
+
69
+ case 'security_hotspots_reviewed' :
70
+ return `${ acc } Security hotspots ${
71
+ current . status === 'ERROR' ? ':x:' : ':white_check_mark:'
72
+ } \n`
73
+
74
+ default :
75
+ return ''
76
+ }
77
+ } , '' )
78
+
79
+ return `
80
+ ### Quality Gate ${
81
+ status . status === 'ERROR' ? 'failed :x:' : 'passed :white_check_mark:'
82
+ } .
83
+ See more details in [SonarQube](${ url } ).
84
+
85
+ ### Conditions
86
+ ${ conditions }
87
+
88
+ `
89
+ }
90
+
51
91
const updateCheckRun = async ( {
52
92
octokit,
53
93
repo,
54
94
checkRunId,
55
95
annotations,
56
- SQDetailsURL ,
96
+ summary ,
57
97
} : {
58
98
octokit : InstanceType < typeof GitHub >
59
99
repo : { owner : string ; repo : string }
60
100
checkRunId : number
61
101
annotations : Annotation [ ]
62
- SQDetailsURL : string
102
+ summary : string
63
103
} ) => {
64
104
info ( 'Updating check with annotations' )
65
-
66
105
try {
67
106
await octokit . checks . update ( {
68
107
...repo ,
@@ -71,7 +110,7 @@ const updateCheckRun = async ({
71
110
conclusion : 'neutral' ,
72
111
output : {
73
112
title : 'SonarQube' ,
74
- summary : `See more details in [SonarQube]( ${ SQDetailsURL } )` ,
113
+ summary,
75
114
annotations,
76
115
} ,
77
116
} )
@@ -99,7 +138,12 @@ async function run() {
99
138
100
139
const SQDetailsURL = `${ sonarqube . host } /dashboard?id=${ sonarqube . project . projectKey } `
101
140
102
- const checkRunId = await createCheckRun ( { octokit, repo, SQDetailsURL } )
141
+ const status = await sonarqube . getStatus ( )
142
+ const summary = status
143
+ ? generateSummary ( status , SQDetailsURL )
144
+ : `See more details in [SonarQube](${ SQDetailsURL } )`
145
+
146
+ const checkRunId = await createCheckRun ( { octokit, repo, summary } )
103
147
104
148
issues . map ( async ( batch ) => {
105
149
const annotations = issuesToAnnotations ( batch )
@@ -109,7 +153,7 @@ async function run() {
109
153
repo,
110
154
checkRunId,
111
155
annotations,
112
- SQDetailsURL ,
156
+ summary ,
113
157
} )
114
158
} )
115
159
}
0 commit comments