From 08bf2d64fd12fc2117afee231dafb9ad8f062f6a Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 2 Jul 2025 19:57:05 +0800 Subject: [PATCH] fix --- routers/api/v1/repo/file.go | 6 ++---- services/repository/files/file.go | 7 ++++++- tests/integration/api_repo_file_create_test.go | 6 ++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/routers/api/v1/repo/file.go b/routers/api/v1/repo/file.go index bcef993011..69b5996222 100644 --- a/routers/api/v1/repo/file.go +++ b/routers/api/v1/repo/file.go @@ -834,10 +834,8 @@ func GetContentsExt(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - treePath := ctx.PathParam("*") - if treePath == "." || treePath == "/" { - treePath = "" - ctx.SetPathParam("*", treePath) + if treePath := ctx.PathParam("*"); treePath == "." || treePath == "/" { + ctx.SetPathParam("*", "") // workaround for swagger, it requires path parameter to be "required", but we need to list root directory } opts := files_service.GetContentsOrListOptions{TreePath: ctx.PathParam("*")} for includeOpt := range strings.SplitSeq(ctx.FormString("includes"), ",") { diff --git a/services/repository/files/file.go b/services/repository/files/file.go index 2a63a0a5b9..13d171d139 100644 --- a/services/repository/files/file.go +++ b/services/repository/files/file.go @@ -22,7 +22,12 @@ import ( func GetContentsListFromTreePaths(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, refCommit *utils.RefCommit, treePaths []string) (files []*api.ContentsResponse) { var size int64 for _, treePath := range treePaths { - fileContents, _ := GetFileContents(ctx, repo, gitRepo, refCommit, GetContentsOrListOptions{TreePath: treePath, IncludeSingleFileContent: true}) // ok if fails, then will be nil + // ok if fails, then will be nil + fileContents, _ := GetFileContents(ctx, repo, gitRepo, refCommit, GetContentsOrListOptions{ + TreePath: treePath, + IncludeSingleFileContent: true, + IncludeCommitMetadata: true, + }) if fileContents != nil && fileContents.Content != nil && *fileContents.Content != "" { // if content isn't empty (e.g., due to the single blob being too large), add file size to response size size += int64(len(*fileContents.Content)) diff --git a/tests/integration/api_repo_file_create_test.go b/tests/integration/api_repo_file_create_test.go index 1233eecbab..af3bc54680 100644 --- a/tests/integration/api_repo_file_create_test.go +++ b/tests/integration/api_repo_file_create_test.go @@ -58,8 +58,8 @@ func normalizeFileContentResponseCommitTime(c *api.ContentsResponse) { } type apiFileResponseInfo struct { - repoFullName, commitID, treePath, lastCommitSHA, lastCommitMessage string - lastCommitterWhen, lastAuthorWhen time.Time + repoFullName, commitID, treePath, lastCommitSHA string + lastCommitterWhen, lastAuthorWhen time.Time } func getExpectedFileResponseForCreate(info apiFileResponseInfo) *api.FileResponse { @@ -78,7 +78,6 @@ func getExpectedFileResponseForCreate(info apiFileResponseInfo) *api.FileRespons LastCommitSHA: util.ToPointer(info.lastCommitSHA), LastCommitterDate: util.ToPointer(info.lastCommitterWhen), LastAuthorDate: util.ToPointer(info.lastAuthorWhen), - LastCommitMessage: util.ToPointer(info.lastCommitMessage), Size: 16, Type: "file", Encoding: &encoding, @@ -195,7 +194,6 @@ func TestAPICreateFile(t *testing.T) { lastCommitSHA: lastCommit.ID.String(), lastCommitterWhen: lastCommit.Committer.When, lastAuthorWhen: lastCommit.Author.When, - lastCommitMessage: lastCommit.Message(), }) var fileResponse api.FileResponse DecodeJSON(t, resp, &fileResponse)