Skip to content

Commit

Permalink
Contributors as paragraph & fix link to Refaster recipes (#85)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
timtebeek authored Nov 20, 2023
1 parent dcf399b commit 03ab9a3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
36 changes: 21 additions & 15 deletions src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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(
"""
Expand All @@ -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(", "))
)
}
}
}

Expand Down
16 changes: 7 additions & 9 deletions src/main/kotlin/org/openrewrite/RecipeOrigin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 03ab9a3

Please sign in to comment.