Skip to content

Commit

Permalink
Fix Bitbucket cloud host (#342)
Browse files Browse the repository at this point in the history
* Fix Bitbucket cloud host

* Update change log
  • Loading branch information
ben-gibson authored Sep 3, 2024
1 parent f82ccf9 commit 2cc706a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Fix warnings and deprecations
- Support dynamic reloading
- Fix error using BitBucket cloud host

## 4.5.0 - 2024-09-02

Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@ 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 {
fun locate(platform: Platform) : UrlFactory {
return when(platform) {
is Chromium -> service<ChromiumUrlFactory>()
is Azure -> service<AzureUrlFactory>()
is BitbucketCloud -> service<BitbucketCloudUrlFactory>()
is BitbucketServer -> service<BitbucketServerUrlFactory>()
else -> service<TemplatedUrlFactoryProvider>().forPlatform(platform)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -23,6 +22,15 @@ class BitBucketServerTest {

@JvmStatic
fun urlExpectationsProvider(): Stream<Arguments> = 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),
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 2cc706a

Please sign in to comment.