···
var _ notify.Notifier = &EmailNotifier{}
37
+
func (n *EmailNotifier) buildIssueEmail(ctx context.Context, repo *db.Repo, issue *db.Issue, comment *db.Comment, did string) (Email, error) {
38
+
// TODO: check email preferences
39
+
email, err := db.GetPrimaryEmail(n.db, did)
41
+
return Email{}, fmt.Errorf("db.GetPrimaryEmail: %w", err)
43
+
commentOwner, err := n.idResolver.ResolveIdent(ctx, comment.OwnerDid)
44
+
if err != nil || commentOwner.Handle.IsInvalidHandle() {
45
+
return Email{}, fmt.Errorf("resolve comment owner did: %w", err)
37
-
// TODO: yeah this is just bad design. should be moved under idResolver ore include repoResolver at first place
38
-
func (n *EmailNotifier) repoOwnerSlashName(ctx context.Context, repo *db.Repo) (string, error) {
repoOwnerID, err := n.idResolver.ResolveIdent(ctx, repo.Did)
if err != nil || repoOwnerID.Handle.IsInvalidHandle() {
49
+
return Email{}, fmt.Errorf("resolve repo owner did: %w", err)
41
-
return "", fmt.Errorf("resolve comment owner did: %w", err)
repoOwnerHandle := repoOwnerID.Handle
var repoOwnerSlashName string
···
repoOwnerSlashName = repo.DidSlashRepo()
50
-
return repoOwnerSlashName, nil
53
-
func (n *EmailNotifier) buildIssueEmail(ctx context.Context, repo *db.Repo, issue *db.Issue, comment *db.Comment, did string) (Email, error) {
54
-
// TODO: check email preferences
55
-
email, err := db.GetPrimaryEmail(n.db, did)
57
-
return Email{}, fmt.Errorf("db.GetPrimaryEmail: %w", err)
59
-
commentOwner, err := n.idResolver.ResolveIdent(ctx, comment.OwnerDid)
60
-
if err != nil || commentOwner.Handle.IsInvalidHandle() {
61
-
return Email{}, fmt.Errorf("resolve comment owner did: %w", err)
// TODO: make this configurable
baseUrl := "https://tangled.sh"
65
-
repoOwnerSlashName, err := n.repoOwnerSlashName(ctx, repo)
url := fmt.Sprintf("%s/%s/issues/%d#comment-%d", baseUrl, repoOwnerSlashName, comment.Issue, comment.CommentId)
APIKey: n.Config.Resend.ApiKey,
···
79
-
func (n *EmailNotifier) buildPullEmail(ctx context.Context, repo *db.Repo, pull *db.Pull, comment *db.PullComment, did string) (Email, error) {
80
-
// TODO: check email preferences
81
-
email, err := db.GetPrimaryEmail(n.db, did)
83
-
return Email{}, fmt.Errorf("db.GetPrimaryEmail: %w", err)
85
-
commentOwner, err := n.idResolver.ResolveIdent(ctx, comment.OwnerDid)
86
-
if err != nil || commentOwner.Handle.IsInvalidHandle() {
87
-
return Email{}, fmt.Errorf("resolve comment owner did: %w", err)
89
-
repoOwnerSlashName, err := n.repoOwnerSlashName(ctx, repo)
93
-
// TODO: make this configurable
94
-
baseUrl := "https://tangled.sh"
95
-
url := fmt.Sprintf("%s/%s/pulls/%d#comment-%d", baseUrl, repoOwnerSlashName, comment.PullId, comment.ID)
97
-
APIKey: n.Config.Resend.ApiKey,
98
-
From: n.Config.Resend.SentFrom,
100
-
Subject: fmt.Sprintf("[%s] %s (pr#%d)", repoOwnerSlashName, pull.Title, pull.PullId),
101
-
Html: fmt.Sprintf(`<p><b>@%s</b> mentioned you:</p><a href="%s">View it on tangled.sh</a>.`, commentOwner.Handle.String(), url),
func (n *EmailNotifier) NewIssueComment(ctx context.Context, repo *db.Repo, issue *db.Issue, comment *db.Comment, mentions []string) {
resolvedIds := n.idResolver.ResolveIdents(ctx, mentions)
handleDidMap := make(map[string]string)
···
88
+
// func (n *EmailNotifier) NewPullComment(ctx context.Context, comment *db.PullComment, []string) {
89
+
// n.usersMentioned(ctx, mentions)
123
-
func (n *EmailNotifier) NewPullComment(ctx context.Context, repo *db.Repo, pull *db.Pull, comment *db.PullComment, mentions []string) {
124
-
resolvedIds := n.idResolver.ResolveIdents(ctx, mentions)
125
-
handleDidMap := make(map[string]string)
126
-
for _, identity := range resolvedIds {
127
-
if !identity.Handle.IsInvalidHandle() {
128
-
handleDidMap[identity.Handle.String()] = identity.DID.String()
131
-
for _, handle := range mentions {
132
-
id, err := n.idResolver.ResolveIdent(ctx, handle)
133
-
email, err := n.buildPullEmail(ctx, repo, pull, comment, id.DID.String())
135
-
log.Println("failed to create issue-email:", err)