summaryrefslogtreecommitdiffstats
path: root/models/issue_comment.go
diff options
context:
space:
mode:
authorKim "BKC" Carlbäcker <kim.carlbacker@gmail.com>2016-12-22 09:29:26 +0100
committerLunny Xiao <xiaolunwen@gmail.com>2016-12-22 16:29:26 +0800
commitdf7fa4e9959ab23fd94c3475d0860af810936e88 (patch)
tree139c29cf98cca4c5ff888e0bd450c50789f23cfa /models/issue_comment.go
parentd5d21b67d24908dfddad95ac9a1e2f66395cad51 (diff)
downloadgitea-df7fa4e9959ab23fd94c3475d0860af810936e88.tar.gz
gitea-df7fa4e9959ab23fd94c3475d0860af810936e88.zip
issue comment api fix (#449)
* ListAllInRepo & Delete Issue-Comments * Moar data in issue-comments
Diffstat (limited to 'models/issue_comment.go')
-rw-r--r--models/issue_comment.go65
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)