From 03ab9a348b63a5def612daf4dfb19c81001866c0 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Mon, 20 Nov 2023 15:33:34 +0100 Subject: [PATCH] Contributors as paragraph & fix link to Refaster recipes (#85) * Write contributors as a paragraph rather than a list Also place the try Moderne just before rather than after. Fixes #70 * Remove Recipe suffix when linking to GitHub Fixes #67 * Do not wrap description in underscores if it multiline Fixes #65 --- .../openrewrite/RecipeMarkdownGenerator.kt | 36 +++++++++++-------- .../kotlin/org/openrewrite/RecipeOrigin.kt | 16 ++++----- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt b/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt index 2626715..4b03679 100644 --- a/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt +++ b/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt @@ -27,6 +27,7 @@ import java.nio.file.StandardOpenOption import java.time.LocalDateTime import java.time.format.DateTimeFormatter import java.util.* +import java.util.stream.Collectors import kotlin.io.path.toPath import kotlin.system.exitProcess @@ -638,7 +639,11 @@ class RecipeMarkdownGenerator : Runnable { @Suppress("SENSELESS_COMPARISON") if (descriptor != null && descriptor.description != null) { appendLine() - appendLine("_${descriptor.description}_") + if (descriptor.description.contains("\n") || descriptor.description.contains("_")){ + appendLine(descriptor.description) + } else { + appendLine("_${descriptor.description}_") + } } appendLine() @@ -1137,20 +1142,6 @@ class RecipeMarkdownGenerator : Runnable { ) } - // Contributors - if (recipeDescriptor.contributors.isNotEmpty()) { - newLine() - writeln("## Contributors") - for (contributors in recipeDescriptor.contributors) { - if (contributors.email.contains("noreply")) { - writeln("* ${contributors.name}") - } else { - writeln("* [${contributors.name}](mailto:${contributors.email})") - } - } - newLine() - } - newLine() writeln( """ @@ -1163,6 +1154,21 @@ class RecipeMarkdownGenerator : Runnable { Please [contact Moderne](https://moderne.io/product) for more information about safely running the recipes on your own codebase in a private SaaS. """.trimIndent() ) + + // Contributors + if (recipeDescriptor.contributors.isNotEmpty()) { + newLine() + writeln("## Contributors") + writeln(recipeDescriptor.contributors.stream() + .map { contributor: Contributor -> + if (contributor.email.contains("noreply")) { + "* " + contributor.name + } else { + "* [" + contributor.name + "](mailto:" + contributor.email + ")" + } + }.collect(Collectors.joining(", ")) + ) + } } } diff --git a/src/main/kotlin/org/openrewrite/RecipeOrigin.kt b/src/main/kotlin/org/openrewrite/RecipeOrigin.kt index 1ca37a0..d3d8b7e 100755 --- a/src/main/kotlin/org/openrewrite/RecipeOrigin.kt +++ b/src/main/kotlin/org/openrewrite/RecipeOrigin.kt @@ -18,24 +18,22 @@ class RecipeOrigin( fun isFromCoreLibrary() = groupId == "org.openrewrite" && coreLibs.contains(artifactId) private fun convertNameToJavaPath(recipeName: String): String = - recipeName.replace('.', '/') + ".java" + recipeName.replace('.', '/').removeSuffix("Recipe") + ".java" fun githubUrl(recipeName: String, source: URI): String { val sourceString = source.toString() - var baseUrl = "" - - if (isFromCoreLibrary()) { - baseUrl = "https://github.com/openrewrite/rewrite/blob/main/$artifactId/src/main" + val baseUrl = if (isFromCoreLibrary()) { + "https://github.com/openrewrite/rewrite/blob/main/$artifactId/src/main" } else { - baseUrl = "https://github.com/openrewrite/$artifactId/blob/main/src/main" + "https://github.com/openrewrite/$artifactId/blob/main/src/main" } // YAML recipes will have a source that ends with META-INF/rewrite/something.yml - if (sourceString.substring(sourceString.length - 3) == "yml") { + return if (sourceString.substring(sourceString.length - 3) == "yml") { val ymlPath = sourceString.substring(source.toString().lastIndexOf("META-INF")) - return "$baseUrl/resources/$ymlPath" + "$baseUrl/resources/$ymlPath" } else { - return baseUrl + "/java/" + convertNameToJavaPath(recipeName) + baseUrl + "/java/" + convertNameToJavaPath(recipeName) } }