Skip to content

Commit a39917d

Browse files
committed
Fix date range for projects
1 parent c23a627 commit a39917d

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

src/Project.elm

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -240,25 +240,36 @@ addYear proj =
240240
getYearFromGithub : String -> Env -> BackendTask FatalError Year
241241
getYearFromGithub repoName env =
242242
let
243-
dateDecoder =
243+
dateDecoder fields =
244244
Iso8601.decoder
245245
|> 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
251271
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
262273

263274

264275

0 commit comments

Comments
 (0)