module GitHub.Endpoints.Repos.Contents (
contentsForR,
readmeForR,
archiveForR,
createFileR,
updateFileR,
deleteFileR,
module GitHub.Data
) where
import GitHub.Data
import GitHub.Internal.Prelude
import Prelude ()
import Data.Maybe (maybeToList)
import qualified Data.Text.Encoding as TE
import Network.URI (URI)
contentsForR
:: Name Owner
-> Name Repo
-> Text
-> Maybe Text
-> Request k Content
contentsForR :: Name Owner -> Name Repo -> Text -> Maybe Text -> Request k Content
contentsForR Name Owner
user Name Repo
repo Text
path Maybe Text
ref =
Paths -> QueryString -> Request k Content
forall (mt :: RW) a. Paths -> QueryString -> Request mt a
query [Text
"repos", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
user, Name Repo -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Repo
repo, Text
"contents", Text
path] QueryString
qs
where
qs :: QueryString
qs = QueryString -> (Text -> QueryString) -> Maybe Text -> QueryString
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Text
r -> [(ByteString
"ref", ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just (ByteString -> Maybe ByteString)
-> (Text -> ByteString) -> Text -> Maybe ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ByteString
TE.encodeUtf8 (Text -> Maybe ByteString) -> Text -> Maybe ByteString
forall a b. (a -> b) -> a -> b
$ Text
r)]) Maybe Text
ref
readmeForR :: Name Owner -> Name Repo -> Request k Content
readmeForR :: Name Owner -> Name Repo -> Request k Content
readmeForR Name Owner
user Name Repo
repo =
Paths -> QueryString -> Request k Content
forall (mt :: RW) a. Paths -> QueryString -> Request mt a
query [Text
"repos", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
user, Name Repo -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Repo
repo, Text
"readme"] []
archiveForR
:: Name Owner
-> Name Repo
-> ArchiveFormat
-> Maybe Text
-> GenRequest 'MtRedirect rw URI
archiveForR :: Name Owner
-> Name Repo
-> ArchiveFormat
-> Maybe Text
-> GenRequest 'MtRedirect rw URI
archiveForR Name Owner
user Name Repo
repo ArchiveFormat
format Maybe Text
ref = Paths -> QueryString -> GenRequest 'MtRedirect rw URI
forall (mt :: MediaType *) (rw :: RW) a.
Paths -> QueryString -> GenRequest mt rw a
Query Paths
path []
where
path :: Paths
path = [Text
"repos", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
user, Name Repo -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Repo
repo, ArchiveFormat -> Text
forall a. IsPathPart a => a -> Text
toPathPart ArchiveFormat
format] Paths -> Paths -> Paths
forall a. Semigroup a => a -> a -> a
<> Maybe Text -> Paths
forall a. Maybe a -> [a]
maybeToList Maybe Text
ref
createFileR
:: Name Owner
-> Name Repo
-> CreateFile
-> Request 'RW ContentResult
createFileR :: Name Owner -> Name Repo -> CreateFile -> Request 'RW ContentResult
createFileR Name Owner
user Name Repo
repo CreateFile
body =
CommandMethod -> Paths -> ByteString -> Request 'RW ContentResult
forall a. CommandMethod -> Paths -> ByteString -> Request 'RW a
command CommandMethod
Put [Text
"repos", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
user, Name Repo -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Repo
repo, Text
"contents", CreateFile -> Text
createFilePath CreateFile
body] (CreateFile -> ByteString
forall a. ToJSON a => a -> ByteString
encode CreateFile
body)
updateFileR
:: Name Owner
-> Name Repo
-> UpdateFile
-> Request 'RW ContentResult
updateFileR :: Name Owner -> Name Repo -> UpdateFile -> Request 'RW ContentResult
updateFileR Name Owner
user Name Repo
repo UpdateFile
body =
CommandMethod -> Paths -> ByteString -> Request 'RW ContentResult
forall a. CommandMethod -> Paths -> ByteString -> Request 'RW a
command CommandMethod
Put [Text
"repos", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
user, Name Repo -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Repo
repo, Text
"contents", UpdateFile -> Text
updateFilePath UpdateFile
body] (UpdateFile -> ByteString
forall a. ToJSON a => a -> ByteString
encode UpdateFile
body)
deleteFileR
:: Name Owner
-> Name Repo
-> DeleteFile
-> GenRequest 'MtUnit 'RW ()
deleteFileR :: Name Owner -> Name Repo -> DeleteFile -> GenRequest 'MtUnit 'RW ()
deleteFileR Name Owner
user Name Repo
repo DeleteFile
body =
CommandMethod -> Paths -> ByteString -> GenRequest 'MtUnit 'RW ()
forall (mt :: MediaType *) a.
CommandMethod -> Paths -> ByteString -> GenRequest mt 'RW a
Command CommandMethod
Delete [Text
"repos", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
user, Name Repo -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Repo
repo, Text
"contents", DeleteFile -> Text
deleteFilePath DeleteFile
body] (DeleteFile -> ByteString
forall a. ToJSON a => a -> ByteString
encode DeleteFile
body)