Skip to content

Commit 4eb09aa

Browse files
committed
Github.GitData.Blobs.blob - get the blob details for the underlying git object.
1 parent f92930a commit 4eb09aa

4 files changed

Lines changed: 38 additions & 0 deletions

File tree

‎Github/Data.hs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ instance FromJSON GistComment where
150150
<*> o .: "id"
151151
parseJSON _ = fail "Could not build a GistComment"
152152

153+
instance FromJSON Blob where
154+
parseJSON (Object o) =
155+
Blob <$> o .: "url"
156+
<*> o .: "encoding"
157+
<*> o .: "content"
158+
<*> o .: "sha"
159+
<*> o .: "size"
160+
parseJSON _ = fail "Could not build a Blob"
161+
153162
(.:<) :: (FromJSON a) => Object -> T.Text -> Parser [a]
154163
obj .:< key = case Map.lookup key obj of
155164
Nothing -> pure []

‎Github/Data/Definitions.hs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,11 @@ data GistComment = GistComment {
135135
,gistCommentUpdatedAt :: GithubDate
136136
,gistCommentId :: Int
137137
} deriving (Show, Data, Typeable, Eq, Ord)
138+
139+
data Blob = Blob {
140+
blobUrl :: String
141+
,blobEncoding :: String
142+
,blobContent :: String
143+
,blobSha :: String
144+
,blobSize :: Int
145+
} deriving (Show, Data, Typeable, Eq, Ord)

‎Github/GitData/Blobs.hs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Github.GitData.Blobs (
2+
blob
3+
,module Github.Data
4+
) where
5+
6+
import Github.Data
7+
import Github.Private
8+
9+
blob :: String -> String -> String -> IO (Either Error Blob)
10+
blob user repoName sha =
11+
githubGet ["repos", user, repoName, "git", "blobs", sha]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module GitHashObject where
2+
3+
import qualified Github.GitData.Blobs as Github
4+
import Data.List( intercalate)
5+
6+
main = do
7+
possibleBlob <- Github.blob "thoughtbot" "paperclip" "bc5c51d1ece1ee45f94b056a0f5a1674d7e8cba9"
8+
case possibleBlob of
9+
(Left error) -> putStrLn $ "Error: " ++ (show error)
10+
(Right blob) -> putStrLn $ Github.blobContent blob

0 commit comments

Comments
 (0)