+30
-3
appview/email/notifier.go
+30
-3
appview/email/notifier.go
···
69
69
}, nil
70
70
}
71
71
72
+
func (n *EmailNotifier) buildPullEmail(ctx context.Context, repo *db.Repo, pull *db.Pull, comment *db.PullComment) (Email, error) {
73
+
commentOwner, err := n.idResolver.ResolveIdent(ctx, comment.OwnerDid)
74
+
if err != nil || commentOwner.Handle.IsInvalidHandle() {
75
+
return Email{}, fmt.Errorf("resolve comment owner did: %w", err)
76
+
}
77
+
repoOwnerSlashName, err := n.repoOwnerSlashName(ctx, repo)
78
+
if err != nil {
79
+
return Email{}, nil
80
+
}
81
+
baseUrl := n.Config.Core.AppviewHost
82
+
url := fmt.Sprintf("%s/%s/pulls/%d#comment-%d", baseUrl, repoOwnerSlashName, comment.PullId, comment.ID)
83
+
return Email{
84
+
APIKey: n.Config.Resend.ApiKey,
85
+
From: n.Config.Resend.SentFrom,
86
+
Subject: fmt.Sprintf("[%s] %s (pr#%d)", repoOwnerSlashName, pull.Title, pull.PullId),
87
+
Html: fmt.Sprintf(`<p><b>@%s</b> mentioned you</p><a href="%s">View it on tangled.sh</a>.`, commentOwner.Handle.String(), url),
88
+
}, nil
89
+
}
90
+
72
91
func (n *EmailNotifier) gatherRecipientEmails(ctx context.Context, handles []string) []string {
73
92
recipients := []string{}
74
93
for _, handle := range handles {
···
109
128
}
110
129
}
111
130
112
-
// func (n *EmailNotifier) NewPullComment(ctx context.Context, comment *db.PullComment, []string) {
113
-
// n.usersMentioned(ctx, mentions)
114
-
// }
131
+
func (n *EmailNotifier) NewPullComment(ctx context.Context, repo *db.Repo, pull *db.Pull, comment *db.PullComment, mentions []string) {
132
+
email, err := n.buildPullEmail(ctx, repo, pull, comment)
133
+
if err != nil {
134
+
log.Println("failed to create pull-email:", err)
135
+
}
136
+
recipients := n.gatherRecipientEmails(ctx, mentions)
137
+
log.Println("sending email to:", recipients)
138
+
if err = SendEmail(email); err != nil {
139
+
log.Println("error sending email:", err)
140
+
}
141
+
}
+2
-2
appview/notify/merged_notifier.go
+2
-2
appview/notify/merged_notifier.go
···
61
61
notifier.NewPull(ctx, pull)
62
62
}
63
63
}
64
-
func (m *mergedNotifier) NewPullComment(ctx context.Context, comment *db.PullComment) {
64
+
func (m *mergedNotifier) NewPullComment(ctx context.Context, repo *db.Repo, pull *db.Pull, comment *db.PullComment, mentions []string) {
65
65
for _, notifier := range m.notifiers {
66
-
notifier.NewPullComment(ctx, comment)
66
+
notifier.NewPullComment(ctx, repo, pull, comment, mentions)
67
67
}
68
68
}
69
69
+2
-2
appview/notify/notifier.go
+2
-2
appview/notify/notifier.go
···
19
19
DeleteFollow(ctx context.Context, follow *db.Follow)
20
20
21
21
NewPull(ctx context.Context, pull *db.Pull)
22
-
NewPullComment(ctx context.Context, comment *db.PullComment)
22
+
NewPullComment(ctx context.Context, repo *db.Repo, pull *db.Pull, comment *db.PullComment, mentions []string)
23
23
24
24
UpdateProfile(ctx context.Context, profile *db.Profile)
25
25
}
···
41
41
func (m *BaseNotifier) DeleteFollow(ctx context.Context, follow *db.Follow) {}
42
42
43
43
func (m *BaseNotifier) NewPull(ctx context.Context, pull *db.Pull) {}
44
-
func (m *BaseNotifier) NewPullComment(ctx context.Context, comment *db.PullComment) {}
44
+
func (m *BaseNotifier) NewPullComment(ctx context.Context, repo *db.Repo, pull *db.Pull, comment *db.PullComment, mentions []string) {}
45
45
46
46
func (m *BaseNotifier) UpdateProfile(ctx context.Context, profile *db.Profile) {}
+1
-1
appview/posthog/notifier.go
+1
-1
appview/posthog/notifier.go
···
98
98
}
99
99
}
100
100
101
-
func (n *posthogNotifier) NewPullComment(ctx context.Context, comment *db.PullComment) {
101
+
func (n *posthogNotifier) NewPullComment(ctx context.Context, repo *db.Repo, pull *db.Pull, comment *db.PullComment, mentions []string) {
102
102
err := n.client.Enqueue(posthog.Capture{
103
103
DistinctId: comment.OwnerDid,
104
104
Event: "new_pull_comment",
+3
-1
appview/pulls/pulls.go
+3
-1
appview/pulls/pulls.go
···
665
665
return
666
666
}
667
667
668
-
s.notifier.NewPullComment(r.Context(), comment)
668
+
mentions := markup.FindUserMentions(comment.Body)
669
+
670
+
s.notifier.NewPullComment(r.Context(), &f.Repo, pull, comment, mentions)
669
671
670
672
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d#comment-%d", f.OwnerSlashRepo(), pull.PullId, commentId))
671
673
return