Skip to content

Commit b0f1671

Browse files
committed
All functions now take a GithubConfig parameter. So far this is just a container for http-conduit's Manager.
1 parent 2caf0f4 commit b0f1671

82 files changed

Lines changed: 368 additions & 288 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Github/Data.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,16 @@ import System.Locale (defaultTimeLocale)
1515
import Data.Attoparsec.Number (Number(..))
1616
import qualified Data.Vector as V
1717
import qualified Data.HashMap.Lazy as Map
18+
import Data.Default
19+
import qualified Network.HTTP.Conduit as HC (def, newManager)
1820

1921
import Github.Data.Definitions
2022

23+
instance Data.Default.Default GithubConfig where
24+
def = GithubConfig {
25+
getHttpManager = HC.newManager HC.def
26+
}
27+
2128
instance FromJSON GithubDate where
2229
parseJSON (String t) =
2330
case parseTime defaultTimeLocale "%FT%T%Z" (T.unpack t) of

Github/Data/Definitions.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ module Github.Data.Definitions where
44

55
import Data.Time
66
import Data.Data
7-
import Network.HTTP.Conduit (HttpException(..))
7+
import Network.HTTP.Conduit (HttpException(..), Manager(..))
88
import qualified Control.Exception as E
99

10+
data GithubConfig = GithubConfig {
11+
getHttpManager :: IO Manager
12+
}
13+
1014
deriving instance Eq Network.HTTP.Conduit.HttpException
1115

1216
-- | Errors have been tagged according to their source, so you can more easily

Github/Gists.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import Github.Private
1010

1111
-- | The list of all public gists created by the user.
1212
--
13-
-- > gists "mike-burns"
14-
gists :: String -> IO (Either Error [Gist])
15-
gists userName = githubGet ["users", userName, "gists"]
13+
-- > gists def "mike-burns"
14+
gists :: GithubConfig -> String -> IO (Either Error [Gist])
15+
gists c userName = githubGet c ["users", userName, "gists"]
1616

1717
-- | A specific gist, given its id.
1818
--
19-
-- > gist "225074"
20-
gist :: String -> IO (Either Error Gist)
21-
gist gistId = githubGet ["gists", gistId]
19+
-- > gist def "225074"
20+
gist :: GithubConfig -> String -> IO (Either Error Gist)
21+
gist c gistId = githubGet c ["gists", gistId]

Github/Gists/Comments.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import Github.Private
1111

1212
-- | All the comments on a Gist, given the Gist ID.
1313
--
14-
-- > commentsOn "1174060"
15-
commentsOn :: String -> IO (Either Error [GistComment])
16-
commentsOn gistId = githubGet ["gists", gistId, "comments"]
14+
-- > commentsOn def "1174060"
15+
commentsOn :: GithubConfig -> String -> IO (Either Error [GistComment])
16+
commentsOn c gistId = githubGet c ["gists", gistId, "comments"]
1717

1818
-- | A specific comment, by the comment ID.
1919
--
20-
-- > comment "62449"
21-
comment :: String -> IO (Either Error GistComment)
22-
comment commentId = githubGet ["gists", "comments", commentId]
20+
-- > comment def "62449"
21+
comment :: GithubConfig -> String -> IO (Either Error GistComment)
22+
comment c commentId = githubGet c ["gists", "comments", commentId]

Github/GitData/Blobs.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Github.Private
1010

1111
-- | Get a blob by SHA1.
1212
--
13-
-- > blob "thoughtbot" "paperclip" "bc5c51d1ece1ee45f94b056a0f5a1674d7e8cba9"
14-
blob :: String -> String -> String -> IO (Either Error Blob)
15-
blob user repoName sha =
16-
githubGet ["repos", user, repoName, "git", "blobs", sha]
13+
-- > blob def "thoughtbot" "paperclip" "bc5c51d1ece1ee45f94b056a0f5a1674d7e8cba9"
14+
blob :: GithubConfig -> String -> String -> String -> IO (Either Error Blob)
15+
blob c user repoName sha =
16+
githubGet c ["repos", user, repoName, "git", "blobs", sha]

Github/GitData/Commits.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ import Github.Private
1111
-- | A single commit, by SHA1.
1212
--
1313
-- > commit "thoughtbot" "paperclip" "bc5c51d1ece1ee45f94b056a0f5a1674d7e8cba9"
14-
commit :: String -> String -> String -> IO (Either Error GitCommit)
15-
commit user repoName sha =
16-
githubGet ["repos", user, repoName, "git", "commits", sha]
14+
commit :: GithubConfig -> String -> String -> String -> IO (Either Error GitCommit)
15+
commit c user repoName sha =
16+
githubGet c ["repos", user, repoName, "git", "commits", sha]

Github/GitData/References.hs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ import Github.Private
1313

1414
-- | A single reference by the ref name.
1515
--
16-
-- > reference "mike-burns" "github" "heads/master"
17-
reference :: String -> String -> String -> IO (Either Error GitReference)
18-
reference user repoName ref =
19-
githubGet ["repos", user, repoName, "git", "refs", ref]
16+
-- > reference def "mike-burns" "github" "heads/master"
17+
reference :: GithubConfig -> String -> String -> String -> IO (Either Error GitReference)
18+
reference c user repoName ref =
19+
githubGet c ["repos", user, repoName, "git", "refs", ref]
2020

