~jan0sch/smederee
Showing details for patch 96e73f03ac46c9c2012561b7986414fdc789faee.
diff -rN -u old-smederee/modules/hub/src/it/scala/de/smederee/hub/BaseSpec.scala new-smederee/modules/hub/src/it/scala/de/smederee/hub/BaseSpec.scala --- old-smederee/modules/hub/src/it/scala/de/smederee/hub/BaseSpec.scala 2025-01-31 19:52:26.165316084 +0000 +++ new-smederee/modules/hub/src/it/scala/de/smederee/hub/BaseSpec.scala 2025-01-31 19:52:26.165316084 +0000 @@ -281,6 +281,38 @@ } yield columns } + /** Find the repository ID for the given owner and repository name. + * + * @param owner + * The unique ID of the user account that owns the repository. + * @param name + * The repository name which must be unique in regard to the owner. + * @return + * An option to the internal database ID. + */ + @throws[java.sql.SQLException]("Errors from the underlying SQL procedures will throw exceptions!") + protected def loadVcsRepositoryId(owner: UserId, name: VcsRepositoryName): IO[Option[Long]] = + connectToDb(configuration).use { con => + for { + statement <- IO.delay( + con.prepareStatement( + """SELECT id FROM "repositories" WHERE owner = ? AND name = ? LIMIT 1""" + ) + ) + _ <- IO.delay(statement.setObject(1, owner)) + _ <- IO.delay(statement.setString(2, name.toString)) + result <- IO.delay(statement.executeQuery) + account <- IO.delay { + if (result.next()) { + Option(result.getLong("id")) + } else { + None + } + } + _ <- IO(statement.close()) + } yield account + } + /** Delete the given directory recursively. * * @param path diff -rN -u old-smederee/modules/hub/src/it/scala/de/smederee/hub/DoobieVcsMetadataRepositoryTest.scala new-smederee/modules/hub/src/it/scala/de/smederee/hub/DoobieVcsMetadataRepositoryTest.scala --- old-smederee/modules/hub/src/it/scala/de/smederee/hub/DoobieVcsMetadataRepositoryTest.scala 2025-01-31 19:52:26.165316084 +0000 +++ new-smederee/modules/hub/src/it/scala/de/smederee/hub/DoobieVcsMetadataRepositoryTest.scala 2025-01-31 19:52:26.165316084 +0000 @@ -32,38 +32,6 @@ final class DoobieVcsMetadataRepositoryTest extends BaseSpec { - /** Find the repository ID for the given owner and repository name. - * - * @param owner - * The unique ID of the user account that owns the repository. - * @param name - * The repository name which must be unique in regard to the owner. - * @return - * An option to the internal database ID. - */ - @throws[java.sql.SQLException]("Errors from the underlying SQL procedures will throw exceptions!") - protected def findVcsRepositoryId(owner: UserId, name: VcsRepositoryName): IO[Option[Long]] = - connectToDb(configuration).use { con => - for { - statement <- IO.delay( - con.prepareStatement( - """SELECT id FROM "repositories" WHERE owner = ? AND name = ? LIMIT 1""" - ) - ) - _ <- IO.delay(statement.setObject(1, owner)) - _ <- IO.delay(statement.setString(2, name.toString)) - result <- IO.delay(statement.executeQuery) - account <- IO.delay { - if (result.next()) { - Option(result.getLong("id")) - } else { - None - } - } - _ <- IO(statement.close()) - } yield account - } - /** Find all forks of the original repository with the given ID. * * @param originalRepoId @@ -123,10 +91,10 @@ ) written <- vcsRepositories.traverse(repo.createVcsRepository) original <- vcsRepositories.headOption.traverse(vcsRepository => - findVcsRepositoryId(vcsRepository.owner.uid, vcsRepository.name) + loadVcsRepositoryId(vcsRepository.owner.uid, vcsRepository.name) ) toFork <- vcsRepositories.drop(1).take(5).traverse { vcsRepository => - findVcsRepositoryId(vcsRepository.owner.uid, vcsRepository.name) + loadVcsRepositoryId(vcsRepository.owner.uid, vcsRepository.name) } forked <- (original, toFork) match { case (Some(Some(originalId)), forkIds) => forkIds.flatten.traverse(id => repo.createFork(originalId, id)) @@ -220,7 +188,7 @@ } } - test("findVcsRepositoryId must return the id of an existing repository") { + test("loadVcsRepositoryId must return the id of an existing repository") { (genValidAccount.sample, genValidVcsRepository.sample) match { case (Some(account), Some(repository)) => val vcsRepository = repository.copy(owner = account.toVcsRepositoryOwner) @@ -230,7 +198,7 @@ val test = for { _ <- createAccount(account, PasswordHash("I am not a password hash!"), None, None) writtenRows <- repo.createVcsRepository(vcsRepository) - writtenId <- findVcsRepositoryId(vcsRepository.owner.uid, vcsRepository.name) + writtenId <- loadVcsRepositoryId(vcsRepository.owner.uid, vcsRepository.name) foundId <- repo.findVcsRepositoryId(vcsRepository.owner, vcsRepository.name) } yield (writtenRows, writtenId, foundId) test.map { result => @@ -288,10 +256,10 @@ ) written <- vcsRepositories.traverse(repo.createVcsRepository) original <- vcsRepositories.headOption.traverse(vcsRepository => - findVcsRepositoryId(vcsRepository.owner.uid, vcsRepository.name) + loadVcsRepositoryId(vcsRepository.owner.uid, vcsRepository.name) ) toFork <- vcsRepositories.drop(1).take(5).traverse { vcsRepository => - findVcsRepositoryId(vcsRepository.owner.uid, vcsRepository.name) + loadVcsRepositoryId(vcsRepository.owner.uid, vcsRepository.name) } forked <- (original, toFork) match { case (Some(Some(originalId)), forkIds) => forkIds.flatten.traverse(id => repo.createFork(originalId, id)) diff -rN -u old-smederee/modules/hub/src/it/scala/de/smederee/tickets/DoobieLabelRepositoryTest.scala new-smederee/modules/hub/src/it/scala/de/smederee/tickets/DoobieLabelRepositoryTest.scala --- old-smederee/modules/hub/src/it/scala/de/smederee/tickets/DoobieLabelRepositoryTest.scala 2025-01-31 19:52:26.165316084 +0000 +++ new-smederee/modules/hub/src/it/scala/de/smederee/tickets/DoobieLabelRepositoryTest.scala 2025-01-31 19:52:26.165316084 +0000 @@ -33,38 +33,6 @@ final class DoobieLabelRepositoryTest extends BaseSpec { - /** Find the repository ID for the given owner and repository name. - * - * @param owner - * The unique ID of the user account that owns the repository. - * @param name - * The repository name which must be unique in regard to the owner. - * @return - * An option to the internal database ID. - */ - @throws[java.sql.SQLException]("Errors from the underlying SQL procedures will throw exceptions!") - protected def findVcsRepositoryId(owner: UserId, name: VcsRepositoryName): IO[Option[Long]] = - connectToDb(configuration).use { con => - for { - statement <- IO.delay( - con.prepareStatement( - """SELECT id FROM "repositories" WHERE owner = ? AND name = ? LIMIT 1""" - ) - ) - _ <- IO.delay(statement.setObject(1, owner)) - _ <- IO.delay(statement.setString(2, name.toString)) - result <- IO.delay(statement.executeQuery) - account <- IO.delay { - if (result.next()) { - Option(result.getLong("id")) - } else { - None - } - } - _ <- IO(statement.close()) - } yield account - } - /** Find the label ID for the given repository and label name. * * @param owner @@ -129,7 +97,7 @@ val test = for { _ <- createAccount(account, PasswordHash("I am not a password hash!"), None, None) createdRepos <- vcsRepo.createVcsRepository(vcsRepository) - repoId <- findVcsRepositoryId(account.uid, vcsRepository.name) + repoId <- loadVcsRepositoryId(account.uid, vcsRepository.name) createdLabels <- repoId match { case None => IO.pure(List.empty) case Some(repoId) => labels.traverse(label => labelRepo.createLabel(repoId)(label)) @@ -160,7 +128,7 @@ val test = for { _ <- createAccount(account, PasswordHash("I am not a password hash!"), None, None) createdRepos <- vcsRepo.createVcsRepository(vcsRepository) - repoId <- findVcsRepositoryId(account.uid, vcsRepository.name) + repoId <- loadVcsRepositoryId(account.uid, vcsRepository.name) createdLabels <- repoId.traverse(id => labelRepo.createLabel(id)(label)) foundLabel <- repoId.traverse(id => labelRepo.findLabel(id)(label.name)) } yield (createdRepos, repoId, createdLabels, foundLabel) @@ -192,7 +160,7 @@ val test = for { _ <- createAccount(account, PasswordHash("I am not a password hash!"), None, None) createdRepos <- vcsRepo.createVcsRepository(vcsRepository) - repoId <- findVcsRepositoryId(account.uid, vcsRepository.name) + repoId <- loadVcsRepositoryId(account.uid, vcsRepository.name) createdLabels <- repoId.traverse(id => labelRepo.createLabel(id)(label)) _ <- repoId.traverse(id => labelRepo.createLabel(id)(label)) } yield (createdRepos, repoId, createdLabels) @@ -212,7 +180,7 @@ val test = for { _ <- createAccount(account, PasswordHash("I am not a password hash!"), None, None) createdRepos <- vcsRepo.createVcsRepository(vcsRepository) - repoId <- findVcsRepositoryId(account.uid, vcsRepository.name) + repoId <- loadVcsRepositoryId(account.uid, vcsRepository.name) createdLabels <- repoId.traverse(id => labelRepo.createLabel(id)(label)) labelId <- findLabelId(account.uid, vcsRepository.name, label.name) deletedLabels <- labelRepo.deleteLabel(label.copy(id = labelId.flatMap(LabelId.from))) @@ -242,7 +210,7 @@ val test = for { _ <- createAccount(account, PasswordHash("I am not a password hash!"), None, None) createdRepos <- vcsRepo.createVcsRepository(vcsRepository) - repoId <- findVcsRepositoryId(account.uid, vcsRepository.name) + repoId <- loadVcsRepositoryId(account.uid, vcsRepository.name) createdLabels <- repoId match { case None => IO.pure(List.empty) case Some(repoId) => labels.traverse(label => labelRepo.createLabel(repoId)(label)) @@ -272,7 +240,7 @@ val test = for { _ <- createAccount(account, PasswordHash("I am not a password hash!"), None, None) createdRepos <- vcsRepo.createVcsRepository(vcsRepository) - repoId <- findVcsRepositoryId(account.uid, vcsRepository.name) + repoId <- loadVcsRepositoryId(account.uid, vcsRepository.name) createdLabels <- repoId.traverse(id => labelRepo.createLabel(id)(label)) labelId <- findLabelId(account.uid, vcsRepository.name, label.name) updatedLabels <- labelRepo.updateLabel(updatedLabel.copy(id = labelId.map(LabelId.apply))) @@ -310,7 +278,7 @@ val test = for { _ <- createAccount(account, PasswordHash("I am not a password hash!"), None, None) createdRepos <- vcsRepo.createVcsRepository(vcsRepository) - repoId <- findVcsRepositoryId(account.uid, vcsRepository.name) + repoId <- loadVcsRepositoryId(account.uid, vcsRepository.name) createdLabels <- repoId.traverse(id => labelRepo.createLabel(id)(label)) labelId <- findLabelId(account.uid, vcsRepository.name, label.name) updatedLabels <- labelRepo.updateLabel(updatedLabel)