diff options
Diffstat (limited to 'sevendaysactivity.hs')
-rw-r--r-- | sevendaysactivity.hs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/sevendaysactivity.hs b/sevendaysactivity.hs new file mode 100644 index 0000000..63da735 --- /dev/null +++ b/sevendaysactivity.hs @@ -0,0 +1,42 @@ +import Data.List (null, nub, sort) +import Data.Time.Clock (getCurrentTime, addUTCTime) +import Data.Time.Clock.POSIX (posixDayLength) +import System.Environment (getArgs) + +import Data.FileStore (gitFileStore, history, TimeRange(TimeRange), Revision(Revision), Author(authorEmail), Change(Added,Deleted,Modified)) + +matchUsername :: String -> Revision -> Bool +matchUsername u (Revision _ _ author _ _) = u == localPart (authorEmail author) + where + localPart = takeWhile (/='@') + +extractFilename :: Change -> FilePath +extractFilename (Added f) = f +extractFilename (Deleted f) = f +extractFilename (Modified f) = f + +extractFilenames :: Revision -> [FilePath] +extractFilenames (Revision _ _ _ _ cs) = map extractFilename cs + +main :: IO () +main = do + args <- getArgs + let username = head args + currentTime <- getCurrentTime + let weekago = addUTCTime (-7 * posixDayLength) currentTime + let store = gitFileStore "." + + revs <- history store [] (TimeRange (Just weekago) Nothing) Nothing + let verrevs = if null args then revs else filter (matchUsername username) revs + let filestouched = sort . nub . concat $ map extractFilenames verrevs + + putStrLn "Summary" + putStrLn "=======" + putStrLn $ "Number of commits: " ++ (show (length verrevs)) + putStrLn $ "Files touched: " ++ (show (length filestouched)) + mapM_ (putStrLn . (" "++)) filestouched + + putStrLn "" + putStrLn "Details" + putStrLn "=======" + mapM_ (putStrLn . show) verrevs |