Skip to content

Commit

Permalink
Remove Recipe suffix when linking to GitHub
Browse files Browse the repository at this point in the history
Fixes #67
  • Loading branch information
timtebeek committed Nov 20, 2023
1 parent 8d07c9a commit 02c6ba4
Showing 1 changed file with 7 additions and 9 deletions.
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 02c6ba4

Please sign in to comment.