@@ -124,13 +124,14 @@ func RunJobs(jobs []orchestrator.Job, prService ci.PullRequestService, orgServic
124
124
}
125
125
126
126
if allAppliesSuccess == true && reportFinalStatusToBackend == true {
127
- _ , jobPrCommentUrl , err := reporter .Flush ()
127
+ _ , jobPrCommentUrls , err := reporter .Flush ()
128
128
if err != nil {
129
129
log .Printf ("error while sending job comments %v" , err )
130
130
return false , false , fmt .Errorf ("error while sending job comments %v" , err )
131
131
}
132
132
133
133
currentJob := jobs [0 ]
134
+ jobPrCommentUrl := jobPrCommentUrls [0 ]
134
135
repoNameForBackendReporting := strings .ReplaceAll (currentJob .Namespace , "/" , "-" )
135
136
projectNameForBackendReporting := currentJob .ProjectName
136
137
// TODO: handle the apply result summary as well to report it to backend. Possibly reporting changed resources as well
@@ -170,12 +171,12 @@ func RunJobs(jobs []orchestrator.Job, prService ci.PullRequestService, orgServic
170
171
func reportPolicyError (projectName string , command string , requestedBy string , reporter reporting.Reporter ) string {
171
172
msg := fmt .Sprintf ("User %s is not allowed to perform action: %s. Check your policies :x:" , requestedBy , command )
172
173
if reporter .SupportsMarkdown () {
173
- err := reporter .Report (msg , coreutils .AsCollapsibleComment (fmt .Sprintf ("Policy violation for <b>%v - %v</b>" , projectName , command ), false ))
174
+ err := reporter .Report (projectName , msg , coreutils .AsCollapsibleComment (fmt .Sprintf ("Policy violation for <b>%v - %v</b>" , projectName , command ), false ))
174
175
if err != nil {
175
176
log .Printf ("Error publishing comment: %v" , err )
176
177
}
177
178
} else {
178
- err := reporter .Report (msg , coreutils .AsComment (fmt .Sprintf ("Policy violation for %v - %v" , projectName , command )))
179
+ err := reporter .Report (projectName , msg , coreutils .AsComment (fmt .Sprintf ("Policy violation for %v - %v" , projectName , command )))
179
180
if err != nil {
180
181
log .Printf ("Error publishing comment: %v" , err )
181
182
}
@@ -284,7 +285,7 @@ func run(command string, job orchestrator.Job, policyChecker policy.Checker, org
284
285
return nil , msg , fmt .Errorf (msg )
285
286
} else if planPerformed {
286
287
if isNonEmptyPlan {
287
- reportTerraformPlanOutput (reporter , projectLock . LockId () , plan )
288
+ reportTerraformPlanOutput (reporter , job . ProjectName , plan )
288
289
planIsAllowed , messages , err := policyChecker .CheckPlanPolicy (SCMrepository , SCMOrganisation , job .ProjectName , job .ProjectDir , planJsonOutput )
289
290
if err != nil {
290
291
msg := fmt .Sprintf ("Failed to validate plan. %v" , err )
@@ -311,7 +312,7 @@ func run(command string, job orchestrator.Job, policyChecker policy.Checker, org
311
312
preformattedMessaged = append (preformattedMessaged , fmt .Sprintf (" %v" , message ))
312
313
}
313
314
planReportMessage = planReportMessage + strings .Join (preformattedMessaged , "<br>" )
314
- err = reporter .Report (planReportMessage , planPolicyFormatter )
315
+ err = reporter .Report (job . ProjectName , planReportMessage , planPolicyFormatter )
315
316
316
317
if err != nil {
317
318
log .Printf ("Failed to report plan. %v" , err )
@@ -320,14 +321,14 @@ func run(command string, job orchestrator.Job, policyChecker policy.Checker, org
320
321
log .Printf (msg )
321
322
return nil , msg , fmt .Errorf (msg )
322
323
} else {
323
- err := reporter .Report ("Terraform plan validation checks succeeded :white_check_mark:" , planPolicyFormatter )
324
+ err := reporter .Report (job . ProjectName , "Terraform plan validation checks succeeded :white_check_mark:" , planPolicyFormatter )
324
325
if err != nil {
325
326
log .Printf ("Failed to report plan. %v" , err )
326
327
}
327
- reportPlanSummary (reporter , planSummary )
328
+ reportPlanSummary (job . ProjectName , reporter , planSummary )
328
329
}
329
330
} else {
330
- reportEmptyPlanOutput (reporter , projectLock .LockId ())
331
+ reportEmptyPlanOutput (job . ProjectName , reporter , projectLock .LockId ())
331
332
}
332
333
err := prService .SetStatus (* job .PullRequestNumber , "success" , job .ProjectName + "/plan" )
333
334
if err != nil {
@@ -370,7 +371,7 @@ func run(command string, job orchestrator.Job, policyChecker policy.Checker, org
370
371
}
371
372
log .Printf ("PR status, mergeable: %v, merged: %v and skipMergeCheck %v\n " , isMergeable , isMerged , job .SkipMergeCheck )
372
373
if ! isMergeable && ! isMerged && ! job .SkipMergeCheck {
373
- comment := reportApplyMergeabilityError (reporter )
374
+ comment := reportApplyMergeabilityError (job . ProjectName , reporter )
374
375
prService .SetStatus (* job .PullRequestNumber , "failure" , job .ProjectName + "/apply" )
375
376
376
377
return nil , comment , fmt .Errorf (comment )
@@ -491,25 +492,25 @@ func run(command string, job orchestrator.Job, policyChecker policy.Checker, org
491
492
return & execution.DiggerExecutorResult {}, "" , nil
492
493
}
493
494
494
- func reportApplyMergeabilityError (reporter reporting.Reporter ) string {
495
+ func reportApplyMergeabilityError (projectName string , reporter reporting.Reporter ) string {
495
496
comment := "cannot perform Apply since the PR is not currently mergeable"
496
497
log .Println (comment )
497
498
498
499
if reporter .SupportsMarkdown () {
499
- err := reporter .Report (comment , coreutils .AsCollapsibleComment ("Apply error" , false ))
500
+ err := reporter .Report (projectName , comment , coreutils .AsCollapsibleComment ("Apply error" , false ))
500
501
if err != nil {
501
502
log .Printf ("error publishing comment: %v\n " , err )
502
503
}
503
504
} else {
504
- err := reporter .Report (comment , coreutils .AsComment ("Apply error" ))
505
+ err := reporter .Report (projectName , comment , coreutils .AsComment ("Apply error" ))
505
506
if err != nil {
506
507
log .Printf ("error publishing comment: %v\n " , err )
507
508
}
508
509
}
509
510
return comment
510
511
}
511
512
512
- func reportTerraformPlanOutput (reporter reporting.Reporter , projectId string , plan string ) {
513
+ func reportTerraformPlanOutput (reporter reporting.Reporter , projectName string , plan string ) {
513
514
var formatter func (string ) string
514
515
515
516
if reporter .SupportsMarkdown () {
@@ -518,13 +519,13 @@ func reportTerraformPlanOutput(reporter reporting.Reporter, projectId string, pl
518
519
formatter = coreutils .GetTerraformOutputAsComment ("Plan output" )
519
520
}
520
521
521
- err := reporter .Report (plan , formatter )
522
+ err := reporter .Report (projectName , plan , formatter )
522
523
if err != nil {
523
524
log .Printf ("Failed to report plan. %v" , err )
524
525
}
525
526
}
526
527
527
- func reportPlanSummary (reporter reporting.Reporter , summary string ) {
528
+ func reportPlanSummary (projectName string , reporter reporting.Reporter , summary string ) {
528
529
var formatter func (string ) string
529
530
530
531
if reporter .SupportsMarkdown () {
@@ -533,19 +534,19 @@ func reportPlanSummary(reporter reporting.Reporter, summary string) {
533
534
formatter = coreutils .AsComment ("Plan summary" )
534
535
}
535
536
536
- err := reporter .Report ("\n " + summary , formatter )
537
+ err := reporter .Report (projectName , "\n " + summary , formatter )
537
538
if err != nil {
538
539
log .Printf ("Failed to report plan summary. %v" , err )
539
540
}
540
541
}
541
542
542
- func reportEmptyPlanOutput (reporter reporting.Reporter , projectId string ) {
543
+ func reportEmptyPlanOutput (projectName string , reporter reporting.Reporter , projectId string ) {
543
544
identityFormatter := func (comment string ) string {
544
545
return comment
545
546
}
546
- err := reporter .Report ("→ No changes in terraform output for " + projectId , identityFormatter )
547
+ err := reporter .Report (projectName , "→ No changes in terraform output for " + projectId , identityFormatter )
547
548
// suppress the comment (if reporter is suppressible)
548
- reporter .Suppress ()
549
+ reporter .Suppress ("" )
549
550
if err != nil {
550
551
log .Printf ("Failed to report plan. %v" , err )
551
552
}
0 commit comments