diff --git a/src/main/kotlin/uk/co/ben_gibson/git/link/pipeline/middleware/GenerateUrl.kt b/src/main/kotlin/uk/co/ben_gibson/git/link/pipeline/middleware/GenerateUrl.kt index 47a8bc9..9941905 100644 --- a/src/main/kotlin/uk/co/ben_gibson/git/link/pipeline/middleware/GenerateUrl.kt +++ b/src/main/kotlin/uk/co/ben_gibson/git/link/pipeline/middleware/GenerateUrl.kt @@ -9,9 +9,6 @@ import uk.co.ben_gibson.git.link.git.* import uk.co.ben_gibson.git.link.pipeline.Pass import uk.co.ben_gibson.git.link.settings.ProjectSettings import uk.co.ben_gibson.git.link.url.UrlOptions -import uk.co.ben_gibson.git.link.url.UrlOptionsCommit -import uk.co.ben_gibson.git.link.url.UrlOptionsFileAtBranch -import uk.co.ben_gibson.git.link.url.UrlOptionsFileAtCommit import uk.co.ben_gibson.git.link.url.factory.UrlFactoryLocator import uk.co.ben_gibson.url.URL @@ -26,12 +23,12 @@ class GenerateUrl : Middleware { val platform = pass.platformOrThrow() - val urlOptions = createUrlOptions(pass, baseUrl, platform.pullRequestWorkflowSupported) + val options = createUrlOptions(pass, platform.pullRequestWorkflowSupported) - return service().locate(platform).createUrl(urlOptions) + return service().locate(platform).createUrl(baseUrl, options) } - private fun createUrlOptions(pass: Pass, baseUrl: URL, pullRequestWorkflowSupported: Boolean): UrlOptions { + private fun createUrlOptions(pass: Pass, pullRequestWorkflowSupported: Boolean): UrlOptions { val remote = pass.remoteOrThrow() val repository = pass.repositoryOrThrow() val context = pass.context @@ -40,16 +37,15 @@ class GenerateUrl : Middleware { val repositoryFile = File.forRepository(context.file, repository) return when (context) { - is ContextFileAtCommit -> UrlOptionsFileAtCommit(baseUrl, repositoryFile, context.commit, context.lineSelection) - is ContextCommit -> UrlOptionsCommit(baseUrl, context.commit) + is ContextFileAtCommit -> UrlOptions.UrlOptionsFileAtCommit(repositoryFile, context.commit, context.lineSelection) + is ContextCommit -> UrlOptions.UrlOptionsCommit(context.commit) is ContextCurrentFile -> { val commit = resolveCommit(repository, remote, settings, pullRequestWorkflowSupported) if (commit != null) { - UrlOptionsFileAtCommit(baseUrl, repositoryFile, commit, context.lineSelection) + UrlOptions.UrlOptionsFileAtCommit(repositoryFile, commit, context.lineSelection) } else { - UrlOptionsFileAtBranch( - baseUrl, + UrlOptions.UrlOptionsFileAtBranch( repositoryFile, resolveBranch(repository, remote, settings), context.lineSelection diff --git a/src/main/kotlin/uk/co/ben_gibson/git/link/ui/validation/ValidationExtensions.kt b/src/main/kotlin/uk/co/ben_gibson/git/link/ui/validation/ValidationExtensions.kt index a467084..859b08f 100644 --- a/src/main/kotlin/uk/co/ben_gibson/git/link/ui/validation/ValidationExtensions.kt +++ b/src/main/kotlin/uk/co/ben_gibson/git/link/ui/validation/ValidationExtensions.kt @@ -61,8 +61,7 @@ fun ValidationInfoBuilder.fileAtCommitTemplate(value: String): ValidationInfo? { return null } - val options = UrlOptionsFileAtCommit( - URL.fromString("https://example.com"), + val options = UrlOptions.UrlOptionsFileAtCommit( File("foo.kt", false, "src/main", false), Commit("734232a3c18f0625843bd161c3f5da272b9d53c1"), LineSelection(10, 20) @@ -76,8 +75,7 @@ fun ValidationInfoBuilder.fileAtBranchTemplate(value: String): ValidationInfo? { return null } - val options = UrlOptionsFileAtBranch( - URL.fromString("https://example.com"), + val options = UrlOptions.UrlOptionsFileAtBranch( File("foo.kt", false, "src/main", false), "master", LineSelection(10, 20) @@ -91,10 +89,7 @@ fun ValidationInfoBuilder.commitTemplate(value: String): ValidationInfo? { return null } - val options = UrlOptionsCommit( - URL.fromString("https://example.com"), - Commit("734232a3c18f0625843bd161c3f5da272b9d53c1") - ) + val options = UrlOptions.UrlOptionsCommit(Commit("734232a3c18f0625843bd161c3f5da272b9d53c1")) return urlTemplate(options, commit = value) } @@ -108,7 +103,7 @@ private fun ValidationInfoBuilder.urlTemplate( val factory = TemplatedUrlFactory(UrlTemplates(fileAtBranch, fileAtCommit, commit)) return try { - factory.createUrl(options) + factory.createUrl(URL.fromString("https://example.com"), options) null } catch (e: Exception) { when(e) { diff --git a/src/main/kotlin/uk/co/ben_gibson/git/link/url/UrlOptions.kt b/src/main/kotlin/uk/co/ben_gibson/git/link/url/UrlOptions.kt index bb16ae1..0bfe72c 100644 --- a/src/main/kotlin/uk/co/ben_gibson/git/link/url/UrlOptions.kt +++ b/src/main/kotlin/uk/co/ben_gibson/git/link/url/UrlOptions.kt @@ -3,33 +3,9 @@ package uk.co.ben_gibson.git.link.url import uk.co.ben_gibson.git.link.git.Commit import uk.co.ben_gibson.git.link.git.File import uk.co.ben_gibson.git.link.ui.LineSelection -import uk.co.ben_gibson.url.URL -sealed class UrlOptions(val baseUrl: URL) - -class UrlOptionsCommit(baseUrl: URL, val commit: Commit) : UrlOptions(baseUrl) - -interface UrlOptionsFileAware { - val baseUrl: URL - val file: File - val ref: String - val lineSelection: LineSelection? -} - -class UrlOptionsFileAtCommit( - baseUrl: URL, - override val file: File, - val commit: Commit, - override val lineSelection: LineSelection? = null -) : UrlOptions(baseUrl), UrlOptionsFileAware { - override val ref: String get() = commit.toString() -} - -class UrlOptionsFileAtBranch( - baseUrl: URL, - override val file: File, - val branch: String, - override val lineSelection: LineSelection? = null -) : UrlOptions(baseUrl), UrlOptionsFileAware { - override val ref: String get() = branch +sealed interface UrlOptions { + class UrlOptionsCommit(val commit: Commit) : UrlOptions + class UrlOptionsFileAtCommit(val file: File, val commit: Commit, val lineSelection: LineSelection? = null) : UrlOptions + class UrlOptionsFileAtBranch(val file: File, val branch: String, val lineSelection: LineSelection? = null) : UrlOptions } \ No newline at end of file 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 e46a58f..1156445 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 @@ -10,8 +10,8 @@ import uk.co.ben_gibson.url.* class AzureUrlFactory: UrlFactory { private val host = Host("dev.azure.com") - override fun createUrl(options: UrlOptions): URL { - val basePathParts = options.baseUrl.path.toString() + override fun createUrl(baseUrl: URL, options: UrlOptions): URL { + val basePathParts = baseUrl.path.toString() .split("/") .toMutableList() @@ -25,13 +25,13 @@ class AzureUrlFactory: UrlFactory { val baseUrl = URL(scheme = Scheme.https(), host = host, path = Path(basePathParts.joinToString("/"))) return when (options) { - is UrlOptionsFileAtBranch -> createUrlToFileAtBranch(baseUrl, options) - is UrlOptionsFileAtCommit -> createUrlToFileAtCommit(baseUrl, options) - is UrlOptionsCommit -> createUrlToCommit(baseUrl, options) + is UrlOptions.UrlOptionsFileAtBranch -> createUrlToFileAtBranch(baseUrl, options) + is UrlOptions.UrlOptionsFileAtCommit -> createUrlToFileAtCommit(baseUrl, options) + is UrlOptions.UrlOptionsCommit -> createUrlToCommit(baseUrl, options) } } - private fun createUrlToFileAtCommit(baseUrl: URL, options: UrlOptionsFileAtCommit) : URL { + private fun createUrlToFileAtCommit(baseUrl: URL, options: UrlOptions.UrlOptionsFileAtCommit) : URL { var queryString = QueryString.fromMap( mapOf( "version" to listOf("GC".plus(options.commit)), @@ -46,7 +46,7 @@ class AzureUrlFactory: UrlFactory { return baseUrl.withQueryString(queryString) } - private fun createUrlToFileAtBranch(baseUrl: URL, options: UrlOptionsFileAtBranch) : URL { + private fun createUrlToFileAtBranch(baseUrl: URL, options: UrlOptions.UrlOptionsFileAtBranch) : URL { var queryString = QueryString.fromMap( mapOf( "version" to listOf("GB".plus(options.branch)), @@ -67,7 +67,7 @@ class AzureUrlFactory: UrlFactory { return file.path.plus("/").plus(fileName) } - private fun createUrlToCommit(baseUrl: URL, options: UrlOptionsCommit): URL { + private fun createUrlToCommit(baseUrl: URL, options: UrlOptions.UrlOptionsCommit): URL { val path = requireNotNull(baseUrl.path) { "Unexpected error: repository path must be present in remote URL" } return baseUrl.withPath(path.with(Path.fromSegments(listOf("commit", options.commit.toString())))) } 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/BitbucketCloudUrlFactory.kt new file mode 100644 index 0000000..bb75fd9 --- /dev/null +++ b/src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/BitbucketCloudUrlFactory.kt @@ -0,0 +1,16 @@ +package uk.co.ben_gibson.git.link.url.factory + +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()) { + override fun createUrl(baseUrl: URL, options: UrlOptions): URL { + return super.createUrl(normaliseBaseUrl(baseUrl), options) + } + + private fun normaliseBaseUrl(baseUrl: URL): URL { + return baseUrl.copy(path = Path(baseUrl.path.toString().removePrefix("scm/"))) + } +} \ No newline at end of file diff --git a/src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/ChromiumUrlFactory.kt b/src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/ChromiumUrlFactory.kt index c672d07..8655cab 100644 --- a/src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/ChromiumUrlFactory.kt +++ b/src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/ChromiumUrlFactory.kt @@ -1,6 +1,7 @@ package uk.co.ben_gibson.git.link.url.factory import com.intellij.openapi.components.Service +import uk.co.ben_gibson.git.link.git.File import uk.co.ben_gibson.git.link.ui.LineSelection import uk.co.ben_gibson.git.link.url.* import uk.co.ben_gibson.url.Host @@ -13,70 +14,71 @@ private const val IDENTIFIER_CHROMIUMOS = "chromiumos" @Service class ChromiumUrlFactory: UrlFactory { - override fun createUrl(options: UrlOptions): URL { - val path = if (options.baseUrl.path.toString().contains(IDENTIFIER_CHROMIUMOS)) - createPathForChromiumos(options) + override fun createUrl(baseUrl: URL, options: UrlOptions): URL { + val path = if (baseUrl.path.toString().contains(IDENTIFIER_CHROMIUMOS)) + createPathForChromiumos(baseUrl, options) else - createPathForChromium(options) + createPathForChromium(baseUrl, options) - return URL(scheme = options.baseUrl.scheme, host = HOST, path = path) + return URL(scheme = baseUrl.scheme, host = HOST, path = path) } - private fun createPathForChromium(options: UrlOptions) : Path { + private fun createPathForChromium(baseUrl: URL, options: UrlOptions) : Path { val path = Path("chromium") - .with(Path(options.baseUrl.path.toString())) + .with(Path(baseUrl.path.toString())) .with(Path("+")) return when (options) { - is UrlOptionsFileAtBranch -> path.with(createChromiumFileSubPath(options)) - is UrlOptionsFileAtCommit -> path.with(createChromiumFileSubPath(options)) - is UrlOptionsCommit -> path.with(Path(options.commit.toString())) + is UrlOptions.UrlOptionsFileAtBranch -> path.with(createChromiumFileSubPath(options.file, options.branch, options.lineSelection)) + is UrlOptions.UrlOptionsFileAtCommit -> path.with(createChromiumFileSubPath(options.file, options.commit.toString(), options.lineSelection)) + is UrlOptions.UrlOptionsCommit -> path.with(Path(options.commit.toString())) } } - private fun createPathForChromiumos(options: UrlOptions) : Path { + private fun createPathForChromiumos(baseUrl: URL, options: UrlOptions) : Path { return when (options) { - is UrlOptionsFileAtBranch -> createChromiumosFileSubPath(options) - is UrlOptionsFileAtCommit -> createChromiumosFileSubPath(options) - is UrlOptionsCommit -> Path("chromiumos/_/chromium/chromiumos") - .withSegments(options.baseUrl.path.toString().split('/').filter{ it.isNotBlank() }.drop(1)) + is UrlOptions.UrlOptionsFileAtBranch -> createChromiumosFileSubPath(baseUrl, options.file, options.branch, options.lineSelection) + is UrlOptions.UrlOptionsFileAtCommit -> createChromiumosFileSubPath(baseUrl, options.file, options.commit.toString(), options.lineSelection) + is UrlOptions.UrlOptionsCommit -> Path("chromiumos/_/chromium/chromiumos") + .withSegments(baseUrl.path.toString().split('/').filter{ it.isNotBlank() }.drop(1)) .with(Path("+")) .with(Path(options.commit.toString())) } } - private fun createChromiumFileSubPath(options: UrlOptionsFileAware): Path { - var path = Path.fromSegments("${options.ref}:".plus(options.file.path.trim('/')).split("/")) + private fun createChromiumFileSubPath(file: File, ref: String, lineSelection: LineSelection?): Path { - if (!options.file.isRoot) { - path = path.withSegment(options.file.name) + var path = Path.fromSegments("${ref}:".plus(file.path.trim('/')).split("/")) + + if (!file.isRoot) { + path = path.withSegment(file.name) } - if (options.file.isDirectory) { + if (file.isDirectory) { return path } - val lineSelection = options.lineSelection ?: return path + lineSelection ?: return path return Path(path.toString() + createLineSelection(lineSelection)) } - private fun createChromiumosFileSubPath(options: UrlOptionsFileAware): Path { + private fun createChromiumosFileSubPath(baseUrl: URL, file: File, ref: String, lineSelection: LineSelection?): Path { var path = Path("chromiumos/chromiumos/codesearch") .with("+") - .with(options.ref.plus(":src")) - .withSegments(options.baseUrl.path.toString().split('/').filter{ it.isNotBlank() }.drop(1)) - .withSegments(options.file.path.split("/").filter { it.isNotBlank() }) + .with(ref.plus(":src")) + .withSegments(baseUrl.path.toString().split('/').filter{ it.isNotBlank() }.drop(1)) + .withSegments(file.path.split("/").filter { it.isNotBlank() }) - if (!options.file.isRoot) { - path = path.withSegment(options.file.name) + if (!file.isRoot) { + path = path.withSegment(file.name) } - if (options.file.isDirectory) { + if (file.isDirectory) { return path } - val lineSelection = options.lineSelection ?: return path + lineSelection ?: return path return Path(path.toString() + createLineSelection(lineSelection)) } diff --git a/src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/TemplatedUrlFactory.kt b/src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/TemplatedUrlFactory.kt index 9d493ec..ac4bbf3 100644 --- a/src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/TemplatedUrlFactory.kt +++ b/src/main/kotlin/uk/co/ben_gibson/git/link/url/factory/TemplatedUrlFactory.kt @@ -9,19 +9,19 @@ import uk.co.ben_gibson.url.URL import java.util.regex.Pattern import com.google.common.net.UrlEscapers -class TemplatedUrlFactory(private val templates: UrlTemplates) : UrlFactory { +open class TemplatedUrlFactory(private val templates: UrlTemplates) : UrlFactory { private val escape = UrlEscapers.urlPathSegmentEscaper().asFunction() private val remotePathPattern = Pattern.compile("\\{remote:url:path:(\\d)}") - override fun createUrl(options: UrlOptions): URL { + override fun createUrl(baseUrl: URL, options: UrlOptions): URL { var processTemplate = when (options) { - is UrlOptionsFileAtCommit -> processTemplate(options) - is UrlOptionsFileAtBranch -> processTemplate(options) - is UrlOptionsCommit -> processTemplate(options) + is UrlOptions.UrlOptionsFileAtCommit -> processTemplate(options) + is UrlOptions.UrlOptionsFileAtBranch -> processTemplate(options) + is UrlOptions.UrlOptionsCommit -> processTemplate(options) } - processTemplate = processBaseUrl(processTemplate, options.baseUrl) + processTemplate = processBaseUrl(processTemplate, baseUrl) processTemplate = removeUnmatchedSubstitutions(processTemplate) processTemplate = processTemplate.replace("(? service() is Azure -> service() + is BitbucketCloud -> service() else -> service().forPlatform(platform) } } 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 c75d897..04aaa50 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 @@ -26,50 +26,58 @@ class AzureTest { @JvmStatic fun urlExpectationsProvider(): Stream = Stream.of( Arguments.of( - UrlOptionsFileAtBranch(REMOTE_BASE_URL_WITH_GIT, FILE, BRANCH, LINE_SELECTION), + REMOTE_BASE_URL_WITH_GIT, + UrlOptions.UrlOptionsFileAtBranch(FILE, BRANCH, LINE_SELECTION), "https://dev.azure.com/ben-gibson/_git/test?version=GBmaster&path=src%2FFoo.java&line=10&lineEnd=21&lineStartColumn=1&lineEndColumn=1" ), Arguments.of( - UrlOptionsFileAtBranch(REMOTE_BASE_URL_WITH_GIT, FILE, BRANCH), + REMOTE_BASE_URL_WITH_GIT, + UrlOptions.UrlOptionsFileAtBranch(FILE, BRANCH), "https://dev.azure.com/ben-gibson/_git/test?version=GBmaster&path=src%2FFoo.java" ), Arguments.of( - UrlOptionsFileAtCommit(REMOTE_BASE_URL_WITH_GIT, FILE, COMMIT, LINE_SELECTION), + REMOTE_BASE_URL_WITH_GIT, + UrlOptions.UrlOptionsFileAtCommit(FILE, COMMIT, LINE_SELECTION), "https://dev.azure.com/ben-gibson/_git/test?version=GCb032a0707beac9a2f24b1b7d97ee4f7156de182c&path=src%2FFoo.java&line=10&lineEnd=21&lineStartColumn=1&lineEndColumn=1" ), Arguments.of( - UrlOptionsFileAtCommit( - REMOTE_BASE_URL_WITH_GIT, + REMOTE_BASE_URL_WITH_GIT, + UrlOptions.UrlOptionsFileAtCommit( File("resources", true, "src/foo", false), COMMIT ), "https://dev.azure.com/ben-gibson/_git/test?version=GCb032a0707beac9a2f24b1b7d97ee4f7156de182c&path=src%2Ffoo%2Fresources" ), Arguments.of( - UrlOptionsFileAtCommit( - REMOTE_BASE_URL_WITH_GIT, + REMOTE_BASE_URL_WITH_GIT, + UrlOptions.UrlOptionsFileAtCommit( File("my-project", true, "", true), COMMIT ), "https://dev.azure.com/ben-gibson/_git/test?version=GCb032a0707beac9a2f24b1b7d97ee4f7156de182c&path=%2F"), Arguments.of( - UrlOptionsFileAtCommit(REMOTE_BASE_URL_WITH_GIT, FILE, COMMIT), + REMOTE_BASE_URL_WITH_GIT, + UrlOptions.UrlOptionsFileAtCommit(FILE, COMMIT), "https://dev.azure.com/ben-gibson/_git/test?version=GCb032a0707beac9a2f24b1b7d97ee4f7156de182c&path=src%2FFoo.java" ), Arguments.of( - UrlOptionsCommit(REMOTE_BASE_URL_WITH_GIT, COMMIT), + REMOTE_BASE_URL_WITH_GIT, + UrlOptions.UrlOptionsCommit(COMMIT), "https://dev.azure.com/ben-gibson/_git/test/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c" ), Arguments.of( - UrlOptionsCommit(REMOTE_BASE_URL_WITHOUT_GIT, COMMIT), + REMOTE_BASE_URL_WITHOUT_GIT, + UrlOptions.UrlOptionsCommit(COMMIT), "https://dev.azure.com/ben-gibson/_git/test/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c" ), Arguments.of( - UrlOptionsCommit(REMOTE_BASE_URL_WITH_COMPANY_AND_GIT, COMMIT), + REMOTE_BASE_URL_WITH_COMPANY_AND_GIT, + UrlOptions.UrlOptionsCommit(COMMIT), "https://dev.azure.com/company/project/_git/test/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c" ), Arguments.of( - UrlOptionsCommit(REMOTE_BASE_URL_WITH_COMPANY_WITHOUT_GIT, COMMIT), + REMOTE_BASE_URL_WITH_COMPANY_WITHOUT_GIT, + UrlOptions.UrlOptionsCommit(COMMIT), "https://dev.azure.com/company/project/_git/test/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c" ) ) @@ -77,9 +85,9 @@ class AzureTest { @ParameterizedTest @MethodSource("urlExpectationsProvider") - fun canGenerateUrl(options: UrlOptions, expectedUrl: String) { + fun canGenerateUrl(baseUrl: URL, options: UrlOptions, expectedUrl: String) { val factory = AzureUrlFactory() - val url = factory.createUrl(options) + val url = factory.createUrl(baseUrl, options) assertEquals(expectedUrl, url.toString()) } 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 aeb9df1..1f804ad 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,6 +8,7 @@ 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 @@ -25,39 +26,53 @@ class BitBucketCloudTest { @JvmStatic fun urlExpectationsProvider(): Stream = Stream.of( Arguments.of( - UrlOptionsFileAtBranch(REMOTE_BASE_URL, FILE, BRANCH, LINE_SELECTION), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtBranch(FILE, BRANCH, LINE_SELECTION), "https://bitbucket.org/foo/bar/src/master/src/Foo.java#lines-10:20" ), Arguments.of( - UrlOptionsFileAtBranch(REMOTE_BASE_URL, FILE, BRANCH), + 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), "https://bitbucket.org/foo/bar/src/master/src/Foo.java" ), Arguments.of( - UrlOptionsFileAtCommit(REMOTE_BASE_URL, FILE, COMMIT, LineSelection(10, 20)), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtCommit(FILE, COMMIT, LineSelection(10, 20)), "https://bitbucket.org/foo/bar/src/b032a0707beac9a2f24b1b7d97ee4f7156de182c/src/Foo.java#lines-10:20" ), Arguments.of( - UrlOptionsFileAtCommit( - REMOTE_BASE_URL, + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtCommit( File("resources", true, "src/foo", false), COMMIT ), "https://bitbucket.org/foo/bar/src/b032a0707beac9a2f24b1b7d97ee4f7156de182c/src/foo/resources" ), Arguments.of( - UrlOptionsFileAtCommit( - REMOTE_BASE_URL, + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtCommit( File("my-project", true, "", true), COMMIT ), "https://bitbucket.org/foo/bar/src/b032a0707beac9a2f24b1b7d97ee4f7156de182c" ), Arguments.of( - UrlOptionsFileAtCommit(REMOTE_BASE_URL, FILE, COMMIT), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtCommit(FILE, COMMIT), "https://bitbucket.org/foo/bar/src/b032a0707beac9a2f24b1b7d97ee4f7156de182c/src/Foo.java" ), Arguments.of( - UrlOptionsCommit(REMOTE_BASE_URL, COMMIT), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsCommit(COMMIT), "https://bitbucket.org/foo/bar/commits/b032a0707beac9a2f24b1b7d97ee4f7156de182c" ) ) @@ -65,9 +80,9 @@ class BitBucketCloudTest { @ParameterizedTest @MethodSource("urlExpectationsProvider") - fun canGenerateUrl(options: UrlOptions, expectedUrl: String) { - val factory = TemplatedUrlFactory(UrlTemplates.bitbucketCloud()) - val url = factory.createUrl(options) + fun canGenerateUrl(baseUrl: URL, options: UrlOptions, expectedUrl: String) { + val factory = BitbucketCloudUrlFactory() + 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 4cc2f26..ba62dd0 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 @@ -24,39 +24,44 @@ class BitBucketServerTest { @JvmStatic fun urlExpectationsProvider(): Stream = Stream.of( Arguments.of( - UrlOptionsFileAtBranch(REMOTE_BASE_URL, FILE, BRANCH, LINE_SELECTION), + REMOTE_BASE_URL, + 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( - UrlOptionsFileAtBranch(REMOTE_BASE_URL, FILE, BRANCH), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtBranch(FILE, BRANCH), "https://stash.example.com/projects/foo/repos/bar/browse/src/Foo.java?at=refs/heads/master" ), Arguments.of( - UrlOptionsFileAtCommit(REMOTE_BASE_URL, FILE, COMMIT, LineSelection(10, 20)), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtCommit(FILE, COMMIT, LineSelection(10, 20)), "https://stash.example.com/projects/foo/repos/bar/browse/src/Foo.java?at=b032a0707beac9a2f24b1b7d97ee4f7156de182c#10-20" ), Arguments.of( - UrlOptionsFileAtCommit( - REMOTE_BASE_URL, + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtCommit( File("resources", true, "src/foo", false), COMMIT ), "https://stash.example.com/projects/foo/repos/bar/browse/src/foo/resources?at=b032a0707beac9a2f24b1b7d97ee4f7156de182c" ), Arguments.of( - UrlOptionsFileAtCommit( - REMOTE_BASE_URL, + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtCommit( File("my-project", true, "", true), COMMIT ), "https://stash.example.com/projects/foo/repos/bar/browse?at=b032a0707beac9a2f24b1b7d97ee4f7156de182c" ), Arguments.of( - UrlOptionsFileAtCommit(REMOTE_BASE_URL, FILE, COMMIT), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtCommit(FILE, COMMIT), "https://stash.example.com/projects/foo/repos/bar/browse/src/Foo.java?at=b032a0707beac9a2f24b1b7d97ee4f7156de182c" ), Arguments.of( - UrlOptionsCommit(REMOTE_BASE_URL, COMMIT), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsCommit(COMMIT), "https://stash.example.com/projects/foo/repos/bar/commits/b032a0707beac9a2f24b1b7d97ee4f7156de182c" ) ) @@ -64,9 +69,9 @@ class BitBucketServerTest { @ParameterizedTest @MethodSource("urlExpectationsProvider") - fun canGenerateUrl(options: UrlOptions, expectedUrl: String) { + fun canGenerateUrl(baseUrl: URL, options: UrlOptions, expectedUrl: String) { val factory = TemplatedUrlFactory(UrlTemplates.bitbucketServer()) - val url = factory.createUrl(options) + val url = factory.createUrl(baseUrl, options) assertEquals(expectedUrl, url.toString()) } diff --git a/src/test/kotlin/uk/co/ben_gibson/git/link/url/ChromiumTest.kt b/src/test/kotlin/uk/co/ben_gibson/git/link/url/ChromiumTest.kt index 3eabdab..03556cb 100644 --- a/src/test/kotlin/uk/co/ben_gibson/git/link/url/ChromiumTest.kt +++ b/src/test/kotlin/uk/co/ben_gibson/git/link/url/ChromiumTest.kt @@ -26,53 +26,63 @@ class ChromiumTest { fun urlExpectationsProvider(): Stream = Stream.of( // Chromiumos file at branch Arguments.of( - UrlOptionsFileAtBranch(REMOTE_BASE_URL_CHROMIUMOS, FILE, BRANCH, LINE_SELECTION), + REMOTE_BASE_URL_CHROMIUMOS, + UrlOptions.UrlOptionsFileAtBranch(FILE, BRANCH, LINE_SELECTION), "https://source.chromium.org/chromiumos/chromiumos/codesearch/+/master:src/platform/ec/board/foo.c;l=10-20" ), Arguments.of( - UrlOptionsFileAtBranch(REMOTE_BASE_URL_CHROMIUMOS, FILE, BRANCH), + REMOTE_BASE_URL_CHROMIUMOS, + UrlOptions.UrlOptionsFileAtBranch(FILE, BRANCH), "https://source.chromium.org/chromiumos/chromiumos/codesearch/+/master:src/platform/ec/board/foo.c" ), // Chromium file at branch Arguments.of( - UrlOptionsFileAtBranch(REMOTE_BASE_URL_CHROMIUM, FILE, BRANCH), + REMOTE_BASE_URL_CHROMIUM, + UrlOptions.UrlOptionsFileAtBranch(FILE, BRANCH), "https://source.chromium.org/chromium/chromium/tools/build/+/master:board/foo.c" ), Arguments.of( - UrlOptionsFileAtBranch(REMOTE_BASE_URL_CHROMIUM, FILE, BRANCH, LINE_SELECTION), + REMOTE_BASE_URL_CHROMIUM, + UrlOptions.UrlOptionsFileAtBranch(FILE, BRANCH, LINE_SELECTION), "https://source.chromium.org/chromium/chromium/tools/build/+/master:board/foo.c;l=10-20" ), // Chromiumos file at commit Arguments.of( - UrlOptionsFileAtCommit(REMOTE_BASE_URL_CHROMIUMOS, FILE, COMMIT, LINE_SELECTION), + REMOTE_BASE_URL_CHROMIUMOS, + UrlOptions.UrlOptionsFileAtCommit(FILE, COMMIT, LINE_SELECTION), "https://source.chromium.org/chromiumos/chromiumos/codesearch/+/b032a0707beac9a2f24b1b7d97ee4f7156de182c:src/platform/ec/board/foo.c;l=10-20" ), Arguments.of( - UrlOptionsFileAtCommit(REMOTE_BASE_URL_CHROMIUMOS, FILE, COMMIT), + REMOTE_BASE_URL_CHROMIUMOS, + UrlOptions.UrlOptionsFileAtCommit(FILE, COMMIT), "https://source.chromium.org/chromiumos/chromiumos/codesearch/+/b032a0707beac9a2f24b1b7d97ee4f7156de182c:src/platform/ec/board/foo.c" ), // Chromium file at commit Arguments.of( - UrlOptionsFileAtCommit(REMOTE_BASE_URL_CHROMIUM, FILE, COMMIT, LINE_SELECTION), + REMOTE_BASE_URL_CHROMIUM, + UrlOptions.UrlOptionsFileAtCommit(FILE, COMMIT, LINE_SELECTION), "https://source.chromium.org/chromium/chromium/tools/build/+/b032a0707beac9a2f24b1b7d97ee4f7156de182c:board/foo.c;l=10-20" ), Arguments.of( - UrlOptionsFileAtCommit(REMOTE_BASE_URL_CHROMIUM, FILE, COMMIT), + REMOTE_BASE_URL_CHROMIUM, + UrlOptions.UrlOptionsFileAtCommit(FILE, COMMIT), "https://source.chromium.org/chromium/chromium/tools/build/+/b032a0707beac9a2f24b1b7d97ee4f7156de182c:board/foo.c" ), // Chromiumos commit Arguments.of( - UrlOptionsCommit(REMOTE_BASE_URL_CHROMIUMOS, COMMIT), + REMOTE_BASE_URL_CHROMIUMOS, + UrlOptions.UrlOptionsCommit(COMMIT), "https://source.chromium.org/chromiumos/_/chromium/chromiumos/platform/ec/+/b032a0707beac9a2f24b1b7d97ee4f7156de182c" ), // Chromium commit Arguments.of( - UrlOptionsCommit(REMOTE_BASE_URL_CHROMIUM, COMMIT), + REMOTE_BASE_URL_CHROMIUM, + UrlOptions.UrlOptionsCommit(COMMIT), "https://source.chromium.org/chromium/chromium/tools/build/+/b032a0707beac9a2f24b1b7d97ee4f7156de182c" ), ) @@ -80,9 +90,9 @@ class ChromiumTest { @ParameterizedTest @MethodSource("urlExpectationsProvider") - fun canGenerateUrl(options: UrlOptions, expectedUrl: String) { + fun canGenerateUrl(baseUrl: URL, options: UrlOptions, expectedUrl: String) { val factory = ChromiumUrlFactory() - val url = factory.createUrl(options) + val url = factory.createUrl(baseUrl, options) assertEquals(expectedUrl, url.toString()) } diff --git a/src/test/kotlin/uk/co/ben_gibson/git/link/url/GerritTest.kt b/src/test/kotlin/uk/co/ben_gibson/git/link/url/GerritTest.kt index c15f7ec..074cd99 100644 --- a/src/test/kotlin/uk/co/ben_gibson/git/link/url/GerritTest.kt +++ b/src/test/kotlin/uk/co/ben_gibson/git/link/url/GerritTest.kt @@ -24,39 +24,44 @@ class GerritTest { @JvmStatic fun urlExpectationsProvider(): Stream = Stream.of( Arguments.of( - UrlOptionsFileAtBranch(REMOTE_BASE_URL, FILE, BRANCH, LINE_SELECTION), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtBranch(FILE, BRANCH, LINE_SELECTION), "https://gerrit.example.com/plugins/gitiles/foo/bar/+/refs/heads/master/src/Foo.java#10" ), Arguments.of( - UrlOptionsFileAtBranch(REMOTE_BASE_URL, FILE, BRANCH), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtBranch(FILE, BRANCH), "https://gerrit.example.com/plugins/gitiles/foo/bar/+/refs/heads/master/src/Foo.java" ), Arguments.of( - UrlOptionsFileAtCommit(REMOTE_BASE_URL, FILE, COMMIT, LineSelection(10, 20)), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtCommit(FILE, COMMIT, LineSelection(10, 20)), "https://gerrit.example.com/plugins/gitiles/foo/bar/+/b032a0707beac9a2f24b1b7d97ee4f7156de182c/src/Foo.java#10" ), Arguments.of( - UrlOptionsFileAtCommit( - REMOTE_BASE_URL, + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtCommit( File("resources", true, "src/foo", false), COMMIT ), "https://gerrit.example.com/plugins/gitiles/foo/bar/+/b032a0707beac9a2f24b1b7d97ee4f7156de182c/src/foo/resources" ), Arguments.of( - UrlOptionsFileAtCommit( - REMOTE_BASE_URL, + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtCommit( File("my-project", true, "", true), COMMIT ), "https://gerrit.example.com/plugins/gitiles/foo/bar/+/b032a0707beac9a2f24b1b7d97ee4f7156de182c" ), Arguments.of( - UrlOptionsFileAtCommit(REMOTE_BASE_URL, FILE, COMMIT), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtCommit(FILE, COMMIT), "https://gerrit.example.com/plugins/gitiles/foo/bar/+/b032a0707beac9a2f24b1b7d97ee4f7156de182c/src/Foo.java" ), Arguments.of( - UrlOptionsCommit(REMOTE_BASE_URL, COMMIT), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsCommit(COMMIT), "https://gerrit.example.com/plugins/gitiles/foo/bar/+/b032a0707beac9a2f24b1b7d97ee4f7156de182c" ) ) @@ -64,9 +69,9 @@ class GerritTest { @ParameterizedTest @MethodSource("urlExpectationsProvider") - fun canGenerateUrl(options: UrlOptions, expectedUrl: String) { + fun canGenerateUrl(baseUrl: URL, options: UrlOptions, expectedUrl: String) { val factory = TemplatedUrlFactory(UrlTemplates.gerrit()) - val url = factory.createUrl(options) + val url = factory.createUrl(baseUrl, options) assertEquals(expectedUrl, url.toString()) } diff --git a/src/test/kotlin/uk/co/ben_gibson/git/link/url/GitHubTest.kt b/src/test/kotlin/uk/co/ben_gibson/git/link/url/GitHubTest.kt index 75a8021..ea3c707 100644 --- a/src/test/kotlin/uk/co/ben_gibson/git/link/url/GitHubTest.kt +++ b/src/test/kotlin/uk/co/ben_gibson/git/link/url/GitHubTest.kt @@ -24,47 +24,52 @@ class GitHubTest { @JvmStatic fun urlExpectationsProvider(): Stream = Stream.of( Arguments.of( - UrlOptionsFileAtBranch(REMOTE_BASE_URL, FILE, BRANCH, LINE_SELECTION), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtBranch(FILE, BRANCH, LINE_SELECTION), "https://github.com/my/repo/blob/master/src/Foo.java#L10-L20" ), Arguments.of( - UrlOptionsFileAtBranch(REMOTE_BASE_URL, FILE, BRANCH, LINE_SELECTION), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtBranch(FILE, BRANCH, LINE_SELECTION), "https://github.com/my/repo/blob/master/src/Foo.java#L10-L20" ), Arguments.of( - UrlOptionsFileAtBranch( - REMOTE_BASE_URL, + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtBranch( File("my-image.png", false, "src/foo bar baz/images", false), BRANCH ), "https://github.com/my/repo/blob/master/src/foo%20bar%20baz/images/my-image.png" ), Arguments.of( - UrlOptionsFileAtCommit(REMOTE_BASE_URL, FILE, COMMIT, LineSelection(10, 20)), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtCommit(FILE, COMMIT, LineSelection(10, 20)), "https://github.com/my/repo/blob/b032a0707beac9a2f24b1b7d97ee4f7156de182c/src/Foo.java#L10-L20" ), Arguments.of( - UrlOptionsFileAtCommit( - REMOTE_BASE_URL, + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtCommit( File("resources", true, "src/foo", false), COMMIT ), "https://github.com/my/repo/tree/b032a0707beac9a2f24b1b7d97ee4f7156de182c/src/foo/resources" ), Arguments.of( - UrlOptionsFileAtCommit( - REMOTE_BASE_URL, + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtCommit( File("my-project", true, "", true), COMMIT ), "https://github.com/my/repo/tree/b032a0707beac9a2f24b1b7d97ee4f7156de182c" ), Arguments.of( - UrlOptionsFileAtCommit(REMOTE_BASE_URL, FILE, COMMIT), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtCommit(FILE, COMMIT), "https://github.com/my/repo/blob/b032a0707beac9a2f24b1b7d97ee4f7156de182c/src/Foo.java" ), Arguments.of( - UrlOptionsCommit(REMOTE_BASE_URL, COMMIT), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsCommit(COMMIT), "https://github.com/my/repo/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c" ) ) @@ -72,10 +77,10 @@ class GitHubTest { @ParameterizedTest @MethodSource("urlExpectationsProvider") - fun canGenerateUrl(options: UrlOptions, expectedUrl: String) { + fun canGenerateUrl(baseUrl: URL, options: UrlOptions, expectedUrl: String) { val factory = TemplatedUrlFactory(UrlTemplates.gitHub()) - val url = factory.createUrl(options) + val url = factory.createUrl(baseUrl, options) assertEquals(expectedUrl, url.toString()) } diff --git a/src/test/kotlin/uk/co/ben_gibson/git/link/url/GitLabTest.kt b/src/test/kotlin/uk/co/ben_gibson/git/link/url/GitLabTest.kt index 3c1f0ae..fa5e4cf 100644 --- a/src/test/kotlin/uk/co/ben_gibson/git/link/url/GitLabTest.kt +++ b/src/test/kotlin/uk/co/ben_gibson/git/link/url/GitLabTest.kt @@ -25,20 +25,23 @@ class GitLabTest { @JvmStatic fun urlExpectationsProvider(): Stream = Stream.of( Arguments.of( - UrlOptionsFileAtBranch(REMOTE_BASE_URL, FILE, BRANCH, LINE_SELECTION), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtBranch(FILE, BRANCH, LINE_SELECTION), "https://gitlab.com/my/repo/blob/master/src/Foo.java#L10-20" ), Arguments.of( - UrlOptionsFileAtBranch(REMOTE_BASE_URL, FILE, BRANCH), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtBranch(FILE, BRANCH), "https://gitlab.com/my/repo/blob/master/src/Foo.java" ), Arguments.of( - UrlOptionsFileAtCommit(REMOTE_BASE_URL, FILE, COMMIT, LineSelection(10, 20)), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtCommit(FILE, COMMIT, LineSelection(10, 20)), "https://gitlab.com/my/repo/blob/b032a0707beac9a2f24b1b7d97ee4f7156de182c/src/Foo.java#L10-20" ), Arguments.of( - UrlOptionsFileAtBranch( - REMOTE_BASE_URL, + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtBranch( File("Code.cs", false, "Assets/#/Sources", false), BRANCH, LINE_SELECTION @@ -46,27 +49,29 @@ class GitLabTest { "https://gitlab.com/my/repo/blob/master/Assets/%23/Sources/Code.cs#L10-20" ), Arguments.of( - UrlOptionsFileAtCommit( - REMOTE_BASE_URL, + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtCommit( File("resources", true, "src/foo", false), COMMIT ), "https://gitlab.com/my/repo/tree/b032a0707beac9a2f24b1b7d97ee4f7156de182c/src/foo/resources" ), Arguments.of( - UrlOptionsFileAtCommit( - REMOTE_BASE_URL, + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtCommit( File("my-project", true, "", true), COMMIT ), "https://gitlab.com/my/repo/tree/b032a0707beac9a2f24b1b7d97ee4f7156de182c" ), Arguments.of( - UrlOptionsFileAtCommit(REMOTE_BASE_URL, FILE, COMMIT), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtCommit(FILE, COMMIT), "https://gitlab.com/my/repo/blob/b032a0707beac9a2f24b1b7d97ee4f7156de182c/src/Foo.java" ), Arguments.of( - UrlOptionsCommit(REMOTE_BASE_URL, COMMIT), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsCommit(COMMIT), "https://gitlab.com/my/repo/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c" ) ) @@ -74,10 +79,10 @@ class GitLabTest { @ParameterizedTest @MethodSource("urlExpectationsProvider") - fun canGenerateUrl(options: UrlOptions, expectedUrl: String) { + fun canGenerateUrl(baseUrl: URL, options: UrlOptions, expectedUrl: String) { val factory = TemplatedUrlFactory(UrlTemplates.gitLab()) - val url = factory.createUrl(options) + val url = factory.createUrl(baseUrl, options) assertEquals(expectedUrl, url.toString()) } diff --git a/src/test/kotlin/uk/co/ben_gibson/git/link/url/GogsTest.kt b/src/test/kotlin/uk/co/ben_gibson/git/link/url/GogsTest.kt index 3b6bc2d..92c1cfb 100644 --- a/src/test/kotlin/uk/co/ben_gibson/git/link/url/GogsTest.kt +++ b/src/test/kotlin/uk/co/ben_gibson/git/link/url/GogsTest.kt @@ -24,38 +24,43 @@ class GogsTest { @JvmStatic fun urlExpectationsProvider(): Stream = Stream.of( Arguments.of( - UrlOptionsFileAtBranch(REMOTE_BASE_URL, FILE, BRANCH, LINE_SELECTION), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtBranch(FILE, BRANCH, LINE_SELECTION), "https://try.gogs.io/foo/bar/src/master/src/Foo.java#L10-L20" ), Arguments.of( - UrlOptionsFileAtBranch(REMOTE_BASE_URL, FILE, BRANCH), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtBranch(FILE, BRANCH), "https://try.gogs.io/foo/bar/src/master/src/Foo.java" ), Arguments.of( - UrlOptionsFileAtCommit(REMOTE_BASE_URL, FILE, COMMIT, LINE_SELECTION), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtCommit(FILE, COMMIT, LINE_SELECTION), "https://try.gogs.io/foo/bar/src/b032a0707beac9a2f24b1b7d97ee4f7156de182c/src/Foo.java#L10-L20" ), Arguments.of( - UrlOptionsFileAtCommit( - REMOTE_BASE_URL, + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtCommit( File("resources", true, "src/foo", false), COMMIT ), "https://try.gogs.io/foo/bar/src/b032a0707beac9a2f24b1b7d97ee4f7156de182c/src/foo/resources" ), Arguments.of( - UrlOptionsFileAtCommit( - REMOTE_BASE_URL, + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtCommit( File("my-project", true, "", true), COMMIT ), "https://try.gogs.io/foo/bar/src/b032a0707beac9a2f24b1b7d97ee4f7156de182c"), Arguments.of( - UrlOptionsFileAtCommit(REMOTE_BASE_URL, FILE, COMMIT), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtCommit(FILE, COMMIT), "https://try.gogs.io/foo/bar/src/b032a0707beac9a2f24b1b7d97ee4f7156de182c/src/Foo.java" ), Arguments.of( - UrlOptionsCommit(REMOTE_BASE_URL, COMMIT), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsCommit(COMMIT), "https://try.gogs.io/foo/bar/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c" ) ) @@ -63,9 +68,9 @@ class GogsTest { @ParameterizedTest @MethodSource("urlExpectationsProvider") - fun canGenerateUrl(options: UrlOptions, expectedUrl: String) { + fun canGenerateUrl(baseUrl: URL, options: UrlOptions, expectedUrl: String) { val factory = TemplatedUrlFactory(UrlTemplates.gogs()) - val url = factory.createUrl(options) + val url = factory.createUrl(baseUrl, options) assertEquals(expectedUrl, url.toString()) } diff --git a/src/test/kotlin/uk/co/ben_gibson/git/link/url/SrhtTest.kt b/src/test/kotlin/uk/co/ben_gibson/git/link/url/SrhtTest.kt index c7894b9..3bdb8f5 100644 --- a/src/test/kotlin/uk/co/ben_gibson/git/link/url/SrhtTest.kt +++ b/src/test/kotlin/uk/co/ben_gibson/git/link/url/SrhtTest.kt @@ -24,23 +24,28 @@ class SourceHutTest { @JvmStatic fun urlExpectationsProvider(): Stream = Stream.of( Arguments.of( - UrlOptionsFileAtBranch(REMOTE_BASE_URL, FILE, BRANCH, LINE_SELECTION), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtBranch(FILE, BRANCH, LINE_SELECTION), "https://git.sr.ht/~myuser/myproject/tree/main/item/src/main.rs#L1" ), Arguments.of( - UrlOptionsFileAtBranch(REMOTE_BASE_URL, FILE, BRANCH), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtBranch(FILE, BRANCH), "https://git.sr.ht/~myuser/myproject/tree/main/item/src/main.rs" ), Arguments.of( - UrlOptionsFileAtCommit(REMOTE_BASE_URL, FILE, COMMIT, LINE_SELECTION), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtCommit(FILE, COMMIT, LINE_SELECTION), "https://git.sr.ht/~myuser/myproject/tree/23471005d2d874bb7ab400d45a2360f988c0be33/item/src/main.rs#L1" ), Arguments.of( - UrlOptionsFileAtCommit(REMOTE_BASE_URL, FILE, COMMIT), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsFileAtCommit(FILE, COMMIT), "https://git.sr.ht/~myuser/myproject/tree/23471005d2d874bb7ab400d45a2360f988c0be33/item/src/main.rs" ), Arguments.of( - UrlOptionsCommit(REMOTE_BASE_URL, COMMIT), + REMOTE_BASE_URL, + UrlOptions.UrlOptionsCommit(COMMIT), "https://git.sr.ht/~myuser/myproject/tree/23471005d2d874bb7ab400d45a2360f988c0be33" ) ) @@ -48,9 +53,9 @@ class SourceHutTest { @ParameterizedTest @MethodSource("urlExpectationsProvider") - fun canGenerateUrl(options: UrlOptions, expectedUrl: String) { + fun canGenerateUrl(baseUrl: URL, options: UrlOptions, expectedUrl: String) { val factory = TemplatedUrlFactory(UrlTemplates.srht()) - val url = factory.createUrl(options) + val url = factory.createUrl(baseUrl, options) assertEquals(expectedUrl, url.toString()) }