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

pcimcioch.gitlabci.dsl.job.OnlyExceptDsl.kt Maven / Gradle / Ivy

There is a newer version: 1.6.0
Show newest version
package pcimcioch.gitlabci.dsl.job

import kotlinx.serialization.Serializable
import pcimcioch.gitlabci.dsl.DslBase
import pcimcioch.gitlabci.dsl.StringRepresentation
import pcimcioch.gitlabci.dsl.serializer.StringRepresentationSerializer

@Serializable
class OnlyExceptDsl : DslBase() {
    var refs: MutableSet? = null
    var changes: MutableSet? = null
    var variables: MutableSet? = null
    var kubernetes: KubernetesState? = null

    fun refs(vararg elements: String) = refs(elements.toList())
    fun refs(elements: Iterable) = ensureRefs().addAll(elements)

    fun variables(vararg elements: String) = variables(elements.toList())
    fun variables(elements: Iterable) = ensureVariables().addAll(elements)

    fun changes(vararg elements: String) = changes(elements.toList())
    fun changes(elements: Iterable) = ensureChanges().addAll(elements)

    fun branches() = refs("branches")
    fun tags() = refs("tags")
    fun api() = refs("api")
    fun external() = refs("external")
    fun pipelines() = refs("pipelines")
    fun pushes() = refs("pushes")
    fun schedules() = refs("schedules")
    fun triggers() = refs("triggers")
    fun web() = refs("web")
    fun mergeRequests() = refs("merge_requests")
    fun externalPullRequests() = refs("external_pull_requests")
    fun chat() = refs("chat")
    fun master() = refs("master")

    private fun ensureRefs() = refs ?: mutableSetOf().also { refs = it }
    private fun ensureVariables() = variables ?: mutableSetOf().also { variables = it }
    private fun ensureChanges() = changes ?: mutableSetOf().also { changes = it }

    companion object {
        init {
            addSerializer(OnlyExceptDsl::class, serializer())
        }
    }
}

fun createOnlyExcept(block: OnlyExceptDsl.() -> Unit = {}) = OnlyExceptDsl().apply(block)
fun createOnlyExcept(vararg elements: String, block: OnlyExceptDsl.() -> Unit = {}) = createOnlyExcept(elements.toList(), block)
fun createOnlyExcept(elements: Iterable, block: OnlyExceptDsl.() -> Unit = {}) = OnlyExceptDsl().apply { elements.forEach { refs(it) } }.apply(block)

@Serializable(with = KubernetesState.KubernetesStateSerializer::class)
enum class KubernetesState(
        override val stringRepresentation: String
) : StringRepresentation {
    ACTIVE("active");

    object KubernetesStateSerializer : StringRepresentationSerializer("KubernetesState")
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy