-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Fix #2001 and fix issue comments hidden #2016
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
Changes from 3 commits
a91be46
d530fa6
e0065ef
94e3e62
bfccf1b
e10341e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import ( | |
"time" | ||
|
||
"github.com/Unknwon/com" | ||
"github.com/go-xorm/builder" | ||
"github.com/go-xorm/xorm" | ||
|
||
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. | ||
type CommentType int | ||
|
||
// define unknown comment type | ||
const ( | ||
CommentTypeUnknown CommentType = -1 | ||
) | ||
|
||
// Enumerate all the comment types | ||
const ( | ||
// Plain comment, can be associated with a commit (CommitID > 0) and a line (LineNum > 0) | ||
|
@@ -568,47 +574,68 @@ func GetCommentByID(id int64) (*Comment, error) { | |
return c, nil | ||
} | ||
|
||
func getCommentsByIssueIDSince(e Engine, issueID, since int64) ([]*Comment, error) { | ||
comments := make([]*Comment, 0, 10) | ||
sess := e. | ||
Where("issue_id = ?", issueID). | ||
Where("type = ?", CommentTypeComment). | ||
Asc("created_unix") | ||
if since > 0 { | ||
sess.And("updated_unix >= ?", since) | ||
// FindCommentsOptions describes the condtions to Find comments | ||
type FindCommentsOptions struct { | ||
RepoID int64 | ||
IssueID int64 | ||
Since int64 | ||
Type CommentType | ||
} | ||
|
||
func (opts *FindCommentsOptions) toConds() builder.Cond { | ||
var cond = builder.NewCond() | ||
if opts.RepoID > 0 { | ||
cond = cond.And(builder.Eq{"issue.repo_id": opts.RepoID}) | ||
} | ||
if opts.IssueID > 0 { | ||
cond = cond.And(builder.Eq{"issue.id": opts.IssueID}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
} | ||
return comments, sess.Find(&comments) | ||
if opts.Since > 0 { | ||
cond = cond.And(builder.Gte{"comment.updated_unix": opts.Since}) | ||
} | ||
if opts.Type > -1 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably it would be better to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
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) | ||
sess := e.Where("issue.repo_id = ?", repoID). | ||
Where("comment.type = ?", CommentTypeComment). | ||
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, e.Join("INNER", "issue", "issue.id = comment.issue_id"). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The join is only necessary if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
Where(opts.toConds()). | ||
Asc("comment.created_unix"). | ||
Find(&comments) | ||
} | ||
|
||
func getCommentsByIssueID(e Engine, issueID int64) ([]*Comment, error) { | ||
return getCommentsByIssueIDSince(e, issueID, -1) | ||
// FindComments returns all comments according options | ||
func FindComments(opts FindCommentsOptions) ([]*Comment, error) { | ||
return findComments(x, opts) | ||
} | ||
|
||
// GetCommentsByIssueID returns all comments of an issue. | ||
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. | ||
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. | ||
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. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
condtions -> conditions