Skip to content

Commit 4ad2a5f

Browse files
committed
Introduce NotifySubjectType
1 parent ce286f9 commit 4ad2a5f

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

modules/convert/notification.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func ToNotificationThread(n *models.Notification) *api.NotificationThread {
2727
//handle Subject
2828
switch n.Source {
2929
case models.NotificationSourceIssue:
30-
result.Subject = &api.NotificationSubject{Type: "Issue"}
30+
result.Subject = &api.NotificationSubject{Type: api.NotifySubjectIssue}
3131
if n.Issue != nil {
3232
result.Subject.Title = n.Issue.Title
3333
result.Subject.URL = n.Issue.APIURL()
@@ -38,7 +38,7 @@ func ToNotificationThread(n *models.Notification) *api.NotificationThread {
3838
}
3939
}
4040
case models.NotificationSourcePullRequest:
41-
result.Subject = &api.NotificationSubject{Type: "Pull"}
41+
result.Subject = &api.NotificationSubject{Type: api.NotifySubjectPull}
4242
if n.Issue != nil {
4343
result.Subject.Title = n.Issue.Title
4444
result.Subject.URL = n.Issue.APIURL()
@@ -55,13 +55,13 @@ func ToNotificationThread(n *models.Notification) *api.NotificationThread {
5555
}
5656
case models.NotificationSourceCommit:
5757
result.Subject = &api.NotificationSubject{
58-
Type: "Commit",
58+
Type: api.NotifySubjectCommit,
5959
Title: n.CommitID,
6060
URL: n.Repository.HTMLURL() + "/commit/" + n.CommitID,
6161
}
6262
case models.NotificationSourceRepository:
6363
result.Subject = &api.NotificationSubject{
64-
Type: "Repository",
64+
Type: api.NotifySubjectRepository,
6565
Title: n.Repository.FullName(),
6666
URL: n.Repository.Link(),
6767
}

modules/structs/notifications.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,28 @@ type NotificationThread struct {
2121

2222
// NotificationSubject contains the notification subject (Issue/Pull/Commit)
2323
type NotificationSubject struct {
24-
Title string `json:"title"`
25-
URL string `json:"url"`
26-
LatestCommentURL string `json:"latest_comment_url"`
27-
Type string `json:"type" binding:"In(Issue,Pull,Commit)"`
28-
State StateType `json:"state"`
24+
Title string `json:"title"`
25+
URL string `json:"url"`
26+
LatestCommentURL string `json:"latest_comment_url"`
27+
Type NotifySubjectType `json:"type"`
28+
State StateType `json:"state"`
2929
}
3030

3131
// NotificationCount number of unread notifications
3232
type NotificationCount struct {
3333
New int64 `json:"new"`
3434
}
35+
36+
// NotifySubjectType represent type of notification subject
37+
type NotifySubjectType string
38+
39+
const (
40+
// NotifySubjectIssue an issue is subject of an notification
41+
NotifySubjectIssue NotifySubjectType = "Issue"
42+
// NotifySubjectPull an pull is subject of an notification
43+
NotifySubjectPull NotifySubjectType = "Pull"
44+
// NotifySubjectCommit an commit is subject of an notification
45+
NotifySubjectCommit NotifySubjectType = "Commit"
46+
// NotifySubjectRepository an repository is subject of an notification
47+
NotifySubjectRepository NotifySubjectType = "Repository"
48+
)

0 commit comments

Comments
 (0)