summaryrefslogtreecommitdiff
path: root/sevendaysactivity.hs
blob: 63da7351bf848c1d48403711703e14a94f35ae62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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