Skip to content

Commit f483749

Browse files
authored
Merge pull request haskell-github#415 from phadej/github-convinience-function
Add github and github' convinience functions
2 parents 12e3e42 + dab2a74 commit f483749

Some content is hidden

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

62 files changed

+287
-2051
lines changed

CHANGELOG.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
## Changes for 0.24
2+
3+
**Major change**:
4+
Introduce `github` n-ary combinator to hoist `... -> Request rw res`
5+
into `... -> IO (Either Error res)` (i.e. n-ary `executeRequest`).
6+
With that in place drop `.. -> IO (Either Error res)` functions.
7+
8+
This reduces symbol bloat in the library.
9+
[#415](https://github.com/phadej/github/pull/415)
10+
11+
- Remove double `withOpenSSL`
12+
[#414](https://github.com/phadej/github/pull/414)
13+
- Pull requests reviews API uses issue number
14+
[#409](https://github.com/phadej/github/pull/409)
15+
- Update `Repo`, `NewRepo` and `EditRepo` data types
16+
[#407](https://github.com/phadej/github/pull/407)
17+
118
## Changes for 0.23
219

320
- Escape URI paths
@@ -93,7 +110,7 @@
93110

94111
## Changes for 0.18
95112

96-
- Endpoints for deleting issue comments.
113+
- Endpoints for deleting issue comments.
97114
[#294](https://github.com/phadej/github/pull/294)
98115
- Endpoints for (un)starring gists.
99116
[#296](https://github.com/phadej/github/pull/296)

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,12 @@ import Data.Text (Text, pack)
6363
import Data.Text.IO as T (putStrLn)
6464
import Data.Monoid ((<>))
6565

66-
import qualified GitHub.Endpoints.Users.Followers as GitHub
66+
import GitHub (github')
67+
import qualified GitHub
6768

6869
main :: IO ()
6970
main = do
70-
possibleUsers <- GitHub.usersFollowing "mike-burns"
71+
possibleUsers <- github GitHub.usersFollowingR "phadej"
7172
T.putStrLn $ either (("Error: " <>) . pack . show)
7273
(foldMap ((<> "\n") . formatUser))
7374
possibleUsers
@@ -98,7 +99,7 @@ Copyright
9899

99100
Copyright 2011-2012 Mike Burns.
100101
Copyright 2013-2015 John Wiegley.
101-
Copyright 2016 Oleg Grenrus.
102+
Copyright 2016-2019 Oleg Grenrus.
102103

103104
Available under the BSD 3-clause license.
104105

github.cabal

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: >=1.10
22
name: github
3-
version: 0.23
3+
version: 0.24
44
synopsis: Access to the GitHub API, v3.
55
category: Network
66
description:
@@ -15,7 +15,7 @@ description:
1515
>
1616
> main :: IO ()
1717
> main = do
18-
> possibleUser <- GH.executeRequest' $ GH.userInfoForR "phadej"
18+
> possibleUser <- GH.github' GH.userInfoForR "phadej"
1919
> print possibleUser
2020
.
2121
For more of an overview please see the README: <https://github.com/phadej/github/blob/master/README.md>

samples/RateLimit.hs

-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ import qualified Github.RateLimit as Github
55
main = do
66
x <- Github.rateLimit
77
print x
8-
+7-9
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
{-# LANGUAGE OverloadedStrings #-}
22
module Main (main) where
33

4-
import qualified GitHub.Data.DeployKeys as DK
5-
import qualified GitHub.Endpoints.Repos.DeployKeys as DK
6-
import qualified GitHub.Auth as Auth
4+
import qualified GitHub as GH
75
import Data.Text (Text)
86

97
main :: IO ()
108
main = do
11-
let auth = Auth.OAuth "auth_token"
12-
eDeployKey <- DK.createRepoDeployKey' auth "your_owner" "your_repo" newDeployKey
9+
let auth = GH.OAuth "auth_token"
10+
eDeployKey <- GH.github auth GH.createRepoDeployKeyR "your_owner" "your_repo" newDeployKey
1311
case eDeployKey of
14-
(Left err) -> putStrLn $ "Error: " ++ (show err)
15-
(Right deployKey) -> putStrLn $ show deployKey
12+
Left err -> putStrLn $ "Error: " ++ show err
13+
Right deployKey -> print deployKey
1614

17-
newDeployKey :: DK.NewRepoDeployKey
18-
newDeployKey = DK.NewRepoDeployKey publicKey "test-key" True
15+
newDeployKey :: GH.NewRepoDeployKey
16+
newDeployKey = GH.NewRepoDeployKey publicKey "test-key" True
1917
where
2018
publicKey :: Text
2119
publicKey = "your_public_key"

samples/Repos/DeployKeys/ListDeployKeys.hs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
{-# LANGUAGE OverloadedStrings #-}
22
module Main (main) where
33

4-
import qualified GitHub.Data.DeployKeys as DK
5-
import qualified GitHub.Endpoints.Repos.DeployKeys as DK
6-
import qualified GitHub.Auth as Auth
4+
import qualified GitHub as GH
75
import Data.List (intercalate)
86
import Data.Vector (toList)
97

108
main :: IO ()
119
main = do
12-
let auth = Auth.OAuth "auth_token"
13-
eDeployKeys <- DK.deployKeysFor' auth "your_owner" "your_repo"
10+
let auth = GH.OAuth "auth_token"
11+
eDeployKeys <- GH.github auth GH.deployKeysForR "your_owner" "your_repo" GH.FetchAll
1412
case eDeployKeys of
15-
(Left err) -> putStrLn $ "Error: " ++ (show err)
16-
(Right deployKeys) -> putStrLn $ intercalate "\n" $ map formatRepoDeployKey (toList deployKeys)
13+
Left err -> putStrLn $ "Error: " ++ show err
14+
Right deployKeys -> putStrLn $ intercalate "\n" $ map formatRepoDeployKey (toList deployKeys)
1715

1816
formatRepoDeployKey :: DK.RepoDeployKey -> String
1917
formatRepoDeployKey = show

samples/Repos/ShowRepo.hs

+9-10
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@ import Data.Maybe
77
main = do
88
possibleRepo <- Github.repository "mike-burns" "trylambda"
99
case possibleRepo of
10-
(Left error) -> putStrLn $ "Error: " ++ (show error)
11-
(Right repo) -> putStrLn $ formatRepo repo
10+
Left error -> putStrLn $ "Error: " ++ show error
11+
Right repo -> putStrLn $ formatRepo repo
1212

13-
formatRepo repo =
14-
(Github.repoName repo) ++ "\t" ++
15-
(fromMaybe "" $ Github.repoDescription repo) ++ "\n" ++
16-
(Github.repoHtmlUrl repo) ++ "\n" ++
17-
(fromMaybe "" $ Github.repoCloneUrl repo) ++ "\t" ++
18-
(fromMaybe "" $ formatDate `fmap` Github.repoUpdatedAt repo) ++ "\n" ++
13+
formatRepo repo = Github.repoName repo ++ "\t" ++
14+
fromMaybe "" (Github.repoDescription repo) ++ "\n" ++
15+
Github.repoHtmlUrl repo ++ "\n" ++
16+
fromMaybe "" (Github.repoCloneUrl repo) ++ "\t" ++
17+
maybe "" formatDate (Github.repoUpdatedAt repo) ++ "\n" ++
1918
formatLanguage (Github.repoLanguage repo) ++
20-
"watchers: " ++ (show $ Github.repoWatchers repo) ++ "\t" ++
21-
"forks: " ++ (show $ Github.repoForks repo)
19+
"watchers: " ++ show (Github.repoWatchers repo) ++ "\t" ++
20+
"forks: " ++ show (Github.repoForks repo)
2221

2322
formatDate = show . Github.fromDate
2423

samples/Teams/EditTeam.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ module Main (main) where
55
import Common
66

77
import qualified GitHub
8-
import qualified GitHub.Endpoints.Organizations.Teams as GitHub
98

109
main :: IO ()
1110
main = do
1211
args <- getArgs
1312
result <- case args of
1413
[token, team_id, team_name, desc] ->
15-
GitHub.editTeam'
14+
GitHub.github
1615
(GitHub.OAuth $ fromString token)
16+
GitHub.editTeamR
1717
(GitHub.mkTeamId $ read team_id)
1818
(GitHub.EditTeam (GitHub.mkTeamName $ fromString team_name) (Just $ fromString desc) GitHub.PermissionPull)
1919
_ ->

samples/Teams/ListRepos.hs

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ module Main (main) where
44
import Common
55
import Prelude ()
66

7-
import qualified GitHub
8-
import qualified GitHub.Endpoints.Organizations.Teams as GitHub
7+
import qualified GitHub as GH
98

109
main :: IO ()
1110
main = do
1211
args <- getArgs
1312
possibleRepos <- case args of
14-
[team_id, token] -> GitHub.listTeamRepos' (Just $ GitHub.OAuth $ fromString token) (GitHub.mkTeamId $ read team_id)
15-
[team_id] -> GitHub.listTeamRepos (GitHub.mkTeamId $ read team_id)
13+
[team_id, token] -> GH.github (GH.OAuth $ fromString token) GH.listTeamReposR (GH.mkTeamId $ read team_id)
14+
[team_id] -> GH.github' GH.listTeamReposR (GH.mkTeamId $ read team_id)
1615
_ -> error "usage: TeamListRepos <team_id> [auth token]"
1716
case possibleRepos of
1817
Left err -> putStrLn $ "Error: " <> tshow err

samples/Teams/ListTeamsCurrent.hs

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ module Main (main) where
44

55
import Common
66

7-
import qualified GitHub
8-
import qualified GitHub.Endpoints.Organizations.Teams as GitHub
7+
import qualified GitHub as GH
98

109
main :: IO ()
1110
main = do
1211
args <- getArgs
1312
result <- case args of
14-
[token] -> GitHub.listTeamsCurrent' (GitHub.OAuth $ fromString token)
13+
[token] -> GH.github (GH.OAuth $ fromString token) GH.listTeamsCurrentR GH.FetchAll
1514
_ -> error "usage: ListTeamsCurrent <token>"
1615
case result of
1716
Left err -> putStrLn $ "Error: " <> tshow err

samples/Teams/Memberships/AddTeamMembershipFor.hs

+7-9
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@ module Main (main) where
55
import Common
66

77
import qualified GitHub
8-
import qualified GitHub.Endpoints.Organizations.Teams as GitHub
98

109
main :: IO ()
1110
main = do
1211
args <- getArgs
1312
result <- case args of
14-
[token, team_id, username] ->
15-
GitHub.addTeamMembershipFor'
16-
(GitHub.OAuth $ fromString token)
17-
(GitHub.mkTeamId $ read team_id)
18-
(GitHub.mkOwnerName $ fromString username)
19-
GitHub.RoleMember
20-
_ ->
21-
error "usage: AddTeamMembershipFor <token> <team_id> <username>"
13+
[token, team_id, username] -> GitHub.github
14+
(GitHub.OAuth $ fromString token)
15+
GitHub.addTeamMembershipForR
16+
(GitHub.mkTeamId $ read team_id)
17+
(GitHub.mkOwnerName $ fromString username)
18+
GitHub.RoleMember
19+
_ -> fail "usage: AddTeamMembershipFor <token> <team_id> <username>"
2220
case result of
2321
Left err -> putStrLn $ "Error: " <> tshow err
2422
Right team -> putStrLn $ tshow team

samples/Teams/TeamInfoFor.hs

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ module Main (main) where
44

55
import Common
66

7-
import qualified GitHub
8-
import qualified GitHub.Endpoints.Organizations.Teams as GitHub
7+
import qualified GitHub as GH
98

109
main :: IO ()
1110
main = do
1211
args <- getArgs
1312
result <- case args of
14-
[team_id, token] -> GitHub.teamInfoFor' (Just $ GitHub.OAuth $ fromString token) (GitHub.mkTeamId $ read team_id)
15-
[team_id] -> GitHub.teamInfoFor (GitHub.mkTeamId $ read team_id)
13+
[team_id, token] -> GH.github (GH.OAuth $ fromString token) GH.teamInfoForR (GH.mkTeamId $ read team_id)
14+
[team_id] -> GH.github' GH.teamInfoForR (GH.mkTeamId $ read team_id)
1615
_ -> error "usage: TeamInfoFor <team_id> [auth token]"
1716
case result of
1817
Left err -> putStrLn $ "Error: " <> tshow err

samples/Users/ShowUser.hs

+22-23
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,37 @@ import Prelude ()
66

77
import Data.Maybe (fromMaybe)
88

9-
import qualified GitHub
10-
import qualified GitHub.Endpoints.Users as GitHub
9+
import qualified GitHub as GH
1110

1211
main :: IO ()
1312
main = do
14-
auth <- getAuth
15-
possibleUser <- GitHub.userInfoFor' auth "mike-burns"
13+
mauth <- getAuth
14+
possibleUser <- maybe GH.github' GH.github mauth GH.userInfoForR "mike-burns"
1615
putStrLn $ either (("Error: " <>) . tshow) formatUser possibleUser
1716

18-
formatUser :: GitHub.User -> Text
17+
formatUser :: GH.User -> Text
1918
formatUser user =
20-
(formatName userName login) <> "\t" <> (fromMaybe "" company) <> "\t" <>
21-
(fromMaybe "" location) <> "\n" <>
22-
(fromMaybe "" blog) <> "\t" <> "<" <> (fromMaybe "" email) <> ">" <> "\n" <>
23-
GitHub.getUrl htmlUrl <> "\t" <> tshow createdAt <> "\n" <>
19+
formatName userName login <> "\t" <> fromMaybe "" company <> "\t" <>
20+
fromMaybe "" location <> "\n" <>
21+
fromMaybe "" blog <> "\t" <> "<" <> fromMaybe "" email <> ">" <> "\n" <>
22+
GH.getUrl htmlUrl <> "\t" <> tshow createdAt <> "\n" <>
2423
"hireable: " <> formatHireable (fromMaybe False isHireable) <> "\n\n" <>
25-
(fromMaybe "" bio)
24+
fromMaybe "" bio
2625
where
27-
userName = GitHub.userName user
28-
login = GitHub.userLogin user
29-
company = GitHub.userCompany user
30-
location = GitHub.userLocation user
31-
blog = GitHub.userBlog user
32-
email = GitHub.userEmail user
33-
htmlUrl = GitHub.userHtmlUrl user
34-
createdAt = GitHub.userCreatedAt user
35-
isHireable = GitHub.userHireable user
36-
bio = GitHub.userBio user
26+
userName = GH.userName user
27+
login = GH.userLogin user
28+
company = GH.userCompany user
29+
location = GH.userLocation user
30+
blog = GH.userBlog user
31+
email = GH.userEmail user
32+
htmlUrl = GH.userHtmlUrl user
33+
createdAt = GH.userCreatedAt user
34+
isHireable = GH.userHireable user
35+
bio = GH.userBio user
3736

38-
formatName :: Maybe Text -> GitHub.Name GitHub.User -> Text
39-
formatName Nothing login = GitHub.untagName login
40-
formatName (Just name) login = name <> "(" <> GitHub.untagName login <> ")"
37+
formatName :: Maybe Text -> GH.Name GH.User -> Text
38+
formatName Nothing login = GH.untagName login
39+
formatName (Just name) login = name <> "(" <> GH.untagName login <> ")"
4140

4241
formatHireable :: Bool -> Text
4342
formatHireable True = "yes"

0 commit comments

Comments
 (0)