This repository has been archived by the owner on Nov 15, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6929425
commit a6f3163
Showing
10 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# GitLab | ||
|
||
The GitLab connector currently provides basic action interfaces. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
dependencies { | ||
api(Libs.http4k_cloudnative) | ||
api(Libs.http4k_format_moshi) { | ||
exclude("org.jetbrains.kotlin", "kotlin-reflect") | ||
} | ||
implementation(Libs.api) | ||
|
||
testApi(Libs.http4k_format_moshi) | ||
testImplementation(project(path = ":http4k-connect-core", configuration = "testArtifacts")) | ||
} |
8 changes: 8 additions & 0 deletions
8
gitlab/client/src/main/kotlin/org/http4k/connect/gitlab/GitLabToken.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.http4k.connect.gitlab | ||
|
||
import dev.forkhandles.values.NonBlankStringValueFactory | ||
import dev.forkhandles.values.StringValue | ||
|
||
class GitLabToken private constructor(value: String) : StringValue(value) { | ||
companion object : NonBlankStringValueFactory<GitLabToken>(::GitLabToken) | ||
} |
13 changes: 13 additions & 0 deletions
13
gitlab/client/src/main/kotlin/org/http4k/connect/gitlab/api/GitLab.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.http4k.connect.gitlab.api | ||
|
||
import dev.forkhandles.result4k.Result | ||
import org.http4k.connect.Http4kConnectAdapter | ||
import org.http4k.connect.RemoteFailure | ||
|
||
@Http4kConnectAdapter | ||
interface GitLab { | ||
operator fun <R> invoke(action: GitLabAction<R>): Result<R, RemoteFailure> | ||
|
||
companion object | ||
} | ||
|
7 changes: 7 additions & 0 deletions
7
gitlab/client/src/main/kotlin/org/http4k/connect/gitlab/api/GitLabAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.http4k.connect.gitlab.api | ||
|
||
import dev.forkhandles.result4k.Result | ||
import org.http4k.connect.Action | ||
import org.http4k.connect.RemoteFailure | ||
|
||
interface GitLabAction<R> : Action<Result<R, RemoteFailure>> |
18 changes: 18 additions & 0 deletions
18
gitlab/client/src/main/kotlin/org/http4k/connect/gitlab/api/HttpGitLab.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.http4k.connect.gitlab.api | ||
|
||
import org.http4k.client.JavaHttpClient | ||
import org.http4k.connect.gitlab.GitLabToken | ||
import org.http4k.core.HttpHandler | ||
import org.http4k.core.Uri | ||
import org.http4k.core.then | ||
import org.http4k.filter.ClientFilters.BearerAuth | ||
import org.http4k.filter.ClientFilters.SetBaseUriFrom | ||
|
||
fun GitLab.Companion.Http(token: () -> GitLabToken, http: HttpHandler = JavaHttpClient()) = | ||
object : GitLab { | ||
private val routedHttp = SetBaseUriFrom(Uri.of("https://gitlab.com")).then(http) | ||
|
||
override fun <R> invoke(action: GitLabAction<R>) = action.toResult( | ||
BearerAuth(token().value).then(routedHttp)(action.toRequest()) | ||
) | ||
} |
33 changes: 33 additions & 0 deletions
33
gitlab/client/src/test/kotlin/org/http4k/connect/gitlab/GitLabContract.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.http4k.connect.gitlab | ||
|
||
import com.natpryce.hamkrest.assertion.assertThat | ||
import com.natpryce.hamkrest.equalTo | ||
import dev.forkhandles.result4k.Result4k | ||
import dev.forkhandles.result4k.Success | ||
import org.http4k.connect.RemoteFailure | ||
import org.http4k.connect.gitlab.api.GitLab | ||
import org.http4k.connect.gitlab.api.GitLabAction | ||
import org.http4k.connect.gitlab.api.Http | ||
import org.http4k.core.Method.POST | ||
import org.http4k.core.Request | ||
import org.http4k.core.Response | ||
import org.http4k.core.Status.Companion.OK | ||
import org.http4k.format.Moshi | ||
import org.junit.jupiter.api.Test | ||
|
||
class TestAction : GitLabAction<Map<String, String>> { | ||
override fun toRequest(): Request = Request(POST, "") | ||
override fun toResult(response: Response): Result4k<Map<String, String>, RemoteFailure> = | ||
Success(Moshi.asA<Map<String, String>>(response.bodyString())) | ||
} | ||
|
||
class GitLabContract { | ||
private val gitLab = GitLab.Http( | ||
{ GitLabToken.of("token") }, { Response(OK).body("""{"hello":"world"}""") } | ||
) | ||
|
||
@Test | ||
fun `test action`() { | ||
assertThat(gitLab(TestAction()), equalTo(Success(mapOf("hello" to "world")))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
object PlaceholderForJacoco |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters