|
| 1 | +module GetContents where |
| 2 | + |
| 3 | +import qualified Github.Repos as Github |
| 4 | +import Data.List |
| 5 | +import Prelude hiding (truncate, getContents) |
| 6 | + |
| 7 | +main = do |
| 8 | + putStrLn "Root" |
| 9 | + putStrLn "====" |
| 10 | + getContents "" |
| 11 | + |
| 12 | + putStrLn "LICENSE" |
| 13 | + putStrLn "=======" |
| 14 | + getContents "LICENSE" |
| 15 | + |
| 16 | +getContents path = do |
| 17 | + contents <- Github.contentsFor "mike-burns" "ohlaunch" path Nothing |
| 18 | + putStrLn $ either (("Error: " ++) . show) formatContents contents |
| 19 | + |
| 20 | +formatContents (Github.ContentFile fileData) = |
| 21 | + formatContentInfo (Github.contentFileInfo fileData) ++ |
| 22 | + unlines |
| 23 | + [ show (Github.contentFileSize fileData) ++ " bytes" |
| 24 | + , "encoding: " ++ Github.contentFileEncoding fileData |
| 25 | + , "data: " ++ truncate (Github.contentFileContent fileData) |
| 26 | + ] |
| 27 | + |
| 28 | +formatContents (Github.ContentDirectory items) = |
| 29 | + intercalate "\n\n" $ map formatItem items |
| 30 | + |
| 31 | +formatContentInfo contentInfo = |
| 32 | + unlines |
| 33 | + [ "name: " ++ Github.contentName contentInfo |
| 34 | + , "path: " ++ Github.contentPath contentInfo |
| 35 | + , "sha: " ++ Github.contentSha contentInfo |
| 36 | + , "url: " ++ Github.contentUrl contentInfo |
| 37 | + , "git url: " ++ Github.contentGitUrl contentInfo |
| 38 | + , "html url: " ++ Github.contentHtmlUrl contentInfo |
| 39 | + ] |
| 40 | + |
| 41 | +formatItem item = |
| 42 | + "type: " ++ show (Github.contentItemType item) ++ "\n" ++ |
| 43 | + formatContentInfo (Github.contentItemInfo item) |
| 44 | + |
| 45 | + |
| 46 | +truncate str = take 40 str ++ "... (truncated)" |
0 commit comments