Fix Repository Contents Upload API for nested path (#3843)

This commit is contained in:
Naoki Takezoe
2025-09-23 09:01:30 +09:00
committed by GitHub
parent d9cc57e8e0
commit af66f8f746
2 changed files with 10 additions and 9 deletions

View File

@@ -142,10 +142,11 @@ trait ApiRepositoryContentsControllerBase extends ControllerBase {
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(branch))
revCommit.name
}
val paths = multiParams("splat").head.split("/")
val fullPath = multiParams("splat").head
val paths = fullPath.split("/")
val path = paths.take(paths.size - 1).toList.mkString("/")
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) { git =>
val fileInfo = getFileInfo(git, commit, path, false)
val fileInfo = getFileInfo(git, commit, fullPath, ignoreCase = false)
fileInfo match {
case Some(f) if !data.sha.contains(f.id.getName) =>

View File

@@ -183,14 +183,14 @@ class ApiIntegrationTest extends AnyFunSuite {
.branch("main")
.content("create")
.message("Create content")
.path("README.md")
.path("test.txt")
.commit()
assert(createResult.getContent.isFile == true)
assert(createResult.getContent.isFile)
assert(IOUtils.toString(createResult.getContent.read(), "UTF-8") == "create")
val content1 = repo.getFileContent("README.md")
assert(content1.isFile == true)
val content1 = repo.getFileContent("test.txt")
assert(content1.isFile)
assert(IOUtils.toString(content1.read(), "UTF-8") == "create")
assert(content1.getSha == createResult.getContent.getSha)
@@ -200,14 +200,14 @@ class ApiIntegrationTest extends AnyFunSuite {
.branch("main")
.content("update")
.message("Update content")
.path("README.md")
.path("test.txt")
.sha(content1.getSha)
.commit()
assert(updateResult.getContent.isFile == true)
assert(updateResult.getContent.isFile)
assert(IOUtils.toString(updateResult.getContent.read(), "UTF-8") == "update")
val content2 = repo.getFileContent("README.md")
val content2 = repo.getFileContent("test.txt")
assert(content2.isFile == true)
assert(IOUtils.toString(content2.read(), "UTF-8") == "update")
assert(content2.getSha == updateResult.getContent.getSha)