Skip to content

Commit

Permalink
Merge pull request #1257 from znsio/triangulate_bcc_commands
Browse files Browse the repository at this point in the history
Triangulate backward compatibility check commands
  • Loading branch information
harikrishnan83 authored Oct 28, 2024
2 parents a815e0c + 444af8d commit b35abe9
Show file tree
Hide file tree
Showing 24 changed files with 787 additions and 115 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package application

import application.BackwardCompatibilityCheckCommand.CompatibilityResult.*
import application.BackwardCompatibilityCheckCommand.CompatibilityResult.FAILED
import application.BackwardCompatibilityCheckCommand.CompatibilityResult.PASSED
import io.specmatic.conversions.OpenApiSpecification
import io.specmatic.core.*
import io.specmatic.core.CONTRACT_EXTENSION
import io.specmatic.core.CONTRACT_EXTENSIONS
import io.specmatic.core.Feature
import io.specmatic.core.WSDL
import io.specmatic.core.git.GitCommand
import io.specmatic.core.git.SystemGit
import io.specmatic.core.log.logger
import io.specmatic.core.testBackwardCompatibility
import io.specmatic.stub.isOpenAPI
import org.springframework.stereotype.Component
import picocli.CommandLine.Command
Expand All @@ -26,7 +31,12 @@ const val TWO_INDENTS = "${ONE_INDENT}${ONE_INDENT}"
@Command(
name = "backwardCompatibilityCheck",
mixinStandardHelpOptions = true,
description = ["Checks backward compatibility of a directory across the current HEAD and the main branch"]
description = [
"""
Checks backward compatibility of a directory across the current HEAD and the main branch.
DEPRECATED: This command will be removed in the next major release. Use 'backward-compatibility-check' command instead.
"""
]
)
class BackwardCompatibilityCheckCommand(
private val gitCommand: GitCommand = SystemGit(),
Expand Down Expand Up @@ -149,7 +159,11 @@ class BackwardCompatibilityCheckCommand(
// newer => the file with changes on the branch
val (newer, unusedExamples) = OpenApiSpecification.fromFile(specFilePath).toFeature().loadExternalisedExamplesAndListUnloadableExamples()

val olderFile = gitCommand.getFileInTheDefaultBranch(specFilePath, treeishWithChanges)
val olderFile = gitCommand.getFileInBranch(
specFilePath,
treeishWithChanges,
gitCommand.defaultBranch()
)
if (olderFile == null) {
println("$specFilePath is a new file.$newLine")
return@mapIndexed PASSED
Expand Down Expand Up @@ -289,7 +303,9 @@ class BackwardCompatibilityCheckCommand(
}

private fun getOpenAPISpecFilesChangedInCurrentBranch(): Set<String> {
return gitCommand.getFilesChangeInCurrentBranch().filter {
return gitCommand.getFilesChangedInCurrentBranch(
gitCommand.defaultBranch()
).filter {
File(it).exists() && File(it).isOpenApiSpec()
}.toSet()
}
Expand Down
7 changes: 6 additions & 1 deletion application/src/main/kotlin/application/CompareCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import kotlin.system.exitProcess

@Command(name = "compare",
mixinStandardHelpOptions = true,
description = ["Checks if two contracts are equivalent"])
description = [
"""
Checks if two contracts are equivalent.
DEPRECATED: This command will be removed in the next major release. Use 'backward-compatibility-check' command instead.
"""
])
class CompareCommand : Callable<Unit> {
@Parameters(index = "0", description = ["Older contract file path"])
lateinit var olderContractFilePath: String
Expand Down
7 changes: 6 additions & 1 deletion application/src/main/kotlin/application/CompatibleCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,12 @@ class GitCompatibleCommand : Callable<Int> {

@Command(name = "compatible",
mixinStandardHelpOptions = true,
description = ["Checks if the newer contract is backward compatible with the older one"],
description = [
"""
Checks if the newer contract is backward compatible with the older one
DEPRECATED: This command will be removed in the next major release. Use 'backward-compatibility-check' command instead.
"""
],
subcommands = [ GitCompatibleCommand::class ])
internal class CompatibleCommand : Callable<Unit> {
override fun call() {
Expand Down
8 changes: 7 additions & 1 deletion application/src/main/kotlin/application/DifferenceCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import kotlin.system.exitProcess

@Command(name = "similar",
mixinStandardHelpOptions = true,
description = ["Show the difference between two contracts"])
description = [
"""
Show the difference between two contracts.
DEPRECATED: This command will be removed in the next major release. Use 'backward-compatibility-check' command instead.
"""
]
)
class DifferenceCommand : Callable<Unit> {
@Parameters(index = "0", description = ["Older contract file path"])
lateinit var olderContractFilePath: String
Expand Down
13 changes: 11 additions & 2 deletions application/src/main/kotlin/application/PushCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ import kotlin.system.exitProcess

private const val pipelineKeyInSpecmaticConfig = "pipeline"

@CommandLine.Command(name = "push", description = ["Check the new contract for backward compatibility with the specified version, then overwrite the old one with it."], mixinStandardHelpOptions = true)
@CommandLine.Command(
name = "push",
description = [
"""
Check the new contract for backward compatibility with the specified version, then overwrite the old one with it.
DEPRECATED: This command will be removed in the next major release. Use 'backward-compatibility-check' command instead.
"""
],
mixinStandardHelpOptions = true
)
class PushCommand: Callable<Unit> {
override fun call() {
val userHome = File(System.getProperty("user.home"))
Expand Down Expand Up @@ -160,4 +169,4 @@ fun registerPipelineCredentials(manifestData: JSONObjectValue, contractPath: Str
sourceGit.add()
}
}
}
}
26 changes: 25 additions & 1 deletion application/src/main/kotlin/application/SpecmaticCommand.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package application

import application.backwardCompatibility.BackwardCompatibilityCheckCommandV2
import org.springframework.stereotype.Component
import picocli.AutoComplete.GenerateCompletion
import picocli.CommandLine.Command
Expand All @@ -10,7 +11,30 @@ import java.util.concurrent.Callable
name = "specmatic",
mixinStandardHelpOptions = true,
versionProvider = VersionProvider::class,
subcommands = [BackwardCompatibilityCheckCommand::class, BundleCommand::class, CompareCommand::class, CompatibleCommand::class, DifferenceCommand::class, GenerateCompletion::class, GraphCommand::class, MergeCommand::class, ToOpenAPICommand::class, ImportCommand::class, InstallCommand::class, ProxyCommand::class, PushCommand::class, ReDeclaredAPICommand::class, ExamplesCommand::class, SamplesCommand::class, StubCommand::class, SubscribeCommand::class, TestCommand::class, ValidateViaLogs::class, CentralContractRepoReportCommand::class]
subcommands = [
BackwardCompatibilityCheckCommandV2::class,
BackwardCompatibilityCheckCommand::class,
BundleCommand::class,
CompareCommand::class,
CompatibleCommand::class,
DifferenceCommand::class,
GenerateCompletion::class,
GraphCommand::class,
MergeCommand::class,
ToOpenAPICommand::class,
ImportCommand::class,
InstallCommand::class,
ProxyCommand::class,
PushCommand::class,
ReDeclaredAPICommand::class,
ExamplesCommand::class,
SamplesCommand::class,
StubCommand::class,
SubscribeCommand::class,
TestCommand::class,
ValidateViaLogs::class,
CentralContractRepoReportCommand::class
]
)
class SpecmaticCommand : Callable<Int> {
override fun call(): Int {
Expand Down
Loading

0 comments on commit b35abe9

Please sign in to comment.