-
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
Fix errors and bugs in RevokePriorityModule #768
Draft
violine1101
wants to merge
2
commits into
master
Choose a base branch
from
fix/priority-module-errors
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.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,21 +2,50 @@ package io.github.mojira.arisa.modules | |
|
||
import arrow.core.Either | ||
import arrow.core.extensions.fx | ||
import arrow.core.left | ||
import arrow.core.right | ||
import io.github.mojira.arisa.domain.ChangeLogItem | ||
import io.github.mojira.arisa.domain.Issue | ||
import org.slf4j.Logger | ||
import org.slf4j.LoggerFactory | ||
import java.time.Instant | ||
import java.time.temporal.ChronoUnit | ||
|
||
class RevokePriorityModule : Module { | ||
val log: Logger = LoggerFactory.getLogger("RevokePriorityModule") | ||
|
||
override fun invoke(issue: Issue, lastRun: Instant): Either<ModuleError, ModuleResponse> = with(issue) { | ||
Either.fx { | ||
val originalPriority = changeLog | ||
// Check if there are recent changes to priority in the changelog | ||
val recentPriorityChanges = changeLog | ||
.filter { item -> item.created >= lastRun } | ||
.filter(::isPriorityChange) | ||
|
||
// If there aren't any recent changes to priority, there's nothing to revoke | ||
assertNotEmpty(recentPriorityChanges).bind() | ||
|
||
// Try to recover original priority by getting entries from the changelog | ||
val originalPriorityItem = changeLog | ||
.filter(::isPriorityChange) | ||
.lastOrNull(::changedByStaff) | ||
?.changedTo.getOrDefaultNull("-1") | ||
|
||
assertNotEquals(getId(priority), originalPriority).bind() | ||
updatePriority(originalPriority) | ||
val originalPriorityId = originalPriorityItem?.changedTo.getOrDefaultNull("-1") | ||
val originalPriorityName = originalPriorityItem?.changedToString.getOrDefaultNull("None") | ||
|
||
// Check whether the original priority differs from the current priority | ||
assertNotEquals(getId(priority), originalPriorityId).bind() | ||
|
||
// Ensure that the priority from the changelog is a currently valid priority value | ||
// (e.g. 11602 was the original value for 'Normal', which is no longer valid) | ||
assertValidPriority(originalPriorityId).mapLeft { result -> | ||
log.error( | ||
"[${issue.key}] Cannot revoke change to priority: " + | ||
"Unknown mojang priority value '$originalPriorityName' [$originalPriorityId]" | ||
) | ||
result | ||
}.bind() | ||
|
||
updatePriority(originalPriorityId) | ||
} | ||
} | ||
|
||
|
@@ -29,6 +58,16 @@ class RevokePriorityModule : Module { | |
else -> "-1" | ||
} | ||
|
||
private fun assertValidPriority(priorityId: String) = | ||
if (isValidPriority(priorityId)) { | ||
Unit.right() | ||
} else { | ||
OperationNotNeededModuleResponse.left() | ||
} | ||
|
||
private fun isValidPriority(priority: String): Boolean = | ||
setOf("-1", "11700", "11701", "11702", "11703").contains(priority) | ||
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. To avoid duplication, what about having a map from priority name to ID, which is then used by |
||
|
||
private fun isPriorityChange(item: ChangeLogItem) = | ||
item.field == "Mojang Priority" | ||
|
||
|
@@ -38,6 +77,6 @@ class RevokePriorityModule : Module { | |
private fun updateIsRecent(item: ChangeLogItem) = | ||
item | ||
.created | ||
.plus(1, ChronoUnit.DAYS) | ||
.plus(1, ChronoUnit.YEARS) | ||
.isAfter(Instant.now()) | ||
} |
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.
I am a bit worried what happens when a new priority is added, and when a Mojang employee then changes the priority of an issue
(which is not "None")to that new priority. To me it looks like this assertion here would erroneously consider them unequal becausegetId
would return"-1"
, even though the new priority is the same set byoriginalPriorityItem
.Is there a way to obtain the priority ID from the issue? If not, would one of these implementations make sense?
getId
to returnString?
and don't try to revert the priority change if the result ofgetId
for the new priority isnull
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.
In theory, in this case,
priority
should always be equal tooriginalPriority
, since that's both the most recent staff priority changelog item and the current priority of the issue.Aka,
priority
is always the already updated priority, not the priority from before the change. Which is what makes things tricky.E.g. Mojang developer changes priority from None to Normal:
priority
is now11702
originalPriorityItem
is `None [-1] -> Normal [11702]originalPriorityId
is11702
Thus this check would fail and the module would return OperationNotNeeded.
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.
The case I was thinking of is:
A new priority "Extremely Important" with ID 11699 is added, and a Mojang developer changes the priority of an issue to "Extremely Important".
originalPriorityId
is therefore"11699"
andpriority
is"Extremely Important"
. However, becausegetId
does not know the ID for "Extremely Important", it returns"-1"
, which is unequal to"11699"
, and therefore the module erroneously reverts the change.Or am I misunderstanding something here?