From 16da5407fbe6b114eba22772c58577ff2b0af552 Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Thu, 23 Oct 2025 23:29:10 +0900 Subject: [PATCH] appview: add `pull_reopen` event Change-Id: xwuoszlpukszxvppqovpvknuxrlmzsnv Signed-off-by: Seongmin Lee --- appview/models/notifications.go | 5 ++ appview/notify/db/db.go | 46 +++++++++++++++++++ appview/notify/merged_notifier.go | 4 ++ appview/notify/notifier.go | 2 + .../notifications/fragments/item.html | 2 + appview/pulls/pulls.go | 4 ++ 6 files changed, 63 insertions(+) diff --git a/appview/models/notifications.go b/appview/models/notifications.go index daef7fb1..c4081b92 100644 --- a/appview/models/notifications.go +++ b/appview/models/notifications.go @@ -19,6 +19,7 @@ const ( NotificationTypeIssueClosed NotificationType = "issue_closed" NotificationTypeIssueReopen NotificationType = "issue_reopen" NotificationTypePullClosed NotificationType = "pull_closed" + NotificationTypePullReopen NotificationType = "pull_reopen" ) type Notification struct { @@ -58,6 +59,8 @@ func (n *Notification) Icon() string { return "git-merge" case NotificationTypePullClosed: return "git-pull-request-closed" + case NotificationTypePullReopen: + return "git-pull-request-create" case NotificationTypeFollowed: return "user-plus" default: @@ -106,6 +109,8 @@ func (prefs *NotificationPreferences) ShouldNotify(t NotificationType) bool { return prefs.PullMerged case NotificationTypePullClosed: return prefs.PullMerged // same pref for now + case NotificationTypePullReopen: + return prefs.PullCreated // same pref for now case NotificationTypeFollowed: return prefs.Followed default: diff --git a/appview/notify/db/db.go b/appview/notify/db/db.go index 0db77394..2e94069d 100644 --- a/appview/notify/db/db.go +++ b/appview/notify/db/db.go @@ -420,6 +420,52 @@ func (n *databaseNotifier) NewPullClosed(ctx context.Context, pull *models.Pull) ) } +func (n *databaseNotifier) NewPullReopen(ctx context.Context, pull *models.Pull) { + // Get repo details + repo, err := db.GetRepo(n.db, db.FilterEq("at_uri", string(pull.RepoAt))) + if err != nil { + log.Printf("NewPullMerged: failed to get repos: %v", err) + return + } + + // build up the recipients list: + // - repo owner + // - all pull participants + var recipients []syntax.DID + recipients = append(recipients, syntax.DID(repo.Did)) + collaborators, err := db.GetCollaborators(n.db, db.FilterEq("repo_at", repo.RepoAt())) + if err != nil { + log.Printf("failed to fetch collaborators: %v", err) + return + } + for _, c := range collaborators { + recipients = append(recipients, c.SubjectDid) + } + for _, p := range pull.Participants() { + recipients = append(recipients, syntax.DID(p)) + } + + actorDid := syntax.DID(repo.Did) + eventType := models.NotificationTypePullReopen + entityType := "pull" + entityId := pull.PullAt().String() + repoId := &repo.Id + var issueId *int64 + p := int64(pull.ID) + pullId := &p + + n.notifyEvent( + actorDid, + recipients, + eventType, + entityType, + entityId, + repoId, + issueId, + pullId, + ) +} + func (n *databaseNotifier) notifyEvent( actorDid syntax.DID, recipients []syntax.DID, diff --git a/appview/notify/merged_notifier.go b/appview/notify/merged_notifier.go index 54c05f63..d473c0b9 100644 --- a/appview/notify/merged_notifier.go +++ b/appview/notify/merged_notifier.go @@ -93,6 +93,10 @@ func (m *mergedNotifier) NewPullClosed(ctx context.Context, pull *models.Pull) { m.fanout("NewPullClosed", ctx, pull) } +func (m *mergedNotifier) NewPullReopen(ctx context.Context, pull *models.Pull) { + m.fanout("NewPullReopen", ctx, pull) +} + func (m *mergedNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) { m.fanout("UpdateProfile", ctx, profile) } diff --git a/appview/notify/notifier.go b/appview/notify/notifier.go index 31dca33d..eb704f34 100644 --- a/appview/notify/notifier.go +++ b/appview/notify/notifier.go @@ -24,6 +24,7 @@ type Notifier interface { NewPullComment(ctx context.Context, comment *models.PullComment) NewPullMerged(ctx context.Context, pull *models.Pull) NewPullClosed(ctx context.Context, pull *models.Pull) + NewPullReopen(ctx context.Context, pull *models.Pull) UpdateProfile(ctx context.Context, profile *models.Profile) @@ -54,6 +55,7 @@ func (m *BaseNotifier) NewPull(ctx context.Context, pull *models.Pull) func (m *BaseNotifier) NewPullComment(ctx context.Context, models *models.PullComment) {} func (m *BaseNotifier) NewPullMerged(ctx context.Context, pull *models.Pull) {} func (m *BaseNotifier) NewPullClosed(ctx context.Context, pull *models.Pull) {} +func (m *BaseNotifier) NewPullReopen(ctx context.Context, pull *models.Pull) {} func (m *BaseNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) {} diff --git a/appview/pages/templates/notifications/fragments/item.html b/appview/pages/templates/notifications/fragments/item.html index 302336c1..ef4e5476 100644 --- a/appview/pages/templates/notifications/fragments/item.html +++ b/appview/pages/templates/notifications/fragments/item.html @@ -50,6 +50,8 @@ merged a pull request {{ else if eq .Type "pull_closed" }} closed a pull request + {{ else if eq .Type "pull_reopen" }} + reopened a pull request {{ else if eq .Type "followed" }} followed you {{ else }} diff --git a/appview/pulls/pulls.go b/appview/pulls/pulls.go index 214f421f..2e1c9631 100644 --- a/appview/pulls/pulls.go +++ b/appview/pulls/pulls.go @@ -2360,6 +2360,10 @@ func (s *Pulls) ReopenPull(w http.ResponseWriter, r *http.Request) { return } + for _, p := range pullsToReopen { + s.notifier.NewPullReopen(r.Context(), p) + } + s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId)) } -- 2.43.0