From cd1d89b2b75124ccff9c62abbc0e66601c0f9740 Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Sat, 1 Nov 2025 13:11:47 +0900 Subject: [PATCH] appview/notify: use correct actor on issue/pr state change events Change-Id: svzvtornkoykvuwvlmzpttoovtlpkkpx Signed-off-by: Seongmin Lee --- appview/indexer/notifier.go | 4 ++-- appview/issues/issues.go | 4 ++-- appview/notify/db/db.go | 10 ++++------ appview/notify/merged_notifier.go | 8 ++++---- appview/notify/notifier.go | 15 ++++++++------- appview/notify/posthog/notifier.go | 6 ++++-- appview/pulls/pulls.go | 7 ++++--- 7 files changed, 28 insertions(+), 26 deletions(-) diff --git a/appview/indexer/notifier.go b/appview/indexer/notifier.go index db722f12..d3125394 100644 --- a/appview/indexer/notifier.go +++ b/appview/indexer/notifier.go @@ -19,7 +19,7 @@ func (ix *Indexer) NewIssue(ctx context.Context, issue *models.Issue) { } } -func (ix *Indexer) NewIssueState(ctx context.Context, issue *models.Issue) { +func (ix *Indexer) NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) { l := log.FromContext(ctx).With("notifier", "indexer", "issue", issue) l.Debug("updating an issue") err := ix.Issues.Index(ctx, *issue) @@ -46,7 +46,7 @@ func (ix *Indexer) NewPull(ctx context.Context, pull *models.Pull) { } } -func (ix *Indexer) NewPullState(ctx context.Context, pull *models.Pull) { +func (ix *Indexer) NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) { l := log.FromContext(ctx).With("notifier", "indexer", "pull", pull) l.Debug("updating a pr") err := ix.Pulls.Index(ctx, pull) diff --git a/appview/issues/issues.go b/appview/issues/issues.go index b32106a7..15b5fad1 100644 --- a/appview/issues/issues.go +++ b/appview/issues/issues.go @@ -309,7 +309,7 @@ func (rp *Issues) CloseIssue(w http.ResponseWriter, r *http.Request) { issue.Open = false // notify about the issue closure - rp.notifier.NewIssueState(r.Context(), issue) + rp.notifier.NewIssueState(r.Context(), syntax.DID(user.Did), issue) rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", f.OwnerSlashRepo(), issue.IssueId)) return @@ -359,7 +359,7 @@ func (rp *Issues) ReopenIssue(w http.ResponseWriter, r *http.Request) { issue.Open = true // notify about the issue reopen - rp.notifier.NewIssueState(r.Context(), issue) + rp.notifier.NewIssueState(r.Context(), syntax.DID(user.Did), issue) rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", f.OwnerSlashRepo(), issue.IssueId)) return diff --git a/appview/notify/db/db.go b/appview/notify/db/db.go index 9c34baea..b5c76fab 100644 --- a/appview/notify/db/db.go +++ b/appview/notify/db/db.go @@ -283,7 +283,7 @@ func (n *databaseNotifier) NewString(ctx context.Context, string *models.String) // no-op } -func (n *databaseNotifier) NewIssueState(ctx context.Context, issue *models.Issue) { +func (n *databaseNotifier) NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) { // build up the recipients list: // - repo owner // - repo collaborators @@ -302,7 +302,6 @@ func (n *databaseNotifier) NewIssueState(ctx context.Context, issue *models.Issu recipients = append(recipients, syntax.DID(p)) } - actorDid := syntax.DID(issue.Repo.Did) entityType := "pull" entityId := issue.AtUri().String() repoId := &issue.Repo.Id @@ -317,7 +316,7 @@ func (n *databaseNotifier) NewIssueState(ctx context.Context, issue *models.Issu } n.notifyEvent( - actorDid, + actor, recipients, eventType, entityType, @@ -328,7 +327,7 @@ func (n *databaseNotifier) NewIssueState(ctx context.Context, issue *models.Issu ) } -func (n *databaseNotifier) NewPullState(ctx context.Context, pull *models.Pull) { +func (n *databaseNotifier) NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) { // Get repo details repo, err := db.GetRepo(n.db, db.FilterEq("at_uri", string(pull.RepoAt))) if err != nil { @@ -353,7 +352,6 @@ func (n *databaseNotifier) NewPullState(ctx context.Context, pull *models.Pull) recipients = append(recipients, syntax.DID(p)) } - actorDid := syntax.DID(repo.Did) entityType := "pull" entityId := pull.PullAt().String() repoId := &repo.Id @@ -374,7 +372,7 @@ func (n *databaseNotifier) NewPullState(ctx context.Context, pull *models.Pull) pullId := &p n.notifyEvent( - actorDid, + actor, recipients, eventType, entityType, diff --git a/appview/notify/merged_notifier.go b/appview/notify/merged_notifier.go index e0213b93..494c3aab 100644 --- a/appview/notify/merged_notifier.go +++ b/appview/notify/merged_notifier.go @@ -61,8 +61,8 @@ func (m *mergedNotifier) NewIssueComment(ctx context.Context, comment *models.Is m.fanout("NewIssueComment", ctx, comment) } -func (m *mergedNotifier) NewIssueState(ctx context.Context, issue *models.Issue) { - m.fanout("NewIssueState", ctx, issue) +func (m *mergedNotifier) NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) { + m.fanout("NewIssueState", ctx, actor, issue) } func (m *mergedNotifier) DeleteIssue(ctx context.Context, issue *models.Issue) { @@ -85,8 +85,8 @@ func (m *mergedNotifier) NewPullComment(ctx context.Context, comment *models.Pul m.fanout("NewPullComment", ctx, comment) } -func (m *mergedNotifier) NewPullState(ctx context.Context, pull *models.Pull) { - m.fanout("NewPullState", ctx, pull) +func (m *mergedNotifier) NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) { + m.fanout("NewPullState", ctx, actor, pull) } func (m *mergedNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) { diff --git a/appview/notify/notifier.go b/appview/notify/notifier.go index f7bcfc37..691c5865 100644 --- a/appview/notify/notifier.go +++ b/appview/notify/notifier.go @@ -3,6 +3,7 @@ package notify import ( "context" + "github.com/bluesky-social/indigo/atproto/syntax" "tangled.org/core/appview/models" ) @@ -14,7 +15,7 @@ type Notifier interface { NewIssue(ctx context.Context, issue *models.Issue) NewIssueComment(ctx context.Context, comment *models.IssueComment) - NewIssueState(ctx context.Context, issue *models.Issue) + NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) DeleteIssue(ctx context.Context, issue *models.Issue) NewFollow(ctx context.Context, follow *models.Follow) @@ -22,7 +23,7 @@ type Notifier interface { NewPull(ctx context.Context, pull *models.Pull) NewPullComment(ctx context.Context, comment *models.PullComment) - NewPullState(ctx context.Context, pull *models.Pull) + NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) UpdateProfile(ctx context.Context, profile *models.Profile) @@ -41,17 +42,17 @@ func (m *BaseNotifier) NewRepo(ctx context.Context, repo *models.Repo) {} func (m *BaseNotifier) NewStar(ctx context.Context, star *models.Star) {} func (m *BaseNotifier) DeleteStar(ctx context.Context, star *models.Star) {} -func (m *BaseNotifier) NewIssue(ctx context.Context, issue *models.Issue) {} -func (m *BaseNotifier) NewIssueComment(ctx context.Context, comment *models.IssueComment) {} -func (m *BaseNotifier) NewIssueState(ctx context.Context, issue *models.Issue) {} -func (m *BaseNotifier) DeleteIssue(ctx context.Context, issue *models.Issue) {} +func (m *BaseNotifier) NewIssue(ctx context.Context, issue *models.Issue) {} +func (m *BaseNotifier) NewIssueComment(ctx context.Context, comment *models.IssueComment) {} +func (m *BaseNotifier) NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) {} +func (m *BaseNotifier) DeleteIssue(ctx context.Context, issue *models.Issue) {} func (m *BaseNotifier) NewFollow(ctx context.Context, follow *models.Follow) {} func (m *BaseNotifier) DeleteFollow(ctx context.Context, follow *models.Follow) {} func (m *BaseNotifier) NewPull(ctx context.Context, pull *models.Pull) {} func (m *BaseNotifier) NewPullComment(ctx context.Context, models *models.PullComment) {} -func (m *BaseNotifier) NewPullState(ctx context.Context, pull *models.Pull) {} +func (m *BaseNotifier) NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) {} func (m *BaseNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) {} diff --git a/appview/notify/posthog/notifier.go b/appview/notify/posthog/notifier.go index ea62d903..7dcc8ccc 100644 --- a/appview/notify/posthog/notifier.go +++ b/appview/notify/posthog/notifier.go @@ -190,7 +190,7 @@ func (n *posthogNotifier) NewIssueComment(ctx context.Context, comment *models.I } } -func (n *posthogNotifier) NewIssueState(ctx context.Context, issue *models.Issue) { +func (n *posthogNotifier) NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) { var event string if issue.Open { event = "issue_reopen" @@ -202,6 +202,7 @@ func (n *posthogNotifier) NewIssueState(ctx context.Context, issue *models.Issue Event: event, Properties: posthog.Properties{ "repo_at": issue.RepoAt.String(), + "actor": actor, "issue_id": issue.IssueId, }, }) @@ -210,7 +211,7 @@ func (n *posthogNotifier) NewIssueState(ctx context.Context, issue *models.Issue } } -func (n *posthogNotifier) NewPullState(ctx context.Context, pull *models.Pull) { +func (n *posthogNotifier) NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) { var event string switch pull.State { case models.PullClosed: @@ -229,6 +230,7 @@ func (n *posthogNotifier) NewPullState(ctx context.Context, pull *models.Pull) { Properties: posthog.Properties{ "repo_at": pull.RepoAt, "pull_id": pull.PullId, + "actor": actor, }, }) if err != nil { diff --git a/appview/pulls/pulls.go b/appview/pulls/pulls.go index 69efde21..6f4859b7 100644 --- a/appview/pulls/pulls.go +++ b/appview/pulls/pulls.go @@ -2106,6 +2106,7 @@ func (s *Pulls) resubmitStackedPullHelper( } func (s *Pulls) MergePull(w http.ResponseWriter, r *http.Request) { + user := s.oauth.GetUser(r) f, err := s.repoResolver.Resolve(r) if err != nil { log.Println("failed to resolve repo:", err) @@ -2216,7 +2217,7 @@ func (s *Pulls) MergePull(w http.ResponseWriter, r *http.Request) { // notify about the pull merge for _, p := range pullsToMerge { - s.notifier.NewPullState(r.Context(), p) + s.notifier.NewPullState(r.Context(), syntax.DID(user.Did), p) } s.pages.HxLocation(w, fmt.Sprintf("/@%s/%s/pulls/%d", f.OwnerHandle(), f.Name, pull.PullId)) @@ -2288,7 +2289,7 @@ func (s *Pulls) ClosePull(w http.ResponseWriter, r *http.Request) { } for _, p := range pullsToClose { - s.notifier.NewPullState(r.Context(), p) + s.notifier.NewPullState(r.Context(), syntax.DID(user.Did), p) } s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId)) @@ -2361,7 +2362,7 @@ func (s *Pulls) ReopenPull(w http.ResponseWriter, r *http.Request) { } for _, p := range pullsToReopen { - s.notifier.NewPullState(r.Context(), p) + s.notifier.NewPullState(r.Context(), syntax.DID(user.Did), p) } s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId)) -- 2.43.0