-----------------------------------------------------------------------------
-- |
-- License     :  BSD-3-Clause
-- Maintainer  :  Oleg Grenrus <oleg.grenrus@iki.fi>
--
-- The repo statuses API as described on
-- <https://developer.github.com/v3/repos/statuses/>.
module GitHub.Endpoints.Repos.Statuses (
    createStatusR,
    statusesForR,
    statusForR,
    module GitHub.Data
    ) where

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

-- | Create a new status
-- See <https://developer.github.com/v3/repos/statuses/#create-a-status>
createStatusR :: Name Owner -> Name Repo -> Name Commit -> NewStatus -> Request 'RW Status
createStatusR :: Name Owner
-> Name Repo -> Name Commit -> NewStatus -> Request 'RW Status
createStatusR Name Owner
owner Name Repo
repo Name Commit
sha =
    CommandMethod -> Paths -> ByteString -> Request 'RW Status
forall a. CommandMethod -> Paths -> ByteString -> Request 'RW a
command CommandMethod
Post Paths
parts (ByteString -> Request 'RW Status)
-> (NewStatus -> ByteString) -> NewStatus -> Request 'RW Status
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NewStatus -> ByteString
forall a. ToJSON a => a -> ByteString
encode
    where
        parts :: Paths
parts = [Text
"repos", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
owner, Name Repo -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Repo
repo, Text
"statuses", Name Commit -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Commit
sha]

-- | All statuses for a commit
-- See <https://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref>
statusesForR :: Name Owner -> Name Repo -> Name Commit -> FetchCount -> Request 'RW (Vector Status)
statusesForR :: Name Owner
-> Name Repo
-> Name Commit
-> FetchCount
-> Request 'RW (Vector Status)
statusesForR Name Owner
user Name Repo
repo Name Commit
sha =
    Paths -> QueryString -> FetchCount -> Request 'RW (Vector Status)
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
"commits", Name Commit -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Commit
sha, Text
"statuses"] []

-- | The combined status for a specific commit
-- See <https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref>
statusForR :: Name Owner -> Name Repo -> Name Commit -> Request 'RW CombinedStatus
statusForR :: Name Owner
-> Name Repo -> Name Commit -> Request 'RW CombinedStatus
statusForR Name Owner
user Name Repo
repo Name Commit
sha =
    Paths -> QueryString -> Request 'RW CombinedStatus
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
"commits", Name Commit -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Commit
sha, Text
"status"] []