mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	API: add html urls to notification subjects (#17178)
* API: add html urls to notification subjects * add "Repository" Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
		@@ -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(),
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user