appview: add pull_reopen event #710

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