{-# 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 =
fromRight (error "repositories error") <$> repositories' (project_id project)
repositories' ::
Int ->
GitLab (Either Status [Repository])
repositories' projectId =
gitlab addr
where
addr =
"/projects/"
<> T.pack (show projectId)
<> "/repository"
<> "/tree"
getFileArchive ::
Project ->
ArchiveFormat ->
FilePath ->
GitLab (Either Status ())
getFileArchive project = getFileArchive' (project_id project)
getFileArchiveBS ::
Project ->
ArchiveFormat ->
GitLab (Either Status BSL.ByteString)
getFileArchiveBS project = getFileArchiveBS' (project_id project)
getFileArchive' ::
Int ->
ArchiveFormat ->
FilePath ->
GitLab (Either Status ())
getFileArchive' projectId format path = do
attempt <- getFileArchiveBS' projectId format
case attempt of
Left st -> return (Left st)
Right archiveData ->
Right <$> liftIO (BSL.writeFile path archiveData)
getFileArchiveBS' ::
Int ->
ArchiveFormat ->
GitLab (Either Status BSL.ByteString)
getFileArchiveBS' projectId format =
gitlabReqByteString addr
where
addr =
"/projects/"
<> T.pack (show projectId)
<> "/repository"
<> "/archive"
<> T.pack (show format)