Merge pull request #428 from usbharu/ci

CIの改善
This commit is contained in:
usbharu 2024-06-17 23:04:24 +09:00 committed by GitHub
commit 2d539f74d2
34 changed files with 147 additions and 135 deletions

View File

@ -4,6 +4,11 @@ on:
pull_request:
branches:
- "develop"
types:
- opened # default
- reopened # default
- synchronize # default
- ready_for_review # 必要
permissions:
@ -15,6 +20,7 @@ permissions:
jobs:
setup:
name: Setup
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
- name: Checkout
@ -257,8 +263,8 @@ jobs:
with:
arguments: :hideout-core:detektMain
- name: "reviewdog-suggester: Suggest any code changes based on diff with reviewdog"
- name: Auto Commit
if: ${{ always() }}
uses: reviewdog/action-suggester@v1
uses: stefanzweifel/git-auto-commit-action@v5
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
commit_message: "style: fix lint (CI)"

View File

@ -133,6 +133,8 @@ naming:
- "**/test/**"
FunctionMinLength:
ignoreFunction:
- of
active: true
LambdaParameterNaming:

View File

@ -33,10 +33,6 @@ class GetUserDetailApplicationService(
transaction: Transaction,
) :
AbstractApplicationService<GetUserDetail, UserDetail>(transaction, Companion.logger) {
companion object {
val logger = LoggerFactory.getLogger(GetUserDetailApplicationService::class.java)
}
override suspend fun internalExecute(command: GetUserDetail, executor: CommandExecutor): UserDetail {
val userDetail = userDetailRepository.findById(command.id)
?: throw IllegalArgumentException("actor does not exist")
@ -46,4 +42,8 @@ class GetUserDetailApplicationService(
return UserDetail.of(actor, userDetail, emojis)
}
companion object {
val logger = LoggerFactory.getLogger(GetUserDetailApplicationService::class.java)
}
}

View File

@ -30,12 +30,12 @@ class UserDeleteFilterApplicationService(private val filterRepository: FilterRep
transaction,
logger
) {
companion object {
private val logger = LoggerFactory.getLogger(UserDeleteFilterApplicationService::class.java)
}
override suspend fun internalExecute(command: DeleteFilter, executor: CommandExecutor) {
val filter = filterRepository.findByFilterId(FilterId(command.filterId)) ?: throw Exception("not found")
filterRepository.delete(filter)
}
companion object {
private val logger = LoggerFactory.getLogger(UserDeleteFilterApplicationService::class.java)
}
}

View File

@ -38,10 +38,6 @@ class UserRegisterFilterApplicationService(
logger
) {
companion object {
private val logger = LoggerFactory.getLogger(UserRegisterFilterApplicationService::class.java)
}
override suspend fun internalExecute(command: RegisterFilter, executor: CommandExecutor): Filter {
require(executor is UserDetailGettableCommandExecutor)
@ -64,4 +60,8 @@ class UserRegisterFilterApplicationService(
filterRepository.save(filter)
return Filter.of(filter)
}
companion object {
private val logger = LoggerFactory.getLogger(UserRegisterFilterApplicationService::class.java)
}
}

View File

@ -39,10 +39,6 @@ class UploadMediaApplicationService(
transaction,
logger
) {
companion object {
private val logger = LoggerFactory.getLogger(UploadMediaApplicationService::class.java)
}
override suspend fun internalExecute(command: UploadMedia, executor: CommandExecutor): Media {
val process = mediaProcessor.process(command.path, command.name, null)
val id = idGenerateService.generateId()
@ -69,4 +65,8 @@ class UploadMediaApplicationService(
return Media.of(media)
}
companion object {
private val logger = LoggerFactory.getLogger(UploadMediaApplicationService::class.java)
}
}

View File

@ -39,10 +39,6 @@ class RegisterLocalPostApplicationService(
transaction: Transaction,
) : AbstractApplicationService<RegisterLocalPost, Long>(transaction, Companion.logger) {
companion object {
val logger: Logger = LoggerFactory.getLogger(RegisterLocalPostApplicationService::class.java)
}
override suspend fun internalExecute(command: RegisterLocalPost, executor: CommandExecutor): Long {
val actorId = (
userDetailRepository.findById(command.userDetailId)
@ -67,4 +63,8 @@ class RegisterLocalPostApplicationService(
return post.id.id
}
companion object {
val logger: Logger = LoggerFactory.getLogger(RegisterLocalPostApplicationService::class.java)
}
}

View File

@ -36,10 +36,6 @@ class UserAcceptFollowRequestApplicationService(
private val userDetailRepository: UserDetailRepository,
) :
AbstractApplicationService<AcceptFollowRequest, Unit>(transaction, logger) {
companion object {
private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java)
}
override suspend fun internalExecute(command: AcceptFollowRequest, executor: CommandExecutor) {
require(executor is UserDetailGettableCommandExecutor)
@ -55,4 +51,8 @@ class UserAcceptFollowRequestApplicationService(
relationshipRepository.save(relationship)
}
companion object {
private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java)
}
}

View File

@ -38,10 +38,6 @@ class UserBlockApplicationService(
private val relationshipDomainService: RelationshipDomainService,
) :
AbstractApplicationService<Block, Unit>(transaction, logger) {
companion object {
private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java)
}
override suspend fun internalExecute(command: Block, executor: CommandExecutor) {
require(executor is UserDetailGettableCommandExecutor)
@ -65,4 +61,8 @@ class UserBlockApplicationService(
relationshipRepository.save(relationship)
relationshipRepository.save(inverseRelationship)
}
companion object {
private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java)
}
}

View File

@ -41,10 +41,6 @@ class GetRelationshipApplicationService(
transaction,
logger
) {
companion object {
private val logger = LoggerFactory.getLogger(GetRelationshipApplicationService::class.java)
}
override suspend fun internalExecute(command: GetRelationship, executor: CommandExecutor): Relationship {
require(executor is UserDetailGettableCommandExecutor)
val userDetail = userDetailRepository.findById(executor.userDetailId)!!
@ -70,4 +66,8 @@ class GetRelationshipApplicationService(
return Relationship.of(relationship, relationship1, actorInstanceRelationship)
}
companion object {
private val logger = LoggerFactory.getLogger(GetRelationshipApplicationService::class.java)
}
}

View File

@ -37,10 +37,6 @@ class UserMuteApplicationService(
private val userDetailRepository: UserDetailRepository,
) :
AbstractApplicationService<Mute, Unit>(transaction, logger) {
companion object {
private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java)
}
override suspend fun internalExecute(command: Mute, executor: CommandExecutor) {
require(executor is UserDetailGettableCommandExecutor)
@ -57,4 +53,8 @@ class UserMuteApplicationService(
relationshipRepository.save(relationship)
}
companion object {
private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java)
}
}

View File

@ -36,10 +36,6 @@ class UserRejectFollowRequestApplicationService(
private val userDetailRepository: UserDetailRepository,
) :
AbstractApplicationService<RejectFollowRequest, Unit>(transaction, logger) {
companion object {
private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java)
}
override suspend fun internalExecute(command: RejectFollowRequest, executor: CommandExecutor) {
require(executor is UserDetailGettableCommandExecutor)
@ -55,4 +51,8 @@ class UserRejectFollowRequestApplicationService(
relationshipRepository.save(relationship)
}
companion object {
private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java)
}
}

View File

@ -37,10 +37,6 @@ class UserRemoveFromFollowersApplicationService(
private val userDetailRepository: UserDetailRepository,
) :
AbstractApplicationService<RemoveFromFollowers, Unit>(transaction, logger) {
companion object {
private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java)
}
override suspend fun internalExecute(command: RemoveFromFollowers, executor: CommandExecutor) {
require(executor is UserDetailGettableCommandExecutor)
@ -57,4 +53,8 @@ class UserRemoveFromFollowersApplicationService(
relationshipRepository.save(relationship)
}
companion object {
private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java)
}
}

View File

@ -37,10 +37,6 @@ class UserUnblockApplicationService(
private val userDetailRepository: UserDetailRepository,
) :
AbstractApplicationService<Unblock, Unit>(transaction, logger) {
companion object {
private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java)
}
override suspend fun internalExecute(command: Unblock, executor: CommandExecutor) {
require(executor is UserDetailGettableCommandExecutor)
@ -57,4 +53,8 @@ class UserUnblockApplicationService(
relationshipRepository.save(relationship)
}
companion object {
private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java)
}
}

