-- |
-- The milestones API as described on
-- <http://developer.github.com/v3/issues/milestones/>.

module GitHub.Endpoints.Issues.Milestones (
    milestonesR,
    milestoneR,
    createMilestoneR,
    updateMilestoneR,
    deleteMilestoneR,
    module GitHub.Data,
    ) where

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

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

-- | Query a single milestone.
-- See <https://developer.github.com/v3/issues/milestones/#get-a-single-milestone>
milestoneR :: Name Owner -> Name Repo -> Id Milestone -> Request k Milestone
milestoneR :: forall (k :: RW).
Name Owner -> Name Repo -> Id Milestone -> Request k Milestone
milestoneR Name Owner
user Name Repo
repo Id Milestone
mid =
    Paths -> QueryString -> Request k Milestone
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
"milestones", Id Milestone -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Milestone
mid] []

-- | Create a milestone.
-- See <https://developer.github.com/v3/issues/milestones/#create-a-milestone>
createMilestoneR :: Name Owner -> Name Repo -> NewMilestone -> Request 'RW Milestone
createMilestoneR :: Name Owner -> Name Repo -> NewMilestone -> Request 'RW Milestone
createMilestoneR Name Owner
user Name Repo
repo =
    CommandMethod -> Paths -> ByteString -> Request 'RW Milestone
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
"milestones"] (ByteString -> Request 'RW Milestone)
-> (NewMilestone -> ByteString)
-> NewMilestone
-> Request 'RW Milestone
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NewMilestone -> ByteString
forall a. ToJSON a => a -> ByteString
encode

-- | Update a milestone.
-- See <https://developer.github.com/v3/issues/milestones/#update-a-milestone>
updateMilestoneR :: Name Owner -> Name Repo -> Id Milestone -> UpdateMilestone -> Request 'RW Milestone
updateMilestoneR :: Name Owner
-> Name Repo
-> Id Milestone
-> UpdateMilestone
-> Request 'RW Milestone
updateMilestoneR Name Owner
user Name Repo
repo Id Milestone
mid =
    CommandMethod -> Paths -> ByteString -> Request 'RW Milestone
forall a. CommandMethod -> Paths -> ByteString -> Request 'RW a
command CommandMethod
Patch [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
"milestones", Id Milestone -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Milestone
mid ] (ByteString -> Request 'RW Milestone)
-> (UpdateMilestone -> ByteString)
-> UpdateMilestone
-> Request 'RW Milestone
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UpdateMilestone -> ByteString
forall a. ToJSON a => a -> ByteString
encode

-- | Delete a milestone.
-- See <https://developer.github.com/v3/issues/milestones/#delete-a-milestone>
deleteMilestoneR :: Name Owner -> Name Repo -> Id Milestone -> GenRequest 'MtUnit 'RW ()
deleteMilestoneR :: Name Owner
-> Name Repo -> Id Milestone -> GenRequest 'MtUnit 'RW ()
deleteMilestoneR Name Owner
user Name Repo
repo Id Milestone
mid =
    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
"milestones", Id Milestone -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Milestone
mid] ByteString
forall a. Monoid a => a
mempty