Created
March 27, 2011 21:28
-
-
Save snoyberg/889642 to your computer and use it in GitHub Desktop.
Download a list of all open issues for a Github user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
import Network.HTTP.Enumerator | |
import Data.Aeson | |
import Data.Aeson.Parser (json) | |
import System.Environment (getArgs) | |
import qualified Data.ByteString.Char8 as S8 | |
import qualified Data.Attoparsec.Lazy as AL | |
import Data.Text (Text, unpack) | |
main = getArgs >>= mapM_ getInfo | |
data UserInfo = UserInfo [Text] | |
deriving Show | |
instance FromJSON UserInfo where | |
parseJSON (Object v) = do | |
rs <- v .: "repositories" | |
x <- mapM (.: "name") rs | |
return $ UserInfo x | |
getInfo n = do | |
lbs <- simpleHttp $ "http://github.com/api/v2/json/repos/show/" ++ n | |
val <- either error return $ AL.eitherResult $ AL.parse json lbs | |
UserInfo repos <- | |
case fromJSON val of | |
Error e -> error e | |
Success a -> return a | |
{- | |
issues <- fmap concat $ mapM (getIssues n) repos | |
mapM_ print issues | |
-} | |
mapM_ (getIssues n) repos | |
data Issue = Issue | |
{ issueNumber :: Int | |
, issueTitle :: Text | |
} | |
deriving Show | |
newtype Issues = Issues [Issue] | |
instance FromJSON Issues where | |
parseJSON (Object v) = do | |
x <- v .: "issues" | |
fmap Issues $ mapM parseJSON x | |
instance FromJSON Issue where | |
parseJSON (Object v) = do | |
number <- v .: "number" | |
title <- v .: "title" | |
return $ Issue number title | |
getIssues name repo = do | |
lbs <- simpleHttp $ concat | |
[ "http://github.com/api/v2/json/issues/list/" | |
, name | |
, "/" | |
, unpack repo | |
, "/open" | |
] | |
val <- either error return $ AL.eitherResult $ AL.parse json lbs | |
Issues issues <- | |
case fromJSON val of | |
Error e -> error e | |
Success a -> return a | |
--return issues | |
flip mapM_ issues $ \(Issue n t) -> putStrLn (concat | |
[ "https://github.com/" | |
, name | |
, "/" | |
, unpack repo | |
, "/issues/" | |
, show n | |
, " " | |
, unpack t | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment