Skip to content

Commit c040067

Browse files
authored
Merge pull request #312 from mwu/master
Fixing isPullRequestMerged and other boolean responses and adding check membership API
2 parents 2353807 + 2374f38 commit c040067

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

spec/GitHub/PullRequestsSpec.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module GitHub.PullRequestsSpec where
44

55
import qualified GitHub
6+
import GitHub.Data.Id (Id(Id))
67

78
import Prelude ()
89
import Prelude.Compat
@@ -50,6 +51,13 @@ spec = do
5051

5152
V.length (GitHub.pullRequestRequestedReviewers pullRequestReviewRequested)
5253
`shouldBe` 1
54+
55+
describe "checking if a pull request is merged" $ do
56+
it "works" $ withAuth $ \auth -> do
57+
b <- GitHub.executeRequest auth $ GitHub.isPullRequestMergedR "phadej" "github" (Id 14)
58+
b `shouldSatisfy` isRight
59+
fromRightS b `shouldBe` True
60+
5361
where
5462
repos =
5563
[ ("thoughtbot", "paperclip")

src/GitHub.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,10 @@ module GitHub (
158158
-- ** Members
159159
-- | See <https://developer.github.com/v3/orgs/members/>
160160
--
161-
-- Missing endpoints: All except /Members List/
161+
-- Missing endpoints: All except /Members List/ and /Check Membership/
162162
membersOfR,
163163
membersOfWithR,
164+
isMemberOfR,
164165

165166
-- ** Teams
166167
-- | See <https://developer.github.com/v3/orgs/teams/>

src/GitHub/Data/Request.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ type StatusMap a = [(Int, a)]
158158

159159
statusOnlyOk :: StatusMap Bool
160160
statusOnlyOk =
161-
[ (202, True)
161+
[ (204, True)
162162
, (404, False)
163163
]
164164

src/GitHub/Endpoints/Organizations/Members.hs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ module GitHub.Endpoints.Organizations.Members (
1010
membersOf',
1111
membersOfR,
1212
membersOfWithR,
13+
isMemberOf,
14+
isMemberOf',
15+
isMemberOfR,
1316
module GitHub.Data,
1417
) where
1518

@@ -54,3 +57,25 @@ membersOfWithR org f r =
5457
OrgMemberRoleAll -> "all"
5558
OrgMemberRoleAdmin -> "admin"
5659
OrgMemberRoleMember -> "member"
60+
61+
-- | Check if a user is a member of an organization,
62+
-- | with or without authentication.
63+
--
64+
-- > isMemberOf' (Just $ OAuth "token") "phadej" "haskell-infra"
65+
isMemberOf' :: Maybe Auth -> Name User -> Name Organization -> IO (Either Error Bool)
66+
isMemberOf' auth user org =
67+
executeRequestMaybe auth $ isMemberOfR user org
68+
69+
-- | Check if a user is a member of an organization,
70+
-- | without authentication.
71+
--
72+
-- > isMemberOf "phadej" "haskell-infra"
73+
isMemberOf :: Name User -> Name Organization -> IO (Either Error Bool)
74+
isMemberOf = isMemberOf' Nothing
75+
76+
-- | Check if a user is a member of an organization.
77+
--
78+
-- See <https://developer.github.com/v3/orgs/members/#check-membership>
79+
isMemberOfR :: Name User -> Name Organization -> Request k Bool
80+
isMemberOfR user org = StatusQuery statusOnlyOk $
81+
Query [ "orgs", toPathPart org, "members", toPathPart user ] []

0 commit comments

Comments
 (0)