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

org.kiwiproject.changelog.config.external.ExternalChangelogConfig.kt Maven / Gradle / Ivy

There is a newer version: 1.0.3
Show newest version
package org.kiwiproject.changelog.config.external

import com.fasterxml.jackson.annotation.JsonSetter
import com.fasterxml.jackson.annotation.Nulls.AS_EMPTY

// The JsonSetter is needed, otherwise null is the actual value when deserializing if there are no values in the YAML

data class ExternalChangelogConfig(
    @JsonSetter(nulls = AS_EMPTY) val categories: List = listOf(),
) {

    fun labelCategoryMap(): Map {
        return categories
            .flatMap { category -> category.labels.map { label -> LabelToCategory(label, category.name) } }
            .associate { labelToCategory -> labelToCategory.label to labelToCategory.category }
    }

    private data class LabelToCategory(val label: String, val category: String)

    fun categoryEmojiMap(): Map =
        categories.associate { category -> category.name to category.emoji }

    fun categoryOrder(): List = categories.map { it.name }

    fun defaultCategory(): String? {
        val categoryOrNull = categories.firstOrNull { it.isDefault }
        return categoryOrNull?.name
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy