-
Notifications
You must be signed in to change notification settings - Fork 61
feat: add email notifications for issue events (#202) #278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nazarli-shabnam
merged 4 commits into
Devlaner:main
from
Jbansal2:feature/email-notifications-202
Jul 8, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| package mail | ||
|
|
||
| import "fmt" | ||
|
|
||
| // NotificationEmailData holds data for building notification email content. | ||
| type NotificationEmailData struct { | ||
| ReceiverName string | ||
| ActorName string | ||
| IssueRef string | ||
| IssueTitle string | ||
| IssueURL string | ||
| WorkspaceName string | ||
| CommentPreview string | ||
| FieldName string | ||
| OldValue string | ||
| NewValue string | ||
| } | ||
|
|
||
| // BuildNotificationEmail returns subject and body for a notification email. | ||
| // sender is one of: "assigned", "mentioned", "commented", "state_changed", "subscribed" | ||
| func BuildNotificationEmail(sender string, data NotificationEmailData) (subject, body string) { | ||
| subject = buildNotificationSubject(sender, data) | ||
| body = buildNotificationBody(sender, data) | ||
| return subject, body | ||
| } | ||
|
|
||
| func buildNotificationSubject(sender string, data NotificationEmailData) string { | ||
| switch sender { | ||
| case "assigned": | ||
| return fmt.Sprintf("%s assigned you to %s", data.ActorName, data.IssueRef) | ||
| case "mentioned": | ||
| return fmt.Sprintf("%s mentioned you in %s", data.ActorName, data.IssueRef) | ||
| case "commented": | ||
| return fmt.Sprintf("%s commented on %s", data.ActorName, data.IssueRef) | ||
| case "state_changed": | ||
| if data.OldValue != "" && data.NewValue != "" { | ||
| return fmt.Sprintf("%s moved %s from %s to %s", data.ActorName, data.IssueRef, data.OldValue, data.NewValue) | ||
| } | ||
| return fmt.Sprintf("%s changed the state of %s", data.ActorName, data.IssueRef) | ||
| case "subscribed": | ||
| if data.FieldName != "" { | ||
| return fmt.Sprintf("%s updated %s on %s", data.ActorName, data.FieldName, data.IssueRef) | ||
| } | ||
| return fmt.Sprintf("%s updated %s", data.ActorName, data.IssueRef) | ||
| default: | ||
| return fmt.Sprintf("Update on %s", data.IssueRef) | ||
| } | ||
| } | ||
|
|
||
| func buildNotificationBody(sender string, data NotificationEmailData) string { | ||
| greeting := fmt.Sprintf("Hi %s,\n\n", data.ReceiverName) | ||
| footer := fmt.Sprintf("\n\nView issue: %s\n\nWorkspace: %s\n\n---\nYou're receiving this because you're watching this issue.", data.IssueURL, data.WorkspaceName) | ||
|
|
||
| switch sender { | ||
| case "assigned": | ||
| return greeting + fmt.Sprintf("%s assigned you to %s: %s", data.ActorName, data.IssueRef, data.IssueTitle) + footer | ||
|
|
||
| case "mentioned": | ||
| return greeting + fmt.Sprintf("%s mentioned you in %s: %s", data.ActorName, data.IssueRef, data.IssueTitle) + footer | ||
|
|
||
| case "commented": | ||
| msg := fmt.Sprintf("%s commented on %s: %s", data.ActorName, data.IssueRef, data.IssueTitle) | ||
| if data.CommentPreview != "" { | ||
| msg += fmt.Sprintf("\n\nComment preview:\n%s", data.CommentPreview) | ||
| } | ||
| return greeting + msg + footer | ||
|
|
||
| case "state_changed": | ||
| msg := fmt.Sprintf("%s changed the state of %s: %s", data.ActorName, data.IssueRef, data.IssueTitle) | ||
| if data.OldValue != "" && data.NewValue != "" { | ||
| msg += fmt.Sprintf("\nFrom: %s\nTo: %s", data.OldValue, data.NewValue) | ||
| } else if data.NewValue != "" { | ||
| msg += fmt.Sprintf("\nTo: %s", data.NewValue) | ||
| } | ||
| return greeting + msg + footer | ||
|
|
||
| case "subscribed": | ||
| var msg string | ||
| if data.FieldName != "" { | ||
| msg = fmt.Sprintf("%s updated %s on %s: %s", data.ActorName, data.FieldName, data.IssueRef, data.IssueTitle) | ||
| } else { | ||
| msg = fmt.Sprintf("%s updated %s: %s", data.ActorName, data.IssueRef, data.IssueTitle) | ||
| } | ||
| if data.OldValue != "" && data.NewValue != "" { | ||
| msg += fmt.Sprintf("\nFrom: %s\nTo: %s", data.OldValue, data.NewValue) | ||
| } else if data.NewValue != "" { | ||
| msg += fmt.Sprintf("\nTo: %s", data.NewValue) | ||
| } | ||
| return greeting + msg + footer | ||
|
|
||
| default: | ||
| return greeting + fmt.Sprintf("%s updated %s: %s", data.ActorName, data.IssueRef, data.IssueTitle) + footer | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| package mail | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestBuildNotificationEmail_Assigned(t *testing.T) { | ||
| data := NotificationEmailData{ | ||
| ReceiverName: "Alice", | ||
| ActorName: "Bob", | ||
| IssueRef: "DEV-123", | ||
| IssueTitle: "Fix login bug", | ||
| IssueURL: "https://app.devlane.io/issue/abc-123", | ||
| WorkspaceName: "Engineering", | ||
| } | ||
|
|
||
| subject, body := BuildNotificationEmail("assigned", data) | ||
|
|
||
| expectedSubject := "Bob assigned you to DEV-123" | ||
| if subject != expectedSubject { | ||
| t.Errorf("subject mismatch: got %q, want %q", subject, expectedSubject) | ||
| } | ||
|
|
||
| if !strings.Contains(body, "Hi Alice") { | ||
| t.Error("body should contain greeting") | ||
| } | ||
| if !strings.Contains(body, "Bob assigned you to DEV-123: Fix login bug") { | ||
| t.Error("body should contain assignment message") | ||
| } | ||
| if !strings.Contains(body, data.IssueURL) { | ||
| t.Error("body should contain issue URL") | ||
| } | ||
| if !strings.Contains(body, "Engineering") { | ||
| t.Error("body should contain workspace name") | ||
| } | ||
| } | ||
|
|
||
| func TestBuildNotificationEmail_Mentioned(t *testing.T) { | ||
| data := NotificationEmailData{ | ||
| ReceiverName: "Charlie", | ||
| ActorName: "Dana", | ||
| IssueRef: "PROD-456", | ||
| IssueTitle: "Deploy to production", | ||
| IssueURL: "https://app.devlane.io/issue/def-456", | ||
| WorkspaceName: "Operations", | ||
| } | ||
|
|
||
| subject, body := BuildNotificationEmail("mentioned", data) | ||
|
|
||
| expectedSubject := "Dana mentioned you in PROD-456" | ||
| if subject != expectedSubject { | ||
| t.Errorf("subject mismatch: got %q, want %q", subject, expectedSubject) | ||
| } | ||
|
|
||
| if !strings.Contains(body, "Dana mentioned you in PROD-456") { | ||
| t.Error("body should contain mention message") | ||
| } | ||
| } | ||
|
|
||
| func TestBuildNotificationEmail_Commented(t *testing.T) { | ||
| data := NotificationEmailData{ | ||
| ReceiverName: "Eve", | ||
| ActorName: "Frank", | ||
| IssueRef: "BUG-789", | ||
| IssueTitle: "Performance issue", | ||
| IssueURL: "https://app.devlane.io/issue/ghi-789", | ||
| WorkspaceName: "Backend", | ||
| CommentPreview: "I think we should optimize the database query here", | ||
| } | ||
|
|
||
| subject, body := BuildNotificationEmail("commented", data) | ||
|
|
||
| expectedSubject := "Frank commented on BUG-789" | ||
| if subject != expectedSubject { | ||
| t.Errorf("subject mismatch: got %q, want %q", subject, expectedSubject) | ||
| } | ||
|
|
||
| if !strings.Contains(body, "Frank commented on BUG-789") { | ||
| t.Error("body should contain comment message") | ||
| } | ||
| if !strings.Contains(body, "Comment preview:") { | ||
| t.Error("body should contain comment preview label") | ||
| } | ||
| if !strings.Contains(body, data.CommentPreview) { | ||
| t.Error("body should contain comment preview text") | ||
| } | ||
| } | ||
|
|
||
| func TestBuildNotificationEmail_StateChanged(t *testing.T) { | ||
| data := NotificationEmailData{ | ||
| ReceiverName: "Grace", | ||
| ActorName: "Henry", | ||
| IssueRef: "FEAT-111", | ||
| IssueTitle: "Add dark mode", | ||
| IssueURL: "https://app.devlane.io/issue/jkl-111", | ||
| WorkspaceName: "Frontend", | ||
| OldValue: "In Progress", | ||
| NewValue: "Done", | ||
| } | ||
|
|
||
| subject, body := BuildNotificationEmail("state_changed", data) | ||
|
|
||
| expectedSubject := "Henry moved FEAT-111 from In Progress to Done" | ||
| if subject != expectedSubject { | ||
| t.Errorf("subject mismatch: got %q, want %q", subject, expectedSubject) | ||
| } | ||
|
|
||
| if !strings.Contains(body, "From: In Progress") { | ||
| t.Error("body should contain old state") | ||
| } | ||
| if !strings.Contains(body, "To: Done") { | ||
| t.Error("body should contain new state") | ||
| } | ||
| } | ||
|
|
||
| func TestBuildNotificationEmail_Subscribed(t *testing.T) { | ||
| data := NotificationEmailData{ | ||
| ReceiverName: "Ivan", | ||
| ActorName: "Jane", | ||
| IssueRef: "TASK-222", | ||
| IssueTitle: "Update documentation", | ||
| IssueURL: "https://app.devlane.io/issue/mno-222", | ||
| WorkspaceName: "Documentation", | ||
| FieldName: "priority", | ||
| OldValue: "Low", | ||
| NewValue: "High", | ||
| } | ||
|
|
||
| subject, body := BuildNotificationEmail("subscribed", data) | ||
|
|
||
| expectedSubject := "Jane updated priority on TASK-222" | ||
| if subject != expectedSubject { | ||
| t.Errorf("subject mismatch: got %q, want %q", subject, expectedSubject) | ||
| } | ||
|
|
||
| if !strings.Contains(body, "Jane updated priority on TASK-222") { | ||
| t.Error("body should contain field change message") | ||
| } | ||
| if !strings.Contains(body, "From: Low") { | ||
| t.Error("body should contain old value") | ||
| } | ||
| if !strings.Contains(body, "To: High") { | ||
| t.Error("body should contain new value") | ||
| } | ||
| } | ||
|
|
||
| func TestBuildNotificationEmail_CommentedWithoutPreview(t *testing.T) { | ||
| data := NotificationEmailData{ | ||
| ReceiverName: "Kevin", | ||
| ActorName: "Laura", | ||
| IssueRef: "FIX-333", | ||
| IssueTitle: "Memory leak", | ||
| IssueURL: "https://app.devlane.io/issue/pqr-333", | ||
| WorkspaceName: "Infrastructure", | ||
| } | ||
|
|
||
| _, body := BuildNotificationEmail("commented", data) | ||
|
|
||
| if strings.Contains(body, "Comment preview:") { | ||
| t.Error("body should not contain comment preview label when no preview provided") | ||
| } | ||
| } | ||
|
|
||
| func TestBuildNotificationEmail_StateChangedWithoutOldValue(t *testing.T) { | ||
| data := NotificationEmailData{ | ||
| ReceiverName: "Mike", | ||
| ActorName: "Nancy", | ||
| IssueRef: "ISSUE-444", | ||
| IssueTitle: "Test coverage", | ||
| IssueURL: "https://app.devlane.io/issue/stu-444", | ||
| WorkspaceName: "QA", | ||
| NewValue: "In Review", | ||
| } | ||
|
|
||
| subject, body := BuildNotificationEmail("state_changed", data) | ||
|
|
||
| expectedSubject := "Nancy changed the state of ISSUE-444" | ||
| if subject != expectedSubject { | ||
| t.Errorf("subject mismatch: got %q, want %q", subject, expectedSubject) | ||
| } | ||
|
|
||
| if !strings.Contains(body, "To: In Review") { | ||
| t.Error("body should contain new state") | ||
| } | ||
| if strings.Contains(body, "From:") { | ||
| t.Error("body should not contain 'From:' when old value is empty") | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package model | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| "github.com/google/uuid" | ||
| "gorm.io/gorm" | ||
| ) | ||
|
|
||
| // EmailNotificationLog tracks notification emails queued/sent for audit. | ||
| // Maps to the existing email_notification_logs table. | ||
| type EmailNotificationLog struct { | ||
| ID uuid.UUID `gorm:"type:uuid;primaryKey;default:gen_random_uuid()" json:"id"` | ||
| ReceiverID uuid.UUID `gorm:"type:uuid;not null" json:"receiver_id"` | ||
| TriggeredByID *uuid.UUID `gorm:"type:uuid" json:"triggered_by_id,omitempty"` | ||
| Subject string `gorm:"type:text" json:"subject"` | ||
| EntityIdentifier *uuid.UUID `gorm:"type:uuid" json:"entity_identifier,omitempty"` | ||
| EntityName string `gorm:"type:varchar(255)" json:"entity_name,omitempty"` | ||
| Data JSONMap `gorm:"type:jsonb;serializer:json" json:"data,omitempty"` | ||
| ProcessedAt *time.Time `gorm:"type:timestamptz" json:"processed_at,omitempty"` | ||
| SentAt *time.Time `gorm:"type:timestamptz" json:"sent_at,omitempty"` // When queued to RabbitMQ | ||
| Entity string `gorm:"type:varchar(200)" json:"entity,omitempty"` // Legacy | ||
| OldValue string `gorm:"type:varchar(300)" json:"old_value,omitempty"` // Legacy | ||
| NewValue string `gorm:"type:varchar(300)" json:"new_value,omitempty"` // Legacy | ||
| CreatedAt time.Time `json:"created_at"` | ||
| UpdatedAt time.Time `json:"updated_at"` | ||
| } | ||
|
|
||
| func (EmailNotificationLog) TableName() string { return "email_notification_logs" } | ||
|
|
||
| func (e *EmailNotificationLog) BeforeCreate(tx *gorm.DB) error { | ||
| if e.ID == uuid.Nil { | ||
| e.ID = uuid.New() | ||
| } | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.