appview/notify: move posthog notifier as subpackage #590

merged
opened by anirudh.fi targeting master from push-xwotmtuuvokm

Also add NewIssueComment to the interface.

Signed-off-by: Anirudh Oppiliappan anirudh@tangled.sh

Changed files
+78 -6
appview
+11
appview/notify/merged_notifier.go
···
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 {
+5 -1
appview/notify/notifier.go
···
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)
···
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) {}
+58 -3
appview/posthog/notifier.go appview/notify/posthog/notifier.go
···
-
package posthog_service
+
package posthog
import (
"context"
···
}
}
+
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,
···
}
}
-
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)
+
}
+
}
+2
appview/state/router.go
···
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())
+2 -2
appview/state/state.go
···
"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"
···
var notifiers []notify.Notifier
if !config.Core.Dev {
-
notifiers = append(notifiers, posthogService.NewPosthogNotifier(posthog))
+
notifiers = append(notifiers, phnotify.NewPosthogNotifier(posthog))
}
notifier := notify.NewMergedNotifier(notifiers...)