diff --git a/build.sbt b/build.sbt index 2e3bee7b..2d6b9f9c 100644 --- a/build.sbt +++ b/build.sbt @@ -155,7 +155,7 @@ lazy val pitgull = "io.chrisdavenport" %% "cats-time" % "0.3.4", "com.github.valskalla" %% "odin-core" % "0.11.0", "com.github.valskalla" %% "odin-slf4j" % "0.11.0", - "io.github.vigoo" %% "prox" % "0.5.2" + "io.github.vigoo" %% "prox-fs2" % "0.6.0" ) ) .dependsOn(core, gitlab) diff --git a/src/main/scala/io/pg/config/ProjectConfig.scala b/src/main/scala/io/pg/config/ProjectConfig.scala index d6c4a2db..5e7a8c37 100644 --- a/src/main/scala/io/pg/config/ProjectConfig.scala +++ b/src/main/scala/io/pg/config/ProjectConfig.scala @@ -1,17 +1,16 @@ package io.pg.config -import cats.effect.Blocker +import cats.Applicative +import cats.MonadThrow import cats.effect.ExitCode -import cats.effect.Concurrent -import cats.effect.ContextShift import cats.syntax.all._ -import java.nio.file.Paths -import io.github.vigoo.prox._ -import scala.util.chaining._ -import cats.Applicative import cats.tagless.finalAlg +import io.github.vigoo.prox.ProxFS2 import io.pg.gitlab.webhook.Project +import java.nio.file.Paths +import scala.util.chaining._ + @finalAlg trait ProjectConfigReader[F[_]] { def readConfig(project: Project): F[ProjectConfig] @@ -55,9 +54,10 @@ object ProjectConfigReader { def readConfig(project: Project): F[ProjectConfig] = config.pure[F] } - def dhallJsonStringConfig[F[_]: Concurrent: ContextShift]( - blocker: Blocker - ): F[ProjectConfigReader[F]] = { + def dhallJsonStringConfig[F[_]: ProxFS2: MonadThrow]: F[ProjectConfigReader[F]] = { + val prox: ProxFS2[F] = implicitly + import prox.{contextShift => _, blocker => _, concurrent => _, _} + val dhallCommand = "dhall-to-json" //todo: not reading a local file val filePath = "./example.dhall" @@ -67,27 +67,25 @@ object ProjectConfigReader { _.exitCode == ExitCode.Success ) - implicit val runner: ProcessRunner[F] = new JVMProcessRunner - val instance: ProjectConfigReader[F] = new ProjectConfigReader[F] { + implicit val runner: ProcessRunner[JVMProcessInfo] = new JVMProcessRunner - def readConfig(project: Project): F[ProjectConfig] = { - val input = fs2.io.file.readAll[F](Paths.get(filePath), blocker, 4096) + val instance: ProjectConfigReader[F] = new ProjectConfigReader[F] { - Process[F](dhallCommand) + def readConfig(project: Project): F[ProjectConfig] = + Process(dhallCommand) .`with`("TOKEN" -> "demo-token") - .fromStream(input, flushChunks = true) + .fromFile(Paths.get(filePath)) .toFoldMonoid(fs2.text.utf8Decode[F]) - .run(blocker) + .run() .pipe(checkExitCode) .map(_.output) .flatMap(io.circe.parser.decode[ProjectConfig](_).liftTo[F]) - } } val ensureCommandExists = - Process[F]("bash", "-c" :: s"command -v $dhallCommand" :: Nil) + Process("bash", "-c" :: s"command -v $dhallCommand" :: Nil) .drainOutput(_.drain) - .run(blocker) + .run() .pipe(checkExitCode) .adaptError { case e => new Throwable(s"Command $dhallCommand not found", e)