{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}
module GitLab.API.Members where
import Control.Concurrent.Async
import Control.Monad
import Control.Monad.IO.Class
import Control.Monad.Trans.Reader
import Data.List
import Data.Text (Text)
import qualified Data.Text as T
import Data.Time.Calendar
import Network.HTTP.Types.Status
import System.IO
import GitLab.Types
import GitLab.WebRequests.GitLabWebCalls
data AccessLevel =
Guest
| Reporter
| Developer
| Maintainer
| Owner
instance Show AccessLevel where
show Guest = "10"
show Reporter = "20"
show Developer = "30"
show Maintainer = "40"
show Owner = "50"
membersOfProject :: (MonadIO m) => Project -> GitLab m [Member]
membersOfProject = membersOfProject' . project_id
membersOfProject' :: (MonadIO m) => Int -> GitLab m [Member]
membersOfProject' projectId =
gitlab addr
where
addr =
"/projects/" <> T.pack (show projectId) <> "/members"
addMemberToProject ::
(MonadIO m)
=> Project
-> AccessLevel
-> User
-> GitLab m (Either Status Member)
addMemberToProject project access user =
addMemberToProject' (project_id project) access (user_id user)
addMemberToProject' ::
(MonadIO m)
=> Int
-> AccessLevel
-> Int
-> GitLab m (Either Status Member)
addMemberToProject' projectId access userId =
gitlabPost addr dataBody
where
dataBody :: Text
dataBody =
"user_id=" <> T.pack (show userId) <> "&access_level=" <> T.pack (show access)
addr =
"/projects/" <> T.pack (show projectId) <> "/members"
addMembersToProject ::
(MonadIO m)
=> Project
-> AccessLevel
-> [User]
-> GitLab m [Either Status Member]
addMembersToProject project access =
mapM (addMemberToProject project access)
addMembersToProject' ::
(MonadIO m)
=> Int
-> AccessLevel
-> [Int]
-> GitLab m [Either Status Member]
addMembersToProject' projectId access =
mapM (addMemberToProject' projectId access)