From 1fe41edabe92a5e775d860283e6ebf80003c2e23 Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Sun, 28 Feb 2016 08:30:25 +0000 Subject: [PATCH] Fix homepage repo table: Failed for empty repos --- src/Vervis/Git.hs | 6 ++++-- src/Vervis/Handler/Home.hs | 15 ++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Vervis/Git.hs b/src/Vervis/Git.hs index f350f4f..2770d7a 100644 --- a/src/Vervis/Git.hs +++ b/src/Vervis/Git.hs @@ -72,14 +72,16 @@ lastBranchChange git branch = do return $ fromMaybe (error "mtime is Nothing") mtime -- | Determine the time of the last commit in any branch for a given repo -lastChange :: FilePath -> IO DateTime +lastChange :: FilePath -> IO (Maybe DateTime) lastChange path = withRepo (fromString path) $ \ git -> do --TODO add a better intro to json-state, the docs are bad there names <- branchList git times <- traverse (lastBranchChange git) $ map refNameRaw $ toList names let datetimes = map timeConvert times - return $ maximum datetimes + return $ if null datetimes + then Nothing + else Just $ maximum datetimes showPeriod :: Period -> Text showPeriod (Period 0 0 d) = T.pack (show d) <> " days" diff --git a/src/Vervis/Handler/Home.hs b/src/Vervis/Handler/Home.hs index c7e21d2..47bb9a2 100644 --- a/src/Vervis/Handler/Home.hs +++ b/src/Vervis/Handler/Home.hs @@ -42,17 +42,14 @@ intro = do , project ^. ProjectIdent , repo ^. RepoIdent ) + root <- appRepoDir . appSettings <$> getYesod liftIO $ forM repos $ \ (Value sharer, Value project, Value repo) -> do let path = - unpack $ - intercalate "/" - [ "state2" - , sharer - , project - , repo - ] - dt <- lastChange path - ago <- timeAgo dt + root unpack sharer unpack project unpack repo + mdt <- lastChange path + ago <- case mdt of + Nothing -> return "never" + Just dt -> timeAgo dt return (sharer, project, repo, ago) defaultLayout $ do setTitle "Welcome to Vervis!"