Add load functions

Add ReviewID to findComments

Signed-off-by: Jonas Franz <info@jonasfranz.software>
This commit is contained in:
Jonas Franz 2018-05-10 14:48:08 +02:00
parent aeb057755a
commit 2c18552576
No known key found for this signature in database
GPG Key ID: 506AEEBE80BEDECD
2 changed files with 48 additions and 7 deletions

View File

@ -663,6 +663,7 @@ func GetCommentByID(id int64) (*Comment, error) {
type FindCommentsOptions struct {
RepoID int64
IssueID int64
ReviewID int64
Since int64
Type CommentType
}
@ -675,6 +676,9 @@ func (opts *FindCommentsOptions) toConds() builder.Cond {
if opts.IssueID > 0 {
cond = cond.And(builder.Eq{"comment.issue_id": opts.IssueID})
}
if opts.ReviewID > 0 {
cond = cond.And(builder.Eq{"comment.review_id": opts.ReviewID})
}
if opts.Since > 0 {
cond = cond.And(builder.Gte{"comment.updated_unix": opts.Since})
}

View File

@ -6,14 +6,15 @@ package models
import "code.gitea.io/gitea/modules/util"
// ReviewType defines the sort of feedback a review gives
type ReviewType int
const (
// Approving changes
// ReviewTypeApprove approves changes
ReviewTypeApprove ReviewType = iota
// General feedback
// ReviewTypeComment gives general feedback
ReviewTypeComment
// Feedback blocking merge
// ReviewTypeReject gives feedback blocking merge
ReviewTypeReject
)
@ -35,6 +36,41 @@ type Review struct {
CodeComments []*Comment `xorm:"-"`
}
func (r *Review) loadCodeComments(e Engine) (err error) {
r.CodeComments, err = findComments(e, FindCommentsOptions{IssueID: r.IssueID, ReviewID: r.ID})
return
}
// LoadCodeComments loads CodeComments
func (r *Review) LoadCodeComments() error {
return r.loadCodeComments(x)
}
func (r *Review) loadIssue(e Engine) (err error) {
r.Issue, err = getIssueByID(e, r.IssueID)
return
}
func (r *Review) loadReviewer(e Engine) (err error) {
r.Reviewer, err = getUserByID(e, r.ReviewerID)
return
}
func (r *Review) loadAttributes(e Engine) (err error) {
if err = r.loadReviewer(e); err != nil {
return
}
if err = r.loadIssue(e); err != nil {
return
}
return
}
// LoadAttributes loads all attributes except CodeComments
func (r *Review) LoadAttributes() error {
return r.loadAttributes(x)
}
func getReviewByID(e Engine, id int64) (*Review, error) {
review := new(Review)
if has, err := e.ID(id).Get(review); err != nil {
@ -46,6 +82,7 @@ func getReviewByID(e Engine, id int64) (*Review, error) {
}
}
// GetReviewByID returns the review by the given ID
func GetReviewByID(id int64) (*Review, error) {
return getReviewByID(x, id)
}