-----------------------------------------------------------------------------
-- |
-- License     :  BSD-3-Clause
-- Maintainer  :  Oleg Grenrus <oleg.grenrus@iki.fi>
--
-- The milestones API as described on
-- <http://developer.github.com/v3/issues/milestones/>.
module GitHub.Endpoints.Issues.Milestones (
    milestones,
    milestones',
    milestonesR,
    milestone,
    milestoneR,
    createMilestone,
    createMilestoneR,
    updateMilestone,
    updateMilestoneR,
    deleteMilestone,
    deleteMilestoneR,
    module GitHub.Data,
    ) where

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

-- | All milestones in the repo.
--
-- > milestones "thoughtbot" "paperclip"
milestones :: Name Owner -> Name Repo -> IO (Either Error (Vector Milestone))
milestones :: Name Owner -> Name Repo -> IO (Either Error (Vector Milestone))
milestones = Maybe Auth
-> Name Owner -> Name Repo -> IO (Either Error (Vector Milestone))
milestones' Maybe Auth
forall a. Maybe a
Nothing

-- | All milestones in the repo, using authentication.
--
-- > milestones' (Just $ BasicAuth "github-username" "github-password") "thoughtbot" "paperclip"
milestones' :: Maybe Auth -> Name Owner -> Name Repo -> IO (Either Error (Vector Milestone))
milestones' :: Maybe Auth
-> Name Owner -> Name Repo -> IO (Either Error (Vector Milestone))
milestones' auth :: Maybe Auth
auth user :: Name Owner
user repo :: Name Repo
repo =
    Maybe Auth
-> GenRequest 'MtJSON 'RO (Vector Milestone)
-> IO (Either Error (Vector Milestone))
forall am (mt :: MediaType *) a.
(AuthMethod am, ParseResponse mt a) =>
Maybe am -> GenRequest mt 'RO a -> IO (Either Error a)
executeRequestMaybe Maybe Auth
auth (GenRequest 'MtJSON 'RO (Vector Milestone)
 -> IO (Either Error (Vector Milestone)))
-> GenRequest 'MtJSON 'RO (Vector Milestone)
-> IO (Either Error (Vector Milestone))
forall a b. (a -> b) -> a -> b
$ Name Owner
-> Name Repo
-> FetchCount
-> GenRequest 'MtJSON 'RO (Vector Milestone)
forall (k :: RW).
Name Owner
-> Name Repo -> FetchCount -> Request k (Vector Milestone)
milestonesR Name Owner
user Name Repo
repo FetchCount
FetchAll

-- | 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 :: Name Owner
-> Name Repo -> FetchCount -> Request k (Vector Milestone)
milestonesR user :: Name Owner
user repo :: Name Repo
repo =
    Paths -> QueryString -> FetchCount -> Request k (Vector Milestone)
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, "milestones"] []

-- | Details on a specific milestone, given it's milestone number.
--
-- > milestone "thoughtbot" "paperclip" (Id 2)
milestone :: Name Owner -> Name Repo -> Id Milestone -> IO (Either Error Milestone)
milestone :: Name Owner
-> Name Repo -> Id Milestone -> IO (Either Error Milestone)
milestone user :: Name Owner
user repo :: Name Repo
repo mid :: Id Milestone
mid =
    GenRequest 'MtJSON 'RO Milestone -> IO (Either Error Milestone)
forall (mt :: MediaType *) a.
ParseResponse mt a =>
GenRequest mt 'RO a -> IO (Either Error a)
executeRequest' (GenRequest 'MtJSON 'RO Milestone -> IO (Either Error Milestone))
-> GenRequest 'MtJSON 'RO Milestone -> IO (Either Error Milestone)
forall a b. (a -> b) -> a -> b
$ Name Owner
-> Name Repo -> Id Milestone -> GenRequest 'MtJSON 'RO Milestone
forall (k :: RW).
Name Owner -> Name Repo -> Id Milestone -> Request k Milestone
milestoneR Name Owner
user Name Repo
repo Id Milestone
mid

-- | 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 :: Name Owner -> Name Repo -> Id Milestone -> Request k Milestone
milestoneR user :: Name Owner
user repo :: Name Repo
repo mid :: Id Milestone
mid =
    Paths -> QueryString -> Request k Milestone
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, "milestones", Id Milestone -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Milestone
mid] []

