{-# LANGUAGE OverloadedStrings #-}
module GitLab
( runGitLab,
runGitLabDbg,
runGitLabWithManager,
module GitLab.Types,
module GitLab.API.Pipelines,
module GitLab.API.Groups,
module GitLab.API.Members,
module GitLab.API.Commits,
module GitLab.API.Projects,
module GitLab.API.Users,
module GitLab.API.Issues,
module GitLab.API.Branches,
module GitLab.API.Jobs,
module GitLab.API.MergeRequests,
module GitLab.API.Repositories,
module GitLab.API.RepositoryFiles,
module GitLab.API.Tags,
module GitLab.API.Todos,
module GitLab.API.Version,
module GitLab.API.Notes,
module GitLab.API.Discussions,
module GitLab.SystemHooks.GitLabSystemHooks,
module GitLab.SystemHooks.Types,
module GitLab.SystemHooks.Rules,
)
where
import Control.Monad.IO.Class
import Control.Monad.Trans.Reader
import GitLab.API.Branches
import GitLab.API.Commits
import GitLab.API.Discussions
import GitLab.API.Groups
import GitLab.API.Issues
import GitLab.API.Jobs
import GitLab.API.Members
import GitLab.API.MergeRequests
import GitLab.API.Notes
import GitLab.API.Pipelines
import GitLab.API.Projects
import GitLab.API.Repositories
import GitLab.API.RepositoryFiles
import GitLab.API.Tags
import GitLab.API.Todos
import GitLab.API.Users
import GitLab.API.Version
import GitLab.SystemHooks.GitLabSystemHooks
import GitLab.SystemHooks.Rules
import GitLab.SystemHooks.Types
import GitLab.Types
import Network.Connection (TLSSettings (..))
import Network.HTTP.Conduit
import Network.HTTP.Types.Status
import System.IO
runGitLab :: GitLabServerConfig -> GitLab a -> IO a
runGitLab :: GitLabServerConfig -> GitLab a -> IO a
runGitLab GitLabServerConfig
cfg GitLab a
action = do
IO () -> IO ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ Handle -> BufferMode -> IO ()
hSetBuffering Handle
stdout BufferMode
LineBuffering
let settings :: ManagerSettings
settings = TLSSettings -> Maybe SockSettings -> ManagerSettings
mkManagerSettings (Bool -> Bool -> Bool -> TLSSettings
TLSSettingsSimple Bool
True Bool
False Bool
False) Maybe SockSettings
forall a. Maybe a
Nothing
Manager
manager <- IO Manager -> IO Manager
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Manager -> IO Manager) -> IO Manager -> IO Manager
forall a b. (a -> b) -> a -> b
$ ManagerSettings -> IO Manager
newManager ManagerSettings
settings
Manager -> GitLabServerConfig -> GitLab a -> IO a
forall a. Manager -> GitLabServerConfig -> GitLab a -> IO a
runGitLabWithManager Manager
manager GitLabServerConfig
cfg GitLab a
action
runGitLabWithManager :: Manager -> GitLabServerConfig -> GitLab a -> IO a
runGitLabWithManager :: Manager -> GitLabServerConfig -> GitLab a -> IO a
runGitLabWithManager Manager
manager GitLabServerConfig
cfg GitLab a
action = do
Either Status (Maybe Version)
tokenTest <- ReaderT GitLabState IO (Either Status (Maybe Version))
-> GitLabState -> IO (Either Status (Maybe Version))
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT ReaderT GitLabState IO (Either Status (Maybe Version))
gitlabVersion (GitLabServerConfig -> Manager -> GitLabState
GitLabState GitLabServerConfig
cfg Manager
manager)
case Either Status (Maybe Version)
tokenTest of
Left (Status Int
401 ByteString
"Unauthorized") -> [Char] -> IO a
forall a. HasCallStack => [Char] -> a
error [Char]
"access token not accepted."
Left Status
st -> [Char] -> IO a
forall a. HasCallStack => [Char] -> a
error ([Char]
"unexpected HTTP status: " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> Status -> [Char]
forall a. Show a => a -> [Char]
show Status
st)
Right Maybe Version
_versionInfo ->
GitLab a -> GitLabState -> IO a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT GitLab a
action (GitLabServerConfig -> Manager -> GitLabState
GitLabState GitLabServerConfig
cfg Manager
manager)
runGitLabDbg :: GitLab a -> IO a
runGitLabDbg :: GitLab a -> IO a
runGitLabDbg GitLab a
action = do
IO () -> IO ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ Handle -> BufferMode -> IO ()
hSetBuffering Handle
stdout BufferMode
LineBuffering
GitLab a -> GitLabState -> IO a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT GitLab a
action GitLabState
forall a. HasCallStack => a
undefined