View File

@ -37,10 +37,6 @@ class UserUnfollowApplicationService(
private val userDetailRepository: UserDetailRepository,
) :
AbstractApplicationService<Unfollow, Unit>(transaction, logger) {
companion object {
private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java)
}
override suspend fun internalExecute(command: Unfollow, executor: CommandExecutor) {
require(executor is UserDetailGettableCommandExecutor)
@ -57,4 +53,8 @@ class UserUnfollowApplicationService(
relationshipRepository.save(relationship)
}
companion object {
private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java)
}
}

View File

@ -55,9 +55,7 @@ import org.springframework.security.web.authentication.LoginUrlAuthenticationEnt
@EnableWebSecurity(debug = true)
class SecurityConfig {
@Bean
fun passwordEncoder(): PasswordEncoder {
return BCryptPasswordEncoder()
}
fun passwordEncoder(): PasswordEncoder = BCryptPasswordEncoder()
@Bean
@Order(1)
@ -93,17 +91,16 @@ class SecurityConfig {
}
@Bean
fun registeredClientRepository(jdbcOperations: JdbcOperations): RegisteredClientRepository {
return JdbcRegisteredClientRepository(jdbcOperations)
}
fun registeredClientRepository(jdbcOperations: JdbcOperations): RegisteredClientRepository =
JdbcRegisteredClientRepository(jdbcOperations)
@Bean
@Suppress("FunctionMaxLength")
fun oauth2AuthorizationConsentService(
jdbcOperations: JdbcOperations,
registeredClientRepository: RegisteredClientRepository,
): OAuth2AuthorizationConsentService {
return JdbcOAuth2AuthorizationConsentService(jdbcOperations, registeredClientRepository)
}
): OAuth2AuthorizationConsentService =
JdbcOAuth2AuthorizationConsentService(jdbcOperations, registeredClientRepository)
@Bean
fun authorizationServerSettings(): AuthorizationServerSettings {

View File

@ -21,9 +21,8 @@ import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEvent
import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventBody
class RelationshipEventFactory(private val relationship: Relationship) {
fun createEvent(relationshipEvent: RelationshipEvent): DomainEvent {
return DomainEvent.create(relationshipEvent.eventName, RelationshipEventBody(relationship))
}
fun createEvent(relationshipEvent: RelationshipEvent): DomainEvent =
DomainEvent.create(relationshipEvent.eventName, RelationshipEventBody(relationship))
}
class RelationshipEventBody(relationship: Relationship) : DomainEventBody(mapOf("relationship" to relationship))

View File

@ -26,7 +26,7 @@ import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventStorable
import java.net.URI
import java.time.Instant
@Suppress("LongParameterList")
@Suppress("LongParameterList", "ClassOrdering")
class Actor(
val id: ActorId,
val name: ActorName,
@ -96,7 +96,7 @@ class Actor(
var alsoKnownAs = alsoKnownAs
set(value) {
require(value.find { it == id } == null)
require(value.none { it == id })
field = value
}

View File

@ -17,10 +17,10 @@
package dev.usbharu.hideout.core.domain.model.actor
class ActorDescription(description: String) {
val description: String = description.take(length)
val description: String = description.take(LENGTH)
companion object {
val length = 10000
const val LENGTH = 10000
val empty = ActorDescription("")
}
}

View File

@ -20,12 +20,12 @@ package dev.usbharu.hideout.core.domain.model.actor
value class ActorName(val name: String) {
init {
require(name.isNotBlank())
require(name.length <= length)
require(name.length <= LENGTH)
require(regex.matches(name))
}
companion object {
val length = 300
private val regex = Regex("^[a-zA-Z0-9_-]{1,$length}\$")
const val LENGTH = 300
private val regex = Regex("^[a-zA-Z0-9_-]{1,$LENGTH}\$")
}
}

View File

@ -18,10 +18,10 @@ package dev.usbharu.hideout.core.domain.model.actor
class ActorScreenName(screenName: String) {
val screenName: String = screenName.take(length)
val screenName: String = screenName.take(LENGTH)
companion object {
val length = 300
const val LENGTH = 300
val empty = ActorScreenName("")
}
}

View File

@ -1,17 +1,7 @@
package dev.usbharu.hideout.core.domain.model.filter
import dev.usbharu.hideout.core.domain.model.filter.FilterMode.*
class FilterKeyword(
val id: FilterKeywordId,
var keyword: FilterKeywordKeyword,
val mode: FilterMode
) {
fun match(string: String): Boolean {
when (mode) {
WHOLE_WORD -> TODO()
REGEX -> TODO()
NONE -> TODO()
}
}
}
)

View File

@ -53,7 +53,5 @@ class Instance(
return id == other.id
}
override fun hashCode(): Int {
return id.hashCode()
}
override fun hashCode(): Int = id.hashCode()
}

View File

@ -28,7 +28,7 @@ import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventStorable
import java.net.URI
import java.time.Instant
@Suppress("LongParameterList", "TooManyFunctions")
@Suppress("LongParameterList", "TooManyFunctions", "ClassOrdering")
class Post(
val id: PostId,
actorId: ActorId,

View File

@ -21,6 +21,7 @@ import dev.usbharu.hideout.core.domain.event.relationship.RelationshipEventFacto
import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventStorable
@Suppress("TooManyFunctions")
class Relationship(
val actorId: ActorId,
val targetActorId: ActorId,

View File

@ -35,7 +35,14 @@ class ActorQueryMapper(private val actorResultRowMapper: ResultRowMapper<Actor>)
.first()
.let(actorResultRowMapper::map)
.apply {
alsoKnownAs = it.mapNotNull { resultRow: ResultRow ->
alsoKnownAs = buildAlsoKnownAs(it)
clearDomainEvents()
}
}
}
private fun buildAlsoKnownAs(it: List<ResultRow>) =
it.mapNotNull { resultRow: ResultRow ->
resultRow.getOrNull(
ActorsAlsoKnownAs.alsoKnownAs
)?.let { actorId ->
@ -44,8 +51,4 @@ class ActorQueryMapper(private val actorResultRowMapper: ResultRowMapper<Actor>)
)
}
}.toSet()
clearDomainEvents()
}
}
}
}

