|
|
@ -10,6 +10,7 @@ import ( |
|
|
|
"time" |
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/Unknwon/com" |
|
|
|
"github.com/Unknwon/com" |
|
|
|
|
|
|
|
"github.com/go-xorm/builder" |
|
|
|
"github.com/go-xorm/xorm" |
|
|
|
"github.com/go-xorm/xorm" |
|
|
|
|
|
|
|
|
|
|
|
api "code.gitea.io/sdk/gitea" |
|
|
|
api "code.gitea.io/sdk/gitea" |
|
|
@ -21,6 +22,11 @@ import ( |
|
|
|
// CommentType defines whether a comment is just a simple comment, an action (like close) or a reference.
|
|
|
|
// CommentType defines whether a comment is just a simple comment, an action (like close) or a reference.
|
|
|
|
type CommentType int |
|
|
|
type CommentType int |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// define unknown comment type
|
|
|
|
|
|
|
|
const ( |
|
|
|
|
|
|
|
CommentTypeUnknown CommentType = -1 |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// Enumerate all the comment types
|
|
|
|
// Enumerate all the comment types
|
|
|
|
const ( |
|
|
|
const ( |
|
|
|
// Plain comment, can be associated with a commit (CommitID > 0) and a line (LineNum > 0)
|
|
|
|
// Plain comment, can be associated with a commit (CommitID > 0) and a line (LineNum > 0)
|
|
|
@ -568,47 +574,71 @@ func GetCommentByID(id int64) (*Comment, error) { |
|
|
|
return c, nil |
|
|
|
return c, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func getCommentsByIssueIDSince(e Engine, issueID, since int64) ([]*Comment, error) { |
|
|
|
// FindCommentsOptions describes the conditions to Find comments
|
|
|
|
comments := make([]*Comment, 0, 10) |
|
|
|
type FindCommentsOptions struct { |
|
|
|
sess := e. |
|
|
|
RepoID int64 |
|
|
|
Where("issue_id = ?", issueID). |
|
|
|
IssueID int64 |
|
|
|
Where("type = ?", CommentTypeComment). |
|
|
|
Since int64 |
|
|
|
Asc("created_unix") |
|
|
|
Type CommentType |
|
|
|
if since > 0 { |
|
|
|
} |
|
|
|
sess.And("updated_unix >= ?", since) |
|
|
|
|
|
|
|
|
|
|
|
func (opts *FindCommentsOptions) toConds() builder.Cond { |
|
|
|
|
|
|
|
var cond = builder.NewCond() |
|
|
|
|
|
|
|
if opts.RepoID > 0 { |
|
|
|
|
|
|
|
cond = cond.And(builder.Eq{"issue.repo_id": opts.RepoID}) |
|
|
|
} |
|
|
|
} |
|
|
|
return comments, sess.Find(&comments) |
|
|
|
if opts.IssueID > 0 { |
|
|
|
|
|
|
|
cond = cond.And(builder.Eq{"comment.issue_id": opts.IssueID}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if opts.Since > 0 { |
|
|
|
|
|
|
|
cond = cond.And(builder.Gte{"comment.updated_unix": opts.Since}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if opts.Type != CommentTypeUnknown { |
|
|
|
|
|
|
|
cond = cond.And(builder.Eq{"comment.type": opts.Type}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return cond |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func getCommentsByRepoIDSince(e Engine, repoID, since int64) ([]*Comment, error) { |
|
|
|
func findComments(e Engine, opts FindCommentsOptions) ([]*Comment, error) { |
|
|
|
comments := make([]*Comment, 0, 10) |
|
|
|
comments := make([]*Comment, 0, 10) |
|
|
|
sess := e.Where("issue.repo_id = ?", repoID). |
|
|
|
sess := e.Where(opts.toConds()) |
|
|
|
Where("comment.type = ?", CommentTypeComment). |
|
|
|
if opts.RepoID > 0 { |
|
|
|
Join("INNER", "issue", "issue.id = comment.issue_id"). |
|
|
|
sess.Join("INNER", "issue", "issue.id = comment.issue_id") |
|
|
|
Asc("comment.created_unix") |
|
|
|
|
|
|
|
if since > 0 { |
|
|
|
|
|
|
|
sess.And("comment.updated_unix >= ?", since) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return comments, sess.Find(&comments) |
|
|
|
return comments, sess. |
|
|
|
|
|
|
|
Asc("comment.created_unix"). |
|
|
|
|
|
|
|
Find(&comments) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func getCommentsByIssueID(e Engine, issueID int64) ([]*Comment, error) { |
|
|
|
// FindComments returns all comments according options
|
|
|
|
return getCommentsByIssueIDSince(e, issueID, -1) |
|
|
|
func FindComments(opts FindCommentsOptions) ([]*Comment, error) { |
|
|
|
|
|
|
|
return findComments(x, opts) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetCommentsByIssueID returns all comments of an issue.
|
|
|
|
// GetCommentsByIssueID returns all comments of an issue.
|
|
|
|
func GetCommentsByIssueID(issueID int64) ([]*Comment, error) { |
|
|
|
func GetCommentsByIssueID(issueID int64) ([]*Comment, error) { |
|
|
|
return getCommentsByIssueID(x, issueID) |
|
|
|
return findComments(x, FindCommentsOptions{ |
|
|
|
|
|
|
|
IssueID: issueID, |
|
|
|
|
|
|
|
Type: CommentTypeUnknown, |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetCommentsByIssueIDSince returns a list of comments of an issue since a given time point.
|
|
|
|
// GetCommentsByIssueIDSince returns a list of comments of an issue since a given time point.
|
|
|
|
func GetCommentsByIssueIDSince(issueID, since int64) ([]*Comment, error) { |
|
|
|
func GetCommentsByIssueIDSince(issueID, since int64) ([]*Comment, error) { |
|
|
|
return getCommentsByIssueIDSince(x, issueID, since) |
|
|
|
return findComments(x, FindCommentsOptions{ |
|
|
|
|
|
|
|
IssueID: issueID, |
|
|
|
|
|
|
|
Type: CommentTypeUnknown, |
|
|
|
|
|
|
|
Since: since, |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetCommentsByRepoIDSince returns a list of comments for all issues in a repo since a given time point.
|
|
|
|
// GetCommentsByRepoIDSince returns a list of comments for all issues in a repo since a given time point.
|
|
|
|
func GetCommentsByRepoIDSince(repoID, since int64) ([]*Comment, error) { |
|
|
|
func GetCommentsByRepoIDSince(repoID, since int64) ([]*Comment, error) { |
|
|
|
return getCommentsByRepoIDSince(x, repoID, since) |
|
|
|
return findComments(x, FindCommentsOptions{ |
|
|
|
|
|
|
|
RepoID: repoID, |
|
|
|
|
|
|
|
Type: CommentTypeUnknown, |
|
|
|
|
|
|
|
Since: since, |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// UpdateComment updates information of comment.
|
|
|
|
// UpdateComment updates information of comment.
|
|
|
|