@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.
- package/dist/SarifToSlackClient.d.ts.map +1 -1
- package/dist/SarifToSlackClient.js +8 -10
- package/dist/index.cjs +141 -90
- package/dist/index.d.ts +12 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -3
- package/dist/model/Color.d.ts +5 -2
- package/dist/model/Color.d.ts.map +1 -1
- package/dist/model/Color.js +13 -14
- package/dist/model/Finding.js +3 -3
- package/dist/model/FindingArray.d.ts +2 -0
- package/dist/model/FindingArray.d.ts.map +1 -0
- package/dist/model/FindingArray.js +24 -0
- package/dist/model/SendIf.d.ts +116 -0
- package/dist/model/SendIf.d.ts.map +1 -0
- package/dist/model/SendIf.js +176 -0
- package/dist/model/SlackMessage.d.ts +23 -0
- package/dist/model/SlackMessage.d.ts.map +1 -0
- package/dist/model/SlackMessage.js +99 -0
- package/dist/representations/Representation.js +3 -3
- package/dist/sarif-to-slack.d.ts +14 -3
- package/dist/types.d.ts +1 -130
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -117
- package/etc/sarif-to-slack.api.md +1 -0
- package/package.json +1 -1
- package/src/SarifToSlackClient.ts +7 -11
- package/src/index.ts +12 -4
- package/src/model/Color.ts +24 -21
- package/src/model/Finding.ts +3 -3
- package/src/model/{FindingsArray.ts → FindingArray.ts} +3 -3
- package/src/model/SendIf.ts +175 -0
- package/src/{SlackMessageBuilder.ts → model/SlackMessage.ts} +31 -6
- package/src/processors/CodeQLProcessor.ts +1 -1
- package/src/representations/CompactGroupByRepresentation.ts +1 -1
- package/src/representations/CompactGroupByRunRepresentation.ts +1 -1
- package/src/representations/CompactGroupBySarifRepresentation.ts +1 -1
- package/src/representations/CompactGroupByToolNameRepresentation.ts +1 -1
- package/src/representations/CompactTotalRepresentation.ts +1 -1
- package/src/representations/Representation.ts +4 -4
- package/src/types.ts +3 -134
- package/src/utils/Comparators.ts +1 -1
- package/tests/integration/SendSarifToSlack.spec.ts +1 -2
- package/dist/SlackMessageBuilder.d.ts +0 -2
- package/dist/SlackMessageBuilder.d.ts.map +0 -1
- package/dist/SlackMessageBuilder.js +0 -91
- package/dist/model/FindingsArray.d.ts +0 -2
- package/dist/model/FindingsArray.d.ts.map +0 -1
- package/dist/model/FindingsArray.js +0 -24
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This enum represents the condition on when message should be sent. If this
|
|
3
|
+
* condition is satisfied then message is sent, otherwise - message is not sent.
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export enum SendIf {
|
|
7
|
+
/**
|
|
8
|
+
* Send message only if there is at least one finding with "Critical" severity.
|
|
9
|
+
* Since it is the higher possible severity, it is the same as "Critical" or
|
|
10
|
+
* higher.
|
|
11
|
+
*/
|
|
12
|
+
SeverityCritical,
|
|
13
|
+
/**
|
|
14
|
+
* Send message only if there is at least one finding with "High" severity.
|
|
15
|
+
*/
|
|
16
|
+
SeverityHigh,
|
|
17
|
+
/**
|
|
18
|
+
* Send message only if there is at least one finding with "High" severity or
|
|
19
|
+
* higher, that includes "High" and "Critical".
|
|
20
|
+
*/
|
|
21
|
+
SeverityHighOrHigher,
|
|
22
|
+
/**
|
|
23
|
+
* Send message only if there is at least one finding with "Medium" severity.
|
|
24
|
+
*/
|
|
25
|
+
SeverityMedium,
|
|
26
|
+
/**
|
|
27
|
+
* Send message only if there is at least one finding with "Medium" severity
|
|
28
|
+
* or higher, that includes "Medium", "High" and "Critical".
|
|
29
|
+
*/
|
|
30
|
+
SeverityMediumOrHigher,
|
|
31
|
+
/**
|
|
32
|
+
* Send message only if there is at least one finding with "Low" severity.
|
|
33
|
+
*/
|
|
34
|
+
SeverityLow,
|
|
35
|
+
/**
|
|
36
|
+
* Send message only if there is at least one finding with "Low" severity or
|
|
37
|
+
* higher, that includes "Low", "Medium", "High" and "Critical".
|
|
38
|
+
*/
|
|
39
|
+
SeverityLowOrHigher,
|
|
40
|
+
/**
|
|
41
|
+
* Send message only if there is at least one finding with "None" severity.
|
|
42
|
+
*/
|
|
43
|
+
SeverityNone,
|
|
44
|
+
/**
|
|
45
|
+
* Send message only if there is at least one finding with "None" severity or
|
|
46
|
+
* higher, that includes "None", "Low", "Medium", "High" and "Critical".
|
|
47
|
+
*/
|
|
48
|
+
SeverityNoneOrHigher,
|
|
49
|
+
/**
|
|
50
|
+
* Send message only if there is at least one finding with "Unknown" severity.
|
|
51
|
+
*/
|
|
52
|
+
SeverityUnknown,
|
|
53
|
+
/**
|
|
54
|
+
* Send message only if there is at least one finding with "Unknown" severity
|
|
55
|
+
* or higher, that includes "Unknown", "None", "Low", "Medium", "High" and "Critical".
|
|
56
|
+
*/
|
|
57
|
+
SeverityUnknownOrHigher,
|
|
58
|
+
/**
|
|
59
|
+
* Send message only if there is at least one finding with "Error" level.
|
|
60
|
+
* Since it is the higher possible level, it is the same as "Error" or higher.
|
|
61
|
+
*/
|
|
62
|
+
LevelError,
|
|
63
|
+
/**
|
|
64
|
+
* Send message only if there is at least one finding with "Warning" level.
|
|
65
|
+
*/
|
|
66
|
+
LevelWarning,
|
|
67
|
+
/**
|
|
68
|
+
* Send message only if there is at least one finding with "Warning" level or
|
|
69
|
+
* higher, that includes "Warning" and "Error".
|
|
70
|
+
*/
|
|
71
|
+
LevelWarningOrHigher,
|
|
72
|
+
/**
|
|
73
|
+
* Send message only if there is at least one finding with "Note" level.
|
|
74
|
+
*/
|
|
75
|
+
LevelNote,
|
|
76
|
+
/**
|
|
77
|
+
* Send message only if there is at least one finding with "Note" level or
|
|
78
|
+
* higher, that includes "Note", "Warning" and "Error.
|
|
79
|
+
*/
|
|
80
|
+
LevelNoteOrHigher,
|
|
81
|
+
/**
|
|
82
|
+
* Send message only if there is at least one finding with "None" level.
|
|
83
|
+
*/
|
|
84
|
+
LevelNone,
|
|
85
|
+
/**
|
|
86
|
+
* Send message only if there is at least one finding with "None" level or
|
|
87
|
+
* higher, that includes "None", "Note", "Warning" and "Error.
|
|
88
|
+
*/
|
|
89
|
+
LevelNoneOrHigher,
|
|
90
|
+
/**
|
|
91
|
+
* Send message only if there is at least one finding with "Unknown" level.
|
|
92
|
+
*/
|
|
93
|
+
LevelUnknown,
|
|
94
|
+
/**
|
|
95
|
+
* Send message only if there is at least one finding with "Unknown" level or
|
|
96
|
+
* higher, that includes "Unknown", "None", "Note", "Warning" and "Error.
|
|
97
|
+
*/
|
|
98
|
+
LevelUnknownOrHigher,
|
|
99
|
+
/**
|
|
100
|
+
* Always send a message.
|
|
101
|
+
*/
|
|
102
|
+
Always,
|
|
103
|
+
/**
|
|
104
|
+
* Send a message if at least 1 vulnerability is found.
|
|
105
|
+
*/
|
|
106
|
+
Some,
|
|
107
|
+
/**
|
|
108
|
+
* Send a message only if no vulnerabilities are found.
|
|
109
|
+
*/
|
|
110
|
+
Empty,
|
|
111
|
+
/**
|
|
112
|
+
* Never send a message.
|
|
113
|
+
*/
|
|
114
|
+
Never,
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Returns log message based on the provided {@param sendIf} parameter.
|
|
119
|
+
* @param sendIf An instance of {@link SendIf} enum.
|
|
120
|
+
* @internal
|
|
121
|
+
*/
|
|
122
|
+
export function sendIfLogMessage(sendIf: SendIf): string {
|
|
123
|
+
switch (sendIf) {
|
|
124
|
+
case SendIf.SeverityCritical:
|
|
125
|
+
return 'No message sent: no findings with "Critical" severity.'
|
|
126
|
+
case SendIf.SeverityHigh:
|
|
127
|
+
return 'No message sent: no findings with "High" severity.'
|
|
128
|
+
case SendIf.SeverityHighOrHigher:
|
|
129
|
+
return 'No message sent: no findings with "High" or higher severity.'
|
|
130
|
+
case SendIf.SeverityMedium:
|
|
131
|
+
return 'No message sent: no findings with "Medium" severity.'
|
|
132
|
+
case SendIf.SeverityMediumOrHigher:
|
|
133
|
+
return 'No message sent: no findings with "Medium" or higher severity.'
|
|
134
|
+
case SendIf.SeverityLow:
|
|
135
|
+
return 'No message sent: no findings with "Low" severity.'
|
|
136
|
+
case SendIf.SeverityLowOrHigher:
|
|
137
|
+
return 'No message sent: no findings with "Low" or higher severity.'
|
|
138
|
+
case SendIf.SeverityNone:
|
|
139
|
+
return 'No message sent: no findings with "None" severity.'
|
|
140
|
+
case SendIf.SeverityNoneOrHigher:
|
|
141
|
+
return 'No message sent: no findings with "None" or higher severity.'
|
|
142
|
+
case SendIf.SeverityUnknown:
|
|
143
|
+
return 'No message sent: no findings with "Unknown" severity.'
|
|
144
|
+
case SendIf.SeverityUnknownOrHigher:
|
|
145
|
+
return 'No message sent: no findings with "Unknown" or higher severity.'
|
|
146
|
+
case SendIf.LevelError:
|
|
147
|
+
return 'No message sent: no findings with "Error" level.'
|
|
148
|
+
case SendIf.LevelWarning:
|
|
149
|
+
return 'No message sent: no findings with "Warning" level.'
|
|
150
|
+
case SendIf.LevelWarningOrHigher:
|
|
151
|
+
return 'No message sent: no findings with "Warning" or higher level.'
|
|
152
|
+
case SendIf.LevelNote:
|
|
153
|
+
return 'No message sent: no findings with "Note" level.'
|
|
154
|
+
case SendIf.LevelNoteOrHigher:
|
|
155
|
+
return 'No message sent: no findings with "Note" or higher level.'
|
|
156
|
+
case SendIf.LevelNone:
|
|
157
|
+
return 'No message sent: no findings with "None" level.'
|
|
158
|
+
case SendIf.LevelNoneOrHigher:
|
|
159
|
+
return 'No message sent: no findings with "None" or higher level.'
|
|
160
|
+
case SendIf.LevelUnknown:
|
|
161
|
+
return 'No message sent: no findings with "Unknown" level.'
|
|
162
|
+
case SendIf.LevelUnknownOrHigher:
|
|
163
|
+
return 'No message sent: no findings with "Unknown" or higher level.'
|
|
164
|
+
case SendIf.Always:
|
|
165
|
+
return 'Message always sent.'
|
|
166
|
+
case SendIf.Some:
|
|
167
|
+
return 'No message sent: findings are not found.'
|
|
168
|
+
case SendIf.Empty:
|
|
169
|
+
return 'No message sent: some findings are found.'
|
|
170
|
+
case SendIf.Never:
|
|
171
|
+
return 'No message sent: sending is disabled.'
|
|
172
|
+
default:
|
|
173
|
+
return 'Unknown SendIf value.'
|
|
174
|
+
}
|
|
175
|
+
}
|
|
@@ -2,26 +2,51 @@ import { AnyBlock } from '@slack/types'
|
|
|
2
2
|
import { ContextBlock, HeaderBlock } from '@slack/types/dist/block-kit/blocks'
|
|
3
3
|
import { TextObject } from '@slack/types/dist/block-kit/composition-objects'
|
|
4
4
|
import { IncomingWebhook } from '@slack/webhook'
|
|
5
|
-
import { FooterType
|
|
6
|
-
import
|
|
7
|
-
import
|
|
5
|
+
import { FooterType } from '../types'
|
|
6
|
+
import Representation from '../representations/Representation'
|
|
7
|
+
import { version } from '../metadata.json'
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Options for the SlackMessageBuilder.
|
|
11
11
|
* @internal
|
|
12
12
|
*/
|
|
13
|
-
export type
|
|
13
|
+
export type SlackMessageOptions = {
|
|
14
14
|
username?: string
|
|
15
15
|
iconUrl?: string
|
|
16
16
|
color?: string
|
|
17
17
|
representation: Representation,
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Interface for a Slack message that can be sent.
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export interface SlackMessage {
|
|
25
|
+
/**
|
|
26
|
+
* Sends the Slack message.
|
|
27
|
+
* @returns A promise that resolves to the response from the Slack webhook.
|
|
28
|
+
*/
|
|
29
|
+
send: () => Promise<string>
|
|
30
|
+
withActor(actor?: string): void
|
|
31
|
+
withFooter(text?: string, type?: FooterType): void
|
|
32
|
+
withHeader(header?: string): void
|
|
33
|
+
withRun(): void
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Creates a new instance of {@link SlackMessage} class.
|
|
38
|
+
* @param url Slack webhook URL
|
|
39
|
+
* @param opts An instance of {@link SlackMessageOptions} type.
|
|
40
|
+
*/
|
|
41
|
+
export function createSlackMessage(url: string, opts: SlackMessageOptions): SlackMessage {
|
|
42
|
+
return new SlackMessageImpl(url, opts)
|
|
43
|
+
}
|
|
44
|
+
|
|
20
45
|
/**
|
|
21
46
|
* Class for building and sending Slack messages based on SARIF logs.
|
|
22
47
|
* @internal
|
|
23
48
|
*/
|
|
24
|
-
|
|
49
|
+
class SlackMessageImpl implements SlackMessage {
|
|
25
50
|
private readonly _webhook: IncomingWebhook
|
|
26
51
|
private readonly _gitHubServerUrl: string
|
|
27
52
|
private readonly _color?: string
|
|
@@ -32,7 +57,7 @@ export class SlackMessageBuilder implements SlackMessage {
|
|
|
32
57
|
private _actor?: string
|
|
33
58
|
private _runId?: string
|
|
34
59
|
|
|
35
|
-
constructor(url: string, opts:
|
|
60
|
+
constructor(url: string, opts: SlackMessageOptions) {
|
|
36
61
|
this._webhook = new IncomingWebhook(url, {
|
|
37
62
|
username: opts.username || 'SARIF results',
|
|
38
63
|
icon_url: opts.iconUrl
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SarifModel } from '../types'
|
|
2
|
-
import
|
|
2
|
+
import Finding from '../model/Finding'
|
|
3
3
|
import { findingsComparatorByKey } from '../utils/Comparators'
|
|
4
|
-
import
|
|
4
|
+
import FindingArray from '../model/FindingArray'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* The most base abstract class for the representation. Every representation class
|
|
@@ -17,10 +17,10 @@ export default abstract class Representation {
|
|
|
17
17
|
.findings
|
|
18
18
|
.map((f: Finding): Finding => f.clone())
|
|
19
19
|
.sort(findingsComparatorByKey(findingSortKey))
|
|
20
|
-
.reduce((arr:
|
|
20
|
+
.reduce((arr: FindingArray, f: Finding): FindingArray => {
|
|
21
21
|
arr.push(f)
|
|
22
22
|
return arr
|
|
23
|
-
}, new
|
|
23
|
+
}, new FindingArray())
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
protected bold(text: string): string {
|
package/src/types.ts
CHANGED
|
@@ -1,22 +1,7 @@
|
|
|
1
1
|
import { Run } from 'sarif'
|
|
2
2
|
import { ColorOptions } from './model/Color'
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Interface for a Slack message that can be sent.
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
9
|
-
export interface SlackMessage {
|
|
10
|
-
/**
|
|
11
|
-
* Sends the Slack message.
|
|
12
|
-
* @returns A promise that resolves to the response from the Slack webhook.
|
|
13
|
-
*/
|
|
14
|
-
send: () => Promise<string>
|
|
15
|
-
withActor(actor?: string): void
|
|
16
|
-
withFooter(text?: string, type?: FooterType): void
|
|
17
|
-
withHeader(header?: string): void
|
|
18
|
-
withRun(): void
|
|
19
|
-
}
|
|
3
|
+
import FindingArray from './model/FindingArray'
|
|
4
|
+
import { SendIf } from './model/SendIf'
|
|
20
5
|
|
|
21
6
|
/**
|
|
22
7
|
* Enum representing log levels for the service.
|
|
@@ -221,122 +206,6 @@ export type SarifOptions = {
|
|
|
221
206
|
extension?: SarifFileExtension,
|
|
222
207
|
}
|
|
223
208
|
|
|
224
|
-
/**
|
|
225
|
-
* This enum represents the condition on when message should be sent. If this
|
|
226
|
-
* condition is satisfied then message is sent, otherwise - message is not sent.
|
|
227
|
-
* @public
|
|
228
|
-
*/
|
|
229
|
-
export enum SendIf {
|
|
230
|
-
/**
|
|
231
|
-
* Send message only if there is at least one finding with "Critical" severity.
|
|
232
|
-
* Since it is the higher possible severity, it is the same as "Critical" or
|
|
233
|
-
* higher.
|
|
234
|
-
*/
|
|
235
|
-
SeverityCritical,
|
|
236
|
-
/**
|
|
237
|
-
* Send message only if there is at least one finding with "High" severity.
|
|
238
|
-
*/
|
|
239
|
-
SeverityHigh,
|
|
240
|
-
/**
|
|
241
|
-
* Send message only if there is at least one finding with "High" severity or
|
|
242
|
-
* higher, that includes "High" and "Critical".
|
|
243
|
-
*/
|
|
244
|
-
SeverityHighOrHigher,
|
|
245
|
-
/**
|
|
246
|
-
* Send message only if there is at least one finding with "Medium" severity.
|
|
247
|
-
*/
|
|
248
|
-
SeverityMedium,
|
|
249
|
-
/**
|
|
250
|
-
* Send message only if there is at least one finding with "Medium" severity
|
|
251
|
-
* or higher, that includes "Medium", "High" and "Critical".
|
|
252
|
-
*/
|
|
253
|
-
SeverityMediumOrHigher,
|
|
254
|
-
/**
|
|
255
|
-
* Send message only if there is at least one finding with "Low" severity.
|
|
256
|
-
*/
|
|
257
|
-
SeverityLow,
|
|
258
|
-
/**
|
|
259
|
-
* Send message only if there is at least one finding with "Low" severity or
|
|
260
|
-
* higher, that includes "Low", "Medium", "High" and "Critical".
|
|
261
|
-
*/
|
|
262
|
-
SeverityLowOrHigher,
|
|
263
|
-
/**
|
|
264
|
-
* Send message only if there is at least one finding with "None" severity.
|
|
265
|
-
*/
|
|
266
|
-
SeverityNone,
|
|
267
|
-
/**
|
|
268
|
-
* Send message only if there is at least one finding with "None" severity or
|
|
269
|
-
* higher, that includes "None", "Low", "Medium", "High" and "Critical".
|
|
270
|
-
*/
|
|
271
|
-
SeverityNoneOrHigher,
|
|
272
|
-
/**
|
|
273
|
-
* Send message only if there is at least one finding with "Unknown" severity.
|
|
274
|
-
*/
|
|
275
|
-
SeverityUnknown,
|
|
276
|
-
/**
|
|
277
|
-
* Send message only if there is at least one finding with "Unknown" severity
|
|
278
|
-
* or higher, that includes "Unknown", "None", "Low", "Medium", "High" and "Critical".
|
|
279
|
-
*/
|
|
280
|
-
SeverityUnknownOrHigher,
|
|
281
|
-
/**
|
|
282
|
-
* Send message only if there is at least one finding with "Error" level.
|
|
283
|
-
* Since it is the higher possible level, it is the same as "Error" or higher.
|
|
284
|
-
*/
|
|
285
|
-
LevelError,
|
|
286
|
-
/**
|
|
287
|
-
* Send message only if there is at least one finding with "Warning" level.
|
|
288
|
-
*/
|
|
289
|
-
LevelWarning,
|
|
290
|
-
/**
|
|
291
|
-
* Send message only if there is at least one finding with "Warning" level or
|
|
292
|
-
* higher, that includes "Warning" and "Error".
|
|
293
|
-
*/
|
|
294
|
-
LevelWarningOrHigher,
|
|
295
|
-
/**
|
|
296
|
-
* Send message only if there is at least one finding with "Note" level.
|
|
297
|
-
*/
|
|
298
|
-
LevelNote,
|
|
299
|
-
/**
|
|
300
|
-
* Send message only if there is at least one finding with "Note" level or
|
|
301
|
-
* higher, that includes "Note", "Warning" and "Error.
|
|
302
|
-
*/
|
|
303
|
-
LevelNoteOrHigher,
|
|
304
|
-
/**
|
|
305
|
-
* Send message only if there is at least one finding with "None" level.
|
|
306
|
-
*/
|
|
307
|
-
LevelNone,
|
|
308
|
-
/**
|
|
309
|
-
* Send message only if there is at least one finding with "None" level or
|
|
310
|
-
* higher, that includes "None", "Note", "Warning" and "Error.
|
|
311
|
-
*/
|
|
312
|
-
LevelNoneOrHigher,
|
|
313
|
-
/**
|
|
314
|
-
* Send message only if there is at least one finding with "Unknown" level.
|
|
315
|
-
*/
|
|
316
|
-
LevelUnknown,
|
|
317
|
-
/**
|
|
318
|
-
* Send message only if there is at least one finding with "Unknown" level or
|
|
319
|
-
* higher, that includes "Unknown", "None", "Note", "Warning" and "Error.
|
|
320
|
-
*/
|
|
321
|
-
LevelUnknownOrHigher,
|
|
322
|
-
/**
|
|
323
|
-
* Always send a message.
|
|
324
|
-
*/
|
|
325
|
-
Always,
|
|
326
|
-
/**
|
|
327
|
-
* Send a message if at least 1 vulnerability is found.
|
|
328
|
-
*/
|
|
329
|
-
Some,
|
|
330
|
-
/**
|
|
331
|
-
* Send a message only if no vulnerabilities are found.
|
|
332
|
-
*/
|
|
333
|
-
Empty,
|
|
334
|
-
/**
|
|
335
|
-
* Never send a message.
|
|
336
|
-
*/
|
|
337
|
-
Never,
|
|
338
|
-
}
|
|
339
|
-
|
|
340
209
|
/**
|
|
341
210
|
* Options for the SarifToSlackClient.
|
|
342
211
|
* @public
|
|
@@ -405,5 +274,5 @@ export type RunData = {
|
|
|
405
274
|
export type SarifModel = {
|
|
406
275
|
sarifFiles: string[],
|
|
407
276
|
runs: RunData[],
|
|
408
|
-
findings:
|
|
277
|
+
findings: FindingArray,
|
|
409
278
|
}
|
package/src/utils/Comparators.ts
CHANGED
|
@@ -105,7 +105,6 @@ describe('(integration): SendSarifToSlack', (): void => {
|
|
|
105
105
|
note: new Color(process.env.SARIF_TO_SLACK_COLOR_NOTE),
|
|
106
106
|
none: new Color(process.env.SARIF_TO_SLACK_COLOR_NONE),
|
|
107
107
|
unknown: new Color(process.env.SARIF_TO_SLACK_COLOR_UNKNOWN),
|
|
108
|
-
empty: new Color(process.env.SARIF_TO_SLACK_COLOR_EMPTY),
|
|
109
108
|
},
|
|
110
109
|
bySeverity: {
|
|
111
110
|
critical: new Color(process.env.SARIF_TO_SLACK_COLOR_CRITICAL),
|
|
@@ -114,8 +113,8 @@ describe('(integration): SendSarifToSlack', (): void => {
|
|
|
114
113
|
low: new Color(process.env.SARIF_TO_SLACK_COLOR_LOW),
|
|
115
114
|
none: new Color(process.env.SARIF_TO_SLACK_COLOR_NONE),
|
|
116
115
|
unknown: new Color(process.env.SARIF_TO_SLACK_COLOR_UNKNOWN),
|
|
117
|
-
empty: new Color(process.env.SARIF_TO_SLACK_COLOR_EMPTY),
|
|
118
116
|
},
|
|
117
|
+
empty: new Color(process.env.SARIF_TO_SLACK_COLOR_EMPTY),
|
|
119
118
|
},
|
|
120
119
|
sarif: {
|
|
121
120
|
path: process.env.SARIF_TO_SLACK_SARIF_PATH as string,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SlackMessageBuilder.d.ts","sourceRoot":"","sources":["../src/SlackMessageBuilder.ts"],"names":[],"mappings":""}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { IncomingWebhook } from '@slack/webhook';
|
|
2
|
-
import { FooterType } from './types';
|
|
3
|
-
import { version } from './metadata.json';
|
|
4
|
-
/**
|
|
5
|
-
* Class for building and sending Slack messages based on SARIF logs.
|
|
6
|
-
* @internal
|
|
7
|
-
*/
|
|
8
|
-
export class SlackMessageBuilder {
|
|
9
|
-
_webhook;
|
|
10
|
-
_gitHubServerUrl;
|
|
11
|
-
_color;
|
|
12
|
-
_representation;
|
|
13
|
-
_header;
|
|
14
|
-
_footer;
|
|
15
|
-
_actor;
|
|
16
|
-
_runId;
|
|
17
|
-
constructor(url, opts) {
|
|
18
|
-
this._webhook = new IncomingWebhook(url, {
|
|
19
|
-
username: opts.username || 'SARIF results',
|
|
20
|
-
icon_url: opts.iconUrl
|
|
21
|
-
});
|
|
22
|
-
this._gitHubServerUrl = process.env.GITHUB_SERVER_URL || 'https://github.com';
|
|
23
|
-
this._color = opts.color;
|
|
24
|
-
this._representation = opts.representation;
|
|
25
|
-
}
|
|
26
|
-
withHeader(header) {
|
|
27
|
-
this._header = {
|
|
28
|
-
type: 'header',
|
|
29
|
-
text: {
|
|
30
|
-
type: 'plain_text',
|
|
31
|
-
text: header || process.env.GITHUB_REPOSITORY || 'SARIF results'
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
withActor(actor) {
|
|
36
|
-
this._actor = actor || process.env.GITHUB_ACTOR;
|
|
37
|
-
}
|
|
38
|
-
withRun() {
|
|
39
|
-
this._runId = process.env.GITHUB_RUN_ID;
|
|
40
|
-
}
|
|
41
|
-
withFooter(text, type) {
|
|
42
|
-
const repoName = 'fabasoad/sarif-to-slack';
|
|
43
|
-
const element = text
|
|
44
|
-
? { type: type || FooterType.PlainText, text }
|
|
45
|
-
: { type: FooterType.Markdown, text: `Generated by <${this._gitHubServerUrl}/${repoName}|@${repoName}@${version}>` };
|
|
46
|
-
this._footer = {
|
|
47
|
-
type: 'context',
|
|
48
|
-
elements: [element],
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
async send() {
|
|
52
|
-
const blocks = [];
|
|
53
|
-
if (this._header) {
|
|
54
|
-
blocks.push(this._header);
|
|
55
|
-
}
|
|
56
|
-
blocks.push({
|
|
57
|
-
type: 'section',
|
|
58
|
-
text: {
|
|
59
|
-
type: 'mrkdwn',
|
|
60
|
-
text: this.buildText(),
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
if (this._footer) {
|
|
64
|
-
blocks.push(this._footer);
|
|
65
|
-
}
|
|
66
|
-
const { text } = await this._webhook.send({
|
|
67
|
-
attachments: [{ color: this._color, blocks }]
|
|
68
|
-
});
|
|
69
|
-
return text;
|
|
70
|
-
}
|
|
71
|
-
buildText() {
|
|
72
|
-
const text = [];
|
|
73
|
-
if (this._actor) {
|
|
74
|
-
const actorUrl = `${this._gitHubServerUrl}/${this._actor}`;
|
|
75
|
-
text.push(`_Triggered by <${actorUrl}|${this._actor}>_`);
|
|
76
|
-
}
|
|
77
|
-
text.push(this._representation.compose());
|
|
78
|
-
if (this._runId) {
|
|
79
|
-
let runText = 'Job ';
|
|
80
|
-
if (process.env.GITHUB_REPOSITORY) {
|
|
81
|
-
runText += `<${this._gitHubServerUrl}/${process.env.GITHUB_REPOSITORY}/actions/runs/${this._runId}|#${this._runId}>`;
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
runText += `#${this._runId}`;
|
|
85
|
-
}
|
|
86
|
-
text.push(runText);
|
|
87
|
-
}
|
|
88
|
-
return text.join('\n\n');
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiU2xhY2tNZXNzYWdlQnVpbGRlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9TbGFja01lc3NhZ2VCdWlsZGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUdBLE9BQU8sRUFBRSxlQUFlLEVBQUUsTUFBTSxnQkFBZ0IsQ0FBQTtBQUNoRCxPQUFPLEVBQUUsVUFBVSxFQUFnQixNQUFNLFNBQVMsQ0FBQTtBQUNsRCxPQUFPLEVBQUUsT0FBTyxFQUFFLE1BQU0saUJBQWlCLENBQUE7QUFjekM7OztHQUdHO0FBQ0gsTUFBTSxPQUFPLG1CQUFtQjtJQUNiLFFBQVEsQ0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BQyxNQUFNLEVBQUUsQ0FBQTtZQUM5QixDQUFDO1lBQ0QsSUFBSSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsQ0FBQTtRQUNwQixDQUFDO1FBQ0QsT0FBTyxJQUFJLENBQUMsSUFBSSxDQUFDLE1BQU0sQ0FBQyxDQUFBO0lBQzFCLENBQUM7Q0FDRiJ9
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FindingsArray.d.ts","sourceRoot":"","sources":["../../src/model/FindingsArray.ts"],"names":[],"mappings":""}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import ExtendedArray from '../utils/ExtendedArray';
|
|
2
|
-
import { SecurityLevel, SecuritySeverity } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* This class represents an array of {@link Finding} objects and adds additional
|
|
5
|
-
* useful methods to it.
|
|
6
|
-
* @internal
|
|
7
|
-
*/
|
|
8
|
-
export default class FindingsArray extends ExtendedArray {
|
|
9
|
-
hasSeverityOrHigher(severity) {
|
|
10
|
-
return Object
|
|
11
|
-
.values(SecuritySeverity)
|
|
12
|
-
.filter((v) => typeof v === 'number')
|
|
13
|
-
.filter((v) => v >= severity)
|
|
14
|
-
.some((v) => this.findByProperty('severity', v) != null);
|
|
15
|
-
}
|
|
16
|
-
hasLevelOrHigher(level) {
|
|
17
|
-
return Object
|
|
18
|
-
.values(SecurityLevel)
|
|
19
|
-
.filter((v) => typeof v === 'number')
|
|
20
|
-
.filter((v) => v >= level)
|
|
21
|
-
.some((v) => this.findByProperty('level', v) != null);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRmluZGluZ3NBcnJheS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9tb2RlbC9GaW5kaW5nc0FycmF5LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNB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