2020-08-16 17:14:41 +02:00
|
|
|
package envoy.event;
|
|
|
|
|
|
|
|
/**
|
2020-10-18 15:16:46 +02:00
|
|
|
* This class allows envoy users to send an issue proposal to the server who, if not disabled by its
|
|
|
|
* administrator, will forward it directly to Gitea.
|
2020-08-16 17:14:41 +02:00
|
|
|
*
|
|
|
|
* @author Leon Hofmeister
|
|
|
|
* @since Envoy Common v0.2-beta
|
|
|
|
*/
|
2020-08-22 13:37:07 +02:00
|
|
|
public final class IssueProposal extends Event<String> {
|
2020-08-16 17:14:41 +02:00
|
|
|
|
|
|
|
private final String description;
|
|
|
|
private final boolean bug;
|
|
|
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
|
|
/**
|
2020-08-16 23:57:04 +02:00
|
|
|
* @param title the title of the reported bug
|
|
|
|
* @param description the description of this bug
|
2020-10-18 15:16:46 +02:00
|
|
|
* @param isBug determines whether this {@code IssueProposal} is supposed to be a feature
|
|
|
|
* or a bug (true = bug, false = feature)
|
2020-08-16 17:14:41 +02:00
|
|
|
* @since Envoy Common v0.2-beta
|
|
|
|
*/
|
2020-08-16 23:57:04 +02:00
|
|
|
public IssueProposal(String title, String description, boolean isBug) {
|
2020-09-27 17:02:24 +02:00
|
|
|
super(escape(title));
|
|
|
|
this.description = sanitizeDescription(description);
|
2020-08-16 17:14:41 +02:00
|
|
|
bug = isBug;
|
|
|
|
}
|
|
|
|
|
2020-09-27 17:02:24 +02:00
|
|
|
/**
|
|
|
|
* @param title the title of the reported bug
|
|
|
|
* @param description the description of this bug
|
|
|
|
* @param user the name of the user creating the issue
|
2020-10-18 15:16:46 +02:00
|
|
|
* @param isBug determines whether this {@code IssueProposal} is supposed to be a feature
|
|
|
|
* or a bug (true = bug, false = feature)
|
2020-09-27 17:02:24 +02:00
|
|
|
* @since Envoy Common v0.2-beta
|
|
|
|
*/
|
|
|
|
public IssueProposal(String title, String description, String user, boolean isBug) {
|
|
|
|
super(escape(title));
|
2020-10-18 15:16:46 +02:00
|
|
|
this.description =
|
|
|
|
sanitizeDescription(description) + String.format("<br>Submitted by user %s.", user);
|
2020-09-27 17:02:24 +02:00
|
|
|
bug = isBug;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Escapes an issue description and normalizes its line breaks.
|
|
|
|
*
|
|
|
|
* @param description the description to normalize
|
|
|
|
* @return the normalized description
|
|
|
|
* @since Envoy Common v0.2-beta
|
|
|
|
*/
|
|
|
|
private static String sanitizeDescription(String description) {
|
|
|
|
return escape(description).replaceAll("\r?\n", "<br>");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Escapes quotes and backslashes from a string.
|
|
|
|
*
|
|
|
|
* @param raw the string to escape
|
|
|
|
* @return the escaped string
|
|
|
|
* @since Envoy Client v0.2-beta
|
|
|
|
*/
|
2020-10-18 15:16:46 +02:00
|
|
|
private static String escape(String raw) {
|
|
|
|
return raw.replace("\\", "\\\\").replace("\"", "\\\"");
|
|
|
|
}
|
2020-09-27 17:02:24 +02:00
|
|
|
|
2020-08-16 17:14:41 +02:00
|
|
|
/**
|
|
|
|
* @return the description
|
|
|
|
* @since Envoy Common v0.2-beta
|
|
|
|
*/
|
|
|
|
public String getDescription() { return description; }
|
|
|
|
|
|
|
|
/**
|
2020-10-18 15:16:46 +02:00
|
|
|
* @return whether this issue is supposed to be a bug - otherwise it is intended as a feature
|
2020-08-16 17:14:41 +02:00
|
|
|
* @since Envoy Common v0.2-beta
|
|
|
|
*/
|
|
|
|
public boolean isBug() { return bug; }
|
|
|
|
}
|