+1
-10
appview/indexer/notifier.go
+1
-10
appview/indexer/notifier.go
···
46
}
47
}
48
49
-
func (ix *Indexer) NewPullMerged(ctx context.Context, pull *models.Pull) {
50
-
l := log.FromContext(ctx).With("notifier", "indexer", "pull", pull)
51
-
l.Debug("updating a pr")
52
-
err := ix.Pulls.Index(ctx, pull)
53
-
if err != nil {
54
-
l.Error("failed to index a pr", "err", err)
55
-
}
56
-
}
57
-
58
-
func (ix *Indexer) NewPullClosed(ctx context.Context, pull *models.Pull) {
59
l := log.FromContext(ctx).With("notifier", "indexer", "pull", pull)
60
l.Debug("updating a pr")
61
err := ix.Pulls.Index(ctx, pull)
+12
-93
appview/notify/db/db.go
+12
-93
appview/notify/db/db.go
···
328
)
329
}
330
331
-
func (n *databaseNotifier) NewPullMerged(ctx context.Context, pull *models.Pull) {
332
// Get repo details
333
repo, err := db.GetRepo(n.db, db.FilterEq("at_uri", string(pull.RepoAt)))
334
if err != nil {
335
-
log.Printf("NewPullMerged: failed to get repos: %v", err)
336
return
337
}
338
···
354
}
355
356
actorDid := syntax.DID(repo.Did)
357
-
eventType := models.NotificationTypePullMerged
358
entityType := "pull"
359
entityId := pull.PullAt().String()
360
repoId := &repo.Id
361
var issueId *int64
362
-
p := int64(pull.ID)
363
-
pullId := &p
364
-
365
-
n.notifyEvent(
366
-
actorDid,
367
-
recipients,
368
-
eventType,
369
-
entityType,
370
-
entityId,
371
-
repoId,
372
-
issueId,
373
-
pullId,
374
-
)
375
-
}
376
-
377
-
func (n *databaseNotifier) NewPullClosed(ctx context.Context, pull *models.Pull) {
378
-
// Get repo details
379
-
repo, err := db.GetRepo(n.db, db.FilterEq("at_uri", string(pull.RepoAt)))
380
-
if err != nil {
381
-
log.Printf("NewPullMerged: failed to get repos: %v", err)
382
return
383
}
384
-
385
-
// build up the recipients list:
386
-
// - repo owner
387
-
// - all pull participants
388
-
var recipients []syntax.DID
389
-
recipients = append(recipients, syntax.DID(repo.Did))
390
-
collaborators, err := db.GetCollaborators(n.db, db.FilterEq("repo_at", repo.RepoAt()))
391
-
if err != nil {
392
-
log.Printf("failed to fetch collaborators: %v", err)
393
-
return
394
-
}
395
-
for _, c := range collaborators {
396
-
recipients = append(recipients, c.SubjectDid)
397
-
}
398
-
for _, p := range pull.Participants() {
399
-
recipients = append(recipients, syntax.DID(p))
400
-
}
401
-
402
-
actorDid := syntax.DID(repo.Did)
403
-
eventType := models.NotificationTypePullClosed
404
-
entityType := "pull"
405
-
entityId := pull.PullAt().String()
406
-
repoId := &repo.Id
407
-
var issueId *int64
408
-
p := int64(pull.ID)
409
-
pullId := &p
410
-
411
-
n.notifyEvent(
412
-
actorDid,
413
-
recipients,
414
-
eventType,
415
-
entityType,
416
-
entityId,
417
-
repoId,
418
-
issueId,
419
-
pullId,
420
-
)
421
-
}
422
-
423
-
func (n *databaseNotifier) NewPullReopen(ctx context.Context, pull *models.Pull) {
424
-
// Get repo details
425
-
repo, err := db.GetRepo(n.db, db.FilterEq("at_uri", string(pull.RepoAt)))
426
-
if err != nil {
427
-
log.Printf("NewPullMerged: failed to get repos: %v", err)
428
-
return
429
-
}
430
-
431
-
// build up the recipients list:
432
-
// - repo owner
433
-
// - all pull participants
434
-
var recipients []syntax.DID
435
-
recipients = append(recipients, syntax.DID(repo.Did))
436
-
collaborators, err := db.GetCollaborators(n.db, db.FilterEq("repo_at", repo.RepoAt()))
437
-
if err != nil {
438
-
log.Printf("failed to fetch collaborators: %v", err)
439
-
return
440
-
}
441
-
for _, c := range collaborators {
442
-
recipients = append(recipients, c.SubjectDid)
443
-
}
444
-
for _, p := range pull.Participants() {
445
-
recipients = append(recipients, syntax.DID(p))
446
-
}
447
-
448
-
actorDid := syntax.DID(repo.Did)
449
-
eventType := models.NotificationTypePullReopen
450
-
entityType := "pull"
451
-
entityId := pull.PullAt().String()
452
-
repoId := &repo.Id
453
-
var issueId *int64
454
p := int64(pull.ID)
455
pullId := &p
456
···
328
)
329
}
330
331
+
func (n *databaseNotifier) NewPullState(ctx context.Context, pull *models.Pull) {
332
// Get repo details
333
repo, err := db.GetRepo(n.db, db.FilterEq("at_uri", string(pull.RepoAt)))
334
if err != nil {
335
+
log.Printf("NewPullState: failed to get repos: %v", err)
336
return
337
}
338
···
354
}
355
356
actorDid := syntax.DID(repo.Did)
357
entityType := "pull"
358
entityId := pull.PullAt().String()
359
repoId := &repo.Id
360
var issueId *int64
361
+
var eventType models.NotificationType
362
+
switch pull.State {
363
+
case models.PullClosed:
364
+
eventType = models.NotificationTypePullClosed
365
+
case models.PullOpen:
366
+
eventType = models.NotificationTypePullReopen
367
+
case models.PullMerged:
368
+
eventType = models.NotificationTypePullMerged
369
+
default:
370
+
log.Println("NewPullState: unexpected new PR state:", pull.State)
371
return
372
}
373
p := int64(pull.ID)
374
pullId := &p
375
+2
-10
appview/notify/merged_notifier.go
+2
-10
appview/notify/merged_notifier.go
···
85
m.fanout("NewPullComment", ctx, comment)
86
}
87
88
-
func (m *mergedNotifier) NewPullMerged(ctx context.Context, pull *models.Pull) {
89
-
m.fanout("NewPullMerged", ctx, pull)
90
-
}
91
-
92
-
func (m *mergedNotifier) NewPullClosed(ctx context.Context, pull *models.Pull) {
93
-
m.fanout("NewPullClosed", ctx, pull)
94
-
}
95
-
96
-
func (m *mergedNotifier) NewPullReopen(ctx context.Context, pull *models.Pull) {
97
-
m.fanout("NewPullReopen", ctx, pull)
98
}
99
100
func (m *mergedNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) {
+2
-6
appview/notify/notifier.go
+2
-6
appview/notify/notifier.go
···
22
23
NewPull(ctx context.Context, pull *models.Pull)
24
NewPullComment(ctx context.Context, comment *models.PullComment)
25
-
NewPullMerged(ctx context.Context, pull *models.Pull)
26
-
NewPullClosed(ctx context.Context, pull *models.Pull)
27
-
NewPullReopen(ctx context.Context, pull *models.Pull)
28
29
UpdateProfile(ctx context.Context, profile *models.Profile)
30
···
53
54
func (m *BaseNotifier) NewPull(ctx context.Context, pull *models.Pull) {}
55
func (m *BaseNotifier) NewPullComment(ctx context.Context, models *models.PullComment) {}
56
-
func (m *BaseNotifier) NewPullMerged(ctx context.Context, pull *models.Pull) {}
57
-
func (m *BaseNotifier) NewPullClosed(ctx context.Context, pull *models.Pull) {}
58
-
func (m *BaseNotifier) NewPullReopen(ctx context.Context, pull *models.Pull) {}
59
60
func (m *BaseNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) {}
61
···
22
23
NewPull(ctx context.Context, pull *models.Pull)
24
NewPullComment(ctx context.Context, comment *models.PullComment)
25
+
NewPullState(ctx context.Context, pull *models.Pull)
26
27
UpdateProfile(ctx context.Context, profile *models.Profile)
28
···
51
52
func (m *BaseNotifier) NewPull(ctx context.Context, pull *models.Pull) {}
53
func (m *BaseNotifier) NewPullComment(ctx context.Context, models *models.PullComment) {}
54
+
func (m *BaseNotifier) NewPullState(ctx context.Context, pull *models.Pull) {}
55
56
func (m *BaseNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) {}
57
+14
-2
appview/notify/posthog/notifier.go
+14
-2
appview/notify/posthog/notifier.go
···
210
}
211
}
212
213
-
func (n *posthogNotifier) NewPullMerged(ctx context.Context, pull *models.Pull) {
214
err := n.client.Enqueue(posthog.Capture{
215
DistinctId: pull.OwnerDid,
216
-
Event: "pull_merged",
217
Properties: posthog.Properties{
218
"repo_at": pull.RepoAt,
219
"pull_id": pull.PullId,
···
210
}
211
}
212
213
+
func (n *posthogNotifier) NewPullState(ctx context.Context, pull *models.Pull) {
214
+
var event string
215
+
switch pull.State {
216
+
case models.PullClosed:
217
+
event = "pull_closed"
218
+
case models.PullOpen:
219
+
event = "pull_reopen"
220
+
case models.PullMerged:
221
+
event = "pull_merged"
222
+
default:
223
+
log.Println("posthog: unexpected new PR state:", pull.State)
224
+
return
225
+
}
226
err := n.client.Enqueue(posthog.Capture{
227
DistinctId: pull.OwnerDid,
228
+
Event: event,
229
Properties: posthog.Properties{
230
"repo_at": pull.RepoAt,
231
"pull_id": pull.PullId,
+3
-3
appview/pulls/pulls.go
+3
-3
appview/pulls/pulls.go
···
2216
2217
// notify about the pull merge
2218
for _, p := range pullsToMerge {
2219
-
s.notifier.NewPullMerged(r.Context(), p)
2220
}
2221
2222
s.pages.HxLocation(w, fmt.Sprintf("/@%s/%s/pulls/%d", f.OwnerHandle(), f.Name, pull.PullId))
···
2288
}
2289
2290
for _, p := range pullsToClose {
2291
-
s.notifier.NewPullClosed(r.Context(), p)
2292
}
2293
2294
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId))
···
2361
}
2362
2363
for _, p := range pullsToReopen {
2364
-
s.notifier.NewPullReopen(r.Context(), p)
2365
}
2366
2367
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId))
···
2216
2217
// notify about the pull merge
2218
for _, p := range pullsToMerge {
2219
+
s.notifier.NewPullState(r.Context(), p)
2220
}
2221
2222
s.pages.HxLocation(w, fmt.Sprintf("/@%s/%s/pulls/%d", f.OwnerHandle(), f.Name, pull.PullId))
···
2288
}
2289
2290
for _, p := range pullsToClose {
2291
+
s.notifier.NewPullState(r.Context(), p)
2292
}
2293
2294
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId))
···
2361
}
2362
2363
for _, p := range pullsToReopen {
2364
+
s.notifier.NewPullState(r.Context(), p)
2365
}
2366
2367
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId))