aboutsummaryrefslogtreecommitdiff
path: root/routers
diff options
context:
space:
mode:
authorsillyguodong2023-02-20 22:22:34 +0800
committerGitHub2023-02-20 22:22:34 +0800
commit36d1d5fb7871058e510e59b027d5ee32bba43f2b (patch)
tree60aa86d8c69948cf972fa53d59a3bae4704afbd0 /routers
parentc3d9a70d0a4fc77fe4c44028e72d1a9aadee3e5a (diff)
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 <xiaolunwen@gmail.com>
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/repo/pull.go6
1 files changed, 4 insertions, 2 deletions
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go
index 7005725cf..fa8b517ae 100644
--- a/routers/api/v1/repo/pull.go
+++ b/routers/api/v1/repo/pull.go
@@ -1420,8 +1420,9 @@ func GetPullRequestFiles(ctx *context.APIContext) {
startCommitID := prInfo.MergeBase
endCommitID := headCommitID
- maxLines, maxFiles := setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffFiles
+ maxLines := setting.Git.MaxGitDiffLines
+ // FIXME: If there are too many files in the repo, may cause some unpredictable issues.
diff, err := gitdiff.GetDiff(baseGitRepo,
&gitdiff.DiffOptions{
BeforeCommitID: startCommitID,
@@ -1429,7 +1430,7 @@ func GetPullRequestFiles(ctx *context.APIContext) {
SkipTo: ctx.FormString("skip-to"),
MaxLines: maxLines,
MaxLineCharacters: setting.Git.MaxGitDiffLineCharacters,
- MaxFiles: maxFiles,
+ MaxFiles: -1, // GetDiff() will return all files
WhitespaceBehavior: gitdiff.GetWhitespaceFlag(ctx.FormString("whitespace")),
})
if err != nil {
@@ -1452,6 +1453,7 @@ func GetPullRequestFiles(ctx *context.APIContext) {
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))