diff options
author | Andrey Nering <andrey.nering@gmail.com> | 2017-01-06 19:19:18 -0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-06 19:19:18 -0200 |
commit | 03b45284e1845f81d996c7f1cb059e8a8eebfe29 (patch) | |
tree | dc80ceec2706ee96bcb4b3403166d289ace58868 /models/pull.go | |
parent | 84b7d29d34e0d51e0c67e2e35803e8e611da7965 (diff) | |
parent | 72bfabfada8fc485b88eb4547b7d3575789a69c8 (diff) | |
download | gitea-03b45284e1845f81d996c7f1cb059e8a8eebfe29.tar.gz gitea-03b45284e1845f81d996c7f1cb059e8a8eebfe29.zip |
Merge pull request #555 from ethantkoenig/tests/pull
Unit tests for models/pull.go
Diffstat (limited to 'models/pull.go')
-rw-r--r-- | models/pull.go | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/models/pull.go b/models/pull.go index 8661fa3aa8..9beab4df64 100644 --- a/models/pull.go +++ b/models/pull.go @@ -21,6 +21,7 @@ import ( api "code.gitea.io/sdk/gitea" "github.com/Unknwon/com" "github.com/go-xorm/xorm" + "code.gitea.io/gitea/modules/base" ) var pullRequestQueue = sync.NewUniqueQueue(setting.Repository.PullRequestQueueLength) @@ -542,7 +543,7 @@ type PullRequestsOptions struct { MilestoneID int64 } -func listPullRequestStatement(baseRepoID int64, opts *PullRequestsOptions) *xorm.Session { +func listPullRequestStatement(baseRepoID int64, opts *PullRequestsOptions) (*xorm.Session, error) { sess := x.Where("pull_request.base_repo_id=?", baseRepoID) sess.Join("INNER", "issue", "pull_request.issue_id = issue.id") @@ -551,7 +552,20 @@ func listPullRequestStatement(baseRepoID int64, opts *PullRequestsOptions) *xorm sess.And("issue.is_closed=?", opts.State == "closed") } - return sess + sortIssuesSession(sess, opts.SortType) + + if labelIDs, err := base.StringsToInt64s(opts.Labels); err != nil { + return nil, err + } else if len(labelIDs) > 0 { + sess.Join("INNER", "issue_label", "issue.id = issue_label.issue_id"). + In("issue_label.label_id", labelIDs) + } + + if opts.MilestoneID > 0 { + sess.And("issue.milestone_id=?", opts.MilestoneID) + } + + return sess, nil } // PullRequests returns all pull requests for a base Repo by the given conditions @@ -560,7 +574,11 @@ func PullRequests(baseRepoID int64, opts *PullRequestsOptions) ([]*PullRequest, opts.Page = 1 } - countSession := listPullRequestStatement(baseRepoID, opts) + countSession, err := listPullRequestStatement(baseRepoID, opts) + if err != nil { + log.Error(4, "listPullRequestStatement", err) + return nil, 0, err + } maxResults, err := countSession.Count(new(PullRequest)) if err != nil { log.Error(4, "Count PRs", err) @@ -568,7 +586,11 @@ func PullRequests(baseRepoID int64, opts *PullRequestsOptions) ([]*PullRequest, } prs := make([]*PullRequest, 0, ItemsPerPage) - findSession := listPullRequestStatement(baseRepoID, opts) + findSession, err := listPullRequestStatement(baseRepoID, opts) + if err != nil { + log.Error(4, "listPullRequestStatement", err) + return nil, maxResults, err + } findSession.Limit(ItemsPerPage, (opts.Page-1)*ItemsPerPage) return prs, maxResults, findSession.Find(&prs) } @@ -624,7 +646,7 @@ func GetPullRequestByIndex(repoID int64, index int64) (*PullRequest, error) { if err != nil { return nil, err } else if !has { - return nil, ErrPullRequestNotExist{0, repoID, index, 0, "", ""} + return nil, ErrPullRequestNotExist{0, 0, 0, repoID, "", ""} } if err = pr.LoadAttributes(); err != nil { |