@fabasoad/sarif-to-slack 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/SarifToSlackClient.d.ts.map +1 -1
  2. package/dist/SarifToSlackClient.js +8 -10
  3. package/dist/index.cjs +141 -90
  4. package/dist/index.d.ts +12 -2
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +12 -3
  7. package/dist/model/Color.d.ts +5 -2
  8. package/dist/model/Color.d.ts.map +1 -1
  9. package/dist/model/Color.js +13 -14
  10. package/dist/model/Finding.js +3 -3
  11. package/dist/model/FindingArray.d.ts +2 -0
  12. package/dist/model/FindingArray.d.ts.map +1 -0
  13. package/dist/model/FindingArray.js +24 -0
  14. package/dist/model/SendIf.d.ts +116 -0
  15. package/dist/model/SendIf.d.ts.map +1 -0
  16. package/dist/model/SendIf.js +176 -0
  17. package/dist/model/SlackMessage.d.ts +23 -0
  18. package/dist/model/SlackMessage.d.ts.map +1 -0
  19. package/dist/model/SlackMessage.js +99 -0
  20. package/dist/representations/Representation.js +3 -3
  21. package/dist/sarif-to-slack.d.ts +14 -3
  22. package/dist/types.d.ts +1 -130
  23. package/dist/types.d.ts.map +1 -1
  24. package/dist/types.js +1 -117
  25. package/etc/sarif-to-slack.api.md +1 -0
  26. package/package.json +1 -1
  27. package/src/SarifToSlackClient.ts +7 -11
  28. package/src/index.ts +12 -4
  29. package/src/model/Color.ts +24 -21
  30. package/src/model/Finding.ts +3 -3
  31. package/src/model/{FindingsArray.ts → FindingArray.ts} +3 -3
  32. package/src/model/SendIf.ts +175 -0
  33. package/src/{SlackMessageBuilder.ts → model/SlackMessage.ts} +31 -6
  34. package/src/processors/CodeQLProcessor.ts +1 -1
  35. package/src/representations/CompactGroupByRepresentation.ts +1 -1
  36. package/src/representations/CompactGroupByRunRepresentation.ts +1 -1
  37. package/src/representations/CompactGroupBySarifRepresentation.ts +1 -1
  38. package/src/representations/CompactGroupByToolNameRepresentation.ts +1 -1
  39. package/src/representations/CompactTotalRepresentation.ts +1 -1
  40. package/src/representations/Representation.ts +4 -4
  41. package/src/types.ts +3 -134
  42. package/src/utils/Comparators.ts +1 -1
  43. package/tests/integration/SendSarifToSlack.spec.ts +1 -2
  44. package/dist/SlackMessageBuilder.d.ts +0 -2
  45. package/dist/SlackMessageBuilder.d.ts.map +0 -1
  46. package/dist/SlackMessageBuilder.js +0 -91
  47. package/dist/model/FindingsArray.d.ts +0 -2
  48. package/dist/model/FindingsArray.d.ts.map +0 -1
  49. package/dist/model/FindingsArray.js +0 -24
package/dist/types.d.ts CHANGED
@@ -1,19 +1,5 @@
1
1
  import { ColorOptions } from './model/Color';
