File tree Expand file tree Collapse file tree 2 files changed +32
-9
lines changed Expand file tree Collapse file tree 2 files changed +32
-9
lines changed Original file line number Diff line number Diff line change @@ -4191,22 +4191,34 @@ def get_slack_payload(pipeline_run):
4191
4191
pipeline_name = pipeline_run .pipeline_name
4192
4192
pretext = f"Project *{ project_display } * update:"
4193
4193
text = f"Pipeline `{ pipeline_name } ` completed with { status } ."
4194
+ blocks = [
4195
+ {
4196
+ "type" : "section" ,
4197
+ "text" : {
4198
+ "type" : "mrkdwn" ,
4199
+ "text" : text ,
4200
+ },
4201
+ }
4202
+ ]
4203
+
4204
+ # Adds the task output in case of run failure
4205
+ if pipeline_run .status == Run .Status .FAILURE and pipeline_run .task_output :
4206
+ task_output_block = {
4207
+ "type" : "section" ,
4208
+ "text" : {
4209
+ "type" : "mrkdwn" ,
4210
+ "text" : f"```{ pipeline_run .task_output } ```" ,
4211
+ },
4212
+ }
4213
+ blocks .append (task_output_block )
4194
4214
4195
4215
return {
4196
4216
"username" : "ScanCode.io" ,
4197
4217
"text" : pretext ,
4198
4218
"attachments" : [
4199
4219
{
4200
4220
"color" : color ,
4201
- "blocks" : [
4202
- {
4203
- "type" : "section" ,
4204
- "text" : {
4205
- "type" : "mrkdwn" ,
4206
- "text" : text ,
4207
- },
4208
- }
4209
- ],
4221
+ "blocks" : blocks ,
4210
4222
}
4211
4223
],
4212
4224
}
Original file line number Diff line number Diff line change @@ -2232,6 +2232,17 @@ def test_scanpipe_webhook_subscription_model_get_slack_payload(self):
2232
2232
payload = WebhookSubscription .get_slack_payload (run1 )
2233
2233
self .assertDictEqual (expected_payload , payload )
2234
2234
2235
+ run1 .set_task_ended (exitcode = 1 , output = "Exception" )
2236
+ self .assertEqual (Run .Status .FAILURE , run1 .status )
2237
+ payload = WebhookSubscription .get_slack_payload (run1 )
2238
+ payload_blocks = payload ["attachments" ][0 ]["blocks" ]
2239
+ self .assertEqual (2 , len (payload_blocks ))
2240
+ expected_task_output_block = {
2241
+ "text" : {"text" : "```Exception```" , "type" : "mrkdwn" },
2242
+ "type" : "section" ,
2243
+ }
2244
+ self .assertEqual (expected_task_output_block , payload_blocks [1 ])
2245
+
2235
2246
def test_scanpipe_discovered_package_model_extract_purl_data (self ):
2236
2247
package_data = {}
2237
2248
expected = {
You can’t perform that action at this time.
0 commit comments