createMilestone :: Auth -> Name Owner -> Name Repo -> NewMilestone -> IO (Either Error Milestone)
createMilestone :: Auth
-> Name Owner
-> Name Repo
-> NewMilestone
-> IO (Either Error Milestone)
createMilestone auth :: Auth
auth user :: Name Owner
user repo :: Name Repo
repo mlstn :: NewMilestone
mlstn = Auth
-> GenRequest 'MtJSON 'RW Milestone -> IO (Either Error Milestone)
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 Milestone -> IO (Either Error Milestone))
-> GenRequest 'MtJSON 'RW Milestone -> IO (Either Error Milestone)
forall a b. (a -> b) -> a -> b
$ Name Owner
-> Name Repo -> NewMilestone -> GenRequest 'MtJSON 'RW Milestone
createMilestoneR Name Owner
user Name Repo
repo NewMilestone
mlstn

-- | 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 -> GenRequest 'MtJSON 'RW Milestone
createMilestoneR user :: Name Owner
user repo :: Name Repo
repo =
    CommandMethod
-> Paths -> ByteString -> GenRequest 'MtJSON 'RW Milestone
forall a. CommandMethod -> Paths -> ByteString -> Request 'RW a
command CommandMethod
Post ["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, "milestones"] (ByteString -> GenRequest 'MtJSON 'RW Milestone)
-> (NewMilestone -> ByteString)
-> NewMilestone
-> GenRequest 'MtJSON 'RW Milestone
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NewMilestone -> ByteString
forall a. ToJSON a => a -> ByteString
encode

updateMilestone :: Auth -> Name Owner -> Name Repo -> Id Milestone -> UpdateMilestone -> IO (Either Error Milestone)
updateMilestone :: Auth
-> Name Owner
-> Name Repo
-> Id Milestone
-> UpdateMilestone
-> IO (Either Error Milestone)
updateMilestone auth :: Auth
auth user :: Name Owner
user repo :: Name Repo
repo mid :: Id Milestone
mid mlstn :: UpdateMilestone
mlstn = Auth
-> GenRequest 'MtJSON 'RW Milestone -> IO (Either Error Milestone)
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 Milestone -> IO (Either Error Milestone))
-> GenRequest 'MtJSON 'RW Milestone -> IO (Either Error Milestone)
forall a b. (a -> b) -> a -> b
$ Name Owner
-> Name Repo
-> Id Milestone
-> UpdateMilestone
-> GenRequest 'MtJSON 'RW Milestone
updateMilestoneR Name Owner
user Name Repo
repo Id Milestone
mid UpdateMilestone
mlstn

-- | 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
-> GenRequest 'MtJSON 'RW Milestone
updateMilestoneR user :: Name Owner
user repo :: Name Repo
repo mid :: Id Milestone
mid =
    CommandMethod
-> Paths -> ByteString -> GenRequest 'MtJSON 'RW Milestone
forall a. CommandMethod -> Paths -> ByteString -> Request 'RW a
command CommandMethod
Patch ["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, "milestones", Id Milestone -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Milestone
mid ] (ByteString -> GenRequest 'MtJSON 'RW Milestone)
-> (UpdateMilestone -> ByteString)
-> UpdateMilestone
-> GenRequest 'MtJSON 'RW Milestone
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UpdateMilestone -> ByteString
forall a. ToJSON a => a -> ByteString
encode

deleteMilestone :: Auth -> Name Owner -> Name Repo -> Id Milestone -> IO (Either Error ())
deleteMilestone :: Auth
-> Name Owner -> Name Repo -> Id Milestone -> IO (Either Error ())
deleteMilestone auth :: Auth
auth user :: Name Owner
user repo :: Name Repo
repo mid :: Id Milestone
mid = Auth -> GenRequest 'MtUnit 'RW () -> IO (Either Error ())
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 'MtUnit 'RW () -> IO (Either Error ()))
-> GenRequest 'MtUnit 'RW () -> IO (Either Error ())
forall a b. (a -> b) -> a -> b
$ Name Owner
-> Name Repo -> Id Milestone -> GenRequest 'MtUnit 'RW ()
deleteMilestoneR Name Owner
user Name Repo
repo Id Milestone
mid

-- | 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 user :: Name Owner
user repo :: Name Repo
repo mid :: Id Milestone
mid =
    CommandMethod -> Paths -> ByteString -> GenRequest 'MtUnit 'RW ()
forall (mt :: MediaType *) a.
CommandMethod -> Paths -> ByteString -> GenRequest mt 'RW a
Command CommandMethod
Delete
        ["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, "milestones", Id Milestone -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Milestone
mid] ByteString
forall a. Monoid a => a
mempty