Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple Azure Devops from git-plugin and prepare for other Git providers #30

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3606479
Introduce a provider package and move Azure code there
MartinKanters Jun 20, 2023
3ca9229
Implemented an interface as GitProvider and ensured Azure is not call…
MartinKanters Jun 20, 2023
78c3bfc
Made URL Factory part of the GitProvider
MartinKanters Jun 20, 2023
1de89fc
Made command tests independent of Azure Devops
MartinKanters Jun 20, 2023
aa39625
Removed azure devops from test method names
MartinKanters Jun 20, 2023
06552f1
Removed dependency on plugin config in command
MartinKanters Jun 20, 2023
0a262a9
Removed unused configurations
MartinKanters Jun 20, 2023
aba7ab6
Removed unused configurations - fixed tests
MartinKanters Jun 20, 2023
0530946
Moved the pluginConfiguration to azure package and renamed it
MartinKanters Jun 20, 2023
4a347dd
Removed generic DTO for the creation of a pull request
MartinKanters Jun 20, 2023
70e5501
Fixed typo in package name
MartinKanters Jun 20, 2023
4b6adbc
Tested the specifics in the Azure Devops Provider
MartinKanters Jun 20, 2023
a28cfbb
Used named imports to make the code clearer
MartinKanters Jun 20, 2023
6df9441
Let the GitUrlFactory return URLs instead of Strings
MartinKanters Jul 12, 2023
43243f7
Removed duplicate function for resolving the URL for the pull request
MartinKanters Jul 12, 2023
85ecc12
Removed unnecessary create prefix and url suffix in the gitUrlFactory
MartinKanters Jul 12, 2023
09f94a8
Fixed code smell by making the GitDomainConvertible a functional inte…
MartinKanters Jul 12, 2023
f6a7d33
Removed AzDo specific code in generic Git Domain (class Branch)
MartinKanters Jul 12, 2023
6029bec
Removed AzDo specific code in generic Git Domain (class Pipeline)
MartinKanters Jul 12, 2023
6602913
Updated Kotlin and RET-plugin version and making use of the new Brows…
MartinKanters Jul 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Made command tests independent of Azure Devops
  • Loading branch information
