Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Github/All.hs
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,11 @@ module Github.All (
--
-- Missing endpoints:
--
-- * List your repositories
-- * List all public repositories
-- * List Teams
-- * Get Branch
-- * Enabling and disabling branch protection
currentUserReposR,
userReposR,

-- ** Collaborators
Expand Down
15 changes: 15 additions & 0 deletions Github/Repos.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
-- <http://developer.github.com/v3/repos/>
module Github.Repos (
-- * Querying repositories
currentUserRepos,
currentUserReposR,
userRepos,
userRepos',
userReposR,
Expand Down Expand Up @@ -69,6 +71,19 @@ repoPublicityQueryString Member = [("type", Just "member")]
repoPublicityQueryString Public = [("type", Just "public")]
repoPublicityQueryString Private = [("type", Just "private")]

-- | List your repositories.
currentUserRepos :: GithubAuth -> RepoPublicity -> IO (Either Error (Vector Repo))
currentUserRepos auth publicity =
executeRequest auth $ currentUserReposR publicity Nothing

-- | List your repositories.
-- See <https://developer.github.com/v3/repos/#list-your-repositories>
currentUserReposR :: RepoPublicity -> Maybe Count -> GithubRequest k(Vector Repo)
currentUserReposR publicity =
GithubPagedGet ["user", "repos"] qs
where
qs = repoPublicityQueryString publicity

-- | The repos for a user, by their login. Can be restricted to just repos they
-- own, are a member of, or publicize. Private repos will return empty list.
--
Expand Down
1 change: 1 addition & 0 deletions github.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ test-suite github-test
other-modules:
Github.CommitsSpec
Github.OrganizationsSpec
Github.ReposSpec
Github.SearchSpec
Github.UsersSpec
main-is: Spec.hs
Expand Down
35 changes: 35 additions & 0 deletions spec/Github/ReposSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module Github.ReposSpec where

import Github.Auth (GithubAuth (..))
import Github.Repos (currentUserRepos, userRepos', RepoPublicity(..))

-- import Data.Aeson.Compat (eitherDecodeStrict)
import Data.Either.Compat (isRight)
-- import Data.FileEmbed (embedFile)
import System.Environment (lookupEnv)
import Test.Hspec (Spec, describe, it, pendingWith, shouldSatisfy)

fromRightS :: Show a => Either a b -> b
fromRightS (Right b) = b
fromRightS (Left a) = error $ "Expected a Right and got a Left" ++ show a

withAuth :: (GithubAuth -> IO ()) -> IO ()
withAuth action = do
mtoken <- lookupEnv "GITHUB_TOKEN"
case mtoken of
Nothing -> pendingWith "no GITHUB_TOKEN"
Just token -> action (GithubOAuth token)

spec :: Spec
spec = do
describe "currentUserRepos" $ do
it "works" $ withAuth $ \auth -> do
cs <- currentUserRepos auth All
cs `shouldSatisfy` isRight

describe "userRepos" $ do
it "works" $ withAuth $ \auth -> do
cs <- userRepos' (Just auth) "phadej" All
cs `shouldSatisfy` isRight