diff options
Diffstat (limited to 'models')
-rw-r--r-- | models/issue_comment.go | 65 |
1 files changed, 60 insertions, 5 deletions
diff --git a/models/issue_comment.go b/models/issue_comment.go index f0fc22af34..fc615d5346 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -123,14 +123,55 @@ func (c *Comment) AfterDelete() { } } +// HTMLURL formats a URL-string to the issue-comment +func (c *Comment) HTMLURL() string { + issue, err := GetIssueByID(c.IssueID) + if err != nil { // Silently dropping errors :unamused: + log.Error(4, "GetIssueByID(%d): %v", c.IssueID, err) + return "" + } + return fmt.Sprintf("%s#issuecomment-%d", issue.HTMLURL(), c.ID) +} + +// IssueURL formats a URL-string to the issue +func (c *Comment) IssueURL() string { + issue, err := GetIssueByID(c.IssueID) + if err != nil { // Silently dropping errors :unamused: + log.Error(4, "GetIssueByID(%d): %v", c.IssueID, err) + return "" + } + + if issue.IsPull { + return "" + } + return issue.HTMLURL() +} + +// PRURL formats a URL-string to the pull-request +func (c *Comment) PRURL() string { + issue, err := GetIssueByID(c.IssueID) + if err != nil { // Silently dropping errors :unamused: + log.Error(4, "GetIssueByID(%d): %v", c.IssueID, err) + return "" + } + + if !issue.IsPull { + return "" + } + return issue.HTMLURL() +} + // APIFormat converts a Comment to the api.Comment format func (c *Comment) APIFormat() *api.Comment { return &api.Comment{ - ID: c.ID, - Poster: c.Poster.APIFormat(), - Body: c.Content, - Created: c.Created, - Updated: c.Updated, + ID: c.ID, + Poster: c.Poster.APIFormat(), + HTMLURL: c.HTMLURL(), + IssueURL: c.IssueURL(), + PRURL: c.PRURL(), + Body: c.Content, + Created: c.Created, + Updated: c.Updated, } } @@ -375,6 +416,15 @@ func getCommentsByIssueIDSince(e Engine, issueID, since int64) ([]*Comment, erro return comments, sess.Find(&comments) } +func getCommentsByRepoIDSince(e Engine, repoID, since int64) ([]*Comment, error) { + comments := make([]*Comment, 0, 10) + sess := e.Where("issue.repo_id = ?", repoID).Join("INNER", "issue", "issue.id = comment.issue_id", repoID).Asc("created_unix") + if since > 0 { + sess.And("updated_unix >= ?", since) + } + return comments, sess.Find(&comments) +} + func getCommentsByIssueID(e Engine, issueID int64) ([]*Comment, error) { return getCommentsByIssueIDSince(e, issueID, -1) } @@ -389,6 +439,11 @@ func GetCommentsByIssueIDSince(issueID, since int64) ([]*Comment, error) { return getCommentsByIssueIDSince(x, issueID, since) } +// GetCommentsByRepoIDSince returns a list of comments for all issues in a repo since a given time point. +func GetCommentsByRepoIDSince(repoID, since int64) ([]*Comment, error) { + return getCommentsByRepoIDSince(x, repoID, since) +} + // UpdateComment updates information of comment. func UpdateComment(c *Comment) error { _, err := x.Id(c.ID).AllCols().Update(c) |