@@ -6,24 +6,45 @@ import { Language } from "./languages";
66import { getActionsLogger } from "./logging" ;
77import { getCodeQLDatabasePath } from "./util" ;
88
9- /** Represents a diagnostic message for the tool status page, etc. */
10- export interface DiagnosticMessage {
9+ /**
10+ * Known tags for diagnostics. There is currently only "internal-error",
11+ * but others may be added in the future.
12+ */
13+ export type DiagnosticTag = "internal-error" ;
14+
15+ /** Optional information about the origin of a diagnostic. */
16+ export type DiagnosticSourceOptions = {
17+ /**
18+ * Name of the CodeQL extractor. This is used to identify which tool component the reporting
19+ * descriptor object should be nested under in SARIF.
20+ */
21+ extractorName ?: string ;
22+ /** An array of tags for the diagnostic. */
23+ tags ?: DiagnosticTag [ ] ;
24+ } ;
25+
26+ /** Represents information about the origin of a diagnostic. */
27+ export type DiagnosticSource = {
28+ /**
29+ * An identifier under which it makes sense to group this diagnostic message.
30+ * This is used to build the SARIF reporting descriptor object.
31+ */
32+ id : string ;
33+ /** Display name for the ID. This is used to build the SARIF reporting descriptor object. */
34+ name : string ;
35+ } & DiagnosticSourceOptions ;
36+
37+ /**
38+ * Represents a diagnostic message for the tool status page, etc.
39+ *
40+ * Unlike {@link DiagnosticMessage}, properties which can automatically
41+ * be populated are optional in this type.
42+ */
43+ export type DiagnosticMessageOptions = {
1144 /** ISO 8601 timestamp */
12- timestamp : string ;
13- source : {
14- /**
15- * An identifier under which it makes sense to group this diagnostic message.
16- * This is used to build the SARIF reporting descriptor object.
17- */
18- id : string ;
19- /** Display name for the ID. This is used to build the SARIF reporting descriptor object. */
20- name : string ;
21- /**
22- * Name of the CodeQL extractor. This is used to identify which tool component the reporting
23- * descriptor object should be nested under in SARIF.
24- */
25- extractorName ?: string ;
26- } ;
45+ timestamp ?: string ;
46+ /** Information about the origin of the diagnostic. */
47+ source ?: DiagnosticSourceOptions ;
2748 /** GitHub flavored Markdown formatted message. Should include inline links to any help pages. */
2849 markdownMessage ?: string ;
2950 /** Plain text message. Used by components where the string processing needed to support Markdown is cumbersome. */
@@ -53,7 +74,15 @@ export interface DiagnosticMessage {
5374 } ;
5475 /** Structured metadata about the diagnostic message */
5576 attributes ?: { [ key : string ] : any } ;
56- }
77+ } ;
78+
79+ /** Represents a diagnostic message for the tool status page, etc. */
80+ export type DiagnosticMessage = DiagnosticMessageOptions & {
81+ /** ISO 8601 timestamp */
82+ timestamp : string ;
83+ /** Information about the origin of the diagnostic. */
84+ source : DiagnosticSource ;
85+ } ;
5786
5887/** Represents a diagnostic message that has not yet been written to the database. */
5988interface UnwrittenDiagnostic {
@@ -90,7 +119,7 @@ let diagnosticCounter = 0;
90119export function makeDiagnostic (
91120 id : string ,
92121 name : string ,
93- data : Partial < DiagnosticMessage > | undefined = undefined ,
122+ data : DiagnosticMessageOptions | undefined = undefined ,
94123) : DiagnosticMessage {
95124 return {
96125 ...data ,
@@ -243,6 +272,7 @@ export function makeTelemetryDiagnostic(
243272 id : string ,
244273 name : string ,
245274 attributes : { [ key : string ] : any } ,
275+ tags ?: DiagnosticTag [ ] ,
246276) : DiagnosticMessage {
247277 return makeDiagnostic ( id , name , {
248278 attributes,
@@ -251,5 +281,8 @@ export function makeTelemetryDiagnostic(
251281 statusPage : false ,
252282 telemetry : true ,
253283 } ,
284+ source : {
285+ tags,
286+ } ,
254287 } ) ;
255288}
0 commit comments