Skip to content

Commit 79275d9

Browse files
qwerty287lunny6543delvh
authored
Fix 500 on PR files API (#21602) (#21607)
Fixes an 500 error/panic if using the changed PR files API with pages that should return empty lists because there are no items anymore. `start-end` is then < 0 which ends in panic. Backport #21602 <!-- Please check the following: 1. Make sure you are targeting the `main` branch, pull requests on release branches are only allowed for bug fixes. 2. Read contributing guidelines: https://github.com/go-gitea/gitea/blob/main/CONTRIBUTING.md 3. Describe what your pull request does and which issue you're targeting (if any) --> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: delvh <dev.lh@web.de>
1 parent 3f7cab4 commit 79275d9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Diff for: routers/api/v1/repo/pull.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,11 @@ func GetPullRequestFiles(ctx *context.APIContext) {
14431443
end = totalNumberOfFiles
14441444
}
14451445

1446-
apiFiles := make([]*api.ChangedFile, 0, end-start)
1446+
lenFiles := end - start
1447+
if lenFiles < 0 {
1448+
lenFiles = 0
1449+
}
1450+
apiFiles := make([]*api.ChangedFile, 0, lenFiles)
14471451
for i := start; i < end; i++ {
14481452
apiFiles = append(apiFiles, convert.ToChangedFile(diff.Files[i], pr.HeadRepo, endCommitID))
14491453
}

0 commit comments

Comments
 (0)