diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fa829678cd23..402f506db48a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -44,7 +44,7 @@ We strongly recommend following this commit message format: - `docs`, `doc` - `format`, `style` - Example: `[ui] typo “accross” → “across”` + Example: ```[ui] typo “accross” → “across”``` ## Building the IDE diff --git a/plugins/devkit/intellij.devkit.git/test/IntelliJPlatformPrePushHandlerTest.kt b/plugins/devkit/intellij.devkit.git/test/IntelliJPlatformPrePushHandlerTest.kt index 7d8dc097b663..6d24afbdf7c9 100644 --- a/plugins/devkit/intellij.devkit.git/test/IntelliJPlatformPrePushHandlerTest.kt +++ b/plugins/devkit/intellij.devkit.git/test/IntelliJPlatformPrePushHandlerTest.kt @@ -1,6 +1,7 @@ // Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.idea.devkit.commit +import com.intellij.openapi.application.PathManager import org.junit.Test import org.junit.experimental.runners.Enclosed import org.junit.runner.RunWith @@ -8,6 +9,9 @@ import org.junit.runners.Parameterized import org.junit.runners.Parameterized.Parameter import java.nio.file.Path import java.nio.file.Paths +import kotlin.io.path.div +import kotlin.io.path.exists +import kotlin.io.path.readText @RunWith(Enclosed::class) class IntelliJPlatformPrePushHandlerTest { @@ -332,6 +336,44 @@ class IntelliJPlatformPrePushHandlerTest { } } } + + class ContributingMdCommitMessagesAreValid { + @Test + fun testCommitMessagesFromContributingMd() { + val contributingFile = Path.of(PathManager.getCommunityHomePath()) / "CONTRIBUTING.md" + assert(contributingFile.exists()) { "CONTRIBUTING.md file not found at expected location" } + + val content = contributingFile.readText() + val commitMessages = extractCommitMessagesFromMarkdown(content) + + assert(commitMessages.isNotEmpty()) { "No commit messages found in CONTRIBUTING.md" } + + commitMessages.forEach { commitMessage -> + assert(prePushHandler.isCommitMessageCorrect(commitMessage)) { + "Commit message from CONTRIBUTING.md is invalid: '$commitMessage'" + } + } + } + + private fun extractCommitMessagesFromMarkdown(content: String): List { + val codeBlockRegex = Regex("```(.*?)```", RegexOption.DOT_MATCHES_ALL) + val commitMessages = mutableListOf() + + codeBlockRegex.findAll(content).forEach { match -> + val codeBlock = match.groupValues[1].trim() + + if (codeBlock.contains("[<") && codeBlock.contains(">]")) { + return@forEach + } + + if (codeBlock.isNotEmpty()) { + commitMessages.add(codeBlock) + } + } + + return commitMessages + } + } } private val prePushHandler = IntelliJPlatformPrePushHandler()