Skip to content

Commit

Permalink
Adds support to sourcehut (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
Regis David Souza Mesquita authored Dec 2, 2023
1 parent fdd6125 commit 5ecea6e
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ class Gogs : Platform(
setOf(Host("gogs.io"))
)

class Srht : Platform(
UUID.fromString("aa358239-5c11-4b53-8b97-723181c48f4f"),
message("platform.srht.name"),
Icons.SOURCEHUT,
setOf(Host("git.sr.ht"))
)

class Gitea : Platform(
UUID.fromString("e0f86390-1091-4871-8aeb-f534fbc99cf0"),
message("platform.gitea.name"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ private val EXISTING_PLATFORMS = setOf(
Gitee(),
Gitea(),
Gogs(),
Srht(),
Azure(),
Chromium(),
Gerrit()
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/uk/co/ben_gibson/git/link/ui/Icons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ object Icons {
val GITLAB = IconLoader.getIcon("/icons/gitlab.svg", javaClass)
val BITBUCKET = IconLoader.getIcon("/icons/bitbucket.svg", javaClass)
val GOGS = IconLoader.getIcon("/icons/gogs.svg", javaClass)
val SOURCEHUT = IconLoader.getIcon("/icons/sourcehut.svg", javaClass)
val AZURE = IconLoader.getIcon("/icons/azure.svg", javaClass)
val GITEA = IconLoader.getIcon("/icons/gitea.svg", javaClass)
val GIT = IconLoader.getIcon("/icons/git.svg", javaClass)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ val PLATFORM_MAP = mapOf(
Gitee::class.java to UrlTemplates.gitee(),
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 @@ -50,6 +50,15 @@ data class UrlTemplates(val fileAtBranch: String, val fileAtCommit : String, val
)
}

fun srht(): UrlTemplates {
return UrlTemplates(
"{remote:url}/tree/{branch}/item/{file:path}/{file:name}{line-block:start}#L{line:start}{line-block:end}",
"{remote:url}/tree/{commit}/item/{file:path}/{file:name}{line-block:start}#L{line:start}{line-block:end}",
"{remote:url}/tree/{commit}"

)
}

fun gitee() = gitHub()

fun gerrit(): UrlTemplates {
Expand Down
36 changes: 36 additions & 0 deletions src/main/resources/icons/sourcehut.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/main/resources/messages/MyBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ platform.bitbucket.cloud.name=Bitbucket Cloud
platform.bitbucket.server.name=Bitbucket Server
platform.gitea.name=Gitea
platform.gogs.name=Gogs
platform.srht.name=SourceHut
platform.azure.name=Azure
platform.gitee.name=Gitee
platform.chromium.name=Chromium (Experimental)
Expand Down
57 changes: 57 additions & 0 deletions src/test/kotlin/uk/co/ben_gibson/git/link/url/SrhtTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package uk.co.ben_gibson.git.link.url

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.params.ParameterizedTest
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 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 SourceHutTest {

companion object {

private val REMOTE_BASE_URL = URL.fromString("https://git.sr.ht/~myuser/myproject")
private const val BRANCH = "main"
private val COMMIT = Commit("23471005d2d874bb7ab400d45a2360f988c0be33")
private val FILE = File("main.rs", false, "src", false)
private val LINE_SELECTION = LineSelection(1, 2)

@JvmStatic
fun urlExpectationsProvider(): Stream<Arguments> = Stream.of(
Arguments.of(
UrlOptionsFileAtBranch(REMOTE_BASE_URL, 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),
"https://git.sr.ht/~myuser/myproject/tree/main/item/src/main.rs"
),
Arguments.of(
UrlOptionsFileAtCommit(REMOTE_BASE_URL, 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),
"https://git.sr.ht/~myuser/myproject/tree/23471005d2d874bb7ab400d45a2360f988c0be33/item/src/main.rs"
),
Arguments.of(
UrlOptionsCommit(REMOTE_BASE_URL, COMMIT),
"https://git.sr.ht/~myuser/myproject/tree/23471005d2d874bb7ab400d45a2360f988c0be33"
)
)
}

@ParameterizedTest
@MethodSource("urlExpectationsProvider")
fun canGenerateUrl(options: UrlOptions, expectedUrl: String) {
val factory = TemplatedUrlFactory(UrlTemplates.srht())
val url = factory.createUrl(options)

assertEquals(expectedUrl, url.toString())
}
}

0 comments on commit 5ecea6e

Please sign in to comment.