summaryrefslogtreecommitdiff
path: root/src/Main.hs
blob: da3c0d8c7110c05a805a10bdde8f977aa00b88b5 (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
43
44
45
46
module Main (main) where

import Control.Monad

import System.IO
import System.Process

import Config
import Job

fitToLength :: Int -> String -> String
fitToLength maxlen str | len <= maxlen = str <> replicate (maxlen - len) ' '
                       | otherwise     = take (maxlen - 1) str <> "…"
    where len = length str

main :: IO ()
main = do
    Just configPath <- findConfig
    config <- parseConfig configPath

    commits <- map (fmap (drop 1) . (span (/=' '))) . lines <$>
        readProcess "git" ["log", "--pretty=oneline", "--first-parent", "--reverse", "origin/master..HEAD"] ""

    putStr $ replicate (8 + 50) ' '
    forM_ (configJobs config) $ \job -> do
        putStr $ (' ':) $ fitToLength 7 $ stringJobName $ jobName job
    putStrLn ""

    forM_ commits $ \(cid, desc) -> do
        let shortCid = take 7 cid
        putStr $ shortCid <> " " <> fitToLength 50 desc
        hFlush stdout
        results <- forM (configJobs config) $ \job -> do
            putStr " "
            hFlush stdout
            out <- runJob "./.minici" cid job
            if | outStatus out -> do
                    putStr "\ESC[92m✓\ESC[0m      "
               | otherwise -> do
                    putStr "\ESC[91m✗\ESC[0m      "
            hFlush stdout
            return $ outStatus out

        when (not $ and results) $ do
            putStr $ "\r\ESC[91m" <> shortCid <> "\ESC[0m"
        putStrLn ""