View File

@ -25,11 +25,13 @@ import org.springframework.stereotype.Component
@Component
class FilterResultRowMapper : ResultRowMapper<Filter> {
override fun map(resultRow: ResultRow): Filter = Filter(
FilterId(resultRow[Filters.id]),
UserDetailId(resultRow[Filters.userId]),
FilterName(resultRow[Filters.name]),
resultRow[Filters.context].split(",").filter { it.isNotEmpty() }.map { FilterContext.valueOf(it) }.toSet(),
FilterAction.valueOf(resultRow[Filters.filterAction]),
emptySet()
id = FilterId(resultRow[Filters.id]),
userDetailId = UserDetailId(resultRow[Filters.userId]),
name = FilterName(resultRow[Filters.name]),
filterContext = resultRow[Filters.context].split(",").filter {
it.isNotEmpty()
}.map { FilterContext.valueOf(it) }.toSet(),
filterAction = FilterAction.valueOf(resultRow[Filters.filterAction]),
filterKeywords = emptySet()
)
}

View File

@ -39,6 +39,12 @@ class PostQueryMapper(private val postResultRowMapper: ResultRowMapper<Post>) :
.first()
.let(postResultRowMapper::map)
.apply {
buildPost(it)
}
}
}
private fun Post.buildPost(it: List<ResultRow>) {
reconstructWith(
mediaIds = it.mapNotNull { resultRow: ResultRow ->
resultRow
@ -59,5 +65,3 @@ class PostQueryMapper(private val postResultRowMapper: ResultRowMapper<Post>) :
)
}
}
}
}

