Monorepo for Tangled tangled.org

appview: add `pull_reopen` event

Signed-off-by: Seongmin Lee <git@boltless.me>

authored by boltless.me and committed by Tangled 9892a080 78198773

Changed files
+63
appview
models
notify
pages
templates
notifications
fragments
pulls
+5
appview/models/notifications.go
··· 19 NotificationTypeIssueClosed NotificationType = "issue_closed" 20 NotificationTypeIssueReopen NotificationType = "issue_reopen" 21 NotificationTypePullClosed NotificationType = "pull_closed" 22 ) 23 24 type Notification struct { ··· 58 return "git-merge" 59 case NotificationTypePullClosed: 60 return "git-pull-request-closed" 61 case NotificationTypeFollowed: 62 return "user-plus" 63 default: ··· 106 return prefs.PullMerged 107 case NotificationTypePullClosed: 108 return prefs.PullMerged // same pref for now 109 case NotificationTypeFollowed: 110 return prefs.Followed 111 default:
··· 19 NotificationTypeIssueClosed NotificationType = "issue_closed" 20 NotificationTypeIssueReopen NotificationType = "issue_reopen" 21 NotificationTypePullClosed NotificationType = "pull_closed" 22 + NotificationTypePullReopen NotificationType = "pull_reopen" 23 ) 24 25 type Notification struct { ··· 59 return "git-merge" 60 case NotificationTypePullClosed: 61 return "git-pull-request-closed" 62 + case NotificationTypePullReopen: 63 + return "git-pull-request-create" 64 case NotificationTypeFollowed: 65 return "user-plus" 66 default: ··· 109 return prefs.PullMerged 110 case NotificationTypePullClosed: 111 return prefs.PullMerged // same pref for now 112 + case NotificationTypePullReopen: 113 + return prefs.PullCreated // same pref for now 114 case NotificationTypeFollowed: 115 return prefs.Followed 116 default:
+46
appview/notify/db/db.go
··· 420 ) 421 } 422 423 func (n *databaseNotifier) notifyEvent( 424 actorDid syntax.DID, 425 recipients []syntax.DID,
··· 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 + 457 + n.notifyEvent( 458 + actorDid, 459 + recipients, 460 + eventType, 461 + entityType, 462 + entityId, 463 + repoId, 464 + issueId, 465 + pullId, 466 + ) 467 + } 468 + 469 func (n *databaseNotifier) notifyEvent( 470 actorDid syntax.DID, 471 recipients []syntax.DID,
+4
appview/notify/merged_notifier.go
··· 93 m.fanout("NewPullClosed", ctx, pull) 94 } 95 96 func (m *mergedNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) { 97 m.fanout("UpdateProfile", ctx, profile) 98 }
··· 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) { 101 m.fanout("UpdateProfile", ctx, profile) 102 }
+2
appview/notify/notifier.go
··· 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 28 UpdateProfile(ctx context.Context, profile *models.Profile) 29 ··· 54 func (m *BaseNotifier) NewPullComment(ctx context.Context, models *models.PullComment) {} 55 func (m *BaseNotifier) NewPullMerged(ctx context.Context, pull *models.Pull) {} 56 func (m *BaseNotifier) NewPullClosed(ctx context.Context, pull *models.Pull) {} 57 58 func (m *BaseNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) {} 59
··· 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 ··· 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
+2
appview/pages/templates/notifications/fragments/item.html
··· 50 merged a pull request 51 {{ else if eq .Type "pull_closed" }} 52 closed a pull request 53 {{ else if eq .Type "followed" }} 54 followed you 55 {{ else }}
··· 50 merged a pull request 51 {{ else if eq .Type "pull_closed" }} 52 closed a pull request 53 + {{ else if eq .Type "pull_reopen" }} 54 + reopened a pull request 55 {{ else if eq .Type "followed" }} 56 followed you 57 {{ else }}
+4
appview/pulls/pulls.go
··· 2360 return 2361 } 2362 2363 s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId)) 2364 } 2365
··· 2360 return 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)) 2368 } 2369