41 lines
1.3 KiB
Java
41 lines
1.3 KiB
Java
|
package envoy.client.util;
|
||
|
|
||
|
/**
|
||
|
* Provides methods to handle outgoing issues.
|
||
|
* <p>
|
||
|
* Project: <strong>client</strong><br>
|
||
|
* File: <strong>IssueUtil.java</strong><br>
|
||
|
* Created: <strong>20.08.2020</strong><br>
|
||
|
*
|
||
|
* @author Leon Hofmeister
|
||
|
* @since Envoy Client v0.2-beta
|
||
|
*/
|
||
|
public class IssueUtil {
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
* @since Envoy Client v0.2-beta
|
||
|
*/
|
||
|
private IssueUtil() {}
|
||
|
|
||
|
/**
|
||
|
* Performs actions to ensure the description of an issue will be displayed as
|
||
|
* intended by the user.
|
||
|
*
|
||
|
* @param rawDescription the description to sanitize
|
||
|
* @param username the user who submitted the issue. Should be
|
||
|
* {@code null} if he does not want to be named.
|
||
|
* @return the sanitized description
|
||
|
* @since Envoy Client v0.2-beta
|
||
|
*/
|
||
|
public static String sanitizeIssueDescription(String rawDescription, String username) {
|
||
|
// Appending the submitter name, if this option was enabled
|
||
|
rawDescription += username != null
|
||
|
? (rawDescription.endsWith("\n") || rawDescription.endsWith("<br>") ? "" : "<br>") + String.format("Submitted by user %s.", username)
|
||
|
: "";
|
||
|
// Markdown does not support "normal" line breaks. It uses "<br>"
|
||
|
rawDescription = rawDescription.replaceAll(System.getProperty("line.separator", "\r?\n"), "<br>");
|
||
|
return rawDescription;
|
||
|
}
|
||
|
}
|