Skip to content

Commit

Permalink
semi-hardcode message in ReopenAwaitingModule
Browse files Browse the repository at this point in the history
  • Loading branch information
violine1101 committed Apr 19, 2024
1 parent d07a492 commit 84121fc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class HelperMessageUpdateService {
private val helperMessagesFile = File("helper-messages.json")
private var helperMessagesLastFetch = Instant.now().minusSeconds(UPDATE_INTERVAL_IN_SECONDS + 1)

init {
this.checkForUpdate()
}

fun checkForUpdate() {
val currentTime = Instant.now()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ import arrow.core.left
import arrow.core.right
import io.github.mojira.arisa.domain.ChangeLogItem
import io.github.mojira.arisa.domain.Comment
import io.github.mojira.arisa.domain.CommentOptions
import io.github.mojira.arisa.domain.Issue
import io.github.mojira.arisa.domain.Project
import io.github.mojira.arisa.domain.User
import io.github.mojira.arisa.infrastructure.HelperMessageService
import java.time.Instant
import java.time.temporal.ChronoUnit

Expand All @@ -26,7 +23,6 @@ class ReopenAwaitingModule(
) : Module {
override fun invoke(issue: Issue, lastRun: Instant): Either<ModuleError, ModuleResponse> = with(issue) {
Either.fx {
log = ""
assertEquals(resolution, "Awaiting Response").bind()
assertCreationIsNotRecent(updated.toEpochMilli(), created.toEpochMilli()).bind()

Expand All @@ -44,8 +40,8 @@ class ReopenAwaitingModule(
reopen()
} else {
assertNotEquals(changeLog.maxByOrNull { it.created }?.author?.name, "arisabot")
if (comments.none { isKeepARMessage(it, project) }) {
addComment(CommentOptions(message))
if (comments.none { isKeepARMessage(it) }) {
addRawBotComment(message)
}
}
}
Expand Down Expand Up @@ -81,28 +77,8 @@ class ReopenAwaitingModule(
comment.visibilityValue == "staff" &&
(comment.body?.contains(keepARTag) ?: false)

var log: String = ""

private fun isKeepARMessage(comment: Comment, project: Project): Boolean {
log += "isKeepAR message: ${comment.body}\n"

if (comment.author.name != "arisabot") {
log += "author: ${comment.author.name}; contains message: false\n"
return false
}

val keepARMessage = HelperMessageService.getMessageWithBotSignature(
project.key,
message,
null,
"en"
)
log += "keep AR message: $keepARMessage\n"

val result = comment.body?.contains(keepARMessage) ?: false
log += "contains message: $result\n"
return result
}
private fun isKeepARMessage(comment: Comment) =
comment.author.name == "arisabot" && comment.body?.contains(message) ?: false

private fun getValidComments(
comments: List<Comment>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.uchuhimo.konf.Config
import com.urielsalis.mccrashlib.CrashReader
import io.github.mojira.arisa.ExecutionTimeframe
import io.github.mojira.arisa.infrastructure.AttachmentUtils
import io.github.mojira.arisa.infrastructure.HelperMessageService
import io.github.mojira.arisa.infrastructure.LanguageDetectionApi
import io.github.mojira.arisa.infrastructure.config.Arisa
import io.github.mojira.arisa.modules.AffectedVersionMessageModule
Expand Down Expand Up @@ -209,7 +210,7 @@ class InstantModuleRegistry(config: Config) : ModuleRegistry(config) {
config[Arisa.Modules.ReopenAwaiting.softARDays],
config[Arisa.Modules.ReopenAwaiting.keepARTag],
config[Arisa.Modules.ReopenAwaiting.onlyOPTag],
config[Arisa.Modules.ReopenAwaiting.message]
HelperMessageService.getMessage("MC", keys = listOf(config[Arisa.Modules.ReopenAwaiting.message]))
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package io.github.mojira.arisa.modules

import arrow.core.right
import io.github.mojira.arisa.domain.User
import io.github.mojira.arisa.infrastructure.HelperMessageService
import io.github.mojira.arisa.utils.RIGHT_NOW
import io.github.mojira.arisa.utils.mockChangeLogItem
import io.github.mojira.arisa.utils.mockComment
Expand All @@ -23,13 +22,16 @@ private val NEWBIE = getUser(name = "newbieUser", newUser = true)
private val TEN_SECONDS_AGO = RIGHT_NOW.minusSeconds(10)
private val TWO_YEARS_AGO = RIGHT_NOW.minus(730, ChronoUnit.DAYS)

private const val NOT_REOPEN_AR_MESSAGE = "This report is currently missing crucial information. " +
"Please take a look at the other comments to find out what we are looking for."

private val MODULE = ReopenAwaitingModule(
setOf("staff", "global-moderators"),
setOf("helper", "staff", "global-moderators"),
365,
"MEQS_KEEP_AR",
"ARISA_REOPEN_OP",
"not-reopen-ar"
NOT_REOPEN_AR_MESSAGE
)
private val AWAITING_RESOLVE = mockChangeLogItem(
created = TEN_SECONDS_AGO,
Expand All @@ -43,39 +45,6 @@ private val OLD_AWAITING_RESOLVE = mockChangeLogItem(
)

class ReopenAwaitingModuleTest : StringSpec({
HelperMessageService.setHelperMessages(
"""
{
"variables": {},
"messages": {
"not-reopen-ar": [
{
"project": "mc",
"name": "Not reopen AR",
"message": "This bug report is old, please check it again! Thanks!",
"fillname": []
}
],
"i-am-a-bot": [
{
"project": "mc",
"name": "I am a bot",
"message": "Beep boop",
"fillname": []
}
]
}
}
""".trimIndent()
)

val notReopenArMessage: String = HelperMessageService.getMessageWithBotSignature(
"MC",
"not-reopen-ar",
null,
"en"
)

"should return OperationNotNeededModuleResponse when there is no resolution" {
val updated = RIGHT_NOW.plusSeconds(3)
val issue = mockIssue(
Expand Down Expand Up @@ -826,7 +795,8 @@ class ReopenAwaitingModuleTest : StringSpec({
comments = listOf(tagComment, normalComment),
changeLog = listOf(AWAITING_RESOLVE),
reopen = { hasReopened = true; Unit.right() },
addComment = { hasCommented = true; Unit.right() }
addComment = { hasCommented = true; Unit.right() },
addRawBotComment = { hasCommented = true; Unit.right() }
)

val result = MODULE(issue, TEN_SECONDS_AGO)
Expand All @@ -849,7 +819,8 @@ class ReopenAwaitingModuleTest : StringSpec({
comments = listOf(comment),
changeLog = listOf(OLD_AWAITING_RESOLVE),
reopen = { hasReopened = true; Unit.right() },
addComment = { hasCommented = true; Unit.right() }
addComment = { hasCommented = true; Unit.right() },
addRawBotComment = { hasCommented = true; Unit.right() }
)

val result = MODULE(issue, TEN_SECONDS_AGO)
Expand All @@ -870,7 +841,7 @@ class ReopenAwaitingModuleTest : StringSpec({
visibilityValue = "staff"
)
val arisaComment = getComment(
body = notReopenArMessage,
body = NOT_REOPEN_AR_MESSAGE,
author = ARISA
)
val normalComment = getComment()
Expand All @@ -888,7 +859,6 @@ class ReopenAwaitingModuleTest : StringSpec({

result.shouldBeRight(ModuleResponse)
hasReopened shouldBe false
MODULE.log shouldBe "test"
hasCommented shouldBe false
}

Expand All @@ -903,7 +873,7 @@ class ReopenAwaitingModuleTest : StringSpec({
visibilityValue = "staff"
)
val fakeComment = getComment(
body = notReopenArMessage,
body = NOT_REOPEN_AR_MESSAGE,
author = RANDOM_USER
)
val issue = mockIssue(
Expand All @@ -913,7 +883,8 @@ class ReopenAwaitingModuleTest : StringSpec({
comments = listOf(tagComment, fakeComment),
changeLog = listOf(AWAITING_RESOLVE),
reopen = { hasReopened = true; Unit.right() },
addComment = { hasCommented = true; Unit.right() }
addComment = { hasCommented = true; Unit.right() },
addRawBotComment = { hasCommented = true; Unit.right() }
)

val result = MODULE(issue, TEN_SECONDS_AGO)
Expand Down

0 comments on commit 84121fc

Please sign in to comment.