mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 11:41:32 +01:00 
			
		
		
		
	Add load functions
Add ReviewID to findComments Signed-off-by: Jonas Franz <info@jonasfranz.software>
This commit is contained in:
		
							parent
							
								
									aeb057755a
								
							
						
					
					
						commit
						2c18552576
					
				| @ -663,6 +663,7 @@ func GetCommentByID(id int64) (*Comment, error) { | |||||||
| type FindCommentsOptions struct { | type FindCommentsOptions struct { | ||||||
| 	RepoID   int64 | 	RepoID   int64 | ||||||
| 	IssueID  int64 | 	IssueID  int64 | ||||||
|  | 	ReviewID int64 | ||||||
| 	Since    int64 | 	Since    int64 | ||||||
| 	Type     CommentType | 	Type     CommentType | ||||||
| } | } | ||||||
| @ -675,6 +676,9 @@ func (opts *FindCommentsOptions) toConds() builder.Cond { | |||||||
| 	if opts.IssueID > 0 { | 	if opts.IssueID > 0 { | ||||||
| 		cond = cond.And(builder.Eq{"comment.issue_id": opts.IssueID}) | 		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 { | 	if opts.Since > 0 { | ||||||
| 		cond = cond.And(builder.Gte{"comment.updated_unix": opts.Since}) | 		cond = cond.And(builder.Gte{"comment.updated_unix": opts.Since}) | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -6,14 +6,15 @@ package models | |||||||
| 
 | 
 | ||||||
| import "code.gitea.io/gitea/modules/util" | import "code.gitea.io/gitea/modules/util" | ||||||
| 
 | 
 | ||||||
|  | // ReviewType defines the sort of feedback a review gives | ||||||
| type ReviewType int | type ReviewType int | ||||||
| 
 | 
 | ||||||
| const ( | const ( | ||||||
| 	// Approving changes | 	// ReviewTypeApprove approves changes | ||||||
| 	ReviewTypeApprove ReviewType = iota | 	ReviewTypeApprove ReviewType = iota | ||||||
| 	// General feedback | 	// ReviewTypeComment gives general feedback | ||||||
| 	ReviewTypeComment | 	ReviewTypeComment | ||||||
| 	// Feedback blocking merge | 	// ReviewTypeReject gives feedback blocking merge | ||||||
| 	ReviewTypeReject | 	ReviewTypeReject | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| @ -35,6 +36,41 @@ type Review struct { | |||||||
| 	CodeComments []*Comment `xorm:"-"` | 	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) { | func getReviewByID(e Engine, id int64) (*Review, error) { | ||||||
| 	review := new(Review) | 	review := new(Review) | ||||||
| 	if has, err := e.ID(id).Get(review); err != nil { | 	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) { | func GetReviewByID(id int64) (*Review, error) { | ||||||
| 	return getReviewByID(x, id) | 	return getReviewByID(x, id) | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user