From 4a966c0371dd9bbf8a047ef105ffdf7e073743c9 Mon Sep 17 00:00:00 2001 From: Anirudh Oppiliappan Date: Mon, 15 Sep 2025 16:59:03 +0300 Subject: [PATCH] appview/notify: move posthog notifier as subpackage Change-Id: umqrkzqnpkoslrztowzmrvxowkuvtttv Also add NewIssueComment to the interface. Signed-off-by: Anirudh Oppiliappan --- appview/notify/merged_notifier.go | 11 +++++ appview/notify/notifier.go | 6 ++- appview/{ => notify}/posthog/notifier.go | 61 ++++++++++++++++++++++-- appview/state/router.go | 2 + appview/state/state.go | 4 +- 5 files changed, 78 insertions(+), 6 deletions(-) rename appview/{ => notify}/posthog/notifier.go (72%) diff --git a/appview/notify/merged_notifier.go b/appview/notify/merged_notifier.go index 3548afd8..4b880dfb 100644 --- a/appview/notify/merged_notifier.go +++ b/appview/notify/merged_notifier.go @@ -38,6 +38,17 @@ func (m *mergedNotifier) NewIssue(ctx context.Context, issue *models.Issue) { notifier.NewIssue(ctx, issue) } } +func (m *mergedNotifier) NewIssueComment(ctx context.Context, comment *models.IssueComment) { + for _, notifier := range m.notifiers { + notifier.NewIssueComment(ctx, comment) + } +} + +func (m *mergedNotifier) NewIssueClosed(ctx context.Context, issue *models.Issue) { + for _, notifier := range m.notifiers { + notifier.NewIssueClosed(ctx, issue) + } +} func (m *mergedNotifier) NewFollow(ctx context.Context, follow *models.Follow) { for _, notifier := range m.notifiers { diff --git a/appview/notify/notifier.go b/appview/notify/notifier.go index f8cbb0f8..83ae2c76 100644 --- a/appview/notify/notifier.go +++ b/appview/notify/notifier.go @@ -13,6 +13,8 @@ type Notifier interface { DeleteStar(ctx context.Context, star *models.Star) NewIssue(ctx context.Context, issue *models.Issue) + NewIssueComment(ctx context.Context, comment *models.IssueComment) + NewIssueClosed(ctx context.Context, issue *models.Issue) NewFollow(ctx context.Context, follow *models.Follow) DeleteFollow(ctx context.Context, follow *models.Follow) @@ -37,7 +39,9 @@ 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) NewIssue(ctx context.Context, issue *models.Issue) {} +func (m *BaseNotifier) NewIssueComment(ctx context.Context, comment *models.IssueComment) {} +func (m *BaseNotifier) NewIssueClosed(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) {} diff --git a/appview/posthog/notifier.go b/appview/notify/posthog/notifier.go similarity index 72% rename from appview/posthog/notifier.go rename to appview/notify/posthog/notifier.go index 4c02974a..c6547c83 100644 --- a/appview/posthog/notifier.go +++ b/appview/notify/posthog/notifier.go @@ -1,4 +1,4 @@ -package posthog_service +package posthog import ( "context" @@ -98,6 +98,20 @@ func (n *posthogNotifier) NewPullComment(ctx context.Context, comment *models.Pu } } +func (n *posthogNotifier) NewPullClosed(ctx context.Context, pull *models.Pull) { + err := n.client.Enqueue(posthog.Capture{ + DistinctId: pull.OwnerDid, + Event: "pull_closed", + Properties: posthog.Properties{ + "repo_at": pull.RepoAt, + "pull_id": pull.PullId, + }, + }) + if err != nil { + log.Println("failed to enqueue posthog event:", err) + } +} + func (n *posthogNotifier) NewFollow(ctx context.Context, follow *models.Follow) { err := n.client.Enqueue(posthog.Capture{ DistinctId: follow.UserDid, @@ -152,13 +166,54 @@ func (n *posthogNotifier) EditString(ctx context.Context, string *models.String) } } -func (n *posthogNotifier) CreateString(ctx context.Context, string models.String) { +func (n *posthogNotifier) NewString(ctx context.Context, string *models.String) { err := n.client.Enqueue(posthog.Capture{ DistinctId: string.Did.String(), - Event: "create_string", + Event: "new_string", Properties: posthog.Properties{"rkey": string.Rkey}, }) if err != nil { log.Println("failed to enqueue posthog event:", err) } } + +func (n *posthogNotifier) NewIssueComment(ctx context.Context, comment *models.IssueComment) { + err := n.client.Enqueue(posthog.Capture{ + DistinctId: comment.Did, + Event: "new_issue_comment", + Properties: posthog.Properties{ + "issue_at": comment.IssueAt, + }, + }) + if err != nil { + log.Println("failed to enqueue posthog event:", err) + } +} + +func (n *posthogNotifier) NewIssueClosed(ctx context.Context, issue *models.Issue) { + err := n.client.Enqueue(posthog.Capture{ + DistinctId: issue.Did, + Event: "issue_closed", + Properties: posthog.Properties{ + "repo_at": issue.RepoAt.String(), + "issue_id": issue.IssueId, + }, + }) + if err != nil { + log.Println("failed to enqueue posthog event:", err) + } +} + +func (n *posthogNotifier) NewPullMerged(ctx context.Context, pull *models.Pull) { + err := n.client.Enqueue(posthog.Capture{ + DistinctId: pull.OwnerDid, + Event: "pull_merged", + Properties: posthog.Properties{ + "repo_at": pull.RepoAt, + "pull_id": pull.PullId, + }, + }) + if err != nil { + log.Println("failed to enqueue posthog event:", err) + } +} diff --git a/appview/state/router.go b/appview/state/router.go index ee343fce..d8a5de06 100644 --- a/appview/state/router.go +++ b/appview/state/router.go @@ -156,6 +156,8 @@ func (s *State) StandardRouter(mw *middleware.Middleware) http.Handler { r.Mount("/strings", s.StringsRouter(mw)) r.Mount("/knots", s.KnotsRouter()) r.Mount("/spindles", s.SpindlesRouter()) + r.Mount("/notifications", s.NotificationsRouter(mw)) + r.Mount("/signup", s.SignupRouter()) r.Mount("/", s.OAuthRouter()) diff --git a/appview/state/state.go b/appview/state/state.go index 1ec9777e..8a590fa6 100644 --- a/appview/state/state.go +++ b/appview/state/state.go @@ -25,9 +25,9 @@ import ( "tangled.org/core/appview/db" "tangled.org/core/appview/models" "tangled.org/core/appview/notify" + phnotify "tangled.org/core/appview/notify/posthog" "tangled.org/core/appview/oauth" "tangled.org/core/appview/pages" - posthogService "tangled.org/core/appview/posthog" "tangled.org/core/appview/reporesolver" "tangled.org/core/appview/validator" xrpcclient "tangled.org/core/appview/xrpcclient" @@ -149,7 +149,7 @@ func Make(ctx context.Context, config *config.Config) (*State, error) { var notifiers []notify.Notifier if !config.Core.Dev { - notifiers = append(notifiers, posthogService.NewPosthogNotifier(posthog)) + notifiers = append(notifiers, phnotify.NewPosthogNotifier(posthog)) } notifier := notify.NewMergedNotifier(notifiers...) -- 2.43.0