Skip to content

Commit 24c7215

Browse files
committed
Implement duplicate issue detection
1 parent d813761 commit 24c7215

File tree

6 files changed

+21
-22
lines changed

6 files changed

+21
-22
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ java {
9191
}
9292
}
9393

94-
val gradleToolingExtension = java().sourceSets["gradle-tooling-extension"]
94+
val gradleToolingExtension = java().sourceSets["gradle-tooling-extension"]!!
9595
val gradleToolingExtensionJar = task<Jar>(gradleToolingExtension.jarTaskName) {
9696
from(gradleToolingExtension.output)
9797
classifier = "gradle-tooling-extension"

src/main/kotlin/com/demonwav/mcdev/buildsystem/gradle/GradleBuildSystem.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,15 @@ class GradleBuildSystem : BuildSystem() {
220220
}
221221

222222
private fun createRepositoriesOrDependencies(project: Project, file: GroovyFile, name: String, expressions: List<String>) {
223-
// Ge the block so we can start working with it
223+
// Get the block so we can start working with it
224224
val block = getClosableBlockByName(file, name) ?: return
225225

226226
// Create a super expression with all the expressions tied together
227227
val expressionText = expressions.joinToString("\n")
228228

229229
// We can't create each expression and add them to the file...that won't work. Groovy requires a new line
230230
// from one method call expression to another, and there's no way to (easily) put whitespace in Psi because Psi is
231-
// stupid. So instead we make hte whole thing as one big clump and insert it into the block.
231+
// stupid. So instead we make the whole thing as one big clump and insert it into the block.
232232
val fakeFile = GroovyPsiElementFactory.getInstance(project).createGroovyFile(expressionText, false, null)
233233
val last = block.children.last()
234234
block.addBefore(fakeFile, last)

src/main/kotlin/com/demonwav/mcdev/error/AnonymousFeedback.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ object AnonymousFeedback {
9292
}
9393

9494
val json = Gson().fromJson<Map<*, *>>(body)
95-
return json["html_url"] as String to (json["id"] as Double).toInt()
95+
return json["html_url"] as String to (json["number"] as Double).toInt()
9696
}
9797

9898
private fun connect(factory: HttpConnectionFactory, url: String): HttpURLConnection {
@@ -103,20 +103,25 @@ object AnonymousFeedback {
103103
}
104104

105105
private fun findDuplicateIssue(envDetails: LinkedHashMap<String, String?>): Int? {
106-
val stack = envDetails["error.stacktrace"] ?: return null
106+
val stack = envDetails["error.stacktrace"]?.replace("\\d+".toRegex(), "") ?: return null
107107

108-
val text = URL("https://api.github.com/repos/minecraft-dev/MinecraftDev/issues").readText()
108+
val text = URL("https://api.github.com/repos/minecraft-dev/MinecraftDev/issues?state=all&creator=minecraft-dev-autoreporter").readText()
109109
val list = Gson().fromJson<List<Map<*, *>>>(text)
110110
val block = list.firstOrNull {
111111
val body = it["body"] as? String ?: return@firstOrNull false
112112

113+
// We can't comment on locked issues
114+
if (it["locked"] as Boolean) {
115+
return@firstOrNull false
116+
}
117+
113118
val first = body.indexOf("\n```\n", startIndex = 0) + 5
114119
val second = body.indexOf("\n```\n", startIndex = first)
115120
val stackText = body.substring(first, second)
116121

117-
stackText == stack
122+
stackText.replace("\\d+".toRegex(), "") == stack
118123
} ?: return null
119-
return (block["id"] as Double).toInt()
124+
return (block["number"] as Double).toInt()
120125
}
121126

122127
private fun sendCommentOnDuplicateIssue(id: Int, factory: HttpConnectionFactory, payload: ByteArray): String {
@@ -160,8 +165,6 @@ object AnonymousFeedback {
160165
}
161166

162167
open class HttpConnectionFactory {
163-
open fun openHttpConnection(url: String): HttpURLConnection {
164-
return URL(url).openConnection() as HttpURLConnection
165-
}
168+
open fun openHttpConnection(url: String) = URL(url).openConnection() as HttpURLConnection
166169
}
167170
}

src/main/kotlin/com/demonwav/mcdev/error/AnonymousFeedbackTask.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import com.intellij.openapi.progress.ProgressIndicator
1414
import com.intellij.openapi.progress.Task
1515
import com.intellij.openapi.project.Project
1616
import com.intellij.util.net.HttpConfigurable
17-
import java.net.HttpURLConnection
1817

1918
class AnonymousFeedbackTask(
2019
project: Project?,
@@ -37,8 +36,6 @@ class AnonymousFeedbackTask(
3736
}
3837

3938
private inner class ProxyHttpConnectionFactory : AnonymousFeedback.HttpConnectionFactory() {
40-
override fun openHttpConnection(url: String): HttpURLConnection {
41-
return HttpConfigurable.getInstance().openHttpConnection(url)
42-
}
39+
override fun openHttpConnection(url: String) = HttpConfigurable.getInstance().openHttpConnection(url)
4340
}
4441
}

src/main/kotlin/com/demonwav/mcdev/error/ErrorReporter.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import com.intellij.util.Consumer
3131
import java.awt.Component
3232

3333
class ErrorReporter : ErrorReportSubmitter() {
34-
val baseUrl = "https://github.com/minecraft-dev/MinecraftDev/issues"
34+
private val baseUrl = "https://github.com/minecraft-dev/MinecraftDev/issues"
3535
override fun getReportActionText() = "Report to Minecraft Dev GitHub Issue Tracker"
3636

3737
override fun submit(events: Array<out IdeaLoggingEvent>,
@@ -73,11 +73,11 @@ class ErrorReporter : ErrorReportSubmitter() {
7373
consumer.consume(reportInfo)
7474

7575
val message = if (!isDuplicate) {
76-
"<html>Created Issue #$token successfully.<br>" +
76+
"<html>Created Issue #$token successfully. " +
7777
"<a href=\"$htmlUrl\">View issue.</a></html>"
7878
} else {
79-
"<html>Commented on existing Issue #$token successfully.<br>" +
80-
"<a href=\"$htmlUrl\" View issue.</a></html>"
79+
"<html>Commented on existing Issue #$token successfully. " +
80+
"<a href=\"$htmlUrl\">View comment.</a></html>"
8181
}
8282

8383
ReportMessages.GROUP.createNotification(

src/main/kotlin/com/demonwav/mcdev/facet/MinecraftFacet.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,8 @@ class MinecraftFacet(module: Module, name: String, configuration: MinecraftFacet
133133
}
134134

135135
@Contract(value = "null -> false", pure = true)
136-
fun isEventClassValidForModule(eventClass: PsiClass?): Boolean {
137-
return eventClass != null && modules.values.any { it.isEventClassValid(eventClass, null) }
138-
}
136+
fun isEventClassValidForModule(eventClass: PsiClass?) =
137+
eventClass != null && modules.values.any { it.isEventClassValid(eventClass, null) }
139138

140139
@Contract(pure = true)
141140
fun isEventClassValid(eventClass: PsiClass, method: PsiMethod): Boolean {

0 commit comments

Comments
 (0)