From 58d8a6d657751e476eef9ebbeb07d01aa5512ff7 Mon Sep 17 00:00:00 2001 From: Ben Gibson Date: Sat, 7 Sep 2024 00:43:01 +0100 Subject: [PATCH 1/2] Fix Azure URL generation --- CHANGELOG.md | 1 + gradle.properties | 2 +- .../git/link/url/factory/AzureUrlFactory.kt | 1 - .../co/ben_gibson/git/link/url/AzureTest.kt | 22 +++++++++---------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c04a288..42cb80c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ # GitLink Changelog ## Unreleased +- Fix Azure URL generation ## 4.5.1 - 2024-09-03 diff --git a/gradle.properties b/gradle.properties index 46640f3..d220f45 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ pluginGroup = uk.co.ben_gibson.git.link pluginName = GitLink # SemVer format -> https://semver.org -pluginVersion = 4.5.1 +pluginVersion = 4.5.2 # See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html # for insight into build numbers and IntelliJ Platform versions. diff --git a/src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/AzureUrlFactory.kt b/src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/AzureUrlFactory.kt index 7f16356..c86755b 100644 --- a/src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/AzureUrlFactory.kt +++ b/src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/AzureUrlFactory.kt @@ -74,7 +74,6 @@ class AzureUrlFactory: UrlFactory { val basePathParts = baseUrl.path .toString() .removePrefix("v3/") - .plus(".git") // Azure expects .git after the repo name .split("/") .toMutableList() diff --git a/src/test/kotlin/uk/co/ben_gibson/git/link/url/AzureTest.kt b/src/test/kotlin/uk/co/ben_gibson/git/link/url/AzureTest.kt index 7c04692..3b25f27 100644 --- a/src/test/kotlin/uk/co/ben_gibson/git/link/url/AzureTest.kt +++ b/src/test/kotlin/uk/co/ben_gibson/git/link/url/AzureTest.kt @@ -28,17 +28,17 @@ class AzureTest { Arguments.of( REMOTE_BASE_URL_WITH_GIT, UrlOptions.UrlOptionsFileAtBranch(FILE, BRANCH, LINE_SELECTION), - "https://dev.azure.com/ben-gibson/_git/test.git?version=GBmaster&path=src%2FFoo.java&line=10&lineEnd=21&lineStartColumn=1&lineEndColumn=1" + "https://dev.azure.com/ben-gibson/_git/test?version=GBmaster&path=src%2FFoo.java&line=10&lineEnd=21&lineStartColumn=1&lineEndColumn=1" ), Arguments.of( REMOTE_BASE_URL_WITH_GIT, UrlOptions.UrlOptionsFileAtBranch(FILE, BRANCH), - "https://dev.azure.com/ben-gibson/_git/test.git?version=GBmaster&path=src%2FFoo.java" + "https://dev.azure.com/ben-gibson/_git/test?version=GBmaster&path=src%2FFoo.java" ), Arguments.of( REMOTE_BASE_URL_WITH_GIT, UrlOptions.UrlOptionsFileAtCommit(FILE, "main", COMMIT, LINE_SELECTION), - "https://dev.azure.com/ben-gibson/_git/test.git?version=GCb032a0707beac9a2f24b1b7d97ee4f7156de182c&path=src%2FFoo.java&line=10&lineEnd=21&lineStartColumn=1&lineEndColumn=1" + "https://dev.azure.com/ben-gibson/_git/test?version=GCb032a0707beac9a2f24b1b7d97ee4f7156de182c&path=src%2FFoo.java&line=10&lineEnd=21&lineStartColumn=1&lineEndColumn=1" ), Arguments.of( REMOTE_BASE_URL_WITH_GIT, @@ -47,7 +47,7 @@ class AzureTest { "main", COMMIT ), - "https://dev.azure.com/ben-gibson/_git/test.git?version=GCb032a0707beac9a2f24b1b7d97ee4f7156de182c&path=src%2Ffoo%2Fresources" + "https://dev.azure.com/ben-gibson/_git/test?version=GCb032a0707beac9a2f24b1b7d97ee4f7156de182c&path=src%2Ffoo%2Fresources" ), Arguments.of( REMOTE_BASE_URL_WITH_GIT, @@ -56,36 +56,36 @@ class AzureTest { "main", COMMIT ), - "https://dev.azure.com/ben-gibson/_git/test.git?version=GCb032a0707beac9a2f24b1b7d97ee4f7156de182c&path=%2F"), + "https://dev.azure.com/ben-gibson/_git/test?version=GCb032a0707beac9a2f24b1b7d97ee4f7156de182c&path=%2F"), Arguments.of( REMOTE_BASE_URL_WITH_GIT, UrlOptions.UrlOptionsFileAtCommit(FILE, "main", COMMIT), - "https://dev.azure.com/ben-gibson/_git/test.git?version=GCb032a0707beac9a2f24b1b7d97ee4f7156de182c&path=src%2FFoo.java" + "https://dev.azure.com/ben-gibson/_git/test?version=GCb032a0707beac9a2f24b1b7d97ee4f7156de182c&path=src%2FFoo.java" ), Arguments.of( REMOTE_BASE_URL_WITH_GIT, UrlOptions.UrlOptionsCommit(COMMIT, "main"), - "https://dev.azure.com/ben-gibson/_git/test.git/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c" + "https://dev.azure.com/ben-gibson/_git/test/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c" ), Arguments.of( REMOTE_BASE_URL_WITHOUT_GIT, UrlOptions.UrlOptionsCommit(COMMIT, "main"), - "https://dev.azure.com/ben-gibson/_git/test.git/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c" + "https://dev.azure.com/ben-gibson/_git/test/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c" ), Arguments.of( REMOTE_BASE_URL_WITH_COMPANY_AND_GIT, UrlOptions.UrlOptionsCommit(COMMIT, "main"), - "https://dev.azure.com/company/project/_git/test.git/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c" + "https://dev.azure.com/company/project/_git/test/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c" ), Arguments.of( REMOTE_BASE_URL_WITH_COMPANY_WITHOUT_GIT, UrlOptions.UrlOptionsCommit(COMMIT, "main"), - "https://dev.azure.com/company/project/_git/test.git/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c" + "https://dev.azure.com/company/project/_git/test/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c" ), Arguments.of( URL.fromString("https://ssh.dev.azure.com/v3/ben-gibson/test/test"), UrlOptions.UrlOptionsCommit(COMMIT, "main"), - "https://dev.azure.com/ben-gibson/test/_git/test.git/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c" + "https://dev.azure.com/ben-gibson/test/_git/test/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c" ) ) } From 37ccc423c4e700e26d326a34ef634a13e3597793 Mon Sep 17 00:00:00 2001 From: Ben Gibson Date: Sat, 7 Sep 2024 00:49:26 +0100 Subject: [PATCH 2/2] Add remote test --- .../uk/co/ben_gibson/git/link/git/RemoteExtensions.kt | 6 +++++- src/test/kotlin/uk/co/ben_gibson/git/link/git/RemoteTest.kt | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/uk/co/ben_gibson/git/link/git/RemoteExtensions.kt b/src/main/kotlin/uk/co/ben_gibson/git/link/git/RemoteExtensions.kt index 979e715..5862b07 100644 --- a/src/main/kotlin/uk/co/ben_gibson/git/link/git/RemoteExtensions.kt +++ b/src/main/kotlin/uk/co/ben_gibson/git/link/git/RemoteExtensions.kt @@ -16,7 +16,11 @@ val GitRemote.httpUrl : URL? get() { var url = firstUrl ?: return null url = url.trim() - .removeSuffix(".git") + + // Azure supports a .git suffix on the repo name, so don't remove it. + if (!url.contains("dev.azure")) { + url = url.removeSuffix(".git") + } // Do not try to remove the port if the URL uses the SSH protocol in the SCP syntax e.g. // 'git@github.com:foo.git' as it does not support port definitions. Attempting to remove the port diff --git a/src/test/kotlin/uk/co/ben_gibson/git/link/git/RemoteTest.kt b/src/test/kotlin/uk/co/ben_gibson/git/link/git/RemoteTest.kt index 9882eec..93613d6 100644 --- a/src/test/kotlin/uk/co/ben_gibson/git/link/git/RemoteTest.kt +++ b/src/test/kotlin/uk/co/ben_gibson/git/link/git/RemoteTest.kt @@ -44,7 +44,11 @@ class RemoteTest { Arguments.of( "xy://custom.gitlab.url/group/project.git", "http://custom.gitlab.url/group/project" - ) + ), + Arguments.of( + "http://ben-gibson@dev.azure.com/ben-gibson/test/_git/test.git", + "http://dev.azure.com/ben-gibson/test/_git/test.git" + ), ) }