-- The Release API, as described at
-- <https://developer.github.com/v3/repos/releases/>.
module GitHub.Endpoints.Repos.Releases (
    releasesR,
    releaseR,
    latestReleaseR,
    releaseByTagNameR,
    module GitHub.Data,
    ) where

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

-- | List releases for a repository.
-- See <https://developer.github.com/v3/repos/releases/#list-releases-for-a-repository>
releasesR :: Name Owner -> Name Repo -> FetchCount -> Request k (Vector Release)
releasesR :: forall (k :: RW).
Name Owner -> Name Repo -> FetchCount -> Request k (Vector Release)
releasesR Name Owner
user Name Repo
repo =
    Paths -> QueryString -> FetchCount -> Request k (Vector Release)
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
"releases"] []

-- | Get a single release.
-- See <https://developer.github.com/v3/repos/releases/#get-a-single-release>
releaseR :: Name Owner -> Name Repo -> Id Release -> Request k Release
releaseR :: forall (k :: RW).
Name Owner -> Name Repo -> Id Release -> Request k Release
releaseR Name Owner
user Name Repo
repo Id Release
reqReleaseId =
    Paths -> QueryString -> Request k Release
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
"releases", Id Release -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Release
reqReleaseId ] []

-- | Get the latest release.
-- See <https://developer.github.com/v3/repos/releases/#get-the-latest-release>
latestReleaseR :: Name Owner -> Name Repo -> Request k Release
latestReleaseR :: forall (k :: RW). Name Owner -> Name Repo -> Request k Release
latestReleaseR Name Owner
user Name Repo
repo =
    Paths -> QueryString -> Request k Release
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
"releases", Text
"latest" ] []

-- | Get a release by tag name
-- See <https://developer.github.com/v3/repos/releases/#get-a-release-by-tag-name>
releaseByTagNameR :: Name Owner -> Name Repo -> Text -> Request k Release
releaseByTagNameR :: forall (k :: RW).
Name Owner -> Name Repo -> Text -> Request k Release
releaseByTagNameR Name Owner
user Name Repo
repo Text
reqTagName =
    Paths -> QueryString -> Request k Release
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
"releases", Text
"tags" , Text
reqTagName ] []

{-
--  TODO: implement the following:
    https://developer.github.com/v3/repos/releases/#create-a-release
    https://developer.github.com/v3/repos/releases/#edit-a-release
    https://developer.github.com/v3/repos/releases/#delete-a-release
    https://developer.github.com/v3/repos/releases/#list-assets-for-a-release
    https://developer.github.com/v3/repos/releases/#upload-a-release-asset
    https://developer.github.com/v3/repos/releases/#get-a-single-release-asset
    https://developer.github.com/v3/repos/releases/#edit-a-release-asset
    https://developer.github.com/v3/repos/releases/#delete-a-release-asset
-}