From a941d345e952fd4769f078c52378753f19543cf2 Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Wed, 26 Oct 2022 14:36:41 +0200 Subject: [PATCH 1/3] Fix 500 on PR files API --- routers/api/v1/repo/pull.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index f6507dceba89a..cbb9a3fa8c676 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1443,7 +1443,7 @@ func GetPullRequestFiles(ctx *context.APIContext) { end = totalNumberOfFiles } - apiFiles := make([]*api.ChangedFile, 0, end-start) + apiFiles := []*api.ChangedFile{} for i := start; i < end; i++ { apiFiles = append(apiFiles, convert.ToChangedFile(diff.Files[i], pr.HeadRepo, endCommitID)) } From e49ce2f8aad71435337e16f8a6ab99a96a140489 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Wed, 26 Oct 2022 15:39:14 +0200 Subject: [PATCH 2/3] Update routers/api/v1/repo/pull.go Co-authored-by: delvh --- routers/api/v1/repo/pull.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index cbb9a3fa8c676..dbc3c762583f9 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1443,7 +1443,11 @@ func GetPullRequestFiles(ctx *context.APIContext) { end = totalNumberOfFiles } - apiFiles := []*api.ChangedFile{} + 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)) } From 4133d74eb979a6c02ade0e722d13e4c1491e23da Mon Sep 17 00:00:00 2001 From: qwerty287 <80460567+qwerty287@users.noreply.github.com> Date: Wed, 26 Oct 2022 16:16:49 +0200 Subject: [PATCH 3/3] Update routers/api/v1/repo/pull.go --- routers/api/v1/repo/pull.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index dbc3c762583f9..ebb9c0f261f0b 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1443,10 +1443,10 @@ func GetPullRequestFiles(ctx *context.APIContext) { end = totalNumberOfFiles } - lenFiles := 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))