]> source.dussan.org Git - gitea.git/commitdiff
Introduce NotifySubjectType (#16320)
author6543 <6543@obermui.de>
Thu, 1 Jul 2021 10:51:24 +0000 (12:51 +0200)
committerGitHub <noreply@github.com>
Thu, 1 Jul 2021 10:51:24 +0000 (12:51 +0200)
* Introduce NotifySubjectType

* update swagger docs

modules/convert/notification.go
modules/structs/notifications.go
templates/swagger/v1_json.tmpl

index cc941678b60382cc5d4963544fc953aa794ed9d2..b0888ee09f0cf1dbff7acdd62d1e976c1f618991 100644 (file)
@@ -27,7 +27,7 @@ func ToNotificationThread(n *models.Notification) *api.NotificationThread {
        //handle Subject
        switch n.Source {
        case models.NotificationSourceIssue:
-               result.Subject = &api.NotificationSubject{Type: "Issue"}
+               result.Subject = &api.NotificationSubject{Type: api.NotifySubjectIssue}
                if n.Issue != nil {
                        result.Subject.Title = n.Issue.Title
                        result.Subject.URL = n.Issue.APIURL()
@@ -38,7 +38,7 @@ func ToNotificationThread(n *models.Notification) *api.NotificationThread {
                        }
                }
        case models.NotificationSourcePullRequest:
-               result.Subject = &api.NotificationSubject{Type: "Pull"}
+               result.Subject = &api.NotificationSubject{Type: api.NotifySubjectPull}
                if n.Issue != nil {
                        result.Subject.Title = n.Issue.Title
                        result.Subject.URL = n.Issue.APIURL()
@@ -55,13 +55,13 @@ func ToNotificationThread(n *models.Notification) *api.NotificationThread {
                }
        case models.NotificationSourceCommit:
                result.Subject = &api.NotificationSubject{
-                       Type:  "Commit",
+                       Type:  api.NotifySubjectCommit,
                        Title: n.CommitID,
                        URL:   n.Repository.HTMLURL() + "/commit/" + n.CommitID,
                }
        case models.NotificationSourceRepository:
                result.Subject = &api.NotificationSubject{
-                       Type:  "Repository",
+                       Type:  api.NotifySubjectRepository,
                        Title: n.Repository.FullName(),
                        URL:   n.Repository.Link(),
                }
index 8daa6de1686f5b2c781c9e6cad397b596ea80ce7..675dcf76b127ebc3a2204cfe44cf4ed92f8eefa7 100644 (file)
@@ -21,14 +21,28 @@ type NotificationThread struct {
 
 // NotificationSubject contains the notification subject (Issue/Pull/Commit)
 type NotificationSubject struct {
-       Title            string    `json:"title"`
-       URL              string    `json:"url"`
-       LatestCommentURL string    `json:"latest_comment_url"`
-       Type             string    `json:"type" binding:"In(Issue,Pull,Commit)"`
-       State            StateType `json:"state"`
+       Title            string            `json:"title"`
+       URL              string            `json:"url"`
+       LatestCommentURL string            `json:"latest_comment_url"`
+       Type             NotifySubjectType `json:"type" binding:"In(Issue,Pull,Commit)"`
+       State            StateType         `json:"state"`
 }
 
 // NotificationCount number of unread notifications
 type NotificationCount struct {
        New int64 `json:"new"`
 }
+
+// NotifySubjectType represent type of notification subject
+type NotifySubjectType string
+
+const (
+       // NotifySubjectIssue an issue is subject of an notification
+       NotifySubjectIssue NotifySubjectType = "Issue"
+       // NotifySubjectPull an pull is subject of an notification
+       NotifySubjectPull NotifySubjectType = "Pull"
+       // NotifySubjectCommit an commit is subject of an notification
+       NotifySubjectCommit NotifySubjectType = "Commit"
+       // NotifySubjectRepository an repository is subject of an notification
+       NotifySubjectRepository NotifySubjectType = "Repository"
+)
index 40dddb06a07858c9e0352d0babda096090c19108..dfd08bcc68f8ad64eadc745e685262d3f45f7315 100644 (file)
           "x-go-name": "Title"
         },
         "type": {
-          "type": "string",
-          "x-go-name": "Type"
+          "$ref": "#/definitions/NotifySubjectType"
         },
         "url": {
           "type": "string",
       },
       "x-go-package": "code.gitea.io/gitea/modules/structs"
     },
+    "NotifySubjectType": {
+      "description": "NotifySubjectType represent type of notification subject",
+      "type": "string",
+      "x-go-package": "code.gitea.io/gitea/modules/structs"
+    },
     "OAuth2Application": {
       "type": "object",
       "title": "OAuth2Application represents an OAuth2 application.",