2
- /**
3
- * Interface for a Slack message that can be sent.
4
- * @public
5
- */
6
- export interface SlackMessage {
7
- /**
8
- * Sends the Slack message.
9
- * @returns A promise that resolves to the response from the Slack webhook.
10
- */
11
- send: () => Promise<string>;
12
- withActor(actor?: string): void;
13
- withFooter(text?: string, type?: FooterType): void;
14
- withHeader(header?: string): void;
15
- withRun(): void;
16
- }
2
+ import { SendIf } from './model/SendIf';
17
3
  /**
18
4
  * Enum representing log levels for the service.
19
5
  * @public
@@ -208,121 +194,6 @@ export type SarifOptions = {
208
194
  recursive?: boolean;
209
195
  extension?: SarifFileExtension;
210
196
  };
211
- /**
212
- * This enum represents the condition on when message should be sent. If this
213
- * condition is satisfied then message is sent, otherwise - message is not sent.
214
- * @public
215
- */
216
- export declare enum SendIf {
217
- /**
218
- * Send message only if there is at least one finding with "Critical" severity.
219
- * Since it is the higher possible severity, it is the same as "Critical" or
220
- * higher.
221
- */
222
- SeverityCritical = 0,
223
- /**
224
- * Send message only if there is at least one finding with "High" severity.
225
- */
226
- SeverityHigh = 1,
227
- /**
228
- * Send message only if there is at least one finding with "High" severity or
229
- * higher, that includes "High" and "Critical".
230
- */
231
- SeverityHighOrHigher = 2,
232
- /**
233
- * Send message only if there is at least one finding with "Medium" severity.
234
- */
235
- SeverityMedium = 3,
236
- /**
237
- * Send message only if there is at least one finding with "Medium" severity
238
- * or higher, that includes "Medium", "High" and "Critical".
239
- */
240
- SeverityMediumOrHigher = 4,
241
- /**
242
- * Send message only if there is at least one finding with "Low" severity.
243
- */
244
- SeverityLow = 5,
245
- /**
246
- * Send message only if there is at least one finding with "Low" severity or
247
- * higher, that includes "Low", "Medium", "High" and "Critical".
248
- */
249
- SeverityLowOrHigher = 6,
250
- /**
251
- * Send message only if there is at least one finding with "None" severity.
252
- */
253
- SeverityNone = 7,
254
- /**
255
- * Send message only if there is at least one finding with "None" severity or
256
- * higher, that includes "None", "Low", "Medium", "High" and "Critical".
257
- */
258
- SeverityNoneOrHigher = 8,
259
- /**
260
- * Send message only if there is at least one finding with "Unknown" severity.
261
- */
262
- SeverityUnknown = 9,
263
- /**
264
- * Send message only if there is at least one finding with "Unknown" severity
265
- * or higher, that includes "Unknown", "None", "Low", "Medium", "High" and "Critical".
266
- */
267
- SeverityUnknownOrHigher = 10,
268
- /**
269
- * Send message only if there is at least one finding with "Error" level.
270
- * Since it is the higher possible level, it is the same as "Error" or higher.
271
- */
272
- LevelError = 11,
273
- /**
274
- * Send message only if there is at least one finding with "Warning" level.
275
- */
276
- LevelWarning = 12,
277
- /**
278
- * Send message only if there is at least one finding with "Warning" level or
279
- * higher, that includes "Warning" and "Error".
280
- */
281
- LevelWarningOrHigher = 13,
282
- /**
283
- * Send message only if there is at least one finding with "Note" level.
284
- */
285
- LevelNote = 14,
286
- /**
287
- * Send message only if there is at least one finding with "Note" level or
288
- * higher, that includes "Note", "Warning" and "Error.
289
- */
290
- LevelNoteOrHigher = 15,
291
- /**
292
- * Send message only if there is at least one finding with "None" level.
293
- */
294
- LevelNone = 16,
295
- /**
296
- * Send message only if there is at least one finding with "None" level or
297
- * higher, that includes "None", "Note", "Warning" and "Error.
298
- */
299
- LevelNoneOrHigher = 17,
300
- /**
301
- * Send message only if there is at least one finding with "Unknown" level.
302
- */
303
- LevelUnknown = 18,
304
- /**
305
- * Send message only if there is at least one finding with "Unknown" level or
306
- * higher, that includes "Unknown", "None", "Note", "Warning" and "Error.
307
- */
308
- LevelUnknownOrHigher = 19,
309
- /**
310
- * Always send a message.
311
- */
312
- Always = 20,
313
- /**
314
- * Send a message if at least 1 vulnerability is found.
315
- */
316
- Some = 21,
317
- /**
318
- * Send a message only if no vulnerabilities are found.
319
- */
320
- Empty = 22,
321
- /**
322
- * Never send a message.
323
- */
324
- Never = 23
325
- }
326
197
  /**
327
198
  * Options for the SarifToSlackClient.
328
199
  * @public
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAG5C;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,IAAI,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAA;IAC3B,SAAS,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,IAAI,CAAA;IAClD,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACjC,OAAO,IAAI,IAAI,CAAA;CAChB;AAED;;;GAGG;AACH,oBAAY,QAAQ;IAClB;;;OAGG;IACH,KAAK,IAAI;IACT;;OAEG;IACH,KAAK,IAAI;IACT;;;OAGG;IACH,KAAK,IAAI;IACT;;;OAGG;IACH,IAAI,IAAI;IACR;;;OAGG;IACH,OAAO,IAAI;IACX;;;OAGG;IACH,KAAK,IAAI;IACT;;;OAGG;IACH,KAAK,IAAI;CACV;AAED;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA;AAED;;;;GAIG;AACH,MAAM,MAAM,4BAA4B,GAAG,mBAAmB,GAAG;IAC/D,KAA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AAG,MAAM,CAAA;AAEjD;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,kBAAkB,CAAC;CAChC,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,YAAY,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,GAAG,CAAC,EAAE,UAAU,CAAC;IACjB,MAAM,CAAC,EAAE,4BAA4B,CAAC;IACtC,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,KAAK,CAAC,EAAE,4BAA4B,CAAC;IACrC,GAAG,CAAC,EAAE,mBAAmB,CAAC;IAC1B,cAAc,CAAC,EAAE,kBAAkB,CAAC;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAA"}
package/dist/types.js CHANGED
@@ -144,122 +144,6 @@ export var RepresentationType;
144
144
  */