2121
-- | The history of references for a repo.
2222
--
23-
-- > references "mike-burns" "github"
24-
references :: String -> String -> IO (Either Error [GitReference])
25-
references user repoName =
26-
githubGet ["repos", user, repoName, "git", "refs"]
23+
-- > references def "mike-burns" "github"
24+
references :: GithubConfig -> String -> String -> IO (Either Error [GitReference])
25+
references c user repoName =
26+
githubGet c ["repos", user, repoName, "git", "refs"]
2727

2828
-- | Limited references by a namespace.
2929
--
30-
-- > namespacedReferences "thoughtbot" "paperclip" "tags"
31-
namespacedReferences :: String -> String -> String -> IO (Either Error [GitReference])
32-
namespacedReferences user repoName namespace =
33-
githubGet ["repos", user, repoName, "git", "refs", namespace]
30+
-- > namespacedReferences def "thoughtbot" "paperclip" "tags"
31+
namespacedReferences :: GithubConfig -> String -> String -> String -> IO (Either Error [GitReference])
32+
namespacedReferences c user repoName namespace =
33+
githubGet c ["repos", user, repoName, "git", "refs", namespace]

Github/GitData/Trees.hs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ import Github.Private
1111

1212
-- | A tree for a SHA1.
1313
--
14-
-- > tree "thoughtbot" "paperclip" "fe114451f7d066d367a1646ca7ac10e689b46844"
15-
tree :: String -> String -> String -> IO (Either Error Tree)
16-
tree user repoName sha =
17-
githubGet ["repos", user, repoName, "git", "trees", sha]
14+
-- > tree def "thoughtbot" "paperclip" "fe114451f7d066d367a1646ca7ac10e689b46844"
15+
tree :: GithubConfig -> String -> String -> String -> IO (Either Error Tree)
16+
tree c user repoName sha =
17+
githubGet c ["repos", user, repoName, "git", "trees", sha]
1818

1919
-- | A recursively-nested tree for a SHA1.
2020
--
21-
-- > nestedTree "thoughtbot" "paperclip" "fe114451f7d066d367a1646ca7ac10e689b46844"
22-
nestedTree :: String -> String -> String -> IO (Either Error Tree)
23-
nestedTree user repoName sha =
24-
githubGetWithQueryString ["repos", user, repoName, "git", "trees", sha]
25-
"recursive=1"
21+
-- > nestedTree def "thoughtbot" "paperclip" "fe114451f7d066d367a1646ca7ac10e689b46844"
22+
nestedTree :: GithubConfig -> String -> String -> String -> IO (Either Error Tree)
23+
nestedTree c user repoName sha =
24+
githubGetWithQueryString c ["repos", user, repoName, "git", "trees", sha]
25+
"recursive=1"

Github/Issues.hs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,19 @@ data IssueLimitation =
3333
-- | Details on a specific issue, given the repo owner and name, and the issue
3434
-- number.
3535
--
36-
-- > issue "thoughtbot" "paperclip" "462"
37-
issue :: String -> String -> Int -> IO (Either Error Issue)
38-
issue user repoName issueNumber =
39-
githubGet ["repos", user, repoName, "issues", show issueNumber]
36+
-- > issue def "thoughtbot" "paperclip" "462"
37+
issue :: GithubConfig -> String -> String -> Int -> IO (Either Error Issue)
38+
issue c user repoName issueNumber =
39+
githubGet c ["repos", user, repoName, "issues", show issueNumber]
4040

4141
-- | All issues for a repo (given the repo owner and name), with optional
4242
-- restrictions as described in the @IssueLimitation@ data type.
4343
--
44-
-- > issuesForRepo "thoughtbot" "paperclip" [NoMilestone, OnlyClosed, Mentions "jyurek", Ascending]
45-
issuesForRepo :: String -> String -> [IssueLimitation] -> IO (Either Error [Issue])
46-
issuesForRepo user repoName issueLimitations =
44+
-- > issuesForRepo def "thoughtbot" "paperclip" [NoMilestone, OnlyClosed, Mentions "jyurek", Ascending]
45+
issuesForRepo :: GithubConfig -> String -> String -> [IssueLimitation] -> IO (Either Error [Issue])
46+
issuesForRepo c user repoName issueLimitations =
4747
githubGetWithQueryString
48+
c
4849
["repos", user, repoName, "issues"]
4950
(queryStringFromLimitations issueLimitations)
5051
where

Github/Issues/Comments.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import Github.Private
1111

1212
-- | A specific comment, by ID.
1313
--
14-
-- > comment "thoughtbot" "paperclip" 1468184
15-
comment :: String -> String -> Int -> IO (Either Error IssueComment)
16-
comment user repoName commentId =
17-
githubGet ["repos", user, repoName, "issues", "comments", show commentId]
14+
-- > comment def "thoughtbot" "paperclip" 1468184
15+
comment :: GithubConfig -> String -> String -> Int -> IO (Either Error IssueComment)
16+
comment c user repoName commentId =
17+
githubGet c ["repos", user, repoName, "issues", "comments", show commentId]
1818

1919
-- | All comments on an issue, by the issue's number.
2020
--
21-
-- > comments "thoughtbot" "paperclip" 635
22-
comments :: String -> String -> Int -> IO (Either Error [IssueComment])
23-
comments user repoName issueNumber =
24-
githubGet ["repos", user, repoName, "issues", show issueNumber, "comments"]
21+
-- > comments def "thoughtbot" "paperclip" 635
22+
comments :: GithubConfig -> String -> String -> Int -> IO (Either Error [IssueComment])
23+
comments c user repoName issueNumber =
24+
githubGet c ["repos", user, repoName, "issues", show issueNumber, "comments"]

0 commit comments

Comments
 (0)