Skip to content

Commit 0e7c944

Browse files
committed
Resolve #94: Implement /user/repos
1 parent 69a772d commit 0e7c944

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

Github/All.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,11 @@ module Github.All (
203203
--
204204
-- Missing endpoints:
205205
--
206-
-- * List your repositories
207206
-- * List all public repositories
208207
-- * List Teams
209208
-- * Get Branch
210209
-- * Enabling and disabling branch protection
210+
currentUserReposR,
211211
userReposR,
212212

213213
-- ** Collaborators

Github/Repos.hs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
-- <http://developer.github.com/v3/repos/>
77
module Github.Repos (
88
-- * Querying repositories
9+
currentUserRepos,
10+
currentUserReposR,
911
userRepos,
1012
userRepos',
1113
userReposR,
@@ -69,6 +71,19 @@ repoPublicityQueryString Member = [("type", Just "member")]
6971
repoPublicityQueryString Public = [("type", Just "public")]
7072
repoPublicityQueryString Private = [("type", Just "private")]
7173

74+
-- | List your repositories.
75+
currentUserRepos :: GithubAuth -> RepoPublicity -> IO (Either Error (Vector Repo))
76+
currentUserRepos auth publicity =
77+
executeRequest auth $ currentUserReposR publicity Nothing
78+
79+
-- | List your repositories.
80+
-- See <https://developer.github.com/v3/repos/#list-your-repositories>
81+
currentUserReposR :: RepoPublicity -> Maybe Count -> GithubRequest k(Vector Repo)
82+
currentUserReposR publicity =
83+
GithubPagedGet ["user", "repos"] qs
84+
where
85+
qs = repoPublicityQueryString publicity
86+
7287
-- | The repos for a user, by their login. Can be restricted to just repos they
7388
-- own, are a member of, or publicize. Private repos will return empty list.
7489
--

github.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ test-suite github-test
118118
other-modules:
119119
Github.CommitsSpec
120120
Github.OrganizationsSpec
121+
Github.ReposSpec
121122
Github.SearchSpec
122123
Github.UsersSpec
123124
main-is: Spec.hs

spec/Github/ReposSpec.hs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
{-# LANGUAGE TemplateHaskell #-}
3+
module Github.ReposSpec where
4+
5+
import Github.Auth (GithubAuth (..))
6+
import Github.Repos (currentUserRepos, userRepos', RepoPublicity(..))
7+
8+
-- import Data.Aeson.Compat (eitherDecodeStrict)
9+
import Data.Either.Compat (isRight)
10+
-- import Data.FileEmbed (embedFile)
11+
import System.Environment (lookupEnv)
12+
import Test.Hspec (Spec, describe, it, pendingWith, shouldSatisfy)
13+
14+
fromRightS :: Show a => Either a b -> b
15+
fromRightS (Right b) = b
16+
fromRightS (Left a) = error $ "Expected a Right and got a Left" ++ show a
17+
18+
withAuth :: (GithubAuth -> IO ()) -> IO ()
19+
withAuth action = do
20+
mtoken <- lookupEnv "GITHUB_TOKEN"
21+
case mtoken of
22+
Nothing -> pendingWith "no GITHUB_TOKEN"
23+
Just token -> action (GithubOAuth token)
24+
25+
spec :: Spec
26+
spec = do
27+
describe "currentUserRepos" $ do
28+
it "works" $ withAuth $ \auth -> do
29+
cs <- currentUserRepos auth All
30+
cs `shouldSatisfy` isRight
31+
32+
describe "userRepos" $ do
33+
it "works" $ withAuth $ \auth -> do
34+
cs <- userRepos' (Just auth) "phadej" All
35+
cs `shouldSatisfy` isRight

0 commit comments

Comments
 (0)