MartinKanters committed Jul 25, 2023
commit 1de89fc5e2b053152ecb7b6be73f9eac83df76e6
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.rabobank.ret.git.plugin.config.PluginConfig
import io.rabobank.ret.git.plugin.provider.GitProvider
import io.rabobank.ret.git.plugin.provider.GitUrlFactory
import io.rabobank.ret.git.plugin.provider.Pipeline
import io.rabobank.ret.git.plugin.provider.azure.AzureDevopsUrlFactory
import io.rabobank.ret.git.plugin.utitilies.TestUrlFactory
import io.rabobank.ret.util.BrowserUtils
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
Expand All @@ -27,7 +27,7 @@ internal class PipelineCommandTest {

@BeforeEach
fun before() {
gitUrlFactory = AzureDevopsUrlFactory(pluginConfigMock, "https://dev.azure.com/my-organization")
gitUrlFactory = TestUrlFactory("https://test.git")
val command = PipelineCommand(browserUtilsMock, gitProviderMock)

commandLine = CommandLine(command)
Expand All @@ -39,7 +39,7 @@ internal class PipelineCommandTest {

@Test
fun `should open browser for the pipeline dashboard`() {
val expectedPipelineRunURL = "https://dev.azure.com/my-organization/org/proj/_build"
val expectedPipelineRunURL = "https://test.git/pipeline"

commandLine.execute("open")

Expand All @@ -49,7 +49,7 @@ internal class PipelineCommandTest {
@Test
fun `should open browser for correct pipeline`() {
val pipelineId = "123"
val expectedPipelineRunURL = "https://dev.azure.com/my-organization/org/proj/_build?definitionId=$pipelineId"
val expectedPipelineRunURL = "https://test.git/pipeline/$pipelineId"

commandLine.execute("open", pipelineId)

Expand All @@ -59,7 +59,7 @@ internal class PipelineCommandTest {
@Test
fun `should open browser for correct pipeline by folder and name`() {
val pipelineId = "folder\\pipeline_name"
val expectedPipelineRunURL = "https://dev.azure.com/my-organization/org/proj/_build?definitionId=123"
val expectedPipelineRunURL = "https://test.git/pipeline/123"
whenever(gitProviderMock.getAllPipelines()).thenReturn(
listOf(
Pipeline(123, "pipeline_name", "\\folder"),
Expand Down Expand Up @@ -92,7 +92,7 @@ internal class PipelineCommandTest {
val pipelineId = "not_used"
val pipelineRunId = "123456"
val expectedPipelineRunURL =
"https://dev.azure.com/my-organization/org/proj/_build/results?buildId=$pipelineRunId"
"https://test.git/pipeline/run/$pipelineRunId"

commandLine.execute("open", pipelineId, pipelineRunId)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import io.rabobank.ret.configuration.Configurable
import io.rabobank.ret.configuration.RetConfig
import io.rabobank.ret.git.plugin.command.PullRequestCreateCommand
import io.rabobank.ret.git.plugin.config.ExceptionMessageHandler
import io.rabobank.ret.git.plugin.config.PluginConfig
import io.rabobank.ret.git.plugin.output.OutputHandler
import io.rabobank.ret.git.plugin.provider.GitProvider
import io.rabobank.ret.git.plugin.provider.CreatePullRequest
import io.rabobank.ret.git.plugin.provider.PullRequestCreated
import io.rabobank.ret.git.plugin.provider.Repository
import io.rabobank.ret.git.plugin.provider.azure.AzureDevopsUrlFactory
import io.rabobank.ret.git.plugin.utitilies.TestUrlFactory
import io.rabobank.ret.picocli.mixin.ContextAwareness
import io.rabobank.ret.util.BrowserUtils
import io.rabobank.ret.util.OsUtils
Expand All @@ -33,7 +32,7 @@ import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import picocli.CommandLine

private const val AZURE_DEVOPS_BASE_URL = "azdo.com"
private const val BASE_URL = "https://test.git"

@QuarkusTest
internal class PullRequestCreateCommandTest {
Expand Down Expand Up @@ -64,7 +63,7 @@ internal class PullRequestCreateCommandTest {

commandLine = spy(CommandLine(command))
commandLine.executionExceptionHandler = ExceptionMessageHandler(outputHandler)
whenever(gitProvider.urlFactory).thenReturn(AzureDevopsUrlFactory(PluginConfig(retConfig), "azdo.com"))
whenever(gitProvider.urlFactory).thenReturn(TestUrlFactory("https://test.git"))
}

@Test
Expand All @@ -78,7 +77,7 @@ internal class PullRequestCreateCommandTest {
assertThat(exitCode).isEqualTo(0)

val expectedURL =
"$AZURE_DEVOPS_BASE_URL/organization/projectId/_git/$repo/pullrequestcreate?sourceRef=feature%2Fmy-branch"
"$BASE_URL/pullrequest/create/$repo/feature/my-branch"

verify(mockedBrowserUtils).openUrl(expectedURL)
}
Expand All @@ -92,7 +91,7 @@ internal class PullRequestCreateCommandTest {
assertThat(exitCode).isEqualTo(0)

val expectedURL =
"$AZURE_DEVOPS_BASE_URL/organization/projectId/_git/$repo/pullrequestcreate?sourceRef=feature%2Fmy-branch"
"$BASE_URL/pullrequest/create/$repo/feature/my-branch"

verify(mockedBrowserUtils).openUrl(expectedURL)
}
Expand All @@ -105,7 +104,7 @@ internal class PullRequestCreateCommandTest {
val exitCode = commandLine.execute(flag, repo)
assertThat(exitCode).isEqualTo(0)

val expectedURL = "$AZURE_DEVOPS_BASE_URL/organization/projectId/_git/$repo/pullrequestcreate"
val expectedURL = "$BASE_URL/pullrequest/create/$repo/"

verify(mockedBrowserUtils).openUrl(expectedURL)
}
Expand All @@ -122,7 +121,7 @@ internal class PullRequestCreateCommandTest {
val exitCode = commandLine.execute(flag, repo)
assertThat(exitCode).isEqualTo(0)

val expectedURL = "$AZURE_DEVOPS_BASE_URL/organization/projectId/_git/$repo/pullrequestcreate"
val expectedURL = "$BASE_URL/pullrequest/create/$repo/"

verify(mockedBrowserUtils).openUrl(expectedURL)
}
Expand All @@ -137,7 +136,7 @@ internal class PullRequestCreateCommandTest {
assertThat(exitCode).isEqualTo(0)

val expectedURL =
"$AZURE_DEVOPS_BASE_URL/organization/projectId/_git/$repo/pullrequestcreate?sourceRef=feature%2Fmy-branch"
"$BASE_URL/pullrequest/create/$repo/feature/my-branch"

verify(mockedBrowserUtils).openUrl(expectedURL)
}
Expand Down Expand Up @@ -176,7 +175,7 @@ internal class PullRequestCreateCommandTest {
val exitCode = commandLine.execute("-r", repo, "--no-prompt", branch)
assertThat(exitCode).isEqualTo(0)
verify(outputHandler)
.println("$AZURE_DEVOPS_BASE_URL/organization/projectId/_git/$repo/pullrequest/$createdPullRequestId")
.println("$BASE_URL/pullrequest/$repo/$createdPullRequestId")
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import io.quarkus.test.junit.QuarkusTest
import io.rabobank.ret.configuration.Configurable
import io.rabobank.ret.configuration.RetConfig
import io.rabobank.ret.git.plugin.command.PullRequestOpenCommand
import io.rabobank.ret.git.plugin.config.PluginConfig
import io.rabobank.ret.git.plugin.output.OutputHandler
import io.rabobank.ret.git.plugin.provider.GitProvider
import io.rabobank.ret.git.plugin.provider.PullRequest
import io.rabobank.ret.git.plugin.provider.Repository
import io.rabobank.ret.git.plugin.provider.Reviewer
import io.rabobank.ret.git.plugin.provider.azure.AzureDevopsUrlFactory
import io.rabobank.ret.git.plugin.utitilies.TestUrlFactory
import io.rabobank.ret.picocli.mixin.ContextAwareness
import io.rabobank.ret.util.BrowserUtils
import io.rabobank.ret.util.OsUtils
Expand All @@ -25,7 +24,7 @@ import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import picocli.CommandLine

private const val AZURE_DEVOPS_BASE_URL = "azdo.com"
private const val BASE_URL = "https://test.git"

@QuarkusTest
internal class PullRequestOpenCommandTest {
Expand Down Expand Up @@ -54,7 +53,7 @@ internal class PullRequestOpenCommandTest {

commandLine = spy(CommandLine(command))

whenever(mockedGitProvider.urlFactory).thenReturn(AzureDevopsUrlFactory(PluginConfig(retConfig), "azdo.com"))
whenever(mockedGitProvider.urlFactory).thenReturn(TestUrlFactory("https://test.git"))
}

@Test
Expand All @@ -70,7 +69,7 @@ internal class PullRequestOpenCommandTest {

val exitCode = commandLine.execute("1234")
assertThat(exitCode).isEqualTo(0)
val expectedURL = "$AZURE_DEVOPS_BASE_URL/organization/projectId/_git/repo/pullrequest/1234"
val expectedURL = "$BASE_URL/pullrequest/repo/1234"

verify(mockedBrowserUtils).openUrl(expectedURL)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import io.rabobank.ret.configuration.Configurable
import io.rabobank.ret.configuration.RetConfig
import io.rabobank.ret.git.plugin.command.RepositoryCommand
import io.rabobank.ret.git.plugin.config.ExceptionMessageHandler
import io.rabobank.ret.git.plugin.config.PluginConfig
import io.rabobank.ret.git.plugin.output.OutputHandler
import io.rabobank.ret.git.plugin.provider.GitProvider
import io.rabobank.ret.git.plugin.provider.Repository
import io.rabobank.ret.git.plugin.provider.azure.AzureDevopsUrlFactory
import io.rabobank.ret.git.plugin.utitilies.TestUrlFactory
import io.rabobank.ret.picocli.mixin.ContextAwareness
import io.rabobank.ret.util.BrowserUtils
import io.rabobank.ret.util.OsUtils
Expand Down Expand Up @@ -69,7 +68,7 @@ internal class RepositoryCommandTest {
Repository("generic-project", "refs/heads/master"),
),
)
whenever(mockedGitProvider.urlFactory).thenReturn(AzureDevopsUrlFactory(PluginConfig(retConfig), "https://dev.azure.com"))
whenever(mockedGitProvider.urlFactory).thenReturn(TestUrlFactory("https://test.git"))
}

@AfterEach
Expand All @@ -83,7 +82,7 @@ internal class RepositoryCommandTest {
val exitCode = commandLine.execute("open", repository)
assertThat(exitCode).isEqualTo(0)

val repoUrl = "https://dev.azure.com/organization/projectId/_git/$repository"
val repoUrl = "https://test.git/repository/$repository"

verify(mockedBrowserUtils).openUrl(repoUrl)
}
Expand All @@ -96,7 +95,7 @@ internal class RepositoryCommandTest {
val exitCode = commandLine.execute("open")
assertThat(exitCode).isEqualTo(0)

val repoUrl = "https://dev.azure.com/organization/projectId/_git/$repository"
val repoUrl = "https://test.git/repository/$repository"

verify(mockedBrowserUtils).openUrl(repoUrl)
}
Expand All @@ -109,7 +108,7 @@ internal class RepositoryCommandTest {
val exitCode = commandLine.execute("open", repository)
assertThat(exitCode).isEqualTo(0)

val repoUrl = "https://dev.azure.com/organization/projectId/_git/$repository"
val repoUrl = "https://test.git/repository/$repository"

verify(mockedBrowserUtils).openUrl(repoUrl)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.rabobank.ret.git.plugin.utitilies

import io.rabobank.ret.git.plugin.provider.GitUrlFactory

class TestUrlFactory(private val domain: String) : GitUrlFactory {
override fun createRepositoryUrl(repositoryName: String) = "$domain/repository/$repositoryName"
override fun createPipelineRunUrl(pipelineRunId: String) = "$domain/pipeline/run/$pipelineRunId"
override fun createPipelineUrl(pipelineId: String) = "$domain/pipeline/$pipelineId"
override fun createPipelineDashboardUrl() = "$domain/pipeline"
override fun createPullRequestUrl(repositoryName: String, pullRequestId: String) = "$domain/pullrequest/$repositoryName/$pullRequestId"
override fun createPullRequestCreateUrl(repositoryName: String, sourceRef: String?) = "$domain/pullrequest/create/$repositoryName/" + (sourceRef ?: "")
override fun pullRequestUrl(repositoryName: String, pullRequestId: String) = "$domain/pullrequest/$repositoryName/$pullRequestId"
}