{-# LANGUAGE OverloadedStrings #-}
module GitLab.API.Repositories where
import Control.Monad.IO.Unlift
import qualified Data.ByteString.Lazy as BSL
import Data.Either
import qualified Data.Text as T
import GitLab.Types
import GitLab.WebRequests.GitLabWebCalls
import Network.HTTP.Types.Status
repositories ::
Project ->
GitLab [Repository]
repositories :: Project -> GitLab [Repository]
repositories Project
project =
[Repository] -> Either Status [Repository] -> [Repository]
forall b a. b -> Either a b -> b
fromRight ([Char] -> [Repository]
forall a. HasCallStack => [Char] -> a
error [Char]
"repositories error") (Either Status [Repository] -> [Repository])
-> ReaderT GitLabState IO (Either Status [Repository])
-> GitLab [Repository]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> ReaderT GitLabState IO (Either Status [Repository])
repositories' (Project -> Int
project_id Project
project)
repositories' ::
Int ->
GitLab (Either Status [Repository])
repositories' :: Int -> ReaderT GitLabState IO (Either Status [Repository])
repositories' Int
projectId =
Text -> ReaderT GitLabState IO (Either Status [Repository])
forall a. FromJSON a => Text -> GitLab (Either Status [a])
gitlab Text
addr
where
addr :: Text
addr =
Text
"/projects/"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> [Char] -> Text
T.pack (Int -> [Char]
forall a. Show a => a -> [Char]
show Int
projectId)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/repository"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/tree"
getFileArchive ::
Project ->
ArchiveFormat ->
FilePath ->
GitLab (Either Status ())
getFileArchive :: Project -> ArchiveFormat -> [Char] -> GitLab (Either Status ())
getFileArchive Project
project = Int -> ArchiveFormat -> [Char] -> GitLab (Either Status ())
getFileArchive' (Project -> Int
project_id Project
project)
getFileArchiveBS ::
Project ->
ArchiveFormat ->
GitLab (Either Status BSL.ByteString)
getFileArchiveBS :: Project -> ArchiveFormat -> GitLab (Either Status ByteString)
getFileArchiveBS Project
project = Int -> ArchiveFormat -> GitLab (Either Status ByteString)
getFileArchiveBS' (Project -> Int
project_id Project
project)
getFileArchive' ::
Int ->
ArchiveFormat ->
FilePath ->
GitLab (Either Status ())
getFileArchive' :: Int -> ArchiveFormat -> [Char] -> GitLab (Either Status ())
getFileArchive' Int
projectId ArchiveFormat
format [Char]
path = do
Either Status ByteString
attempt <- Int -> ArchiveFormat -> GitLab (Either Status ByteString)
getFileArchiveBS' Int
projectId ArchiveFormat
format
case Either Status ByteString
attempt of
Left Status
st -> Either Status () -> GitLab (Either Status ())
forall (m :: * -> *) a. Monad m => a -> m a
return (Status -> Either Status ()
forall a b. a -> Either a b
Left Status
st)
Right ByteString
archiveData ->
() -> Either Status ()
forall a b. b -> Either a b
Right (() -> Either Status ())
-> ReaderT GitLabState IO () -> GitLab (Either Status ())
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO () -> ReaderT GitLabState IO ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO ([Char] -> ByteString -> IO ()
BSL.writeFile [Char]
path ByteString
archiveData)
getFileArchiveBS' ::
Int ->
ArchiveFormat ->
GitLab (Either Status BSL.ByteString)
getFileArchiveBS' :: Int -> ArchiveFormat -> GitLab (Either Status ByteString)
getFileArchiveBS' Int
projectId ArchiveFormat
format =
Text -> GitLab (Either Status ByteString)
gitlabReqByteString Text
addr
where
addr :: Text
addr =
Text
"/projects/"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> [Char] -> Text
T.pack (Int -> [Char]
forall a. Show a => a -> [Char]
show Int
projectId)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/repository"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/archive"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> [Char] -> Text
T.pack (ArchiveFormat -> [Char]
forall a. Show a => a -> [Char]
show ArchiveFormat
format)