View File

@ -105,10 +105,10 @@ class ExposedActorRepository(
object Actors : Table("actors") {
val id = long("id")
val name = varchar("name", ActorName.length)
val name = varchar("name", ActorName.LENGTH)
val domain = varchar("domain", Domain.LENGTH)
val screenName = varchar("screen_name", ActorScreenName.length)
val description = varchar("description", ActorDescription.length)
val screenName = varchar("screen_name", ActorScreenName.LENGTH)
val description = varchar("description", ActorDescription.LENGTH)
val inbox = varchar("inbox", 1000).uniqueIndex()
val outbox = varchar("outbox", 1000).uniqueIndex()
val url = varchar("url", 1000).uniqueIndex()

View File

@ -34,12 +34,12 @@ class ExposedFilterRepository(private val filterQueryMapper: QueryMapper<Filter>
get() = Companion.logger
override suspend fun save(filter: Filter): Filter = query {
Filters.upsert {
it[id] = filter.id.id
it[userId] = filter.userDetailId.id
it[name] = filter.name.name
it[context] = filter.filterContext.joinToString(",") { it.name }
it[filterAction] = filter.filterAction.name
Filters.upsert { upsertStatement ->
upsertStatement[id] = filter.id.id
upsertStatement[userId] = filter.userDetailId.id
upsertStatement[name] = filter.name.name
upsertStatement[context] = filter.filterContext.joinToString(",") { it.name }
upsertStatement[filterAction] = filter.filterAction.name
}
FilterKeywords.deleteWhere {
filterId eq filter.id.id

View File

@ -35,6 +35,7 @@ class PostFactoryImpl(
private val postContentFactoryImpl: PostContentFactoryImpl,
private val applicationConfig: ApplicationConfig,
) {
@Suppress("LongParameterList")
suspend fun createLocal(
actor: Actor,
actorName: ActorName,

View File

@ -28,6 +28,7 @@ class FFmpegVideoProcessor(
override fun isSupported(mimeType: MimeType): Boolean =
mimeType.fileType == FileType.Video || mimeType.type == "video"
@Suppress("LongMethod", "CyclomaticComplexMethod", "CognitiveComplexMethod", "NestedBlockDepth")
override suspend fun process(path: Path, filename: String, mimeType: MimeType?): ProcessedMedia {
val tempFile = Files.createTempFile("hideout-movie-processor-", ".tmp")
val thumbnailFile = Files.createTempFile("hideout-movie-thumbnail-generate-", ".tmp")

View File

@ -8,6 +8,6 @@ class ActorScreenNameTest {
fun screenNameがlengthを超えると無視される() {
val actorScreenName = ActorScreenName("a".repeat(1000))
assertEquals(ActorScreenName.length, actorScreenName.screenName.length)
assertEquals(ActorScreenName.LENGTH, actorScreenName.screenName.length)
}
}

View File

@ -2,5 +2,13 @@
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:recommended"
]
],
"autoApprove": true,
"platformAutomerge": true,
"prHourlyLimit": 0,
"labels": [
"dependencies",
"renovate"
],
"prConcurrentLimit": 5
}