-- |
-- The repo collaborators API as described on
-- <http://developer.github.com/v3/repos/collaborators/>.

module GitHub.Endpoints.Repos.Collaborators (
    collaboratorsOnR,
    collaboratorPermissionOnR,
    isCollaboratorOnR,
    addCollaboratorR,
    module GitHub.Data,
    ) where

import GitHub.Data
import GitHub.Internal.Prelude
import Prelude ()

-- | List collaborators.
-- See <https://developer.github.com/v3/repos/collaborators/#list-collaborators>
collaboratorsOnR :: Name Owner -> Name Repo -> FetchCount -> Request k (Vector SimpleUser)
collaboratorsOnR :: forall (k :: RW).
Name Owner
-> Name Repo -> FetchCount -> Request k (Vector SimpleUser)
collaboratorsOnR Name Owner
user Name Repo
repo =
    Paths -> QueryString -> FetchCount -> Request k (Vector SimpleUser)
forall a (mt :: RW).
FromJSON a =>
Paths -> QueryString -> FetchCount -> Request mt (Vector a)
pagedQuery [Text
"repos", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
user, Name Repo -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Repo
repo, Text
"collaborators"] []

-- | Review a user's permission level.
-- <https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level>
collaboratorPermissionOnR
    :: Name Owner        -- ^ Repository owner
    -> Name Repo         -- ^ Repository name
    -> Name User         -- ^ Collaborator to check permissions of.
    -> GenRequest 'MtJSON rw CollaboratorWithPermission
collaboratorPermissionOnR :: forall (rw :: RW).
Name Owner
-> Name Repo
-> Name User
-> GenRequest 'MtJSON rw CollaboratorWithPermission
collaboratorPermissionOnR Name Owner
owner Name Repo
repo Name User
coll =
    Paths -> QueryString -> Request rw CollaboratorWithPermission
forall (mt :: RW) a. Paths -> QueryString -> Request mt a
query [Text
"repos", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
owner, Name Repo -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Repo
repo, Text
"collaborators", Name User -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name User
coll, Text
"permission"] []

-- | Check if a user is a collaborator.
-- See <https://developer.github.com/v3/repos/collaborators/#check-if-a-user-is-a-collaborator>
isCollaboratorOnR
    :: Name Owner  -- ^ Repository owner
    -> Name Repo         -- ^ Repository name
    -> Name User         -- ^ Collaborator?
    -> GenRequest 'MtStatus rw Bool
isCollaboratorOnR :: forall (rw :: RW).
Name Owner
-> Name Repo -> Name User -> GenRequest 'MtStatus rw Bool
isCollaboratorOnR Name Owner
user Name Repo
repo Name User
coll =
    Paths -> QueryString -> GenRequest 'MtStatus rw Bool
forall (mt :: MediaType (*)) (rw :: RW) a.
Paths -> QueryString -> GenRequest mt rw a
Query [Text
"repos", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
user, Name Repo -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Repo
repo, Text
"collaborators", Name User -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name User
coll] []

-- | Invite a user as a collaborator.
-- See <https://developer.github.com/v3/repos/collaborators/#add-user-as-a-collaborator>
addCollaboratorR
    :: Name Owner        -- ^ Repository owner
    -> Name Repo         -- ^ Repository name
    -> Name User         -- ^ Collaborator to add
    -> GenRequest 'MtJSON 'RW (Maybe RepoInvitation)
addCollaboratorR :: Name Owner
-> Name Repo
-> Name User
-> GenRequest 'MtJSON 'RW (Maybe RepoInvitation)
addCollaboratorR Name Owner
owner Name Repo
repo Name User
coll =
    CommandMethod
-> Paths
-> ByteString
-> GenRequest 'MtJSON 'RW (Maybe RepoInvitation)
forall (mt :: MediaType (*)) a.
CommandMethod -> Paths -> ByteString -> GenRequest mt 'RW a
Command CommandMethod
Put [Text
"repos", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
owner, Name Repo -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Repo
repo, Text
"collaborators", Name User -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name User
coll] ByteString
forall a. Monoid a => a
mempty