Skip to content

Commit eae9154

Browse files
ethantkoeniglafriks
authored andcommitted
Fix SQL bug in models.PullRequests
1 parent 3c0705e commit eae9154

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

integrations/api_pull_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2017 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package integrations
6+
7+
import (
8+
"net/http"
9+
"testing"
10+
11+
"code.gitea.io/gitea/models"
12+
api "code.gitea.io/sdk/gitea"
13+
14+
"github.com/stretchr/testify/assert"
15+
)
16+
17+
func TestAPIViewPulls(t *testing.T) {
18+
prepareTestEnv(t)
19+
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
20+
owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
21+
22+
session := loginUser(t, "user2")
23+
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/pulls?state=all", owner.Name, repo.Name)
24+
resp := session.MakeRequest(t, req)
25+
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
26+
27+
var pulls []*api.PullRequest
28+
DecodeJSON(t, resp, &pulls)
29+
expectedLen := models.GetCount(t, &models.Issue{RepoID: repo.ID}, models.Cond("is_pull = ?", true))
30+
assert.Len(t, pulls, expectedLen)
31+
}

models/pull.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,6 @@ func listPullRequestStatement(baseRepoID int64, opts *PullRequestsOptions) (*xor
688688
sess.And("issue.is_closed=?", opts.State == "closed")
689689
}
690690

691-
sortIssuesSession(sess, opts.SortType)
692-
693691
if labelIDs, err := base.StringsToInt64s(opts.Labels); err != nil {
694692
return nil, err
695693
} else if len(labelIDs) > 0 {
@@ -723,6 +721,7 @@ func PullRequests(baseRepoID int64, opts *PullRequestsOptions) ([]*PullRequest,
723721

724722
prs := make([]*PullRequest, 0, ItemsPerPage)
725723
findSession, err := listPullRequestStatement(baseRepoID, opts)
724+
sortIssuesSession(findSession, opts.SortType)
726725
if err != nil {
727726
log.Error(4, "listPullRequestStatement", err)
728727
return nil, maxResults, err

0 commit comments

Comments
 (0)