Skip to content

Commit 36d1d5f

Browse files
sillyguodonglunny
andauthored
Fix panic when call api (/repos/{owner}/{repo}/pulls/{index}/files) (#22921)
Close: #22910 --- I'm confused about that why does the api (`GET /repos/{owner}/{repo}/pulls/{index}/files`) require caller to pass the parameters `limit` and `page`. In my case, the caller only needs to pass a `skip-to` to paging. This is consistent with the api `GET /{owner}/{repo}/pulls/{index}/files` So, I deleted the code related to `listOptions` --------- Co-authored-by: Lunny Xiao <[email protected]>
1 parent c3d9a70 commit 36d1d5f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

routers/api/v1/repo/pull.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -1420,16 +1420,17 @@ func GetPullRequestFiles(ctx *context.APIContext) {
14201420
startCommitID := prInfo.MergeBase
14211421
endCommitID := headCommitID
14221422

1423-
maxLines, maxFiles := setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffFiles
1423+
maxLines := setting.Git.MaxGitDiffLines
14241424

1425+
// FIXME: If there are too many files in the repo, may cause some unpredictable issues.
14251426
diff, err := gitdiff.GetDiff(baseGitRepo,
14261427
&gitdiff.DiffOptions{
14271428
BeforeCommitID: startCommitID,
14281429
AfterCommitID: endCommitID,
14291430
SkipTo: ctx.FormString("skip-to"),
14301431
MaxLines: maxLines,
14311432
MaxLineCharacters: setting.Git.MaxGitDiffLineCharacters,
1432-
MaxFiles: maxFiles,
1433+
MaxFiles: -1, // GetDiff() will return all files
14331434
WhitespaceBehavior: gitdiff.GetWhitespaceFlag(ctx.FormString("whitespace")),
14341435
})
14351436
if err != nil {
@@ -1452,6 +1453,7 @@ func GetPullRequestFiles(ctx *context.APIContext) {
14521453
if lenFiles < 0 {
14531454
lenFiles = 0
14541455
}
1456+
14551457
apiFiles := make([]*api.ChangedFile, 0, lenFiles)
14561458
for i := start; i < end; i++ {
14571459
apiFiles = append(apiFiles, convert.ToChangedFile(diff.Files[i], pr.HeadRepo, endCommitID))

0 commit comments

Comments
 (0)