145
145
  RepresentationType[RepresentationType["CompactTotalPerSeverity"] = 7] = "CompactTotalPerSeverity";
146
146
  })(RepresentationType || (RepresentationType = {}));
147
- /**
148
- * This enum represents the condition on when message should be sent. If this
149
- * condition is satisfied then message is sent, otherwise - message is not sent.
150
- * @public
151
- */
152
- export var SendIf;
153
- (function (SendIf) {
154
- /**
155
- * Send message only if there is at least one finding with "Critical" severity.
156
- * Since it is the higher possible severity, it is the same as "Critical" or
157
- * higher.
158
- */
159
- SendIf[SendIf["SeverityCritical"] = 0] = "SeverityCritical";
160
- /**
161
- * Send message only if there is at least one finding with "High" severity.
162
- */
163
- SendIf[SendIf["SeverityHigh"] = 1] = "SeverityHigh";
164
- /**
165
- * Send message only if there is at least one finding with "High" severity or
166
- * higher, that includes "High" and "Critical".
167
- */
168
- SendIf[SendIf["SeverityHighOrHigher"] = 2] = "SeverityHighOrHigher";
169
- /**
170
- * Send message only if there is at least one finding with "Medium" severity.
171
- */
172
- SendIf[SendIf["SeverityMedium"] = 3] = "SeverityMedium";
173
- /**
174
- * Send message only if there is at least one finding with "Medium" severity
175
- * or higher, that includes "Medium", "High" and "Critical".
176
- */
177
- SendIf[SendIf["SeverityMediumOrHigher"] = 4] = "SeverityMediumOrHigher";
178
- /**
179
- * Send message only if there is at least one finding with "Low" severity.
180
- */
181
- SendIf[SendIf["SeverityLow"] = 5] = "SeverityLow";
182
- /**
183
- * Send message only if there is at least one finding with "Low" severity or
184
- * higher, that includes "Low", "Medium", "High" and "Critical".
185
- */
186
- SendIf[SendIf["SeverityLowOrHigher"] = 6] = "SeverityLowOrHigher";
187
- /**
188
- * Send message only if there is at least one finding with "None" severity.
189
- */
190
- SendIf[SendIf["SeverityNone"] = 7] = "SeverityNone";
191
- /**
192
- * Send message only if there is at least one finding with "None" severity or
193
- * higher, that includes "None", "Low", "Medium", "High" and "Critical".
194
- */
195
- SendIf[SendIf["SeverityNoneOrHigher"] = 8] = "SeverityNoneOrHigher";
196
- /**
197
- * Send message only if there is at least one finding with "Unknown" severity.
198
- */
199
- SendIf[SendIf["SeverityUnknown"] = 9] = "SeverityUnknown";
200
- /**
201
- * Send message only if there is at least one finding with "Unknown" severity
202
- * or higher, that includes "Unknown", "None", "Low", "Medium", "High" and "Critical".
203
- */
204
- SendIf[SendIf["SeverityUnknownOrHigher"] = 10] = "SeverityUnknownOrHigher";
205
- /**
206
- * Send message only if there is at least one finding with "Error" level.
207
- * Since it is the higher possible level, it is the same as "Error" or higher.
208
- */
209
- SendIf[SendIf["LevelError"] = 11] = "LevelError";
210
- /**
211
- * Send message only if there is at least one finding with "Warning" level.
212
- */
213
- SendIf[SendIf["LevelWarning"] = 12] = "LevelWarning";
214
- /**
215
- * Send message only if there is at least one finding with "Warning" level or
216
- * higher, that includes "Warning" and "Error".
217
- */
218
- SendIf[SendIf["LevelWarningOrHigher"] = 13] = "LevelWarningOrHigher";
219
- /**
220
- * Send message only if there is at least one finding with "Note" level.
221
- */
222
- SendIf[SendIf["LevelNote"] = 14] = "LevelNote";
223
- /**
224
- * Send message only if there is at least one finding with "Note" level or
225
- * higher, that includes "Note", "Warning" and "Error.
226
- */
227
- SendIf[SendIf["LevelNoteOrHigher"] = 15] = "LevelNoteOrHigher";
228
- /**
229
- * Send message only if there is at least one finding with "None" level.
230
- */
231
- SendIf[SendIf["LevelNone"] = 16] = "LevelNone";
232
- /**
233
- * Send message only if there is at least one finding with "None" level or
234
- * higher, that includes "None", "Note", "Warning" and "Error.
235
- */
236
- SendIf[SendIf["LevelNoneOrHigher"] = 17] = "LevelNoneOrHigher";
237
- /**
238
- * Send message only if there is at least one finding with "Unknown" level.
239
- */
240
- SendIf[SendIf["LevelUnknown"] = 18] = "LevelUnknown";
241
- /**
242
- * Send message only if there is at least one finding with "Unknown" level or
243
- * higher, that includes "Unknown", "None", "Note", "Warning" and "Error.
244
- */
245
- SendIf[SendIf["LevelUnknownOrHigher"] = 19] = "LevelUnknownOrHigher";
246
- /**
247
- * Always send a message.
248
- */
249
- SendIf[SendIf["Always"] = 20] = "Always";
250
- /**
251
- * Send a message if at least 1 vulnerability is found.
252
- */
253
- SendIf[SendIf["Some"] = 21] = "Some";
254
- /**
255
- * Send a message only if no vulnerabilities are found.
256
- */
257
- SendIf[SendIf["Empty"] = 22] = "Empty";
258
- /**
259
- * Never send a message.
260
- */
261
- SendIf[SendIf["Never"] = 23] = "Never";
262
- })(SendIf || (SendIf = {}));
263
147
  /**
264
148
  * Enum of security severity.
265
149
  * @privateRemarks Order should remain unchanged. It is used in multiple places,
@@ -291,4 +175,4 @@ export var SecurityLevel;
291
175
  SecurityLevel[SecurityLevel["Warning"] = 3] = "Warning";
292
176
  SecurityLevel[SecurityLevel["Error"] = 4] = "Error";
293
177
  })(SecurityLevel || (SecurityLevel = {}));
294
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJ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QUNQLDJEQUFVLENBQUE7SUFDVix1REFBUSxDQUFBO0lBQ1IsK0RBQVksQ0FBQTtBQUNkLENBQUMsRUFQVyxnQkFBZ0IsS0FBaEIsZ0JBQWdCLFFBTzNCO0FBRUQ7Ozs7OztHQU1HO0FBQ0gsTUFBTSxDQUFOLElBQVksYUFNWDtBQU5ELFdBQVksYUFBYTtJQUN2Qix1REFBVyxDQUFBO0lBQ1gsaURBQVEsQ0FBQTtJQUNSLGlEQUFRLENBQUE7SUFDUix1REFBVyxDQUFBO0lBQ1gsbURBQVMsQ0FBQTtBQUNYLENBQUMsRUFOVyxhQUFhLEtBQWIsYUFBYSxRQU14QiJ9
@@ -32,6 +32,7 @@ export type ColorOptions = {
32
32
  default?: Color;
33
33
  byLevel?: ColorGroupByLevel;
34
34
  bySeverity?: ColorGroupBySeverity;
35
+ empty?: Color;
35
36
  };
36
37
 
37
38
  // @public
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabasoad/sarif-to-slack",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "TypeScript library to send results of SARIF file to Slack webhook URL.",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -1,7 +1,6 @@
1
1
  import { promises as fs } from 'fs'
2
2
  import { Log } from 'sarif'
3
3
  import Logger from './Logger'
4
- import { SlackMessageBuilder } from './SlackMessageBuilder'
5
4
  import {
6
5
  LogOptions,
7
6
  RunData,
@@ -9,9 +8,7 @@ import {
9
8
  SarifOptions,
10
9
  SarifToSlackClientOptions,
11
10
  SecurityLevel,
12
- SecuritySeverity,
13
- SendIf,
14
- SlackMessage
11
+ SecuritySeverity
15
12
  } from './types'
16
13
  import System from './System'
17
14
  import { extractListOfFiles } from './utils/FileUtils'
@@ -19,7 +16,9 @@ import { createRepresentation } from './representations/RepresentationFactory'
19
16
  import { createFinding } from './model/Finding'
20
17
  import { findToolComponent, findToolComponentDriver } from './utils/SarifUtils'
21
18
  import { identifyColor } from './model/Color'
22
- import FindingsArray from './model/FindingsArray'
19
+ import FindingArray from './model/FindingArray'
20
+ import { createSlackMessage, SlackMessage } from './model/SlackMessage'
21
+ import { SendIf, sendIfLogMessage } from './model/SendIf'
23
22
 
24
23
  /**
25
24
  * Service to convert SARIF files to Slack messages and send them.
@@ -45,12 +44,9 @@ export class SarifToSlackClient {
45
44
 
46
45
  public static async create(opts: SarifToSlackClientOptions): Promise<SarifToSlackClient> {
47
46
  const instance = new SarifToSlackClient(opts.log)
48
- Logger.trace('opts', opts)
49
47
  instance._sendIf = opts.sendIf ?? instance._sendIf
50
48
  instance._sarifModel = await SarifToSlackClient.buildModel(opts.sarif)
51
- Logger.trace('instance._sarifModel', instance._sarifModel)
52
49
  instance._message = await SarifToSlackClient.initialize(instance._sarifModel, opts)
53
- Logger.trace('instance._message', instance._message)
54
50
  return instance;
55
51
  }
56
52
 
@@ -60,7 +56,7 @@ export class SarifToSlackClient {
60
56
  throw new Error(`No SARIF files found at the provided path: ${sarifOpts.path}`)
61
57
  }
62
58
 
63
- const model: SarifModel = { sarifFiles, runs: [], findings: new FindingsArray() }
59
+ const model: SarifModel = { sarifFiles, runs: [], findings: new FindingArray() }
64
60
  const runIdGenerator: Generator<number> = SarifToSlackClient.createRunIdGenerator()
65
61
  for (const sarifPath of sarifFiles) {
66
62
  const sarifJson: string = await fs.readFile(sarifPath, 'utf8')
@@ -99,7 +95,7 @@ export class SarifToSlackClient {
99
95
  sarifModel: SarifModel,
100
96
  opts: Omit<SarifToSlackClientOptions, 'sarif' | 'log' | 'sendIf'>
101
97
  ): Promise<SlackMessage> {
102
- const message: SlackMessage = new SlackMessageBuilder(opts.webhookUrl, {
98
+ const message: SlackMessage = createSlackMessage(opts.webhookUrl, {
103
99
  username: opts.username,
104
100
  iconUrl: opts.iconUrl,
105
101
  color: identifyColor(sarifModel.findings, opts.color),
@@ -137,7 +133,7 @@ export class SarifToSlackClient {
137
133
  const text: string = await this._message.send()
138
134
  Logger.info('Message sent. Status:', text)
139
135
  } else {
140
- Logger.info('Message was not sent based on the sendIf parameter:', SendIf[this._sendIf])
136
+ Logger.info(sendIfLogMessage(this._sendIf))
141
137
  }
142
138
  }
143
139
 
package/src/index.ts CHANGED
@@ -23,6 +23,8 @@
23
23
  * username: 'SARIF to Slack Bot',
24
24
  * iconUrl: 'https://example.com/icon.png',
25
25
  * color: {
26
+ * default: new Color('failure'),
27
+ * empty: new Color('success'),
26
28
  * bySeverity: {
27
29
  * critical: new Color('#ff0000'),
28
30
  * high: new Color('#ff4500'),
@@ -30,7 +32,13 @@
30
32
  * low: new Color('#ffff00'),
31
33
  * none: new Color('#808080'),
32
34
  * unknown: new Color('#800080'),
33
- * empty: new Color('#d3d3d3'),
35
+ * },
36
+ * byLevel: {
37
+ * error: new Color('#ff0000'),
38
+ * warning: new Color('#ffa500'),
39
+ * note: new Color('#ffff00'),
40
+ * none: new Color('#808080'),
41
+ * unknown: new Color('#800080'),
34
42
  * },
35
43
  * },
36
44
  * sarif: {
@@ -75,6 +83,8 @@ export {
75
83
  ColorGroupByLevel,
76
84
  ColorGroupBySeverity
77
85
  } from './model/Color'
86
+ export { SendIf } from './model/SendIf'
87
+ export { SlackMessage } from './model/SlackMessage'
78
88
  export { SarifToSlackClient } from './SarifToSlackClient'
79
89
  export {
80
90
  FooterOptions,
@@ -86,7 +96,5 @@ export {
86
96
  RepresentationType,
87
97
  SarifFileExtension,
88
98
  SarifOptions,
89
- SarifToSlackClientOptions,
90
- SendIf,
91
- SlackMessage,
99
+ SarifToSlackClientOptions
92
100
  } from './types'
@@ -1,6 +1,6 @@
1
1
  import { SecurityLevel, SecuritySeverity } from '../types'
2
- import { Finding } from './Finding'
3
- import FindingsArray from './FindingsArray'
2
+ import Finding from './Finding'
3
+ import FindingArray from './FindingArray'
4
4
 
5
5
  /**
6
6
  * This class represents a color in hex format.
@@ -20,7 +20,7 @@ export class Color {
20
20
  */
