1
1
package io .pg .config
2
2
3
- import cats .effect .Blocker
3
+ import cats .Applicative
4
+ import cats .MonadThrow
4
5
import cats .effect .ExitCode
5
- import cats .effect .Concurrent
6
- import cats .effect .ContextShift
7
6
import cats .syntax .all ._
8
- import java .nio .file .Paths
9
- import io .github .vigoo .prox ._
10
- import scala .util .chaining ._
11
- import cats .Applicative
12
7
import cats .tagless .finalAlg
8
+ import io .github .vigoo .prox .ProxFS2
13
9
import io .pg .gitlab .webhook .Project
14
10
11
+ import java .nio .file .Paths
12
+ import scala .util .chaining ._
13
+
15
14
@ finalAlg
16
15
trait ProjectConfigReader [F [_]] {
17
16
def readConfig (project : Project ): F [ProjectConfig ]
@@ -55,9 +54,10 @@ object ProjectConfigReader {
55
54
def readConfig (project : Project ): F [ProjectConfig ] = config.pure[F ]
56
55
}
57
56
58
- def dhallJsonStringConfig [F [_]: Concurrent : ContextShift ](
59
- blocker : Blocker
60
- ): F [ProjectConfigReader [F ]] = {
57
+ def dhallJsonStringConfig [F [_]: ProxFS2 : MonadThrow ]: F [ProjectConfigReader [F ]] = {
58
+ val prox : ProxFS2 [F ] = implicitly
59
+ import prox .{contextShift => _ , blocker => _ , concurrent => _ , _ }
60
+
61
61
val dhallCommand = " dhall-to-json"
62
62
// todo: not reading a local file
63
63
val filePath = " ./example.dhall"
@@ -67,27 +67,25 @@ object ProjectConfigReader {
67
67
_.exitCode == ExitCode .Success
68
68
)
69
69
70
- implicit val runner : ProcessRunner [F ] = new JVMProcessRunner
71
- val instance : ProjectConfigReader [F ] = new ProjectConfigReader [F ] {
70
+ implicit val runner : ProcessRunner [JVMProcessInfo ] = new JVMProcessRunner
72
71
73
- def readConfig (project : Project ): F [ProjectConfig ] = {
74
- val input = fs2.io.file.readAll[F ](Paths .get(filePath), blocker, 4096 )
72
+ val instance : ProjectConfigReader [F ] = new ProjectConfigReader [F ] {
75
73
76
- Process [F ](dhallCommand)
74
+ def readConfig (project : Project ): F [ProjectConfig ] =
75
+ Process (dhallCommand)
77
76
.`with`(" TOKEN" -> " demo-token" )
78
- .fromStream(input, flushChunks = true )
77
+ .fromFile( Paths .get(filePath) )
79
78
.toFoldMonoid(fs2.text.utf8Decode[F ])
80
- .run(blocker )
79
+ .run()
81
80
.pipe(checkExitCode)
82
81
.map(_.output)
83
82
.flatMap(io.circe.parser.decode[ProjectConfig ](_).liftTo[F ])
84
- }
85
83
}
86
84
87
85
val ensureCommandExists =
88
- Process [ F ] (" bash" , " -c" :: s " command -v $dhallCommand" :: Nil )
86
+ Process (" bash" , " -c" :: s " command -v $dhallCommand" :: Nil )
89
87
.drainOutput(_.drain)
90
- .run(blocker )
88
+ .run()
91
89
.pipe(checkExitCode)
92
90
.adaptError { case e =>
93
91
new Throwable (s " Command $dhallCommand not found " , e)
0 commit comments