From 273fa6dc54028959da3619397aa230229b515ca0 Mon Sep 17 00:00:00 2001 From: Ben Gibson Date: Tue, 3 Sep 2024 08:38:43 +0100 Subject: [PATCH 1/2] Fix Bitbucket cloud host --- ...UrlFactory.kt => BitbucketServerUrlFactory.kt} | 4 +++- .../url/factory/TemplatedUrlFactoryProvider.kt | 2 +- .../git/link/url/factory/UrlFactoryLocator.kt | 7 ++----- .../ben_gibson/git/link/url/BitBucketCloudTest.kt | 15 ++++----------- .../git/link/url/BitBucketServerTest.kt | 14 +++++++++++--- 5 files changed, 21 insertions(+), 21 deletions(-) rename src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/{BitbucketCloudUrlFactory.kt => BitbucketServerUrlFactory.kt} (78%) diff --git a/src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/BitbucketCloudUrlFactory.kt b/src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/BitbucketServerUrlFactory.kt similarity index 78% rename from src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/BitbucketCloudUrlFactory.kt rename to src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/BitbucketServerUrlFactory.kt index bb75fd9..806b003 100644 --- a/src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/BitbucketCloudUrlFactory.kt +++ b/src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/BitbucketServerUrlFactory.kt @@ -1,11 +1,13 @@ package uk.co.ben_gibson.git.link.url.factory +import com.intellij.openapi.components.Service import uk.co.ben_gibson.git.link.url.UrlOptions import uk.co.ben_gibson.git.link.url.template.UrlTemplates import uk.co.ben_gibson.url.Path import uk.co.ben_gibson.url.URL -class BitbucketCloudUrlFactory : TemplatedUrlFactory(UrlTemplates.bitbucketCloud()) { +@Service +class BitbucketServerUrlFactory : TemplatedUrlFactory(UrlTemplates.bitbucketServer()) { override fun createUrl(baseUrl: URL, options: UrlOptions): URL { return super.createUrl(normaliseBaseUrl(baseUrl), options) } diff --git a/src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/TemplatedUrlFactoryProvider.kt b/src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/TemplatedUrlFactoryProvider.kt index bb40855..5fd873a 100644 --- a/src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/TemplatedUrlFactoryProvider.kt +++ b/src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/TemplatedUrlFactoryProvider.kt @@ -14,7 +14,7 @@ val PLATFORM_MAP = mapOf( Gitea::class.java to UrlTemplates.gitea(), Gogs::class.java to UrlTemplates.gogs(), Srht::class.java to UrlTemplates.srht(), - BitbucketServer::class.java to UrlTemplates.bitbucketServer(), + BitbucketCloud::class.java to UrlTemplates.bitbucketCloud(), Gerrit::class.java to UrlTemplates.gerrit(), ) diff --git a/src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/UrlFactoryLocator.kt b/src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/UrlFactoryLocator.kt index bc04bde..0332284 100644 --- a/src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/UrlFactoryLocator.kt +++ b/src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/UrlFactoryLocator.kt @@ -2,10 +2,7 @@ package uk.co.ben_gibson.git.link.url.factory import com.intellij.openapi.components.Service import com.intellij.openapi.components.service -import uk.co.ben_gibson.git.link.platform.Azure -import uk.co.ben_gibson.git.link.platform.BitbucketCloud -import uk.co.ben_gibson.git.link.platform.Chromium -import uk.co.ben_gibson.git.link.platform.Platform +import uk.co.ben_gibson.git.link.platform.* @Service class UrlFactoryLocator { @@ -13,7 +10,7 @@ class UrlFactoryLocator { return when(platform) { is Chromium -> service() is Azure -> service() - is BitbucketCloud -> service() + is BitbucketServer -> service() else -> service().forPlatform(platform) } } diff --git a/src/test/kotlin/uk/co/ben_gibson/git/link/url/BitBucketCloudTest.kt b/src/test/kotlin/uk/co/ben_gibson/git/link/url/BitBucketCloudTest.kt index a234ae9..28e2a89 100644 --- a/src/test/kotlin/uk/co/ben_gibson/git/link/url/BitBucketCloudTest.kt +++ b/src/test/kotlin/uk/co/ben_gibson/git/link/url/BitBucketCloudTest.kt @@ -8,7 +8,8 @@ import uk.co.ben_gibson.git.link.git.File import uk.co.ben_gibson.git.link.ui.LineSelection import java.util.stream.Stream import uk.co.ben_gibson.git.link.git.Commit -import uk.co.ben_gibson.git.link.url.factory.BitbucketCloudUrlFactory +import uk.co.ben_gibson.git.link.url.factory.TemplatedUrlFactory +import uk.co.ben_gibson.git.link.url.template.UrlTemplates import uk.co.ben_gibson.url.URL class BitBucketCloudTest { @@ -28,15 +29,6 @@ class BitBucketCloudTest { UrlOptions.UrlOptionsFileAtBranch(FILE, BRANCH, LINE_SELECTION), "https://bitbucket.org/foo/bar/src/master/src/Foo.java#lines-10:20" ), - Arguments.of( - URL.fromString("https://dev.example.com/scm/foo/bar"), - UrlOptions.UrlOptionsFileAtBranch( - FILE, - BRANCH, - LINE_SELECTION - ), - "https://dev.example.com/foo/bar/src/master/src/Foo.java#lines-10:20" - ), Arguments.of( REMOTE_BASE_URL, UrlOptions.UrlOptionsFileAtBranch(FILE, BRANCH), @@ -81,7 +73,8 @@ class BitBucketCloudTest { @ParameterizedTest @MethodSource("urlExpectationsProvider") fun canGenerateUrl(baseUrl: URL, options: UrlOptions, expectedUrl: String) { - val factory = BitbucketCloudUrlFactory() + val factory = TemplatedUrlFactory(UrlTemplates.bitbucketCloud()) + val url = factory.createUrl(baseUrl, options) assertEquals(expectedUrl, url.toString()) diff --git a/src/test/kotlin/uk/co/ben_gibson/git/link/url/BitBucketServerTest.kt b/src/test/kotlin/uk/co/ben_gibson/git/link/url/BitBucketServerTest.kt index 6b3293d..116c8f8 100644 --- a/src/test/kotlin/uk/co/ben_gibson/git/link/url/BitBucketServerTest.kt +++ b/src/test/kotlin/uk/co/ben_gibson/git/link/url/BitBucketServerTest.kt @@ -6,9 +6,8 @@ import org.junit.jupiter.params.provider.Arguments import org.junit.jupiter.params.provider.MethodSource import uk.co.ben_gibson.git.link.git.* import uk.co.ben_gibson.git.link.ui.LineSelection +import uk.co.ben_gibson.git.link.url.factory.BitbucketServerUrlFactory import java.util.stream.Stream -import uk.co.ben_gibson.git.link.url.factory.TemplatedUrlFactory -import uk.co.ben_gibson.git.link.url.template.UrlTemplates import uk.co.ben_gibson.url.URL class BitBucketServerTest { @@ -23,6 +22,15 @@ class BitBucketServerTest { @JvmStatic fun urlExpectationsProvider(): Stream = Stream.of( + Arguments.of( + URL.fromString("https://stash.example.com/scm/foo/bar"), + UrlOptions.UrlOptionsFileAtBranch( + FILE, + BRANCH, + LINE_SELECTION + ), + "https://stash.example.com/projects/foo/repos/bar/browse/src/Foo.java?at=refs/heads/master#10-20" + ), Arguments.of( REMOTE_BASE_URL, UrlOptions.UrlOptionsFileAtBranch(FILE, BRANCH, LINE_SELECTION), @@ -72,7 +80,7 @@ class BitBucketServerTest { @ParameterizedTest @MethodSource("urlExpectationsProvider") fun canGenerateUrl(baseUrl: URL, options: UrlOptions, expectedUrl: String) { - val factory = TemplatedUrlFactory(UrlTemplates.bitbucketServer()) + val factory = BitbucketServerUrlFactory() val url = factory.createUrl(baseUrl, options) assertEquals(expectedUrl, url.toString()) From 11a86cc9c96d4d65d4528cfabacbafb4c1c17060 Mon Sep 17 00:00:00 2001 From: Ben Gibson Date: Tue, 3 Sep 2024 08:39:47 +0100 Subject: [PATCH 2/2] Update change log --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ddb1d6f..d3a8e5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Fix warnings and deprecations - Support dynamic reloading +- Fix error using BitBucket cloud host ## 4.5.0 - 2024-09-02