@@ -3,6 +3,13 @@ package controllers
3
3
import (
4
4
"encoding/json"
5
5
"fmt"
6
+ "log/slog"
7
+ "os"
8
+ "runtime/debug"
9
+ "slices"
10
+ "strconv"
11
+ "time"
12
+
6
13
"github.com/diggerhq/digger/backend/ci_backends"
7
14
config2 "github.com/diggerhq/digger/backend/config"
8
15
locking2 "github.com/diggerhq/digger/backend/locking"
@@ -16,12 +23,6 @@ import (
16
23
"github.com/diggerhq/digger/libs/scheduler"
17
24
"github.com/google/go-github/v61/github"
18
25
"github.com/samber/lo"
19
- "log/slog"
20
- "os"
21
- "runtime/debug"
22
- "slices"
23
- "strconv"
24
- "time"
25
26
)
26
27
27
28
func handlePullRequestEvent (gh utils.GithubClientProvider , payload * github.PullRequestEvent , ciBackendProvider ci_backends.CiBackendProvider , appId int64 ) error {
@@ -49,6 +50,12 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
49
50
branch := payload .PullRequest .Head .GetRef ()
50
51
action := * payload .Action
51
52
labels := payload .PullRequest .Labels
53
+ var vcsActorId string = ""
54
+ if payload .Sender != nil && payload .Sender .Email != nil {
55
+ vcsActorId = * payload .Sender .Email
56
+ } else if payload .Sender != nil && payload .Sender .Login != nil {
57
+ vcsActorId = * payload .Sender .Login
58
+ }
52
59
prLabelsStr := lo .Map (labels , func (label * github.Label , i int ) string {
53
60
return * label .Name
54
61
})
@@ -141,6 +148,15 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
141
148
}
142
149
}
143
150
151
+ org , err := models .DB .GetOrganisationById (organisationId )
152
+ if err != nil || org == nil {
153
+ slog .Error ("Error getting organisation" ,
154
+ "orgId" , organisationId ,
155
+ "error" , err )
156
+ commentReporterManager .UpdateComment (fmt .Sprintf (":x: Failed to get organisation by ID" ))
157
+ return fmt .Errorf ("error getting organisation" )
158
+ }
159
+
144
160
diggerYmlStr , ghService , config , projectsGraph , _ , _ , changedFiles , err := getDiggerConfigForPR (gh , organisationId , prLabelsStr , installationId , repoFullName , repoOwner , repoName , cloneURL , prNumber )
145
161
if err != nil {
146
162
slog .Error ("Error getting Digger config for PR" ,
@@ -244,6 +260,7 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
244
260
"commands" , jobsForImpactedProjects [0 ].Commands ,
245
261
"error" , err ,
246
262
)
263
+ segment .Track (* org , repoOwner , vcsActorId , "github" , "pull_request_ERROR" , map [string ]string {"error" : err .Error ()})
247
264
commentReporterManager .UpdateComment (fmt .Sprintf (":x: could not determine digger command from job: %v" , err ))
248
265
return fmt .Errorf ("unknown digger command in comment %v" , err )
249
266
}
@@ -340,12 +357,16 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
340
357
return nil
341
358
}
342
359
360
+ // a pull request has led to jobs which would be triggered (ignoring closed event by here)
361
+ segment .Track (* org , repoOwner , vcsActorId , "github" , "pull_request" , map [string ]string {})
362
+
343
363
commentReporter , err := commentReporterManager .UpdateComment (":construction_worker: Digger starting... Config loaded successfully" )
344
364
if err != nil {
345
365
slog .Error ("Error initializing comment reporter" ,
346
366
"prNumber" , prNumber ,
347
367
"error" , err ,
348
368
)
369
+ segment .Track (* org , repoOwner , vcsActorId , "github" , "pull_request_ERROR" , map [string ]string {"error" : err .Error ()})
349
370
return fmt .Errorf ("error initializing comment reporter" )
350
371
}
351
372
@@ -355,6 +376,7 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
355
376
"prNumber" , prNumber ,
356
377
"error" , err ,
357
378
)
379
+ segment .Track (* org , repoOwner , vcsActorId , "github" , "pull_request_ERROR" , map [string ]string {"error" : err .Error ()})
358
380
commentReporterManager .UpdateComment (fmt .Sprintf (":x: error setting status for PR: %v" , err ))
359
381
return fmt .Errorf ("error setting status for PR: %v" , err )
360
382
}
@@ -415,6 +437,7 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
415
437
"commentId" , commentReporter .CommentId ,
416
438
"error" , err ,
417
439
)
440
+ segment .Track (* org , repoOwner , vcsActorId , "github" , "pull_request_ERROR" , map [string ]string {"error" : err .Error ()})
418
441
commentReporterManager .UpdateComment (fmt .Sprintf (":x: could not handle commentId: %v" , err ))
419
442
}
420
443
@@ -427,6 +450,7 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
427
450
"prNumber" , prNumber ,
428
451
"error" , err ,
429
452
)
453
+ segment .Track (* org , repoOwner , vcsActorId , "github" , "pull_request_ERROR" , map [string ]string {"error" : err .Error ()})
430
454
commentReporterManager .UpdateComment (fmt .Sprintf (":x: could not post ai comment summary comment id: %v" , err ))
431
455
return fmt .Errorf ("could not post ai summary comment: %v" , err )
432
456
}
@@ -470,6 +494,7 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
470
494
"prNumber" , prNumber ,
471
495
"error" , err ,
472
496
)
497
+ segment .Track (* org , repoOwner , vcsActorId , "github" , "pull_request_ERROR" , map [string ]string {"error" : err .Error ()})
473
498
commentReporterManager .UpdateComment (fmt .Sprintf (":x: ConvertJobsToDiggerJobs error: %v" , err ))
474
499
return fmt .Errorf ("error converting jobs" )
475
500
}
@@ -525,7 +550,7 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
525
550
slog .Debug ("Successfully updated batch with source details" , "batchId" , batchId )
526
551
}
527
552
528
- segment .Track (strconv . Itoa ( int ( organisationId )), " backend_trigger_job" )
553
+ segment .Track (* org , repoOwner , vcsActorId , "github" , " backend_trigger_job", map [ string ] string {} )
529
554
530
555
slog .Info ("Getting CI backend" ,
531
556
"prNumber" , prNumber ,
@@ -548,6 +573,7 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
548
573
"repoFullName" , repoFullName ,
549
574
"error" , err ,
550
575
)
576
+ segment .Track (* org , repoOwner , vcsActorId , "github" , "pull_request_ERROR" , map [string ]string {"error" : err .Error ()})
551
577
commentReporterManager .UpdateComment (fmt .Sprintf (":x: GetCiBackend error: %v" , err ))
552
578
return fmt .Errorf ("error fetching ci backed %v" , err )
553
579
}
@@ -565,6 +591,7 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
565
591
"batchId" , batchId ,
566
592
"error" , err ,
567
593
)
594
+ segment .Track (* org , repoOwner , vcsActorId , "github" , "pull_request_ERROR" , map [string ]string {"error" : err .Error ()})
568
595
commentReporterManager .UpdateComment (fmt .Sprintf (":x: TriggerDiggerJobs error: %v" , err ))
569
596
return fmt .Errorf ("error triggering Digger Jobs" )
570
597
}
0 commit comments