-- |
-- The underlying git references on a Github repo, exposed for the world to
-- see. The git internals documentation will also prove handy for understanding
-- these. API documentation at <http://developer.github.com/v3/git/refs/>.

module GitHub.Endpoints.GitData.References (
    referenceR,
    referencesR,
    createReferenceR,
    deleteReferenceR,
    namespacedReferencesR,
    module GitHub.Data,
    ) where

import GitHub.Data
import GitHub.Internal.Prelude
import Prelude ()

-- | A single reference -- | Query a reference.
-- See <https://developer.github.com/v3/git/refs/#get-a-reference>
referenceR :: Name Owner -> Name Repo -> Name GitReference -> Request k GitReference
referenceR :: forall (k :: RW).
Name Owner
-> Name Repo -> Name GitReference -> Request k GitReference
referenceR Name Owner
user Name Repo
repo Name GitReference
ref =
    Paths -> QueryString -> Request k GitReference
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
"git", Text
"refs", Name GitReference -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name GitReference
ref] []

-- | Query all References.
-- See <https://developer.github.com/v3/git/refs/#get-all-references>
referencesR :: Name Owner -> Name Repo -> FetchCount -> Request k (Vector GitReference)
referencesR :: forall (k :: RW).
Name Owner
-> Name Repo -> FetchCount -> Request k (Vector GitReference)
referencesR Name Owner
user Name Repo
repo =
    Paths
-> QueryString -> FetchCount -> Request k (Vector GitReference)
forall a (mt :: RW).
FromJSON a =>
Paths -> QueryString -> FetchCount -> Request mt (Vector a)
pagedQuery [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
"git", Text
"refs"] []

-- | Create a reference.
-- See <https://developer.github.com/v3/git/refs/#create-a-reference>
createReferenceR :: Name Owner -> Name Repo -> NewGitReference -> Request 'RW GitReference
createReferenceR :: Name Owner
-> Name Repo -> NewGitReference -> Request 'RW GitReference
createReferenceR Name Owner
user Name Repo
repo NewGitReference
newRef =
     CommandMethod -> Paths -> ByteString -> Request 'RW GitReference
forall a. CommandMethod -> Paths -> ByteString -> Request 'RW a
command CommandMethod
Post  [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
"git", Text
"refs"] (NewGitReference -> ByteString
forall a. ToJSON a => a -> ByteString
encode NewGitReference
newRef)

-- | Delete a reference.
-- See <https://developer.github.com/v3/git/refs/#delete-a-reference>
deleteReferenceR :: Name Owner -> Name Repo -> Name GitReference -> GenRequest 'MtUnit 'RW ()
deleteReferenceR :: Name Owner
-> Name Repo -> Name GitReference -> GenRequest 'MtUnit 'RW ()
deleteReferenceR Name Owner
user Name Repo
repo Name GitReference
ref =
    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
"git", Text
"refs", Name GitReference -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name GitReference
ref] ByteString
forall a. Monoid a => a
mempty

-- | Query namespaced references.
-- See <https://developer.github.com/v3/git/refs/#get-all-references>
namespacedReferencesR :: Name Owner -> Name Repo -> Text -> Request k [GitReference]
namespacedReferencesR :: forall (k :: RW).
Name Owner -> Name Repo -> Text -> Request k [GitReference]
namespacedReferencesR Name Owner
user Name Repo
repo Text
namespace =
    Paths -> QueryString -> Request k [GitReference]
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
"git", Text
"refs", Text
namespace] []