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
12 changes: 10 additions & 2 deletions spec/GitHub/SearchSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import qualified Data.Vector as V

import GitHub (github)
import GitHub.Data
(Auth (..), Issue (..), IssueNumber (..), IssueState (..), mkId)
import GitHub.Endpoints.Search (SearchResult (..), searchIssuesR)
(Auth (..), Issue (..), IssueNumber (..), IssueState (..),
SimpleUser (..), User, mkId)
import GitHub.Endpoints.Search (SearchResult (..), searchIssuesR, searchUsersR)

fromRightS :: Show a => Either a b -> b
fromRightS (Right b) = b
Expand Down Expand Up @@ -57,3 +58,10 @@ spec = do
issues <- searchResultResults . fromRightS <$> github auth searchIssuesR query
length issues `shouldBe` 1
issueId (V.head issues) `shouldBe` mkId (Proxy :: Proxy Issue) 119694665

describe "searchUsers" $
it "performs a user search via the API" $ withAuth $ \auth -> do
let query = "oleg.grenrus@iki.fi created:<2020-01-01"
users <- searchResultResults . fromRightS <$> github auth searchUsersR query
length users `shouldBe` 1
simpleUserId (V.head users) `shouldBe` mkId (Proxy :: Proxy User) 51087
5 changes: 1 addition & 4 deletions src/GitHub.hs
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,10 @@ module GitHub (

-- * Search
-- | See <https://developer.github.com/v3/search/>
--
-- Missing endpoints:
--
-- * Search users
searchReposR,
searchCodeR,
searchIssuesR,
searchUsersR,

-- * Users
-- | See <https://developer.github.com/v3/users/>
Expand Down
7 changes: 7 additions & 0 deletions src/GitHub/Endpoints/Search.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module GitHub.Endpoints.Search(
searchReposR,
searchCodeR,
searchIssuesR,
searchUsersR,
module GitHub.Data,
) where

Expand All @@ -35,3 +36,9 @@ searchCodeR searchString =
searchIssuesR :: Text -> Request k (SearchResult Issue)
searchIssuesR searchString =
query ["search", "issues"] [("q", Just $ TE.encodeUtf8 searchString)]

-- | Search users.
-- See <https://developer.github.com/v3/search/#search-code>
searchUsersR :: Text -> Request k (SearchResult SimpleUser)
searchUsersR searchString =
query ["search", "users"] [("q", Just $ TE.encodeUtf8 searchString)]