Skip to content

Commit

Permalink
refactor(devops): split changelog modules under code mods #8
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Oct 17, 2023
1 parent 6e21742 commit 150c7d1
Show file tree
Hide file tree
Showing 22 changed files with 109 additions and 93 deletions.
1 change: 1 addition & 0 deletions client/devops-genius/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies {
implementation(libs.archguard.analyser.diffChanges)

implementation(projects.codeModules.codeSplitter)
implementation(projects.codeModules.gitCommitMessage)

implementation(projects.llmModules.sentenceTransformers)
implementation(projects.ragModules.storeElasticsearch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import kotlinx.serialization.json.Json
import org.slf4j.LoggerFactory
import org.changelog.CommitParser
import org.changelog.ParserOptions
import com.charleskorn.kaml.PolymorphismStyle
import com.charleskorn.kaml.Yaml
import com.charleskorn.kaml.YamlConfiguration
import kotlinx.serialization.serializer
import java.io.File
import kotlin.io.path.Path
import kotlin.io.path.exists
Expand Down Expand Up @@ -105,3 +109,33 @@ class CodeReviewCommand : CliktCommand(help = "Code Review with AIGC") {
val logger = LoggerFactory.getLogger(CodeReviewCommand::class.java)
}
}

private fun ParserOptions.Companion.fromString(content: String): ParserOptions? {
return try {
val conf = YamlConfiguration(polymorphismStyle = PolymorphismStyle.Property)
val userOptions = Yaml(configuration = conf).decodeFromString<ParserOptions>(serializer(), content)
// merge default options
defaultOptions().copy(
commentChar = userOptions.commentChar ?: defaultOptions().commentChar,
mergePattern = userOptions.mergePattern ?: defaultOptions().mergePattern,
mergeCorrespondence = userOptions.mergeCorrespondence ?: defaultOptions().mergeCorrespondence,
headerPattern = userOptions.headerPattern ?: defaultOptions().headerPattern,
breakingHeaderPattern = userOptions.breakingHeaderPattern
?: defaultOptions().breakingHeaderPattern,
headerCorrespondence = userOptions.headerCorrespondence ?: defaultOptions().headerCorrespondence,
revertPattern = userOptions.revertPattern ?: defaultOptions().revertPattern,
revertCorrespondence = userOptions.revertCorrespondence ?: defaultOptions().revertCorrespondence,
fieldPattern = userOptions.fieldPattern ?: defaultOptions().fieldPattern,
noteKeywords = userOptions.noteKeywords ?: defaultOptions().noteKeywords,
notesPattern = userOptions.notesPattern ?: defaultOptions().notesPattern,
issuePrefixes = userOptions.issuePrefixes ?: defaultOptions().issuePrefixes,
issuePrefixesCaseSensitive = userOptions.issuePrefixesCaseSensitive
?: defaultOptions().issuePrefixesCaseSensitive,
referenceActions = userOptions.referenceActions ?: defaultOptions().referenceActions,
)

} catch (e: Exception) {
e.printStackTrace()
null
}
}

This file was deleted.

15 changes: 15 additions & 0 deletions code-modules/git-commit-message/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@Suppress("DSL_SCOPE_VIOLATION")
plugins {
java
alias(libs.plugins.jvm)
alias(libs.plugins.serialization)
}

dependencies {
implementation(libs.kotlin.stdlib)
implementation(libs.serialization.json)
implementation(libs.logging.slf4j.api)

testImplementation(libs.bundles.test)
testRuntimeOnly(libs.test.junit.engine)
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.changelog

data class ParserOptions(
val commentChar: String? = null,
val mergePattern: Regex? = null,
val mergeCorrespondence: List<String>? = null,
val headerPattern: Regex? = null,
val breakingHeaderPattern: Regex? = null,
val headerCorrespondence: List<String>? = null,
val revertPattern: Regex? = null,
val revertCorrespondence: List<String>? = null,
val fieldPattern: Regex? = null,
val noteKeywords: List<String>? = null,
val notesPattern: ((String) -> Regex)? = null,
val issuePrefixes: List<String>? = null,
val issuePrefixesCaseSensitive: Boolean? = null,
val referenceActions: List<String>? = null,
) {
companion object {
fun defaultOptions(): ParserOptions {
return ParserOptions(
noteKeywords = listOf("BREAKING CHANGE", "BREAKING-CHANGE"),
issuePrefixes = listOf("#"),
referenceActions = listOf(
"close",
"closes",
"closed",
"fix",
"fixes",
"fixed",
"resolve",
"resolves",
"resolved"
),
headerPattern = Regex("^(\\w*)(?:\\(([\\w$.*\\-*/ ]*)\\))?: (.*)$"),
headerCorrespondence = listOf(
"type",
"scope",
"subject"
),
revertPattern = Regex("^Revert\\s\"([\\s\\S]*)\"\\s*This reverts commit (\\w*)\\."),
revertCorrespondence = listOf("header", "hash"),
fieldPattern = Regex("^-(.*?)-$")
)
}
}
}

//
///**
// * What warn function to use. For example, `console.warn.bind(console)`. By default, it's a noop. If it is `true`, it will error if commit cannot be parsed (strict).
// */
//class ParserStreamOptions(
// warn: Boolean? = null,
// warnFunction: ((String) -> Unit)? = null,
//) : ParserOptions(
//
//)
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ include(":llm-tools:web-tools")

include(":code-modules:code-splitter")
include(":code-modules:git-differ")
include(":code-modules:git-commit-message")

include(":client:devops-genius")

Expand Down

0 comments on commit 150c7d1

Please sign in to comment.