1
0
Fork 0
forked from forgejo/forgejo

Add GetCurrentReview to simplify fetching current review

Signed-off-by: Jonas Franz <info@jonasfranz.software>
This commit is contained in:
Jonas Franz 2018-05-10 21:50:57 +02:00
parent 4ad563d66f
commit 17af2d17be
No known key found for this signature in database
GPG key ID: 506AEEBE80BEDECD
2 changed files with 28 additions and 12 deletions

View file

@ -6,6 +6,7 @@ package models
import (
"code.gitea.io/gitea/modules/util"
"github.com/go-xorm/builder"
)
@ -156,3 +157,23 @@ func createReview(e Engine, opts CreateReviewOptions) (*Review, error) {
func CreateReview(opts CreateReviewOptions) (*Review, error) {
return createReview(x, opts)
}
func getCurrentReview(e Engine, reviewer *User, issue *Issue) (*Review, error) {
reviews, err := findReviews(e, FindReviewOptions{
Type: ReviewTypePending,
IssueID: issue.ID,
ReviewerID: reviewer.ID,
})
if err != nil {
return nil, err
}
if len(reviews) == 0 {
return nil, ErrReviewNotExist{}
}
return reviews[0], nil
}
// GetCurrentReview returns the current pending review of reviewer for given issue
func GetCurrentReview(reviewer *User, issue *Issue) (*Review, error) {
return getCurrentReview(x, reviewer, issue)
}