io.specmatic.core.utilities.ContractSource.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of specmatic-core Show documentation
Show all versions of specmatic-core Show documentation
Turn your contracts into executable specifications. Contract Driven Development - Collaboratively Design & Independently Deploy MicroServices & MicroFrontends.
package io.specmatic.core.utilities
import io.specmatic.core.git.NonZeroExitError
import io.specmatic.core.git.SystemGit
import io.specmatic.core.git.exitErrorMessageContains
import java.io.File
sealed interface ContractSource {
val type:String?
val testContracts: List
val stubContracts: List
fun pathDescriptor(path: String): String
fun install(workingDirectory: File)
fun directoryRelativeTo(workingDirectory: File): File
fun getLatest(sourceGit: SystemGit)
fun pushUpdates(sourceGit: SystemGit)
fun loadContracts(selector: ContractsSelectorPredicate, workingDirectory: String, configFilePath: String): List
}
fun commitAndPush(sourceGit: SystemGit) {
val pushRequired = try {
sourceGit.commit()
true
} catch (e: NonZeroExitError) {
if (!exitErrorMessageContains(e, listOf("nothing to commit")))
throw e
exitErrorMessageContains(e, listOf("branch is ahead of"))
}
when {
pushRequired -> {
println("Pushing changes")
sourceGit.push()
}
else -> println("No changes were made to the repo, so nothing was pushed.")
}
}