From 8168580d6030743e6047ab5fb4febd58ac7c51f4 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Mon, 16 Dec 2024 00:27:56 +0900 Subject: [PATCH] Restore the original response of list-repository-tags API (#3662) --- .../scala/gitbucket/core/api/ApiTag.scala | 29 +++++++++++++++++++ .../api/ApiRepositoryControllerBase.scala | 2 +- .../core/api/ApiIntegrationTest.scala | 6 +++- 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/main/scala/gitbucket/core/api/ApiTag.scala diff --git a/src/main/scala/gitbucket/core/api/ApiTag.scala b/src/main/scala/gitbucket/core/api/ApiTag.scala new file mode 100644 index 000000000..46fd25a23 --- /dev/null +++ b/src/main/scala/gitbucket/core/api/ApiTag.scala @@ -0,0 +1,29 @@ +package gitbucket.core.api + +import gitbucket.core.util.RepositoryName + +case class ApiTagCommit( + sha: String, + url: ApiPath +) + +case class ApiTag( + name: String, + commit: ApiTagCommit, + zipball_url: ApiPath, + tarball_url: ApiPath +) + +object ApiTag { + def apply( + tagName: String, + repositoryName: RepositoryName, + commitId: String + ): ApiTag = + ApiTag( + name = tagName, + commit = ApiTagCommit(sha = commitId, url = ApiPath(s"/${repositoryName.fullName}/commits/${commitId}")), + zipball_url = ApiPath(s"/${repositoryName.fullName}/archive/${tagName}.zip"), + tarball_url = ApiPath(s"/${repositoryName.fullName}/archive/${tagName}.tar.gz") + ) +} diff --git a/src/main/scala/gitbucket/core/controller/api/ApiRepositoryControllerBase.scala b/src/main/scala/gitbucket/core/controller/api/ApiRepositoryControllerBase.scala index e4555b934..ccd6b35d1 100644 --- a/src/main/scala/gitbucket/core/controller/api/ApiRepositoryControllerBase.scala +++ b/src/main/scala/gitbucket/core/controller/api/ApiRepositoryControllerBase.scala @@ -182,7 +182,7 @@ trait ApiRepositoryControllerBase extends ControllerBase { get("/api/v3/repos/:owner/:repository/tags")(referrersOnly { repository => Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git => JsonFormat( - self.getRef("tags", repository) + repository.tags.map(tagInfo => ApiTag(tagInfo.name, RepositoryName(repository), tagInfo.commitId)) ) } }) diff --git a/src/test/scala/gitbucket/core/api/ApiIntegrationTest.scala b/src/test/scala/gitbucket/core/api/ApiIntegrationTest.scala index d914db69b..af312348c 100644 --- a/src/test/scala/gitbucket/core/api/ApiIntegrationTest.scala +++ b/src/test/scala/gitbucket/core/api/ApiIntegrationTest.scala @@ -158,11 +158,15 @@ class ApiIntegrationTest extends AnyFunSuite { // get tag v1.0 { Using.resource(Git.open(new File(server.getDirectory(), "repositories/root/create_status_test"))) { git => - git.tag().setName("v1.0").call() + git.tag().setName("v1.0").call().getPeeledObjectId } val ref = repo.getRef("tags/v1.0") assert(ref.getRef == "refs/tags/v1.0") assert(ref.getUrl.toString == "http://localhost:19999/api/v3/repos/root/create_status_test/git/refs/tags/v1.0") + + val tags = repo.listTags().toList + assert(tags.size() == 1) + assert(tags.get(0).getName == "v1.0") } } }