From 3110d1dc54a1ec34360013bb9fa1faa568702c81 Mon Sep 17 00:00:00 2001 From: Ikhun Um Date: Wed, 11 Dec 2024 20:12:55 +0900 Subject: [PATCH] Expose a port number of `remoteUrl` in the mirror UI Motivation: I found that the port number of the remote URI was missing and was shown in the mirror UI. Modifications: - Use `URI.getAuthority()` to include the port number of a remote URI. Result: The custom port number of a remote URI is correctly displayed in the mirror UI. --- .../MirroringAndCredentialServiceV1Test.java | 34 +++++++++++++++++++ .../internal/api/MirroringServiceV1.java | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/server-mirror-git/src/test/java/com/linecorp/centraldogma/server/internal/mirror/MirroringAndCredentialServiceV1Test.java b/server-mirror-git/src/test/java/com/linecorp/centraldogma/server/internal/mirror/MirroringAndCredentialServiceV1Test.java index 5cc4082ee..3ae649b6a 100644 --- a/server-mirror-git/src/test/java/com/linecorp/centraldogma/server/internal/mirror/MirroringAndCredentialServiceV1Test.java +++ b/server-mirror-git/src/test/java/com/linecorp/centraldogma/server/internal/mirror/MirroringAndCredentialServiceV1Test.java @@ -292,6 +292,40 @@ private void createAndReadMirror() { final MirrorDto savedMirror = response1.content(); assertThat(savedMirror).isEqualTo(newMirror); } + + // Make sure that the mirror with a port number in the remote URL can be created and read. + final MirrorDto mirrorWithPort = new MirrorDto("mirror-with-port-3", + true, + FOO_PROJ, + "5 * * * * ?", + "REMOTE_TO_LOCAL", + BAR_REPO, + "/updated/local-path/", + "git+https", + "git.com:922/line/centraldogma-test.git", + "/updated/remote-path/", + "updated-mirror-branch", + ".updated-env", + "public-key-credential", + null); + + final ResponseEntity response0 = + userClient.prepare() + .post("/api/v1/projects/{proj}/mirrors") + .pathParam("proj", FOO_PROJ) + .contentJson(mirrorWithPort) + .asJson(PushResultDto.class) + .execute(); + assertThat(response0.status()).isEqualTo(HttpStatus.CREATED); + final ResponseEntity response1 = + userClient.prepare() + .get("/api/v1/projects/{proj}/mirrors/{id}") + .pathParam("proj", FOO_PROJ) + .pathParam("id", mirrorWithPort.id()) + .asJson(MirrorDto.class) + .execute(); + final MirrorDto savedMirror = response1.content(); + assertThat(savedMirror).isEqualTo(mirrorWithPort); } private void updateMirror() { diff --git a/server/src/main/java/com/linecorp/centraldogma/server/internal/api/MirroringServiceV1.java b/server/src/main/java/com/linecorp/centraldogma/server/internal/api/MirroringServiceV1.java index d6b28e4b2..bad33e69b 100644 --- a/server/src/main/java/com/linecorp/centraldogma/server/internal/api/MirroringServiceV1.java +++ b/server/src/main/java/com/linecorp/centraldogma/server/internal/api/MirroringServiceV1.java @@ -223,7 +223,7 @@ private static MirrorDto convertToMirrorDto(String projectName, Mirror mirror) { mirror.localRepo().name(), mirror.localPath(), remoteRepoUri.getScheme(), - remoteRepoUri.getHost() + remoteRepoUri.getPath(), + remoteRepoUri.getAuthority() + remoteRepoUri.getPath(), mirror.remotePath(), mirror.remoteBranch(), mirror.gitignore(),