back interdiff of round #2 and #1

appview: wrap posthog under unified notifier #333

merged
opened by boltless.me targeting master from boltless.me/core: push-pslnqmxvulmp
  • Make db.New*() methods to accept complete model object instead of individual fields
  • Remove posthog field from most Service structs. Oauth still has one as an edge-case
  • Add more notifier methods to replace posthog logics

Signed-off-by: Seongmin Lee boltlessengineer@proton.me

ERROR
appview/db/follow.go

Failed to calculate interdiff for this file.

REBASED
appview/db/star.go

This patch was likely rebased, as context lines do not match.

ERROR
appview/ingester.go

Failed to calculate interdiff for this file.

ERROR
appview/issues/issues.go

Failed to calculate interdiff for this file.

ERROR
appview/notify/merged_notifier.go

Failed to calculate interdiff for this file.

ERROR
appview/notify/notifier.go

Failed to calculate interdiff for this file.

ERROR
appview/pipelines/pipelines.go

Failed to calculate interdiff for this file.

REBASED
appview/pulls/pulls.go

This patch was likely rebased, as context lines do not match.

ERROR
appview/repo/repo.go

Failed to calculate interdiff for this file.

ERROR
appview/state/follow.go

Failed to calculate interdiff for this file.

REVERTED
appview/state/posthog.go
···
-
package state
-
-
import (
-
"context"
-
"log"
-
-
"github.com/posthog/posthog-go"
-
"tangled.sh/tangled.sh/core/appview/db"
-
"tangled.sh/tangled.sh/core/appview/notify"
-
)
-
-
type PosthogNotifier struct {
-
client posthog.Client
-
notify.BaseNotifier
-
}
-
-
func NewPosthogNotifier(client posthog.Client) notify.Notifier {
-
return &PosthogNotifier{
-
client,
-
notify.BaseNotifier{},
-
}
-
}
-
-
var _ notify.Notifier = &PosthogNotifier{}
-
-
func (n *PosthogNotifier) NewRepo(ctx context.Context, repo *db.Repo) {
-
err := n.client.Enqueue(posthog.Capture{
-
DistinctId: repo.Did,
-
Event: "new_repo",
-
Properties: posthog.Properties{"repo": repo.Name, "repo_at": repo.AtUri},
-
})
-
if err != nil {
-
log.Println("failed to enqueue posthog event:", err)
-
}
-
}
-
-
func (n *PosthogNotifier) NewStar(ctx context.Context, star *db.Star) {
-
err := n.client.Enqueue(posthog.Capture{
-
DistinctId: star.StarredByDid,
-
Event: "star",
-
Properties: posthog.Properties{"repo_at": star.RepoAt.String()},
-
})
-
if err != nil {
-
log.Println("failed to enqueue posthog event:", err)
-
}
-
}
-
-
func (n *PosthogNotifier) DeleteStar(ctx context.Context, star *db.Star) {
-
err := n.client.Enqueue(posthog.Capture{
-
DistinctId: star.StarredByDid,
-
Event: "unstar",
-
Properties: posthog.Properties{"repo_at": star.RepoAt.String()},
-
})
-
if err != nil {
-
log.Println("failed to enqueue posthog event:", err)
-
}
-
}
-
-
func (n *PosthogNotifier) NewIssue(ctx context.Context, issue *db.Issue) {
-
err := n.client.Enqueue(posthog.Capture{
-
DistinctId: issue.OwnerDid,
-
Event: "new_issue",
-
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) NewPull(ctx context.Context, pull *db.Pull) {
-
err := n.client.Enqueue(posthog.Capture{
-
DistinctId: pull.OwnerDid,
-
Event: "new_pull",
-
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) NewPullComment(ctx context.Context, comment *db.PullComment) {
-
err := n.client.Enqueue(posthog.Capture{
-
DistinctId: comment.OwnerDid,
-
Event: "new_pull_comment",
-
Properties: posthog.Properties{
-
"repo_at": comment.RepoAt,
-
"pull_id": comment.PullId,
-
},
-
})
-
if err != nil {
-
log.Println("failed to enqueue posthog event:", err)
-
}
-
}
-
-
func (n *PosthogNotifier) NewFollow(ctx context.Context, follow *db.Follow) {
-
err := n.client.Enqueue(posthog.Capture{
-
DistinctId: follow.UserDid,
-
Event: "follow",
-
Properties: posthog.Properties{"subject": follow.SubjectDid},
-
})
-
if err != nil {
-
log.Println("failed to enqueue posthog event:", err)
-
}
-
}
-
-
func (n *PosthogNotifier) DeleteFollow(ctx context.Context, follow *db.Follow) {
-
err := n.client.Enqueue(posthog.Capture{
-
DistinctId: follow.UserDid,
-
Event: "unfollow",
-
Properties: posthog.Properties{"subject": follow.SubjectDid},
-
})
-
if err != nil {
-
log.Println("failed to enqueue posthog event:", err)
-
}
-
}
-
-
func (n *PosthogNotifier) UpdateProfile(ctx context.Context, profile *db.Profile) {
-
err := n.client.Enqueue(posthog.Capture{
-
DistinctId: profile.Did,
-
Event: "edit_profile",
-
})
-
if err != nil {
-
log.Println("failed to enqueue posthog event:", err)
-
}
-
}
···
REBASED
appview/state/profile.go

This patch was likely rebased, as context lines do not match.

ERROR
appview/state/router.go

Failed to calculate interdiff for this file.

ERROR
appview/state/star.go

Failed to calculate interdiff for this file.

ERROR
appview/state/state.go

Failed to calculate interdiff for this file.

NEW
appview/posthog/notifier.go
···
···
+
package posthog_service
+
+
import (
+
"context"
+
"log"
+
+
"github.com/posthog/posthog-go"
+
"tangled.sh/tangled.sh/core/appview/db"
+
"tangled.sh/tangled.sh/core/appview/notify"
+
)
+
+
type posthogNotifier struct {
+
client posthog.Client
+
notify.BaseNotifier
+
}
+
+
func NewPosthogNotifier(client posthog.Client) notify.Notifier {
+
return &posthogNotifier{
+
client,
+
notify.BaseNotifier{},
+
}
+
}
+
+
var _ notify.Notifier = &posthogNotifier{}
+
+
func (n *posthogNotifier) NewRepo(ctx context.Context, repo *db.Repo) {
+
err := n.client.Enqueue(posthog.Capture{
+
DistinctId: repo.Did,
+
Event: "new_repo",
+
Properties: posthog.Properties{"repo": repo.Name, "repo_at": repo.AtUri},
+
})
+
if err != nil {
+
log.Println("failed to enqueue posthog event:", err)
+
}
+
}
+
+
func (n *posthogNotifier) NewStar(ctx context.Context, star *db.Star) {
+
err := n.client.Enqueue(posthog.Capture{
+
DistinctId: star.StarredByDid,
+
Event: "star",
+
Properties: posthog.Properties{"repo_at": star.RepoAt.String()},
+
})
+
if err != nil {
+
log.Println("failed to enqueue posthog event:", err)
+
}
+
}
+
+
func (n *posthogNotifier) DeleteStar(ctx context.Context, star *db.Star) {
+
err := n.client.Enqueue(posthog.Capture{
+
DistinctId: star.StarredByDid,
+
Event: "unstar",
+
Properties: posthog.Properties{"repo_at": star.RepoAt.String()},
+
})
+
if err != nil {
+
log.Println("failed to enqueue posthog event:", err)
+
}
+
}
+
+
func (n *posthogNotifier) NewIssue(ctx context.Context, issue *db.Issue) {
+
err := n.client.Enqueue(posthog.Capture{
+
DistinctId: issue.OwnerDid,
+
Event: "new_issue",
+
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) NewPull(ctx context.Context, pull *db.Pull) {
+
err := n.client.Enqueue(posthog.Capture{
+
DistinctId: pull.OwnerDid,
+
Event: "new_pull",
+
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) NewPullComment(ctx context.Context, comment *db.PullComment) {
+
err := n.client.Enqueue(posthog.Capture{
+
DistinctId: comment.OwnerDid,
+
Event: "new_pull_comment",
+
Properties: posthog.Properties{
+
"repo_at": comment.RepoAt,
+
"pull_id": comment.PullId,
+
},
+
})
+
if err != nil {
+
log.Println("failed to enqueue posthog event:", err)
+
}
+
}
+
+
func (n *posthogNotifier) NewFollow(ctx context.Context, follow *db.Follow) {
+
err := n.client.Enqueue(posthog.Capture{
+
DistinctId: follow.UserDid,
+
Event: "follow",
+
Properties: posthog.Properties{"subject": follow.SubjectDid},
+
})
+
if err != nil {
+
log.Println("failed to enqueue posthog event:", err)
+
}
+
}
+
+
func (n *posthogNotifier) DeleteFollow(ctx context.Context, follow *db.Follow) {
+
err := n.client.Enqueue(posthog.Capture{
+
DistinctId: follow.UserDid,
+
Event: "unfollow",
+
Properties: posthog.Properties{"subject": follow.SubjectDid},
+
})
+
if err != nil {
+
log.Println("failed to enqueue posthog event:", err)
+
}
+
}
+
+
func (n *posthogNotifier) UpdateProfile(ctx context.Context, profile *db.Profile) {
+
err := n.client.Enqueue(posthog.Capture{
+
DistinctId: profile.Did,
+
Event: "edit_profile",
+
})
+
if err != nil {
+
log.Println("failed to enqueue posthog event:", err)
+
}
+
}