Skip to content

Commit 8430f73

Browse files
qwerty287lunny6543delvh
authored
Fix 500 on PR files API (#21602)
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 <[email protected]> Co-authored-by: 6543 <[email protected]> Co-authored-by: delvh <[email protected]>
1 parent ed47d00 commit 8430f73

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

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)