Skip to content

Commit dfa18a8

Browse files
authored
Introduce NotifySubjectType (#16320)
* Introduce NotifySubjectType * update swagger docs
1 parent ce286f9 commit dfa18a8

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

modules/convert/notification.go

+4-4
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

+19-5
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" binding:"In(Issue,Pull,Commit)"`
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+
)

templates/swagger/v1_json.tmpl

+6-2
Original file line numberDiff line numberDiff line change
@@ -15241,8 +15241,7 @@
1524115241
"x-go-name": "Title"
1524215242
},
1524315243
"type": {
15244-
"type": "string",
15245-
"x-go-name": "Type"
15244+
"$ref": "#/definitions/NotifySubjectType"
1524615245
},
1524715246
"url": {
1524815247
"type": "string",
@@ -15286,6 +15285,11 @@
1528615285
},
1528715286
"x-go-package": "code.gitea.io/gitea/modules/structs"
1528815287
},
15288+
"NotifySubjectType": {
15289+
"description": "NotifySubjectType represent type of notification subject",
15290+
"type": "string",
15291+
"x-go-package": "code.gitea.io/gitea/modules/structs"
15292+
},
1528915293
"OAuth2Application": {
1529015294
"type": "object",
1529115295
"title": "OAuth2Application represents an OAuth2 application.",

0 commit comments

Comments
 (0)