Skip to content

Commit 1c973ff

Browse files
committed
Add list pending organization invitations req
1 parent 3085a78 commit 1c973ff

File tree

5 files changed

+69
-1
lines changed

5 files changed

+69
-1
lines changed

github.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Library
7979
GitHub.Data.Gists
8080
GitHub.Data.GitData
8181
GitHub.Data.Id
82+
GitHub.Data.Invitation
8283
GitHub.Data.Issues
8384
GitHub.Data.Milestone
8485
GitHub.Data.Name

src/GitHub.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ module GitHub (
162162
membersOfR,
163163
membersOfWithR,
164164
isMemberOfR,
165+
orgInvitationsR,
165166

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

src/GitHub/Data.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ module GitHub.Data (
4141
module GitHub.Data.Events,
4242
module GitHub.Data.Gists,
4343
module GitHub.Data.GitData,
44+
module GitHub.Data.Invitation,
4445
module GitHub.Data.Issues,
4546
module GitHub.Data.Milestone,
4647
module GitHub.Data.Options,
@@ -70,6 +71,7 @@ import GitHub.Data.Events
7071
import GitHub.Data.Gists
7172
import GitHub.Data.GitData
7273
import GitHub.Data.Id
74+
import GitHub.Data.Invitation
7375
import GitHub.Data.Issues
7476
import GitHub.Data.Milestone
7577
import GitHub.Data.Name

src/GitHub/Data/Invitation.hs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
-----------------------------------------------------------------------------
2+
-- |
3+
-- License : BSD-3-Clause
4+
-- Maintainer : Oleg Grenrus <oleg.grenrus@iki.fi>
5+
--
6+
module GitHub.Data.Invitation where
7+
8+
import GitHub.Data.Definitions
9+
import GitHub.Data.Id (Id)
10+
import GitHub.Data.Name (Name)
11+
import GitHub.Internal.Prelude
12+
import Prelude ()
13+
14+
data Invitation = Invitation
15+
{ invitationId :: !(Id Invitation)
16+
-- TODO: technically either one should be, maybe both. use `these` ?
17+
, invitationLogin :: !(Maybe (Name User))
18+
, invitationEmail :: !(Maybe Text)
19+
, invitationRole :: !InvitationRole
20+
, invitationCreatedAt :: !UTCTime
21+
, inviter :: !SimpleUser
22+
}
23+
deriving (Show, Data, Typeable, Eq, Ord, Generic)
24+
25+
instance NFData Invitation where rnf = genericRnf
26+
instance Binary Invitation
27+
28+
instance FromJSON Invitation where
29+
parseJSON = withObject "Invitation" $ \o -> Invitation
30+
<$> o .: "id"
31+
<*> o .:? "login"
32+
<*> o .:? "email"
33+
<*> o .: "role"
34+
<*> o .: "created_at"
35+
<*> o .: "inviter"
36+
37+
38+
data InvitationRole
39+
= InvitationRoleDirectMember
40+
| InvitationRoleAdmin
41+
| InvitationRoleBillingManager
42+
| InvitationRoleHiringManager
43+
| InvitationRoleReinstate
44+
deriving
45+
(Eq, Ord, Show, Enum, Bounded, Generic, Typeable, Data)
46+
47+
instance NFData InvitationRole where rnf = genericRnf
48+
instance Binary InvitationRole
49+
50+
instance FromJSON InvitationRole where
51+
parseJSON = withText "InvirationRole" $ \t -> case t of
52+
"direct_member" -> pure InvitationRoleDirectMember
53+
"admin" -> pure InvitationRoleAdmin
54+
"billing_manager" -> pure InvitationRoleBillingManager
55+
"hiring_manager" -> pure InvitationRoleHiringManager
56+
"reinstate" -> pure InvitationRoleReinstate
57+
_ -> fail $ "Invalid role " ++ show t

src/GitHub/Endpoints/Organizations/Members.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module GitHub.Endpoints.Organizations.Members (
1313
isMemberOf,
1414
isMemberOf',
1515
isMemberOfR,
16+
orgInvitationsR,
1617
module GitHub.Data,
1718
) where
1819

@@ -78,4 +79,10 @@ isMemberOf = isMemberOf' Nothing
7879
-- See <https://developer.github.com/v3/orgs/members/#check-membership>
7980
isMemberOfR :: Name User -> Name Organization -> Request k Bool
8081
isMemberOfR user org = StatusQuery statusOnlyOk $
81-
Query [ "orgs", toPathPart org, "members", toPathPart user ] []
82+
Query [ "orgs", toPathPart org, "members", toPathPart user ] []
83+
84+
-- | List pending organization invitations
85+
--
86+
-- See <https://developer.github.com/v3/orgs/members/#list-pending-organization-invitations>
87+
orgInvitationsR :: Name Organization -> FetchCount -> Request 'RA (Vector Invitation)
88+
orgInvitationsR org = pagedQuery ["orgs", toPathPart org, "invitations"] []

0 commit comments

Comments
 (0)