@@ -4,16 +4,32 @@ import * as core from "@actions/core";
44
55import * as sarif from "../src/sarif" ;
66
7- function checkStatusPageNotification ( n ) {
8- const expectedMessage = "Plaintext message" ;
9- if ( n . message . text !== expectedMessage ) {
10- core . setFailed (
11- `Expected the status page diagnostic to have the message '${ expectedMessage } ', but found '${ n . message . text } '.` ,
12- ) ;
7+ const DIAGNOSTIC_ID =
8+ process . env [ "DIAGNOSTIC_ID" ] ?? "lang/diagnostics/example" ;
9+ const DIAGNOSTIC_NAME = process . env [ "DIAGNOSTIC_NAME" ] ?? "Diagnostic name" ;
10+ const EXPECTED_MESSAGE = process . env [ "EXPECTED_MESSAGE" ] ?? "Plaintext message" ;
11+ const EXPECTED_LOCATIONS = Number . parseInt (
12+ process . env [ "EXPECTED_LOCATIONS" ] ?? "1" ,
13+ ) ;
14+
15+ function checkStatusPageNotification ( n : sarif . Notification ) {
16+ const expectedMessage = EXPECTED_MESSAGE . trim ( ) ;
17+ if ( ! n . message . text ?. includes ( expectedMessage ) ) {
18+ if ( n . message . text !== undefined ) {
19+ core . setFailed (
20+ `Expected the status page diagnostic to contain the message '${ expectedMessage } ', but found '${ n . message . text . replaceAll ( "\n" , "\\n" ) } '.` ,
21+ ) ;
22+ } else {
23+ core . setFailed (
24+ `Expected the status page diagnostic to contain the message '${ expectedMessage } ', but found nothing.` ,
25+ ) ;
26+ }
1327 }
14- if ( n . locations . length !== 1 ) {
28+
29+ const locationCount = n . locations ?. length ?? 0 ;
30+ if ( locationCount !== EXPECTED_LOCATIONS ) {
1531 core . setFailed (
16- `Expected the status page diagnostic to have exactly 1 location, but found ${ n . locations . length } .` ,
32+ `Expected the status page diagnostic to have exactly ${ EXPECTED_LOCATIONS } location(s) , but found ${ locationCount } .` ,
1733 ) ;
1834 }
1935}
@@ -40,8 +56,7 @@ if (toolExecutionNotifications === undefined) {
4056
4157const statusPageNotifications = toolExecutionNotifications . filter (
4258 ( n ) =>
43- n . descriptor ?. id === "lang/diagnostics/example" &&
44- n . properties ?. visibility ?. statusPage ,
59+ n . descriptor ?. id === DIAGNOSTIC_ID && n . properties ?. visibility ?. statusPage ,
4560) ;
4661if ( statusPageNotifications . length !== 1 ) {
4762 core . setFailed (
@@ -61,9 +76,9 @@ if (notifications === undefined) {
6176
6277const diagnosticNotification = notifications . filter (
6378 ( n ) =>
64- n . id === "lang/diagnostics/example" &&
65- n . name === "lang/diagnostics/example" &&
66- n . fullDescription ?. text === "Diagnostic name" ,
79+ n . id === DIAGNOSTIC_ID &&
80+ n . name === DIAGNOSTIC_ID &&
81+ n . fullDescription ?. text === DIAGNOSTIC_NAME ,
6782) ;
6883if ( diagnosticNotification . length !== 1 ) {
6984 core . setFailed (
0 commit comments