mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[devkit] IJPL-200209 add test which ensures that CONTRIBUTING.md examples of commit messages are valid
Signed-off-by: Dmitry Batkovich <dmitry.batkovich@jetbrains.com> GitOrigin-RevId: 7d9a4771cf587cd65f8fe36c82840397ab1db771
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a38d9e91da
commit
455d4b96a2
+1
-1
@@ -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
|
||||
|
||||
|
||||
@@ -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<String> {
|
||||
val codeBlockRegex = Regex("```(.*?)```", RegexOption.DOT_MATCHES_ALL)
|
||||
val commitMessages = mutableListOf<String>()
|
||||
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user