mirror of
https://github.com/go-gitea/gitea
synced 2025-07-23 02:38:35 +00:00
Fix GetPullRequestByIndex by validate index > 1 Signed-off-by: Danila Kryukov <pricly_yellow@dismail.de> Co-authored-by: a1012112796 <1012112796@qq.com>
This commit is contained in:
@@ -502,6 +502,9 @@ func GetLatestPullRequestByHeadInfo(repoID int64, branch string) (*PullRequest,
|
||||
|
||||
// GetPullRequestByIndex returns a pull request by the given index
|
||||
func GetPullRequestByIndex(repoID, index int64) (*PullRequest, error) {
|
||||
if index < 1 {
|
||||
return nil, ErrPullRequestNotExist{}
|
||||
}
|
||||
pr := &PullRequest{
|
||||
BaseRepoID: repoID,
|
||||
Index: index,
|
||||
|
@@ -133,6 +133,10 @@ func TestGetPullRequestByIndex(t *testing.T) {
|
||||
_, err = GetPullRequestByIndex(9223372036854775807, 9223372036854775807)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, IsErrPullRequestNotExist(err))
|
||||
|
||||
_, err = GetPullRequestByIndex(1, 0)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, IsErrPullRequestNotExist(err))
|
||||
}
|
||||
|
||||
func TestGetPullRequestByID(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user