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
1 change: 1 addition & 0 deletions github.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ test-suite github-test
GitHub.ReposSpec
GitHub.SearchSpec
GitHub.UsersSpec
GitHub.EventsSpec
main-is: Spec.hs
ghc-options: -Wall
build-depends: base,
Expand Down
36 changes: 36 additions & 0 deletions spec/GitHub/EventsSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{-# LANGUAGE OverloadedStrings #-}
module GitHub.EventsSpec where

import Data.Either (isRight)
import Data.String (fromString)
import Prelude ()
import Prelude.Compat
import System.Environment (lookupEnv)
import Test.Hspec (Spec, describe, it, shouldSatisfy,
pendingWith)

import qualified GitHub
import GitHub.Data (Auth(..))

fromRightS :: Show a => Either a b -> b
fromRightS (Left xs) = error $ "Should be Right" ++ show xs
fromRightS (Right xs) = xs

withAuth :: (Auth -> IO ()) -> IO ()
withAuth action = do
mtoken <- lookupEnv "GITHUB_TOKEN"
case mtoken of
Nothing -> pendingWith "no GITHUB_TOKEN"
Just token -> action (OAuth $ fromString token)

spec :: Spec
spec = do
describe "repositoryEventsR" $ do
it "returns non empty list of events" $ shouldSucceed $
GitHub.repositoryEventsR "phadej" "github" 1
describe "userEventsR" $ do
it "returns non empty list of events" $ shouldSucceed $ GitHub.userEventsR "phadej" 1
where shouldSucceed f = withAuth $ \auth -> do

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: refactor this when merged (quicker to do myself, than try to explain what I want).

cs <- GitHub.executeRequest auth $ f
cs `shouldSatisfy` isRight
length (fromRightS cs) `shouldSatisfy` (> 1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use

import Prelude ()
import Prelude.Compat

to get correct (polymorphic) length.

2 changes: 1 addition & 1 deletion src/GitHub.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module GitHub (
-- ** Events
-- | See https://developer.github.com/v3/activity/events/#events
repositoryEventsR,

userEventsR,
-- ** Starring
-- | See <https://developer.github.com/v3/activity/starring/>
--
Expand Down
7 changes: 7 additions & 0 deletions src/GitHub/Endpoints/Activity/Events.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
module GitHub.Endpoints.Activity.Events (
-- * Events
repositoryEventsR,
userEventsR,
module GitHub.Data,
) where

Expand All @@ -19,3 +20,9 @@ import Prelude ()
repositoryEventsR :: Name Owner -> Name Repo -> FetchCount -> Request 'RO (Vector Event)
repositoryEventsR user repo =
pagedQuery ["repos", toPathPart user, toPathPart repo, "events"] []

-- | List user public events.
-- See <https://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user>
userEventsR :: Name User -> FetchCount -> Request 'RO (Vector Event)
userEventsR user =
pagedQuery ["users", toPathPart user, "events", "public"] []