{-# LANGUAGE OverloadedStrings #-}
module GitLab.API.RepositoryFiles where
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import GitLab.Types
import GitLab.WebRequests.GitLabWebCalls
import Network.HTTP.Types.Status
import Network.HTTP.Types.URI
repositoryFiles ::
Project ->
Text ->
Text ->
GitLab (Either Status (Maybe RepositoryFile))
repositoryFiles :: Project
-> Text -> Text -> GitLab (Either Status (Maybe RepositoryFile))
repositoryFiles Project
project = Int
-> Text -> Text -> GitLab (Either Status (Maybe RepositoryFile))
repositoryFiles' (Project -> Int
project_id Project
project)
repositoryFiles' ::
Int ->
Text ->
Text ->
GitLab (Either Status (Maybe RepositoryFile))
repositoryFiles' :: Int
-> Text -> Text -> GitLab (Either Status (Maybe RepositoryFile))
repositoryFiles' Int
projectId Text
filePath Text
reference =
Text -> Text -> GitLab (Either Status (Maybe RepositoryFile))
forall a.
FromJSON a =>
Text -> Text -> GitLab (Either Status (Maybe a))
gitlabWithAttrsOne Text
addr (Text
"&ref=" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
reference)
where
addr :: Text
addr =
Text
"/projects/"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
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
"/files"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ByteString -> Text
T.decodeUtf8 (Bool -> ByteString -> ByteString
urlEncode Bool
False (Text -> ByteString
T.encodeUtf8 Text
filePath))
repositoryFileBlob ::
Int ->
Text ->
GitLab (Either Status String)
repositoryFileBlob :: Int -> Text -> GitLab (Either Status String)
repositoryFileBlob Int
projectId Text
blobSha =
Text -> GitLab (Either Status String)
gitlabReqText Text
addr
where
addr :: Text
addr =
Text
"/projects/"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
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
"/blobs/"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
blobSha
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/raw"