Skip to content

Commit

Permalink
Merge branch 'master' into optional-comment-author
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/kotlin/io/github/mojira/arisa/domain/Comment.kt
#	src/main/kotlin/io/github/mojira/arisa/modules/ReopenAwaitingModule.kt
  • Loading branch information
violine1101 committed Oct 7, 2024
2 parents 53dba85 + 68d1928 commit 85f9a87
Show file tree
Hide file tree
Showing 21 changed files with 162 additions and 132 deletions.
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ updates:
directory: "/" # Location of package manifests
schedule:
interval: "weekly"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
4 changes: 2 additions & 2 deletions .github/workflows/gradle-wrapper-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ jobs:
name: "Validation"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: gradle/wrapper-validation[email protected]
- uses: actions/checkout@v4
- uses: gradle/actions/wrapper-validation@v4
12 changes: 6 additions & 6 deletions .github/workflows/pull-request-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: Setup and build with Gradle
uses: gradle/gradle-build-action@v2
with:
arguments: build
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4
- name: Build with Gradle
run: ./gradlew build
117 changes: 38 additions & 79 deletions .github/workflows/push-build-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Build and deploy

permissions:
id-token: write # Require write permission to Fetch an OIDC token.

on:
push:
branches: [ master ]
Expand All @@ -8,87 +11,43 @@ on:

jobs:
build:

