-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #223 from jonesbusy/feature/pr-template
Add PR template using JTE
- Loading branch information
Showing
10 changed files
with
180 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...rnizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/utils/TemplateUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package io.jenkins.tools.pluginmodernizer.core.utils; | ||
|
||
import gg.jte.ContentType; | ||
import gg.jte.TemplateEngine; | ||
import gg.jte.TemplateOutput; | ||
import gg.jte.output.StringOutput; | ||
import io.jenkins.tools.pluginmodernizer.core.model.ModernizerException; | ||
import io.jenkins.tools.pluginmodernizer.core.model.Plugin; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.openrewrite.Recipe; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Utility class to render JTE templates | ||
*/ | ||
public class TemplateUtils { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(TemplateUtils.class); | ||
|
||
/** | ||
* Hidden constructor | ||
*/ | ||
private TemplateUtils() {} | ||
|
||
/** | ||
* Render the pull request body | ||
* @param plugin Plugin to modernize | ||
* @param recipes List of recipes to apply | ||
* @return The rendered pull request body | ||
*/ | ||
public static String renderPullRequestBody(Plugin plugin, List<Recipe> recipes) { | ||
return renderTemplate("pr-body.jte", Map.of("plugin", plugin, "recipes", recipes)); | ||
} | ||
|
||
/** | ||
* Render the commit message | ||
* @param plugin Plugin to modernize | ||
* @param recipes List of recipes to apply | ||
* @return The rendered commit message | ||
*/ | ||
public static String renderCommitMessage(Plugin plugin, List<Recipe> recipes) { | ||
return renderTemplate("commit.jte", Map.of("plugin", plugin, "recipes", recipes)); | ||
} | ||
|
||
/** | ||
* Render the pull request title | ||
* @param plugin Plugin to modernize | ||
* @param recipes List of recipes to apply | ||
* @return The rendered pull request title | ||
*/ | ||
public static String renderPullRequestTitle(Plugin plugin, List<Recipe> recipes) { | ||
return renderTemplate("pr-title.jte", Map.of("plugin", plugin, "recipes", recipes)); | ||
} | ||
|
||
/** | ||
* Render a generic template | ||
* @param templateName Name of the template | ||
* @param params Parameters to pass to the template | ||
* @return The rendered template | ||
*/ | ||
private static String renderTemplate(String templateName, Map<String, Object> params) { | ||
try { | ||
TemplateEngine templateEngine = TemplateEngine.createPrecompiled(ContentType.Html); | ||
TemplateOutput output = new StringOutput(); | ||
templateEngine.render(templateName, params, output); | ||
return output.toString().trim(); | ||
} catch (Exception e) { | ||
LOG.error("Error rendering template {}", templateName, e); | ||
throw new ModernizerException("Error rendering template " + templateName, e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@import io.jenkins.tools.pluginmodernizer.core.model.Plugin | ||
@import org.openrewrite.Recipe | ||
@import java.util.List | ||
@import static io.jenkins.tools.pluginmodernizer.core.config.Settings.RECIPE_FQDN_PREFIX | ||
@param Plugin plugin | ||
@param List<Recipe> recipes | ||
Applied recipes ${recipes.stream().map(r -> r.getName().replaceAll(RECIPE_FQDN_PREFIX + ".", "")).collect(java.util.stream.Collectors.joining(", "))} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@import io.jenkins.tools.pluginmodernizer.core.model.Plugin | ||
@import org.openrewrite.Recipe | ||
@import java.util.List | ||
@param Plugin plugin | ||
@param List<Recipe> recipes | ||
Hello `${plugin.getName()}` developers! | ||
|
||
This is an automated pull request created by the [Jenkins Plugin Modernizer](https://github.com/jenkinsci/plugin-modernizer-tool) tool. The tool has applied the following recipes to modernize the plugin: | ||
@for(var recipe : recipes) | ||
<details> | ||
<summary>${recipe.getDisplayName()}</summary> | ||
<p><em>${recipe.getName()}</em></p> | ||
<blockquote>${recipe.getDescription()}</blockquote> | ||
</details> | ||
@endfor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@import io.jenkins.tools.pluginmodernizer.core.config.Settings | ||
@import io.jenkins.tools.pluginmodernizer.core.model.Plugin | ||
@import org.openrewrite.Recipe | ||
@import java.util.List | ||
@import static io.jenkins.tools.pluginmodernizer.core.config.Settings.RECIPE_FQDN_PREFIX | ||
@param Plugin plugin | ||
@param List<Recipe> recipes | ||
Applied recipes ${recipes.stream().map(r -> r.getName().replaceAll(RECIPE_FQDN_PREFIX + ".", "")).collect(java.util.stream.Collectors.joining(", "))} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.