@@ -240,25 +240,36 @@ addYear proj =
240
240
getYearFromGithub : String -> Env -> BackendTask FatalError Year
241
241
getYearFromGithub repoName env =
242
242
let
243
- dateDecoder =
243
+ dateDecoder fields =
244
244
Iso8601 . decoder
245
245
|> Json . Decode . map ( Date . fromPosix Time . utc)
246
-
247
- yearDecoder =
248
- Json . Decode . map2 Range
249
- ( Json . Decode . field " created_at" dateDecoder)
250
- ( Json . Decode . field " pushed_at" dateDecoder)
246
+ |> Json . Decode . at fields
247
+
248
+ startDate =
249
+ BackendTask . Http . getWithOptions
250
+ { url = " https://api.github.com/repos/" ++ repoName
251
+ , expect = BackendTask . Http . expectJson ( dateDecoder [ " created_at" ] )
252
+ , headers = githubApiAuthHeader env
253
+ , cacheStrategy = Nothing
254
+ , retries = Nothing
255
+ , timeoutInMs = Nothing
256
+ , cachePath = Nothing
257
+ }
258
+ |> BackendTask . allowFatal
259
+
260
+ endDate =
261
+ BackendTask . Http . getWithOptions
262
+ { url = " https://api.github.com/repos/" ++ repoName ++ " /commits?per_page=1"
263
+ , expect = BackendTask . Http . expectJson ( Json . Decode . index 0 <| dateDecoder [ " commit" , " author" , " date" ] )
264
+ , headers = githubApiAuthHeader env
265
+ , cacheStrategy = Nothing
266
+ , retries = Nothing
267
+ , timeoutInMs = Nothing
268
+ , cachePath = Nothing
269
+ }
270
+ |> BackendTask . allowFatal
251
271
in
252
- BackendTask . Http . getWithOptions
253
- { url = " https://api.github.com/repos/" ++ repoName
254
- , expect = BackendTask . Http . expectJson yearDecoder
255
- , headers = githubApiAuthHeader env
256
- , cacheStrategy = Nothing
257
- , retries = Nothing
258
- , timeoutInMs = Nothing
259
- , cachePath = Nothing
260
- }
261
- |> BackendTask . allowFatal
272
+ BackendTask . map2 Range startDate endDate
262
273
263
274
264
275
0 commit comments