21
21
  public constructor(color?: string) {
22
22
  this._color = this.mapColor(color)
23
- this.validateHexColor()
23
+ this.assertHexColor()
24
24
  }
25
25
 
26
26
  /**
@@ -30,7 +30,7 @@ export class Color {
30
30
  return this._color
31
31
  }
32
32
 
33
- private validateHexColor(): void {
33
+ private assertHexColor(): void {
34
34
  if (this._color != null) {
35
35
  const hexColorRegex = /^#(?:[0-9A-Fa-f]{3}|[0-9A-Fa-f]{4}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/;
36
36
 
@@ -64,7 +64,6 @@ export class Color {
64
64
  type ColorGroupCommon = {
65
65
  none?: Color,
66
66
  unknown?: Color,
67
- empty?: Color,
68
67
  }
69
68
 
70
69
  /**
@@ -113,10 +112,14 @@ export type ColorOptions = {
113
112
  * Color scheme for the findings where certain severity is presented.
114
113
  */
115
114
  bySeverity?: ColorGroupBySeverity,
115
+ /**
116
+ * Color when no findings are found.
117
+ */
118
+ empty?: Color,
116
119
  }
117
120
 
118
121
  function identifyColorCommon<K extends keyof Finding>(
119
- findings: FindingsArray,
122
+ findings: FindingArray,
120
123
  prop: K,
121
124
  none: Finding[K],
122
125
  unknown: Finding[K],
@@ -131,14 +134,10 @@ function identifyColorCommon<K extends keyof Finding>(
131
134
  return color.unknown.value
132
135
  }
133
136
 
134
- if (color.empty != null && findings.length === 0) {
135
- return color.empty.value
136
- }
137
-
138
137
  return defaultColor?.value
139
138
  }
