Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HTML urls to notification API #17178

Merged
merged 5 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions modules/convert/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,25 @@ 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:
result.Subject = &api.NotificationSubject{Type: api.NotifySubjectPull}
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()
Expand All @@ -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
6543 marked this conversation as resolved.
Show resolved Hide resolved
URL: n.Repository.Link(),
HTMLURL: n.Repository.HTMLURL(),
}
}

Expand Down
12 changes: 7 additions & 5 deletions modules/structs/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,Repository)"`
State StateType `json:"state"`
}

// NotificationCount number of unread notifications
Expand Down
8 changes: 8 additions & 0 deletions templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15728,6 +15728,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"
Expand Down