Skip to content

Commit 3b7048a

Browse files
committed
Squashed commit of the following:
commit 267979d Author: Sajid Ibne Anower <sajidanower23@gmail.com> Date: Thu May 2 13:16:38 2019 +1000 Add function to list user's invitations ... and others
1 parent 1119ad4 commit 3b7048a

6 files changed

Lines changed: 81 additions & 3 deletions

File tree

github.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ library
132132
GitHub.Endpoints.Repos.Releases
133133
GitHub.Endpoints.Repos.Statuses
134134
GitHub.Endpoints.Repos.Webhooks
135+
GitHub.Endpoints.Repos.Invitations
135136
GitHub.Endpoints.Search
136137
GitHub.Endpoints.Users
137138
GitHub.Endpoints.Users.Emails

src/GitHub.hs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,19 @@ module GitHub (
319319
latestReleaseR,
320320
releaseByTagNameR,
321321

322+
-- ** Invitations
323+
-- | See <https://developer.github.com/v3/repos/invitations/>
324+
-- Missing endpoints:
325+
326+
-- * Delete a repository invitation
327+
-- * Update a repository invitation
328+
-- * Decline a repository invitation
329+
330+
listInvitationsOnR,
331+
acceptInvitationFromR,
332+
listInvitationsForR,
333+
334+
322335
-- * Search
323336
-- | See <https://developer.github.com/v3/search/>
324337
--
@@ -408,6 +421,7 @@ import GitHub.Endpoints.Repos.Comments
408421
import GitHub.Endpoints.Repos.Commits
409422
import GitHub.Endpoints.Repos.Deployments
410423
import GitHub.Endpoints.Repos.Forks
424+
import GitHub.Endpoints.Repos.Invitations
411425
import GitHub.Endpoints.Repos.Releases
412426
import GitHub.Endpoints.Repos.Statuses
413427
import GitHub.Endpoints.Repos.Webhooks

src/GitHub/Data/Invitation.hs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ module GitHub.Data.Invitation where
88
import GitHub.Data.Definitions
99
import GitHub.Data.Id (Id)
1010
import GitHub.Data.Name (Name)
11+
import GitHub.Data.Repos (Repo)
12+
import GitHub.Data.URL (URL)
1113
import GitHub.Internal.Prelude
1214
import Prelude ()
1315

@@ -57,3 +59,29 @@ instance FromJSON InvitationRole where
5759
"hiring_manager" -> pure InvitationRoleHiringManager
5860
"reinstate" -> pure InvitationRoleReinstate
5961
_ -> fail $ "Unknown InvitationRole: " <> T.unpack t
62+
63+
data RepoInvitation = RepoInvitation
64+
{ repoInvitationId :: !(Id RepoInvitation)
65+
, repoInvitationInvitee :: !SimpleUser
66+
, repoInvitationInviter :: !SimpleUser
67+
, repoInvitationRepo :: !Repo
68+
, repoInvitationUrl :: !URL
69+
, repoInvitationCreatedAt :: !UTCTime
70+
, repoInvitationPermission :: !Text
71+
, repoInvitationHtmlUrl :: !URL
72+
}
73+
deriving (Show, Data, Typeable, Eq, Ord, Generic)
74+
75+
instance NFData RepoInvitation where rnf = genericRnf
76+
instance Binary RepoInvitation
77+
78+
instance FromJSON RepoInvitation where
79+
parseJSON = withObject "RepoInvitation" $ \o -> RepoInvitation
80+
<$> o .: "id"
81+
<*> o .: "invitee"
82+
<*> o .: "inviter"
83+
<*> o .: "repository"
84+
<*> o .: "url"
85+
<*> o .: "created_at"
86+
<*> o .: "permissions"
87+
<*> o .: "html_url"

src/GitHub/Data/Request.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module GitHub.Data.Request (
2626
Count,
2727
) where
2828

29-
import GitHub.Data.Definitions (Count, QueryString, IssueNumber, unIssueNumber)
29+
import GitHub.Data.Definitions (Count, IssueNumber, QueryString, unIssueNumber)
3030
import GitHub.Data.Id (Id, untagId)
3131
import GitHub.Data.Name (Name, untagName)
3232
import GitHub.Internal.Prelude

src/GitHub/Endpoints/Repos/Collaborators.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ addCollaborator
6868
-> Name Owner -- ^ Repository owner
6969
-> Name Repo -- ^ Repository name
7070
-> Name User -- ^ Collaborator to add
71-
-> IO (Either Error ())
71+
-> IO (Either Error (Maybe RepoInvitation))
7272
addCollaborator auth owner repo coll =
7373
executeRequest auth $ addCollaboratorR owner repo coll
7474

@@ -78,6 +78,6 @@ addCollaboratorR
7878
:: Name Owner -- ^ Repository owner
7979
-> Name Repo -- ^ Repository name
8080
-> Name User -- ^ Collaborator to add
81-
-> GenRequest 'MtUnit 'RW ()
81+
-> GenRequest 'MtJSON 'RW (Maybe RepoInvitation)
8282
addCollaboratorR owner repo coll =
8383
Command Put ["repos", toPathPart owner, toPathPart repo, "collaborators", toPathPart coll] mempty
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
-----------------------------------------------------------------------------
2+
-- |
3+
-- License : BSD-3-Clause
4+
-- Maintainer : Oleg Grenrus <oleg.grenrus@iki.fi>
5+
--
6+
-- The repo invitations API as described on
7+
-- <https://developer.github.com/v3/repos/invitations/>.
8+
module GitHub.Endpoints.Repos.Invitations (
9+
listInvitationsOnR,
10+
listInvitationsForR,
11+
acceptInvitationFromR
12+
) where
13+
14+
import GitHub.Data
15+
import GitHub.Internal.Prelude
16+
import Prelude ()
17+
18+
-- | List open invitations of a repository
19+
-- See <https://developer.github.com/v3/repos/invitations/#list-invitations-for-a-repository>
20+
listInvitationsOnR :: Name Owner -> Name Repo -> FetchCount -> GenRequest 'MtJSON k (Vector RepoInvitation)
21+
listInvitationsOnR user repo =
22+
PagedQuery ["repos", toPathPart user, toPathPart repo, "invitations"] []
23+
24+
-- | List a user's repository invitations
25+
-- See <https://developer.github.com/v3/repos/invitations/#list-a-users-repository-invitations>
26+
listInvitationsForR :: FetchCount -> Request k (Vector RepoInvitation)
27+
listInvitationsForR =
28+
pagedQuery ["user", "repository_invitations"] []
29+
30+
31+
-- | Accept a repository invitation
32+
-- See <https://developer.github.com/v3/repos/invitations/#accept-a-repository-invitation>
33+
acceptInvitationFromR :: Id RepoInvitation -> GenRequest 'MtUnit 'RW ()
34+
acceptInvitationFromR invId =
35+
Command Patch ["user", "repository_invitations", toPathPart invId] mempty

0 commit comments

Comments
 (0)