-----------------------------------------------------------------------------
-- |
-- 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 (
    createStatus,
    createStatusR,
    statusesFor,
    statusesForR,
    statusFor,
    statusForR,
    module GitHub.Data
    ) where

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

-- | Create a new status
--
-- > createStatus (BasicAuth user password) "thoughtbot" "paperclip"
-- >   "41f685f6e01396936bb8cd98e7cca517e2c7d96b"
-- >   (NewStatus StatusSuccess Nothing "Looks good!" Nothing)
createStatus :: Auth -> Name Owner -> Name Repo -> Name Commit -> NewStatus -> IO (Either Error Status)
createStatus :: Auth
-> Name Owner
-> Name Repo
-> Name Commit
-> NewStatus
-> IO (Either Error Status)
createStatus auth :: Auth
auth owner :: Name Owner
owner repo :: Name Repo
repo sha :: Name Commit
sha ns :: NewStatus
ns =
    Auth -> GenRequest 'MtJSON 'RW Status -> IO (Either Error Status)
forall am (mt :: MediaType *) a (rw :: RW).
(AuthMethod am, ParseResponse mt a) =>
am -> GenRequest mt rw a -> IO (Either Error a)
executeRequest Auth
auth (GenRequest 'MtJSON 'RW Status -> IO (Either Error Status))
-> GenRequest 'MtJSON 'RW Status -> IO (Either Error Status)
forall a b. (a -> b) -> a -> b
$ Name Owner
-> Name Repo
-> Name Commit
-> NewStatus
-> GenRequest 'MtJSON 'RW Status
createStatusR Name Owner
owner Name Repo
repo Name Commit
sha NewStatus
ns

-- | 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
-> GenRequest 'MtJSON 'RW Status
createStatusR owner :: Name Owner
owner repo :: Name Repo
repo sha :: Name Commit
sha =
    CommandMethod
-> Paths -> ByteString -> GenRequest 'MtJSON 'RW Status
forall a. CommandMethod -> Paths -> ByteString -> Request 'RW a
command CommandMethod
Post Paths
parts (ByteString -> GenRequest 'MtJSON 'RW Status)
-> (NewStatus -> ByteString)
-> NewStatus
-> GenRequest 'MtJSON '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 = ["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, "statuses", Name Commit -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Commit
sha]

-- | All statuses for a commit
--
-- > statusesFor (BasicAuth user password) "thoughtbot" "paperclip"
-- >   "41f685f6e01396936bb8cd98e7cca517e2c7d96b"
statusesFor :: Auth -> Name Owner -> Name Repo -> Name Commit -> IO (Either Error (Vector Status))
statusesFor :: Auth
-> Name Owner
-> Name Repo
-> Name Commit
-> IO (Either Error (Vector Status))
statusesFor auth :: Auth
auth user :: Name Owner
user repo :: Name Repo
repo sha :: Name Commit
sha =
    Auth
-> GenRequest 'MtJSON 'RW (Vector Status)
-> IO (Either Error (Vector Status))
forall am (mt :: MediaType *) a (rw :: RW).
(AuthMethod am, ParseResponse mt a) =>
am -> GenRequest mt rw a -> IO (Either Error a)
executeRequest Auth
auth (GenRequest 'MtJSON 'RW (Vector Status)
 -> IO (Either Error (Vector Status)))
-> GenRequest 'MtJSON 'RW (Vector Status)
-> IO (Either Error (Vector Status))
forall a b. (a -> b) -> a -> b
$ Name Owner
-> Name Repo
-> Name Commit
-> FetchCount
-> GenRequest 'MtJSON 'RW (Vector Status)
statusesForR Name Owner
user Name Repo
repo Name Commit
sha FetchCount
FetchAll

-- | 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
-> GenRequest 'MtJSON 'RW (Vector Status)
statusesForR user :: Name Owner
user repo :: Name Repo
repo sha :: Name Commit
sha =
    Paths
-> QueryString
-> FetchCount
-> GenRequest 'MtJSON 'RW (Vector Status)
forall a (mt :: RW).
FromJSON a =>
Paths -> QueryString -> FetchCount -> Request mt (Vector a)
pagedQuery ["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, "commits", Name Commit -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Commit
sha, "statuses"] []

-- | The combined status for a specific commit
--
-- > statusFor (BasicAuth user password) "thoughtbot" "paperclip"
-- >   "41f685f6e01396936bb8cd98e7cca517e2c7d96b"
statusFor :: Auth -> Name Owner -> Name Repo -> Name Commit -> IO (Either Error CombinedStatus)
statusFor :: Auth
-> Name Owner
-> Name Repo
-> Name Commit
-> IO (Either Error CombinedStatus)
statusFor auth :: Auth
auth user :: Name Owner
user repo :: Name Repo
repo sha :: Name Commit
sha =
    Auth
-> GenRequest 'MtJSON 'RW CombinedStatus
-> IO (Either Error CombinedStatus)
forall am (mt :: MediaType *) a (rw :: RW).
(AuthMethod am, ParseResponse mt a) =>
am -> GenRequest mt rw a -> IO (Either Error a)
executeRequest Auth
auth (GenRequest 'MtJSON 'RW CombinedStatus
 -> IO (Either Error CombinedStatus))
-> GenRequest 'MtJSON 'RW CombinedStatus
-> IO (Either Error CombinedStatus)
forall a b. (a -> b) -> a -> b
$ Name Owner
-> Name Repo
-> Name Commit
-> GenRequest 'MtJSON 'RW CombinedStatus
statusForR Name Owner
user Name Repo
repo Name Commit
sha

-- | 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
-> GenRequest 'MtJSON 'RW CombinedStatus
statusForR user :: Name Owner
user repo :: Name Repo
repo sha :: Name Commit
sha =
    Paths -> QueryString -> GenRequest 'MtJSON 'RW CombinedStatus
forall (mt :: RW) a. Paths -> QueryString -> Request mt a
query ["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, "commits", Name Commit -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Commit
sha, "status"] []