-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update description with crash #627
Open
urielsalis
wants to merge
20
commits into
master
Choose a base branch
from
add-comment-with-crash
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
41eee62
Add comment with crash
urielsalis 65ac2d3
Merge branch 'master' into add-comment-with-crash
urielsalis 3300974
Regenerate cache
urielsalis a60cba2
Regenerate cache
urielsalis 1b5d3b7
Regenerate cache
urielsalis 66dbce4
fix comments
urielsalis 6387c2a
Use named release
urielsalis a92c10f
Use named release
urielsalis 331bd64
Latest version of mc crash lib
urielsalis 082b8a4
Merge branch 'master' into add-comment-with-crash
urielsalis c7dc318
Update src/test/kotlin/io/github/mojira/arisa/modules/CrashModuleTest.kt
urielsalis fbc34be
Update src/test/kotlin/io/github/mojira/arisa/modules/CrashInfoModule…
urielsalis ce84853
Update src/main/kotlin/io/github/mojira/arisa/modules/CrashInfoModule.kt
urielsalis 69d379d
Merge branch 'master' into add-comment-with-crash
urielsalis 50a46d4
Merge master into add-comment-with-crash
chandler05 54cede8
Update CrashInfoModule.kt
chandler05 a6e1b0b
Update CrashInfoModule.kt
chandler05 f1c3be8
Remove unused stuff
chandler05 d158019
Add crash to description instead of comment
chandler05 0409c1b
Fix test
chandler05 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
77 changes: 77 additions & 0 deletions
77
src/main/kotlin/io/github/mojira/arisa/modules/CrashInfoModule.kt
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,77 @@ | ||
package io.github.mojira.arisa.modules | ||
|
||
import arrow.core.Either | ||
import arrow.core.extensions.fx | ||
import arrow.core.left | ||
import arrow.core.right | ||
import arrow.syntax.function.partially2 | ||
import io.github.mojira.arisa.domain.Issue | ||
import io.github.mojira.arisa.infrastructure.AttachmentUtils | ||
import me.urielsalis.mccrashlib.Crash | ||
import me.urielsalis.mccrashlib.CrashReader | ||
import java.io.File | ||
import java.time.Instant | ||
|
||
class CrashInfoModule( | ||
private val crashReportExtensions: List<String>, | ||
private val crashReader: CrashReader | ||
) : Module { | ||
override fun invoke(issue: Issue, lastRun: Instant): Either<ModuleError, ModuleResponse> = with(issue) { | ||
Either.fx { | ||
val crashes = AttachmentUtils(crashReportExtensions, crashReader).extractCrashesFromAttachments(issue) | ||
val newCrashes = assertContainsNewCrash(crashes, lastRun).bind() | ||
uploadDeobfuscatedCrashes(issue, newCrashes) | ||
|
||
newCrashes | ||
.filter { it.second is Crash.Minecraft } | ||
.filterNot { it.first.name.endsWith("deobfuscated.txt") } | ||
Comment on lines
+26
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably restrict this to crash reports attached by the reporter (or by a helper / moderator?). |
||
.forEach { | ||
addRawComment(generateCrashMessage(it.first.name, it.second as Crash.Minecraft)) | ||
} | ||
} | ||
} | ||
|
||
private fun generateCrashMessage(name: String, minecraft: Crash.Minecraft) = | ||
"{code:title=(${minecraft.minecraftVersion}) [^$name]}\n\n" + | ||
"Description: ${minecraft.exception.split("\n").first()}\n\n" + | ||
"Exception: ${minecraft.exception}\n\n" + | ||
(if (minecraft.deobfException != null) "Deobfuscated: ${minecraft.deobfException}\n" else "\n") + | ||
"{code}\n" | ||
|
||
private fun uploadDeobfuscatedCrashes(issue: Issue, crashes: List<Pair<AttachmentUtils.TextDocument, Crash>>) { | ||
val minecraftCrashesWithDeobf = crashes | ||
.map { it.first.name to it.second } | ||
.filter { it.second is Crash.Minecraft } | ||
.map { it.first to (it.second as Crash.Minecraft).deobf } | ||
.filter { it.second != null } | ||
.filterNot { | ||
issue.attachments.any { attachment -> | ||
attachment.name == getDeobfName(it.first) || attachment.name.endsWith( | ||
"deobfuscated.txt" | ||
) | ||
} | ||
} | ||
minecraftCrashesWithDeobf.forEach { | ||
val file = File(getDeobfName(it.first)) | ||
file.writeText(it.second!!) | ||
urielsalis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
issue.addAttachment(file) | ||
Marcono1234 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
private fun getDeobfName(name: String): String = "${name.substringBeforeLast(".")}-deobfuscated.txt" | ||
|
||
private fun crashNewlyAdded(crash: Pair<AttachmentUtils.TextDocument, Crash>, lastRun: Instant) = | ||
crash.first.created.isAfter(lastRun) | ||
|
||
private fun assertContainsNewCrash( | ||
crashes: List<Pair<AttachmentUtils.TextDocument, Crash>>, | ||
lastRun: Instant | ||
): Either<OperationNotNeededModuleResponse, List<Pair<AttachmentUtils.TextDocument, Crash>>> { | ||
val newCrashes = crashes.filter(::crashNewlyAdded.partially2(lastRun)) | ||
return if (newCrashes.isNotEmpty()) { | ||
newCrashes.right() | ||
} else { | ||
OperationNotNeededModuleResponse.left() | ||
} | ||
} | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed anymore, is it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be nice to leave it for future purposes.