Skip to content

Commit 3bbdce2

Browse files
noerw6543lunny
authored
API: add html urls to notification subjects (#17178)
* API: add html urls to notification subjects * add "Repository" Co-authored-by: 6543 <[email protected]> Co-authored-by: Lunny Xiao <[email protected]>
1 parent ac10c4e commit 3bbdce2

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

modules/convert/notification.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,25 @@ func ToNotificationThread(n *models.Notification) *api.NotificationThread {
3131
if n.Issue != nil {
3232
result.Subject.Title = n.Issue.Title
3333
result.Subject.URL = n.Issue.APIURL()
34+
result.Subject.HTMLURL = n.Issue.HTMLURL()
3435
result.Subject.State = n.Issue.State()
3536
comment, err := n.Issue.GetLastComment()
3637
if err == nil && comment != nil {
3738
result.Subject.LatestCommentURL = comment.APIURL()
39+
result.Subject.LatestCommentHTMLURL = comment.HTMLURL()
3840
}
3941
}
4042
case models.NotificationSourcePullRequest:
4143
result.Subject = &api.NotificationSubject{Type: api.NotifySubjectPull}
4244
if n.Issue != nil {
4345
result.Subject.Title = n.Issue.Title
4446
result.Subject.URL = n.Issue.APIURL()
47+
result.Subject.HTMLURL = n.Issue.HTMLURL()
4548
result.Subject.State = n.Issue.State()
4649
comment, err := n.Issue.GetLastComment()
4750
if err == nil && comment != nil {
4851
result.Subject.LatestCommentURL = comment.APIURL()
52+
result.Subject.LatestCommentHTMLURL = comment.HTMLURL()
4953
}
5054

5155
pr, _ := n.Issue.GetPullRequest()
@@ -54,16 +58,20 @@ func ToNotificationThread(n *models.Notification) *api.NotificationThread {
5458
}
5559
}
5660
case models.NotificationSourceCommit:
61+
url := n.Repository.HTMLURL() + "/commit/" + n.CommitID
5762
result.Subject = &api.NotificationSubject{
58-
Type: api.NotifySubjectCommit,
59-
Title: n.CommitID,
60-
URL: n.Repository.HTMLURL() + "/commit/" + n.CommitID,
63+
Type: api.NotifySubjectCommit,
64+
Title: n.CommitID,
65+
URL: url,
66+
HTMLURL: url,
6167
}
6268
case models.NotificationSourceRepository:
6369
result.Subject = &api.NotificationSubject{
6470
Type: api.NotifySubjectRepository,
6571
Title: n.Repository.FullName(),
66-
URL: n.Repository.Link(),
72+
// FIXME: this is a relative URL, rather useless and inconsistent, but keeping for backwards compat
73+
URL: n.Repository.Link(),
74+
HTMLURL: n.Repository.HTMLURL(),
6775
}
6876
}
6977

modules/structs/notifications.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ 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 NotifySubjectType `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+
HTMLURL string `json:"html_url"`
28+
LatestCommentHTMLURL string `json:"latest_comment_html_url"`
29+
Type NotifySubjectType `json:"type" binding:"In(Issue,Pull,Commit,Repository)"`
30+
State StateType `json:"state"`
2931
}
3032

3133
// NotificationCount number of unread notifications

templates/swagger/v1_json.tmpl

+8
Original file line numberDiff line numberDiff line change
@@ -15728,6 +15728,14 @@
1572815728
"description": "NotificationSubject contains the notification subject (Issue/Pull/Commit)",
1572915729
"type": "object",
1573015730
"properties": {
15731+
"html_url": {
15732+
"type": "string",
15733+
"x-go-name": "HTMLURL"
15734+
},
15735+
"latest_comment_html_url": {
15736+
"type": "string",
15737+
"x-go-name": "LatestCommentHTMLURL"
15738+
},
1573115739
"latest_comment_url": {
1573215740
"type": "string",
1573315741
"x-go-name": "LatestCommentURL"

0 commit comments

Comments
 (0)