Skip to content
This repository has been archived by the owner on Nov 15, 2024. It is now read-only.

Commit

Permalink
added gitlab module
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddenton committed Nov 20, 2023
1 parent 6929425 commit a6f3163
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
This list is not intended to be all-encompassing - it will document major and breaking API
changes with their rationale when appropriate. Given version `A.B.C.D`, breaking changes are to be expected in version number increments where changes in the `A` or `B` sections:

### v5.5.1.0
- **http4k-connect-gitlab** - [New module] Basic adapter module

### v5.5.0.1
- **http4k-connect-amazon-eventbridge** - Support newline characters inside JSON

Expand Down
3 changes: 3 additions & 0 deletions gitlab/client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# GitLab

The GitLab connector currently provides basic action interfaces.
10 changes: 10 additions & 0 deletions gitlab/client/build.gradle.kts
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"))
}
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)
}
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
}

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>>
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())
)
}
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"))))
}
}
1 change: 1 addition & 0 deletions gitlab/fake/src/test/kotlin/PlaceholderForJacoco.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
object PlaceholderForJacoco
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ includeVendorSystem("amazon", "evidently")
includeSystem("example")

includeSystem("github")
includeSystem("gitlab")
includeSystem("mattermost")
includeSystem("openai", "plugin")
includeVendorSystem("kafka", "rest")
Expand Down

0 comments on commit a6f3163

Please sign in to comment.