Skip to content

Commit

Permalink
Fix 500 on PR files API (#21602)
Browse files Browse the repository at this point in the history
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.

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: delvh <dev.lh@web.de>
  • Loading branch information
4 people authored Oct 26, 2022
1 parent ed47d00 commit 8430f73
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion routers/api/v1/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,11 @@ func GetPullRequestFiles(ctx *context.APIContext) {
end = totalNumberOfFiles
}

apiFiles := make([]*api.ChangedFile, 0, end-start)
lenFiles := end - start
if lenFiles < 0 {
lenFiles = 0
}
apiFiles := make([]*api.ChangedFile, 0, lenFiles)
for i := start; i < end; i++ {
apiFiles = append(apiFiles, convert.ToChangedFile(diff.Files[i], pr.HeadRepo, endCommitID))
}
Expand Down

0 comments on commit 8430f73

Please sign in to comment.