forked from batya239/NyanProgressBar
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ErrorSubmitter.kt
86 lines (82 loc) · 3.38 KB
/
ErrorSubmitter.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package pers.wjx.plugin.progress.error
import com.intellij.ide.BrowserUtil
import com.intellij.ide.plugins.PluginManagerCore
import com.intellij.openapi.application.ApplicationInfo
import com.intellij.openapi.diagnostic.ErrorReportSubmitter
import com.intellij.openapi.diagnostic.IdeaLoggingEvent
import com.intellij.openapi.diagnostic.SubmittedReportInfo
import com.intellij.openapi.extensions.PluginId
import com.intellij.openapi.util.SystemInfo
import com.intellij.openapi.util.text.StringUtil
import com.intellij.util.ArrayUtil
import com.intellij.util.Consumer
import pers.wjx.plugin.progress.common.ProgressBarBundle
import java.awt.Component
import java.net.URLEncoder
import java.nio.charset.StandardCharsets
/**
* @author wjx
*/
class ErrorSubmitter : ErrorReportSubmitter() {
private val url = "https://github.com/Wujiaxuan007/YourProgressBar/issues/new?"
private val pluginId = "pers.wjx.plugin.yourProgressBar"
private val label = "exception"
private val stacktraceLen = 6500
override fun getReportActionText(): String {
return ProgressBarBundle.message("report.to.vendor")
}
override fun submit(
events: Array<out IdeaLoggingEvent>,
additionalInfo: String?,
parentComponent: Component,
consumer: Consumer<in SubmittedReportInfo>
): Boolean {
val event = ArrayUtil.getFirstElement(events)
var title = "Exception: "
var stacktrace = "Please paste the full stacktrace from the IDEA error popup.\n"
if (event != null) {
val throwableText = event.throwableText
val exceptionTitle: String = throwableText.lines().first()
title += if (!StringUtil.isEmptyOrSpaces(exceptionTitle)) exceptionTitle else "<Fill in title>"
if (!StringUtil.isEmptyOrSpaces(throwableText)) {
val quotes = "\n```\n"
stacktrace += quotes + StringUtil.first(
throwableText,
stacktraceLen,
true
) + quotes
}
}
val plugin = PluginManagerCore.getPlugin(PluginId.getId(pluginId))
val pluginVersion = if (plugin != null) plugin.version else ""
val ideaVersion = ApplicationInfo.getInstance().build.asString()
val template = StringBuilder()
template.append("### Description\n")
if (additionalInfo != null) {
template.append(additionalInfo).append("\n")
}
template.append("\n")
template.append("### Stacktrace\n").append(stacktrace).append("\n")
template.append("### Version and Environment Details\n")
.append("Operation system: ").append(SystemInfo.getOsNameAndVersion()).append("\n")
.append("IDE version: ").append(ideaVersion).append("\n")
.append("Plugin version: ").append(pluginVersion).append("\n")
val charset = StandardCharsets.UTF_8
val url = String.format(
"%stitle=%s&labels=%s&body=%s",
url,
URLEncoder.encode(title, charset),
URLEncoder.encode(label, charset),
URLEncoder.encode(template.toString(), charset)
)
BrowserUtil.browse(url)
consumer.consume(
SubmittedReportInfo(
null,
"GitHub issue",
SubmittedReportInfo.SubmissionStatus.NEW_ISSUE
)
)
return true
}
}