diff options
author | CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> | 2024-10-12 05:39:53 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-11 20:39:53 +0200 |
commit | d763b99107a0a9da4f0a9e59ebe51d4a2704bc0e (patch) | |
tree | 55b90b2538e68d8506d39fdeab4718d2f2086020 /buildSrc | |
parent | d503510e9afd77f55c1c8d76aae298393de1c846 (diff) | |
download | skyhanni-d763b99107a0a9da4f0a9e59ebe51d4a2704bc0e.tar.gz skyhanni-d763b99107a0a9da4f0a9e59ebe51d4a2704bc0e.tar.bz2 skyhanni-d763b99107a0a9da4f0a9e59ebe51d4a2704bc0e.zip |
Backend: Add Changelog Verification (#2692)
Diffstat (limited to 'buildSrc')
-rw-r--r-- | buildSrc/build.gradle.kts | 17 | ||||
-rw-r--r-- | buildSrc/src/main/kotlin/skyhannibuildsystem/ChangelogVerification.kt | 63 |
2 files changed, 80 insertions, 0 deletions
diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 000000000..505f438b9 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,17 @@ +plugins { + `kotlin-dsl` +} + +repositories { + mavenCentral() + maven("https://jitpack.io") { + content { + includeGroupByRegex("com\\.github\\..*") + } + } +} + +dependencies { + implementation("org.jetbrains.kotlin:kotlin-stdlib") + implementation("com.github.SkyHanniStudios:SkyHanniChangelogBuilder:1.0.1") +} diff --git a/buildSrc/src/main/kotlin/skyhannibuildsystem/ChangelogVerification.kt b/buildSrc/src/main/kotlin/skyhannibuildsystem/ChangelogVerification.kt new file mode 100644 index 000000000..422a62cb1 --- /dev/null +++ b/buildSrc/src/main/kotlin/skyhannibuildsystem/ChangelogVerification.kt @@ -0,0 +1,63 @@ +package skyhannibuildsystem + +import at.hannibal2.changelog.SkyHanniChangelogBuilder +import org.gradle.api.DefaultTask +import org.gradle.api.GradleException +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.Internal +import org.gradle.api.tasks.OutputDirectory +import org.gradle.api.tasks.TaskAction +import java.io.File + +abstract class ChangelogVerification : DefaultTask() { + + @get:OutputDirectory + abstract val outputDirectory: DirectoryProperty + + @Input + var prTitle: String = "" + + @Input + var prBody: String = "" + + @get:Internal + val prBodyLines get() = prBody.lines() + + private val prLink = "ignored" + private val templateLocation = "https://github.com/hannibal002/SkyHanni/blob/beta/pull_request_template.md" + + @TaskAction + fun scanChangelog() { + if (prBodyLines.contains("exclude_from_changelog")) { + println("PR is excluded from changelog verification") + return + } + + val (changes, bodyErrors) = SkyHanniChangelogBuilder.findChanges(prBodyLines, prLink) + val titleErrors = SkyHanniChangelogBuilder.findPullRequestNameErrors(prTitle, changes) + + if (bodyErrors.isEmpty() && titleErrors.isEmpty()) { + println("Changelog and title verification successful") + } else { + bodyErrors.forEach { println(it.message) } + titleErrors.forEach { println(it.message) } + + // Export errors so that they can be listed in the PR comment + val errorFile = File(outputDirectory.get().asFile, "changelog_errors.txt") + + errorFile.appendText("I have detected some issues with your pull request:\n\n") + + if (bodyErrors.isNotEmpty()) { + errorFile.appendText("Body issues:\n${bodyErrors.joinToString("\n") { it.formatLine() }}\n\n") + } + if (titleErrors.isNotEmpty()) { + errorFile.appendText("Title issues:\n${titleErrors.joinToString("\n") { it.message }}\n\n") + } + + errorFile.appendText("Please fix these issues. For the correct format, refer to the [pull request template]($templateLocation).") + + throw GradleException("Changelog verification failed") + } + } +} |