pcimcioch.gitlabci.dsl.job.ArtifactsDsl.kt Maven / Gradle / Ivy
package pcimcioch.gitlabci.dsl.job
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import pcimcioch.gitlabci.dsl.DslBase
import pcimcioch.gitlabci.dsl.Duration
import pcimcioch.gitlabci.dsl.StringRepresentation
import pcimcioch.gitlabci.dsl.serializer.StringRepresentationSerializer
@Serializable
class ArtifactsDsl : DslBase() {
var name: String? = null
@SerialName("expose_as")
var exposeAs: String? = null
var untracked: Boolean? = null
@SerialName("when")
var whenUpload: WhenUploadType? = null
@SerialName("expire_in")
var expireIn: Duration? = null
var paths: MutableSet? = null
var reports: ArtifactsReportsDsl? = null
fun paths(vararg elements: String) = paths(elements.toList())
fun paths(elements: Iterable) = ensurePaths().addAll(elements)
fun reports(block: ArtifactsReportsDsl.() -> Unit) = ensureReports().apply(block)
override fun validate(errors: MutableList) {
addErrors(errors, "[artifacts]", reports)
}
private fun ensureReports() = reports ?: ArtifactsReportsDsl().also { reports = it }
private fun ensurePaths() = paths ?: mutableSetOf().also { paths = it }
companion object {
init {
addSerializer(ArtifactsDsl::class, serializer())
}
}
}
fun createArtifacts(block: ArtifactsDsl.() -> Unit = {}) = ArtifactsDsl().apply(block)
fun createArtifacts(vararg elements: String, block: ArtifactsDsl.() -> Unit = {}) = createArtifacts(elements.toList(), block)
fun createArtifacts(elements: Iterable, block: ArtifactsDsl.() -> Unit = {}) = ArtifactsDsl().apply { paths(elements) }.apply(block)
@Serializable(with = WhenUploadType.WhenUploadTypeSerializer::class)
enum class WhenUploadType(
override val stringRepresentation: String
) : StringRepresentation {
ON_SUCCESS("on_success"),
ON_FAILURE("on_failure"),
ALWAYS("always");
object WhenUploadTypeSerializer : StringRepresentationSerializer("WhenUploadType")
}
@Serializable
class ArtifactsReportsDsl : DslBase() {
var junit: MutableSet? = null
var dotenv: MutableSet? = null
var codequality: MutableSet? = null
var sast: MutableSet? = null
var dependencyScanning: MutableSet? = null
var containerScanning: MutableSet? = null
var dast: MutableSet? = null
var licenseManagement: MutableSet? = null
var licenseScanning: MutableSet? = null
var performance: MutableSet? = null
var metrics: MutableSet? = null
fun junit(vararg elements: String) = junit(elements.toList())
fun junit(elements: Iterable) = ensureJunit().addAll(elements)
fun dotenv(vararg elements: String) = dotenv(elements.toList())
fun dotenv(elements: Iterable) = ensureDotenv().addAll(elements)
fun codequality(vararg elements: String) = codequality(elements.toList())
fun codequality(elements: Iterable) = ensureCodequality().addAll(elements)
fun sast(vararg elements: String) = sast(elements.toList())
fun sast(elements: Iterable) = ensureSast().addAll(elements)
fun dependencyScanning(vararg elements: String) = dependencyScanning(elements.toList())
fun dependencyScanning(elements: Iterable) = ensureDependencyScanning().addAll(elements)
fun containerScanning(vararg elements: String) = containerScanning(elements.toList())
fun containerScanning(elements: Iterable) = ensureContainerScanning().addAll(elements)
fun dast(vararg elements: String) = dast(elements.toList())
fun dast(elements: Iterable) = ensureDast().addAll(elements)
fun licenseManagement(vararg elements: String) = licenseManagement(elements.toList())
fun licenseManagement(elements: Iterable) = ensureLicenseManagement().addAll(elements)
fun licenseScanning(vararg elements: String) = licenseScanning(elements.toList())
fun licenseScanning(elements: Iterable) = ensureLicenseScanning().addAll(elements)
fun performance(vararg elements: String) = performance(elements.toList())
fun performance(elements: Iterable) = ensurePerformance().addAll(elements)
fun metrics(vararg elements: String) = metrics(elements.toList())
fun metrics(elements: Iterable) = ensureMetrics().addAll(elements)
private fun ensureJunit() = junit ?: mutableSetOf().also { junit = it }
private fun ensureDotenv() = dotenv ?: mutableSetOf().also { dotenv = it }
private fun ensureCodequality() = codequality ?: mutableSetOf().also { codequality = it }
private fun ensureSast() = sast ?: mutableSetOf().also { sast = it }
private fun ensureDependencyScanning() = dependencyScanning ?: mutableSetOf().also { dependencyScanning = it }
private fun ensureContainerScanning() = containerScanning ?: mutableSetOf().also { containerScanning = it }
private fun ensureDast() = dast ?: mutableSetOf().also { dast = it }
private fun ensureLicenseManagement() = licenseManagement ?: mutableSetOf().also { licenseManagement = it }
private fun ensureLicenseScanning() = licenseScanning ?: mutableSetOf().also { licenseScanning = it }
private fun ensurePerformance() = performance ?: mutableSetOf().also { performance = it }
private fun ensureMetrics() = metrics ?: mutableSetOf().also { metrics = it }
companion object {
init {
addSerializer(ArtifactsReportsDsl::class, serializer())
}
}
}
fun createArtifactsReports(block: ArtifactsReportsDsl.() -> Unit = {}) = ArtifactsReportsDsl().apply(block)