From 3d18fe3a6926eca5f548e926606727b498753aaf 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 | 8 ++++---- appview/notify/posthog/notifier.go | 6 ++++-- appview/pulls/pulls.go | 7 ++++--- 7 files changed, 24 insertions(+), 23 deletions(-) diff --git a/appview/indexer/notifier.go b/appview/indexer/notifier.go index 0ace5050..e23e7e50 100644 --- a/appview/indexer/notifier.go +++ b/appview/indexer/notifier.go @@ -20,7 +20,7 @@ func (ix *Indexer) NewIssue(ctx context.Context, issue *models.Issue, mentions [ } } -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) @@ -47,7 +47,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 9850a168..5bf5199a 100644 --- a/appview/issues/issues.go +++ b/appview/issues/issues.go @@ -310,7 +310,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 @@ -360,7 +360,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 28007617..ee815905 100644 --- a/appview/notify/db/db.go +++ b/appview/notify/db/db.go @@ -311,7 +311,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 @@ -330,7 +330,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 @@ -345,7 +344,7 @@ func (n *databaseNotifier) NewIssueState(ctx context.Context, issue *models.Issu } n.notifyEvent( - actorDid, + actor, recipients, eventType, entityType, @@ -356,7 +355,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 { @@ -381,7 +380,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 @@ -402,7 +400,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 abada0ff..deaf57e5 100644 --- a/appview/notify/merged_notifier.go +++ b/appview/notify/merged_notifier.go @@ -62,8 +62,8 @@ func (m *mergedNotifier) NewIssueComment(ctx context.Context, comment *models.Is m.fanout("NewIssueComment", ctx, comment, mentions) } -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) { @@ -86,8 +86,8 @@ func (m *mergedNotifier) NewPullComment(ctx context.Context, comment *models.Pul m.fanout("NewPullComment", ctx, comment, mentions) } -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 509bd907..3c173573 100644 --- a/appview/notify/notifier.go +++ b/appview/notify/notifier.go @@ -15,7 +15,7 @@ type Notifier interface { NewIssue(ctx context.Context, issue *models.Issue, mentions []syntax.DID) NewIssueComment(ctx context.Context, comment *models.IssueComment, mentions []syntax.DID) - 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) @@ -23,7 +23,7 @@ type Notifier interface { NewPull(ctx context.Context, pull *models.Pull) NewPullComment(ctx context.Context, comment *models.PullComment, mentions []syntax.DID) - NewPullState(ctx context.Context, pull *models.Pull) + NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) UpdateProfile(ctx context.Context, profile *models.Profile) @@ -44,7 +44,7 @@ func (m *BaseNotifier) DeleteStar(ctx context.Context, star *models.Star) {} func (m *BaseNotifier) NewIssue(ctx context.Context, issue *models.Issue, mentions []syntax.DID) {} func (m *BaseNotifier) NewIssueComment(ctx context.Context, comment *models.IssueComment, mentions []syntax.DID) {} -func (m *BaseNotifier) NewIssueState(ctx context.Context, issue *models.Issue) {} +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) {} @@ -52,7 +52,7 @@ 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, mentions []syntax.DID) {} -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 acef2a1e..4ca57511 100644 --- a/appview/notify/posthog/notifier.go +++ b/appview/notify/posthog/notifier.go @@ -194,7 +194,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" @@ -206,6 +206,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, }, }) @@ -214,7 +215,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: @@ -233,6 +234,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 765ec844..254f8ee4 100644 --- a/appview/pulls/pulls.go +++ b/appview/pulls/pulls.go @@ -2117,6 +2117,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) @@ -2227,7 +2228,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)) @@ -2299,7 +2300,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)) @@ -2372,7 +2373,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