All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.specmatic.core.utilities.ContractSource.kt Maven / Gradle / Ivy

Go to download

Turn your contracts into executable specifications. Contract Driven Development - Collaboratively Design & Independently Deploy MicroServices & MicroFrontends.

There is a newer version: 2.0.37
Show newest version
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.")
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy