Skip to content

Fixing isPullRequestMerged and other boolean responses and adding check membership API #312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions spec/GitHub/PullRequestsSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module GitHub.PullRequestsSpec where

import qualified GitHub
import GitHub.Data.Id (Id(Id))

import Prelude ()
import Prelude.Compat
Expand Down Expand Up @@ -50,6 +51,13 @@ spec = do

V.length (GitHub.pullRequestRequestedReviewers pullRequestReviewRequested)
`shouldBe` 1

describe "checking if a pull request is merged" $ do
it "works" $ withAuth $ \auth -> do
b <- GitHub.executeRequest auth $ GitHub.isPullRequestMergedR "phadej" "github" (Id 14)
b `shouldSatisfy` isRight
fromRightS b `shouldBe` True

where
repos =
[ ("thoughtbot", "paperclip")
Expand Down
3 changes: 2 additions & 1 deletion src/GitHub.hs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,10 @@ module GitHub (
-- ** Members
-- | See <https://developer.github.com/v3/orgs/members/>
--
-- Missing endpoints: All except /Members List/
-- Missing endpoints: All except /Members List/ and /Check Membership/
membersOfR,
membersOfWithR,
isMemberOfR,

-- ** Teams
-- | See <https://developer.github.com/v3/orgs/teams/>
Expand Down
2 changes: 1 addition & 1 deletion src/GitHub/Data/Request.hs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ type StatusMap a = [(Int, a)]

statusOnlyOk :: StatusMap Bool
statusOnlyOk =
[ (202, True)
[ (204, True)
, (404, False)
]

Expand Down
25 changes: 25 additions & 0 deletions src/GitHub/Endpoints/Organizations/Members.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ module GitHub.Endpoints.Organizations.Members (
membersOf',
membersOfR,
membersOfWithR,
isMemberOf,
isMemberOf',
isMemberOfR,
module GitHub.Data,
) where

Expand Down Expand Up @@ -54,3 +57,25 @@ membersOfWithR org f r =
OrgMemberRoleAll -> "all"
OrgMemberRoleAdmin -> "admin"
OrgMemberRoleMember -> "member"

-- | Check if a user is a member of an organization,
-- | with or without authentication.
--
-- > isMemberOf' (Just $ OAuth "token") "phadej" "haskell-infra"
isMemberOf' :: Maybe Auth -> Name User -> Name Organization -> IO (Either Error Bool)
isMemberOf' auth user org =
executeRequestMaybe auth $ isMemberOfR user org

-- | Check if a user is a member of an organization,
-- | without authentication.
--
-- > isMemberOf "phadej" "haskell-infra"
isMemberOf :: Name User -> Name Organization -> IO (Either Error Bool)
isMemberOf = isMemberOf' Nothing

-- | Check if a user is a member of an organization.
--
-- See <https://developer.github.com/v3/orgs/members/#check-membership>
isMemberOfR :: Name User -> Name Organization -> Request k Bool
isMemberOfR user org = StatusQuery statusOnlyOk $
Query [ "orgs", toPathPart org, "members", toPathPart user ] []