pcimcioch.gitlabci.dsl.job.OnlyExceptDsl.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gitlab-ci-kotlin-dsl Show documentation
Show all versions of gitlab-ci-kotlin-dsl Show documentation
Library providing Kotlin DSL to configure GitlabCI file
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")
}