name: Build and deploy
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: temurin
- name: Setup and build with Gradle
uses: gradle/gradle-build-action@v2
with:
arguments: clean installDist
- name: Upload new libraries
uses: urielsalis/rsync-deploy@master
env:
DEPLOY_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SERVER_PORT: 50022
FOLDER: "build/install/arisa-kt/lib"
ARGS: "-avhW --delete"
SERVER_IP: localhost
USERNAME: arisakt
SERVER_DESTINATION: /home/arisakt/arisa-kt
CLIENT_ID: ${{ secrets.CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
RESOURCE_ID: ${{ secrets.RESOURCE_ID }}
RESOURCE_GROUP: ${{ secrets.RESOURCE_GROUP }}
TENANT_ID: ${{ secrets.TENANT_ID }}
BASTION_NAME: ${{ secrets.BASTION_NAME }}
- name: Upload new binaries
uses: urielsalis/rsync-deploy@master
env:
DEPLOY_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SERVER_PORT: 50022
FOLDER: "build/install/arisa-kt/bin"
ARGS: "-avhW --delete"
SERVER_IP: localhost
USERNAME: arisakt
SERVER_DESTINATION: /home/arisakt/arisa-kt
CLIENT_ID: ${{ secrets.CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
RESOURCE_ID: ${{ secrets.RESOURCE_ID }}
RESOURCE_GROUP: ${{ secrets.RESOURCE_GROUP }}
TENANT_ID: ${{ secrets.TENANT_ID }}
BASTION_NAME: ${{ secrets.BASTION_NAME }}
- name: Upload new configuration
uses: urielsalis/rsync-deploy@master
env:
DEPLOY_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SERVER_PORT: 50022
FOLDER: "config"
ARGS: "-avhW --delete --exclude='local.yml'"
SERVER_IP: localhost
USERNAME: arisakt
SERVER_DESTINATION: /home/arisakt/arisa-kt
CLIENT_ID: ${{ secrets.CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
RESOURCE_ID: ${{ secrets.RESOURCE_ID }}
RESOURCE_GROUP: ${{ secrets.RESOURCE_GROUP }}
TENANT_ID: ${{ secrets.TENANT_ID }}
BASTION_NAME: ${{ secrets.BASTION_NAME }}
- name: Run internal deploy script
uses: urielsalis/azure-bastion-ssh-action@master
env:
CLIENT_ID: ${{ secrets.CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
RESOURCE_ID: ${{ secrets.RESOURCE_ID }}
RESOURCE_GROUP: ${{ secrets.RESOURCE_GROUP }}
TENANT_ID: ${{ secrets.TENANT_ID }}
BASTION_NAME: ${{ secrets.BASTION_NAME }}
with:
host: localhost
port: 50022
user: arisakt
key: ${{ secrets.SSH_PRIVATE_KEY }}
command: |
/usr/bin/screen -ls | /bin/egrep 'Detached|Attached' | /usr/bin/cut -d. -f1 | /usr/bin/awk '{print $1}' | /usr/bin/xargs /bin/kill
sleep 1
cd arisa-kt
/usr/bin/screen -d -m bash -c '/home/arisakt/arisa-kt/bin/arisa-kt; exec sh'
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin

- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4

args: "-tt"
- name: Build with Gradle
run: ./gradlew clean installDist

- name: Deploy
uses: mojira/deploy@main
with:
azure_client_id: ${{ secrets.AZURE_CLIENT_ID }}
azure_tenant_id: ${{ secrets.AZURE_TENANT_ID }}
azure_subscription_id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
bastion_name: ${{ secrets.BASTION_NAME }}
resource_group: ${{ secrets.RESOURCE_GROUP }}
resource_id: ${{ secrets.RESOURCE_ID }}
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
username: arisakt
artifact_paths: |
build/install/arisa-kt/lib
build/install/arisa-kt/bin
config/config.*
artifact_destination: /home/arisakt/arisa-kt
script: |
/usr/bin/screen -ls | /bin/egrep 'Detached|Attached' | /usr/bin/cut -d. -f1 | /usr/bin/awk '{print $1}' | /usr/bin/xargs /bin/kill
sleep 1
cd arisa-kt
/usr/bin/screen -d -m bash -c '/home/arisakt/arisa-kt/bin/arisa-kt; exec sh'
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
kotlin("jvm") version "1.9.10"
kotlin("jvm") version "2.0.20"
id("org.jlleitschuh.gradle.ktlint") version "11.5.0"
application
id("io.gitlab.arturbosch.detekt") version "1.23.0"
Expand Down
2 changes: 0 additions & 2 deletions config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ arisa:

privateSecurityLevel:
default: '10318'
special:
mcl: '10502'

modules:
affectedVersionMessage:
Expand Down
1 change: 1 addition & 0 deletions docs/Modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ Hides the comments created by users who look like an impostor.
and some texts after the brackets. e.g. `[dev] foo`.
- The comment is not restricted to `staff`.
- The comment's author is not a `helper`, `global-moderators`, nor `staff`.
- The user who last updated the comment is not a `helper`, `global-moderators`, nor `staff`.

## IncompleteModule

Expand Down
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
2 changes: 2 additions & 0 deletions src/main/kotlin/io/github/mojira/arisa/domain/Comment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ data class Comment(
val id: String,
val body: String?,
val author: User?,
val updateAuthor: User?,
val getAuthorGroups: () -> List<String>?,
val getUpdateAuthorGroups: () -> List<String>?,
val created: Instant,
val updated: Instant,
val visibilityType: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ object Arisa : ConfigSpec() {
val default by required<String>(
description = "The default security id used by projects not defined in special."
)
val special by required<Map<String, String>>(
description = "Some projects define their own security level. These projects need to be defined here with" +
" their own ID.. Default is all projects use the default ID"
)
}

object Debug : ConfigSpec() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ fun getCreationDate(issue: JiraIssue, id: String, default: Instant) = issue.chan
?.created
?.toInstant() ?: default

fun JiraProject.getSecurityLevelId(config: Config) =
config[Arisa.PrivateSecurityLevel.special][key.lowercase()] ?: config[Arisa.PrivateSecurityLevel.default]
fun JiraProject.getSecurityLevelId(config: Config) = config[Arisa.PrivateSecurityLevel.default]

fun JiraVersion.toDomain() = Version(
id,
Expand Down Expand Up @@ -221,7 +220,9 @@ fun JiraComment.toDomain(
id,
body,
author.toDomain(jiraClient, config),
updateAuthor?.toDomain(jiraClient, config),
{ getGroups(jiraClient, author.name).fold({ null }, { it }) },
{ if (updateAuthor == null) emptyList() else getGroups(jiraClient, updateAuthor.name).fold({ null }, { it }) },
createdDate.toInstant(),
updatedDate.toInstant(),
visibility?.type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class HideImpostorsModule : Module {
.filter(::commentIsRecent)
.filter(::userContainsBrackets)
.filter(::isNotStaffRestricted)
.filter(::userIsNotVolunteer)
.filter(::authorIsNotVolunteer)
.filter(::updateAuthorIsNotVolunteer)
.map { it.restrict.partially1(it.body ?: "") }
.toList()

Expand All @@ -34,8 +35,13 @@ class HideImpostorsModule : Module {
this != null && matches("""\[(?:\p{L}|\p{N}|\s)+]\s.+""".toRegex())
}

private fun userIsNotVolunteer(comment: Comment) =
!(comment.getAuthorGroups()?.any { it == "helper" || it == "global-moderators" || it == "staff" } ?: false)
private val staffGroups = setOf("helper", "global-moderators", "staff")

private fun authorIsNotVolunteer(comment: Comment) =
comment.getAuthorGroups()?.none { staffGroups.contains(it) } ?: true

private fun updateAuthorIsNotVolunteer(comment: Comment) =
comment.getUpdateAuthorGroups()?.none { staffGroups.contains(it) } ?: true

private fun isNotStaffRestricted(comment: Comment) =
comment.visibilityType != "group" || comment.visibilityValue != "staff"
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 Down Expand Up @@ -43,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 @@ -80,17 +77,8 @@ class ReopenAwaitingModule(
comment.visibilityValue == "staff" &&
(comment.body?.contains(keepARTag) ?: false)

private fun isKeepARMessage(comment: Comment, project: Project) = comment.author?.name == "arisabot" &&
(
comment.body?.contains(
HelperMessageService.getMessageWithBotSignature(
project.key,
message,
null,
"en"
)
) ?: false
)
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 @@ -28,7 +28,7 @@ class ListUserActivityCommand(
is Either.Left ->
throw CommandExceptions.CANNOT_QUERY_USER_ACTIVITY
.create(sanitizedUserName, jql)
.initCause(either.a)
.apply { addSuppressed(either.a) }

is Either.Right -> either.b
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class RemoveContentCommand(
is Either.Left ->
throw CommandExceptions.CANNOT_QUERY_USER_ACTIVITY
.create(sanitizedUserName, jql)
.initCause(either.a)
.apply { addSuppressed(either.a) }

is Either.Right -> either.b
}
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
Loading

0 comments on commit 85f9a87

Please sign in to comment.