140
139
 
141
- function identifyColorBySeverity(findings: FindingsArray, color: ColorGroupBySeverity, defaultColor?: Color): string | undefined {
140
+ function identifyColorBySeverity(findings: FindingArray, color: ColorGroupBySeverity, defaultColor?: Color): string | undefined {
142
141
  if (color.critical != null && findings.findByProperty('severity', SecuritySeverity.Critical) != null) {
143
142
  return color.critical.value
144
143
  }
@@ -158,7 +157,7 @@ function identifyColorBySeverity(findings: FindingsArray, color: ColorGroupBySev
158
157
  return identifyColorCommon(findings, 'severity', SecuritySeverity.None, SecuritySeverity.Unknown, color, defaultColor)
159
158
  }
160
159
 
161
- function identifyColorByLevel(findings: FindingsArray, color: ColorGroupByLevel, defaultColor?: Color): string | undefined {
160
+ function identifyColorByLevel(findings: FindingArray, color: ColorGroupByLevel, defaultColor?: Color): string | undefined {
162
161
  if (color.error != null && findings.findByProperty('level', SecurityLevel.Error) != null) {
163
162
  return color.error.value
164
163
  }
@@ -178,18 +177,22 @@ function identifyColorByLevel(findings: FindingsArray, color: ColorGroupByLevel,
178
177
  * Makes an ultimate decision on what color should be Slack message. The decision
179
178
  * is based on the provided {@param colorOpts} parameter and {@param findings}
180
179
  * list.
181
- * @param findings An instance of {@link FindingsArray} object.
180
+ * @param findings An instance of {@link FindingArray} object.
182
181
  * @param colorOpts An instance of {@link ColorOptions} type.
183
182
  * @internal
184
183
  */
185
- export function identifyColor(findings: FindingsArray, colorOpts?: ColorOptions): string | undefined {
186
- if (colorOpts?.bySeverity != null) {
187
- return identifyColorBySeverity(findings, colorOpts.bySeverity, colorOpts.default)
188
- }
184
+ export function identifyColor(findings: FindingArray, colorOpts?: ColorOptions): string | undefined {
185
+ let result: string | undefined = colorOpts?.bySeverity
186
+ ? identifyColorBySeverity(findings, colorOpts.bySeverity, colorOpts.default)
187
+ : undefined
189
188
 
190
- if (colorOpts?.byLevel != null) {
191
- return identifyColorByLevel(findings, colorOpts.byLevel, colorOpts.default)
192
- }
189
+ result ??= colorOpts?.byLevel
190
+ ? identifyColorByLevel(findings, colorOpts.byLevel, colorOpts.default)
191
+ : result
192
+
193
+ result ??= findings.length === 0 ? colorOpts?.empty?.value : result
194
+
195
+ result ??= colorOpts?.default?.value
193
196
 
194
- return colorOpts?.default?.value
197
+ return result
195
198
  }
@@ -18,7 +18,7 @@ export type FindingOptions = {
18
18
  * This interface represents a finding from SARIF file.
19
19
  * @internal
20
20
  */
21
- export interface Finding {
21
+ export default interface Finding {
22
22
  get sarifPath(): string,
23
23
  get runId(): number,
24
24
  get toolName(): string,
@@ -33,7 +33,7 @@ export interface Finding {
33
33
  * @internal
34
34
  */
35
35
  export function createFinding(opts: FindingOptions): Finding {
36
- return new SarifFinding(opts)
36
+ return new FindingImpl(opts)
37
37
  }
38
38
 
39
39
  /**
@@ -42,7 +42,7 @@ export function createFinding(opts: FindingOptions): Finding {
42
42
  * create a new {@link Finding}.
43
43
  * @private
44
44
  */
45
- class SarifFinding implements Finding {
45
+ class FindingImpl implements Finding {
46
46
  private readonly _runMetadata: RunData
47
47
  private readonly _result: Result
48
48
  private readonly _sarifPath: string
@@ -1,13 +1,13 @@
1
- import { Finding } from './Finding'
2
- import ExtendedArray from '../utils/ExtendedArray'
1
+ import Finding from './Finding'
3
2
  import { SecurityLevel, SecuritySeverity } from '../types'
3
+ import ExtendedArray from '../utils/ExtendedArray'
4
4
 
5
5
  /**
6
6
  * This class represents an array of {@link Finding} objects and adds additional
7
7
  * useful methods to it.
8
8
  * @internal
9
9
  */
10
- export default class FindingsArray extends ExtendedArray<Finding> {
10
+ export default class FindingArray extends ExtendedArray<Finding> {
11
11
 
12
12
  public hasSeverityOrHigher(severity: SecuritySeverity): boolean {
13
13
  return Object