Skip to content

Commit 070269f

Browse files
committed
Sample of authenticated Issue report from private repo
1 parent 92f5697 commit 070269f

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
module Main where
3+
4+
import qualified Github.Issues as Github
5+
import qualified Data.ByteString as B
6+
import Report
7+
import Text.PrettyPrint.Leijen
8+
9+
auth :: Maybe (B.ByteString, B.ByteString)
10+
auth = Just ("yourgithub id", "somepassword")
11+
12+
mkIssue :: ReportedIssue -> Doc
13+
mkIssue (Issue n t h) = hsep [
14+
fill 5 (text ("#" ++ (show n))),
15+
fill 50 (text t),
16+
fill 5 (text (show h))]
17+
18+
vissues :: ([Doc], [Doc], [Doc]) -> Doc
19+
vissues (x, y, z) = hsep [(vcat x), align (vcat y), align (vcat z)]
20+
21+
mkDoc :: Report -> Doc
22+
mkDoc (Report issues total) = vsep [
23+
text "Report for the milestone",
24+
(vsep . map mkIssue) issues,
25+
text ("Total hours : " ++ (show total) ++" hours")
26+
]
27+
28+
mkFullDoc :: [Github.Issue] -> Doc
29+
mkFullDoc = mkDoc . prepareReport
30+
31+
-- The public repo is used as private are quite sensitive for this report
32+
--
33+
-- The main idea is to use labels like 1h, 2h etc for man-hour estimation of issues
34+
-- on private repos for development "on hire"
35+
--
36+
-- This tool is used to generate report on work done for the customer
37+
--
38+
main :: IO ()
39+
main = do
40+
let limitations = [Github.OnlyClosed, Github.MilestoneId 4]
41+
possibleIssues <- Github.issuesForRepo' auth "paulrzcz" "hquantlib" limitations
42+
case possibleIssues of
43+
(Left err) -> putStrLn $ "Error: " ++ show err
44+
(Right issues) -> putDoc $ mkFullDoc issues
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
module Report (
3+
ReportedIssue (..),
4+
Report (..),
5+
prepareReport,
6+
convertLabels
7+
) where
8+
9+
import Text.Regex.Posix
10+
import qualified Github.Issues as Github
11+
12+
data ReportedIssue = Issue {
13+
riNumber :: Int,
14+
riTitle :: String,
15+
riHour :: Double
16+
} deriving (Show)
17+
18+
data Report = Report {
19+
rIssues :: [ReportedIssue],
20+
rTotal :: Double
21+
} deriving (Show)
22+
23+
convertIssue :: Github.Issue -> ReportedIssue
24+
convertIssue issue = Issue {
25+
riNumber = Github.issueNumber issue,
26+
riTitle = Github.issueTitle issue,
27+
riHour = convertLabels issue
28+
}
29+
30+
convertLabels :: Github.Issue -> Double
31+
convertLabels = sumUp . toNames . Github.issueLabels
32+
33+
prepareReport :: [Github.Issue] -> Report
34+
prepareReport issues = Report {
35+
rIssues = reportedIssues,
36+
rTotal = foldl summator 0 reportedIssues
37+
} where reportedIssues = map convertIssue issues
38+
summator z x = z + (riHour x)
39+
40+
-- Helper functions to construct a sum of hour labels
41+
42+
sumUp :: [Maybe Double] -> Double
43+
sumUp = foldl s 0.0
44+
where s z Nothing = z
45+
s z (Just x) = z+x
46+
47+
toNames :: [Github.IssueLabel] -> [Maybe Double]
48+
toNames = map (toValue . Github.labelName)
49+
50+
isValue :: String -> Bool
51+
isValue label = (label =~ ("^[0-9]h" :: String)) :: Bool
52+
53+
convert :: Read a => [Char] -> a
54+
convert label = read $ take len label
55+
where len = (length label) - 1
56+
57+
toValue :: Read a => String -> Maybe a
58+
toValue label
59+
| isValue label = Just (convert label)
60+
| otherwise = Nothing
61+
62+

0 commit comments

Comments
 (0)