Skip to content

Commit

Permalink
moving interfaces to the domain package
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-ali-55 committed Aug 28, 2023
1 parent 30e2a91 commit 3da1640
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package net.leanix.vsm.gitlab.broker.connector.runner

import net.leanix.vsm.gitlab.broker.connector.application.AssignmentService
import net.leanix.vsm.gitlab.broker.shared.cache.AssignmentsCache
import net.leanix.vsm.gitlab.broker.webhook.application.WebhookService
import net.leanix.vsm.gitlab.broker.webhook.domain.WebhookService
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.boot.ApplicationArguments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ package net.leanix.vsm.gitlab.broker.webhook.adapter.feign

import net.leanix.vsm.gitlab.broker.connector.application.AssignmentService
import net.leanix.vsm.gitlab.broker.webhook.domain.GitlabWebhook
import net.leanix.vsm.gitlab.broker.webhook.domain.WebhookProvider
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Component

interface WebhookProvider {
fun getAllWebhooks(): List<GitlabWebhook>
fun deleteWebhook(webhookId: Int)
fun createWebhook(): GitlabWebhook
}
const val LEANIX_WEBHOOK_PATH = "/leanix-vsm/webhook"

@Component
class GitlabWebhookProvider(
Expand Down Expand Up @@ -45,7 +42,7 @@ class GitlabWebhookProvider(
override fun createWebhook(): GitlabWebhook {
return kotlin.runCatching {
webhookClient.createWebhook(
url = "$gitlabWebhookUrl/webhook",
url = "$gitlabWebhookUrl$LEANIX_WEBHOOK_PATH",
token = leanixId,
receivePushEvents = true,
receiveTagPushEvents = false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.leanix.vsm.gitlab.broker.webhook.application

import net.leanix.vsm.gitlab.broker.webhook.adapter.feign.leanixWebhookPath
import net.leanix.vsm.gitlab.broker.webhook.adapter.feign.LEANIX_WEBHOOK_PATH
import net.leanix.vsm.gitlab.broker.webhook.domain.GitlabWebhook
import net.leanix.vsm.gitlab.broker.webhook.domain.WebhookProvider
import net.leanix.vsm.gitlab.broker.webhook.domain.WebhookService
Expand All @@ -15,7 +15,7 @@ class GitlabWebhookServiceImpl(
val webhook = webhookProvider.createWebhook()

webhookProvider.getAllWebhooks()
.filter { it.url.contains(leanixWebhookPath) && it.id != webhook.id }
.filter { it.url.contains(LEANIX_WEBHOOK_PATH) && it.id != webhook.id }
.forEach { webhookProvider.deleteWebhook(it.id) }

return webhook
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package net.leanix.vsm.gitlab.broker.webhook.domain

class WebhookProvider {
}
interface WebhookProvider {

fun getAllWebhooks(): List<GitlabWebhook>
fun deleteWebhook(webhookId: Int)
fun createWebhook(): GitlabWebhook
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package net.leanix.vsm.gitlab.broker.webhook.domain

class WebhookService {
}
interface WebhookService {
fun registerWebhook(): GitlabWebhook
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package net.leanix.vsm.gitlab.broker.webhook.application

import net.leanix.vsm.gitlab.broker.webhook.adapter.feign.WebhookProvider
import net.leanix.vsm.gitlab.broker.webhook.adapter.feign.LEANIX_WEBHOOK_PATH
import net.leanix.vsm.gitlab.broker.webhook.domain.GitlabWebhook
import net.leanix.vsm.gitlab.broker.webhook.domain.WebhookProvider
import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers.eq
import org.mockito.Mockito.mock
Expand Down Expand Up @@ -34,7 +35,7 @@ class GitlabWebhookServiceImplTest {

fun dummyGitlabWebhookDto(id: Int) = GitlabWebhook(
id = id,
url = "https://gitlab.example.com/hook",
url = "https://gitlab.example.com$LEANIX_WEBHOOK_PATH",
createdAt = Date(),
pushEvents = true,
tagPushEvents = false,
Expand Down

0 comments on commit 3da1640

Please sign in to comment.