From ebe77ae7bddeb64f3004f7d41188ddeb449bbc23 Mon Sep 17 00:00:00 2001 From: Norwin Date: Wed, 29 Sep 2021 14:38:14 +0200 Subject: [PATCH 1/2] API: add html urls to notification subjects --- modules/convert/notification.go | 16 ++++++++++++---- modules/structs/notifications.go | 12 +++++++----- templates/swagger/v1_json.tmpl | 8 ++++++++ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/modules/convert/notification.go b/modules/convert/notification.go index b0888ee09f0c..fae7be1257d2 100644 --- a/modules/convert/notification.go +++ b/modules/convert/notification.go @@ -31,10 +31,12 @@ func ToNotificationThread(n *models.Notification) *api.NotificationThread { if n.Issue != nil { result.Subject.Title = n.Issue.Title result.Subject.URL = n.Issue.APIURL() + result.Subject.HTMLURL = n.Issue.HTMLURL() result.Subject.State = n.Issue.State() comment, err := n.Issue.GetLastComment() if err == nil && comment != nil { result.Subject.LatestCommentURL = comment.APIURL() + result.Subject.LatestCommentHTMLURL = comment.HTMLURL() } } case models.NotificationSourcePullRequest: @@ -42,10 +44,12 @@ func ToNotificationThread(n *models.Notification) *api.NotificationThread { if n.Issue != nil { result.Subject.Title = n.Issue.Title result.Subject.URL = n.Issue.APIURL() + result.Subject.HTMLURL = n.Issue.HTMLURL() result.Subject.State = n.Issue.State() comment, err := n.Issue.GetLastComment() if err == nil && comment != nil { result.Subject.LatestCommentURL = comment.APIURL() + result.Subject.LatestCommentHTMLURL = comment.HTMLURL() } pr, _ := n.Issue.GetPullRequest() @@ -54,16 +58,20 @@ func ToNotificationThread(n *models.Notification) *api.NotificationThread { } } case models.NotificationSourceCommit: + url := n.Repository.HTMLURL() + "/commit/" + n.CommitID result.Subject = &api.NotificationSubject{ - Type: api.NotifySubjectCommit, - Title: n.CommitID, - URL: n.Repository.HTMLURL() + "/commit/" + n.CommitID, + Type: api.NotifySubjectCommit, + Title: n.CommitID, + URL: url, + HTMLURL: url, } case models.NotificationSourceRepository: result.Subject = &api.NotificationSubject{ Type: api.NotifySubjectRepository, Title: n.Repository.FullName(), - URL: n.Repository.Link(), + // FIXME: this is a relative URL, rather useless and inconsistent, but keeping for backwards compat + URL: n.Repository.Link(), + HTMLURL: n.Repository.HTMLURL(), } } diff --git a/modules/structs/notifications.go b/modules/structs/notifications.go index 675dcf76b127..6e2c8e1fd5aa 100644 --- a/modules/structs/notifications.go +++ b/modules/structs/notifications.go @@ -21,11 +21,13 @@ 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 NotifySubjectType `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"` + HTMLURL string `json:"html_url"` + LatestCommentHTMLURL string `json:"latest_comment_html_url"` + Type NotifySubjectType `json:"type" binding:"In(Issue,Pull,Commit)"` + State StateType `json:"state"` } // NotificationCount number of unread notifications diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 63eba4583288..67440766e3b6 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -15584,6 +15584,14 @@ "description": "NotificationSubject contains the notification subject (Issue/Pull/Commit)", "type": "object", "properties": { + "html_url": { + "type": "string", + "x-go-name": "HTMLURL" + }, + "latest_comment_html_url": { + "type": "string", + "x-go-name": "LatestCommentHTMLURL" + }, "latest_comment_url": { "type": "string", "x-go-name": "LatestCommentURL" From 1cb478beadb3255e4fb5da90bca684c56b93fa32 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Wed, 29 Sep 2021 17:34:21 +0200 Subject: [PATCH 2/2] add "Repository" --- modules/structs/notifications.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/structs/notifications.go b/modules/structs/notifications.go index 6e2c8e1fd5aa..3fd9088ce385 100644 --- a/modules/structs/notifications.go +++ b/modules/structs/notifications.go @@ -26,7 +26,7 @@ type NotificationSubject struct { LatestCommentURL string `json:"latest_comment_url"` HTMLURL string `json:"html_url"` LatestCommentHTMLURL string `json:"latest_comment_html_url"` - Type NotifySubjectType `json:"type" binding:"In(Issue,Pull,Commit)"` + Type NotifySubjectType `json:"type" binding:"In(Issue,Pull,Commit,Repository)"` State StateType `json:"state"` }