@@ -18,16 +18,17 @@ module Registry.App.Effect.GitHub
18
18
19
19
import Registry.App.Prelude
20
20
21
- import Data.Argonaut.Parser as Argonaut.Parser
22
- import Data.Codec.Argonaut as CA
23
- import Data.Codec.Argonaut .Common as CA .Common
24
- import Data.Codec.Argonaut .Record as CA .Record
21
+ import Codec.JSON.DecodeError as CJ.DecodeError
22
+ import Data.Codec.JSON as CJ
23
+ import Data.Codec.JSON .Common as CJ .Common
24
+ import Data.Codec.JSON .Record as CJ .Record
25
25
import Data.DateTime (DateTime )
26
26
import Data.DateTime as DateTime
27
27
import Data.Exists as Exists
28
28
import Data.HTTP.Method (Method (..))
29
29
import Data.Time.Duration as Duration
30
30
import Foreign.Object as Object
31
+ import JSON as JSON
31
32
import Registry.App.Effect.Cache (class FsEncodable , class MemoryEncodable , Cache , CacheRef , FsEncoding (..), MemoryEncoding (..))
32
33
import Registry.App.Effect.Cache as Cache
33
34
import Registry.App.Effect.Env (RESOURCE_ENV )
@@ -67,7 +68,7 @@ instance MemoryEncodable GitHubCache where
67
68
instance FsEncodable GitHubCache where
68
69
encodeFs = case _ of
69
70
Request route next -> do
70
- let codec = CA .Common .either Octokit .githubErrorCodec requestResultCodec
71
+ let codec = CJ .Common .either Octokit .githubErrorCodec requestResultCodec
71
72
Exists .mkExists $ AsJson (" Request__" <> Octokit .printGitHubRoute route) codec next
72
73
73
74
data GitHub a
@@ -99,14 +100,14 @@ getContent :: forall r. Address -> RawVersion -> FilePath -> Run (GITHUB + r) (E
99
100
getContent address (RawVersion ref) path = Run .lift _github (GetContent address ref path identity)
100
101
101
102
-- | Read the content of a JSON file in the provided repo, decoding its contents.
102
- getJsonFile :: forall r a . Address -> RawVersion -> JsonCodec a -> FilePath -> Run (GITHUB + r ) (Either GitHubError a )
103
+ getJsonFile :: forall r a . Address -> RawVersion -> CJ.Codec a -> FilePath -> Run (GITHUB + r ) (Either GitHubError a )
103
104
getJsonFile address ref codec path = do
104
105
content <- getContent address ref path
105
106
let
106
- attemptDecode inner = case Argonaut.Parser .jsonParser (JsonRepair .tryRepair inner) of
107
+ attemptDecode inner = case JSON .parse (JsonRepair .tryRepair inner) of
107
108
Left jsonError -> Left $ Octokit.DecodeError $ " Not Json: " <> jsonError
108
- Right json -> case CA .decode codec json of
109
- Left decodeError -> Left $ Octokit.DecodeError $ CA .printJsonDecodeError decodeError
109
+ Right json -> case CJ .decode codec json of
110
+ Left decodeError -> Left $ Octokit.DecodeError $ CJ.DecodeError .print decodeError
110
111
Right decoded -> Right decoded
111
112
pure $ attemptDecode =<< content
112
113
@@ -178,7 +179,7 @@ request octokit githubRequest@{ route: route@(GitHubRoute method _ _), codec } =
178
179
case entry of
179
180
Nothing -> do
180
181
result <- requestWithBackoff octokit githubRequest
181
- Cache .put _githubCache (Request route) (result <#> \response -> { modified: now, etag: Nothing , response: CA .encode codec response })
182
+ Cache .put _githubCache (Request route) (result <#> \response -> { modified: now, etag: Nothing , response: CJ .encode codec response })
182
183
pure result
183
184
184
185
Just cached -> case cached of
@@ -195,9 +196,9 @@ request octokit githubRequest@{ route: route@(GitHubRoute method _ _), codec } =
195
196
Cache .delete _githubCache (Request route)
196
197
request octokit githubRequest
197
198
198
- Right prevResponse -> case CA .decode codec prevResponse.response of
199
+ Right prevResponse -> case CJ .decode codec prevResponse.response of
199
200
Left err -> do
200
- Log .debug $ " Could not decode previous response data using the provided codec: " <> CA .printJsonDecodeError err
201
+ Log .debug $ " Could not decode previous response data using the provided codec: " <> CJ.DecodeError .print err
201
202
Log .debug $ " This indicates an out-of-date cache entry. Clearing cache for route " <> printedRoute
202
203
Cache .delete _githubCache (Request route)
203
204
Log .debug " Retrying request..."
@@ -216,7 +217,7 @@ request octokit githubRequest@{ route: route@(GitHubRoute method _ _), codec } =
216
217
Right decoded | Just etag <- prevResponse.etag -> do
217
218
Log .debug $ " Found valid cache entry with etags for " <> printedRoute
218
219
let headers = Object .insert " If-None-Match" etag githubRequest.headers
219
- Log .debug $ " Verifying cached status with headers: " <> stringifyJson (CA .Common .foreignObject CA .string) headers
220
+ Log .debug $ " Verifying cached status with headers: " <> stringifyJson (CJ .Common .foreignObject CJ .string) headers
220
221
let modifiedRequest = githubRequest { headers = headers }
221
222
conditionalResponse <- requestWithBackoff octokit modifiedRequest
222
223
case conditionalResponse of
@@ -234,7 +235,7 @@ request octokit githubRequest@{ route: route@(GitHubRoute method _ _), codec } =
234
235
Cache .put _githubCache (Request route) (Left otherError)
235
236
pure (Left otherError)
236
237
Right valid -> do
237
- Cache .put _githubCache (Request route) (Right { response: CA .encode codec valid, modified: now, etag: Nothing })
238
+ Cache .put _githubCache (Request route) (Right { response: CJ .encode codec valid, modified: now, etag: Nothing })
238
239
pure $ Right valid
239
240
240
241
-- Since we don't have support for conditional requests via etags, we'll instead
@@ -244,7 +245,7 @@ request octokit githubRequest@{ route: route@(GitHubRoute method _ _), codec } =
244
245
Right _ | DateTime .diff now prevResponse.modified >= Duration.Hours 4.0 -> do
245
246
Log .debug $ " Found cache entry but it was modified more than 4 hours ago, refetching " <> printedRoute
246
247
result <- requestWithBackoff octokit githubRequest
247
- Cache .put _githubCache (Request route) (result <#> \resp -> { response: CA .encode codec resp, modified: now, etag: Nothing })
248
+ Cache .put _githubCache (Request route) (result <#> \resp -> { response: CJ .encode codec resp, modified: now, etag: Nothing })
248
249
pure result
249
250
250
251
Right decoded -> do
@@ -285,12 +286,12 @@ requestWithBackoff octokit githubRequest = do
285
286
type RequestResult =
286
287
{ modified :: DateTime
287
288
, etag :: Maybe String
288
- , response :: Json
289
+ , response :: JSON
289
290
}
290
291
291
- requestResultCodec :: JsonCodec RequestResult
292
- requestResultCodec = CA.Record .object " RequestResult"
293
- { etag: CA .Common .maybe CA .string
292
+ requestResultCodec :: CJ.Codec RequestResult
293
+ requestResultCodec = CJ .named " RequestResult" $ CJ.Record .object
294
+ { etag: CJ .Common .maybe CJ .string
294
295
, modified: Internal.Codec .iso8601DateTime
295
- , response: CA .json
296
+ , response: CJ .json
296
297
}
0 commit comments