-----------------------------------------------------------------------------
-- |
-- License     :  BSD-3-Clause
-- Maintainer  :  Oleg Grenrus <oleg.grenrus@iki.fi>
--
-- The reviews API as described on <http://developer.github.com/v3/pulls/reviews/>.
module GitHub.Endpoints.PullRequests.Reviews
    ( pullRequestReviewsR
    , pullRequestReviews
    , pullRequestReviews'
    , pullRequestReviewR
    , pullRequestReview
    , pullRequestReview'
    , pullRequestReviewCommentsR
    , pullRequestReviewCommentsIO
    , pullRequestReviewCommentsIO'
    , module GitHub.Data
    ) where

import GitHub.Data
import GitHub.Data.Id (Id)
import GitHub.Internal.Prelude
import GitHub.Request
       (Request, executeRequest', executeRequestMaybe)
import Prelude ()

-- | List reviews for a pull request.
-- See <https://developer.github.com/v3/pulls/reviews/#list-reviews-on-a-pull-request>
pullRequestReviewsR
    :: Name Owner
    -> Name Repo
    -> Id PullRequest
    -> FetchCount
    -> Request k (Vector Review)
pullRequestReviewsR :: Name Owner
-> Name Repo
-> Id PullRequest
-> FetchCount
-> Request k (Vector Review)
pullRequestReviewsR owner :: Name Owner
owner repo :: Name Repo
repo prid :: Id PullRequest
prid =
    Paths -> QueryString -> FetchCount -> Request k (Vector Review)
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
owner
        , Name Repo -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Repo
repo
        , "pulls"
        , Id PullRequest -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id PullRequest
prid
        , "reviews"
        ]
        []

-- | All reviews for a pull request given the repo owner, repo name and the pull
-- request id.
--
-- > pullRequestReviews "thoughtbot" "paperclip" (Id 101)
pullRequestReviews
    :: Name Owner
    -> Name Repo
    -> Id PullRequest
    -> IO (Either Error (Vector Review))
pullRequestReviews :: Name Owner
-> Name Repo -> Id PullRequest -> IO (Either Error (Vector Review))
pullRequestReviews owner :: Name Owner
owner repo :: Name Repo
repo prid :: Id PullRequest
prid =
    GenRequest 'MtJSON 'RO (Vector Review)
-> IO (Either Error (Vector Review))
forall (mt :: MediaType *) a.
ParseResponse mt a =>
GenRequest mt 'RO a -> IO (Either Error a)
executeRequest' (GenRequest 'MtJSON 'RO (Vector Review)
 -> IO (Either Error (Vector Review)))
-> GenRequest 'MtJSON 'RO (Vector Review)
-> IO (Either Error (Vector Review))
forall a b. (a -> b) -> a -> b
$ Name Owner
-> Name Repo
-> Id PullRequest
-> FetchCount
-> GenRequest 'MtJSON 'RO (Vector Review)
forall (k :: RW).
Name Owner
-> Name Repo
-> Id PullRequest
-> FetchCount
-> Request k (Vector Review)
pullRequestReviewsR Name Owner
owner Name Repo
repo Id PullRequest
prid FetchCount
FetchAll

-- | All reviews for a pull request given the repo owner, repo name and the pull
-- request id. With authentication.
--
-- > pullRequestReviews' (Just $ BasicAuth "github-username" "github-password") "thoughtbot" "paperclip" (Id 101)
pullRequestReviews'
    :: Maybe Auth
    -> Name Owner
    -> Name Repo
    -> Id PullRequest
    -> IO (Either Error (Vector Review))
pullRequestReviews' :: Maybe Auth
-> Name Owner
-> Name Repo
-> Id PullRequest
-> IO (Either Error (Vector Review))
pullRequestReviews' auth :: Maybe Auth
auth owner :: Name Owner
owner repo :: Name Repo
repo pr :: Id PullRequest
pr =
    Maybe Auth
-> GenRequest 'MtJSON 'RO (Vector Review)
-> IO (Either Error (Vector Review))
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 Review)
 -> IO (Either Error (Vector Review)))
-> GenRequest 'MtJSON 'RO (Vector Review)
-> IO (Either Error (Vector Review))
forall a b. (a -> b) -> a -> b
$ Name Owner
-> Name Repo
-> Id PullRequest
-> FetchCount
-> GenRequest 'MtJSON 'RO (Vector Review)
forall (k :: RW).
Name Owner
-> Name Repo
-> Id PullRequest
-> FetchCount
-> Request k (Vector Review)
pullRequestReviewsR Name Owner
owner Name Repo
repo Id PullRequest
pr FetchCount
FetchAll

-- | Query a single pull request review.
-- see <https://developer.github.com/v3/pulls/reviews/#get-a-single-review>
pullRequestReviewR
    :: Name Owner
    -> Name Repo
    -> Id PullRequest
    -> Id Review
    -> Request k Review
pullRequestReviewR :: Name Owner
-> Name Repo -> Id PullRequest -> Id Review -> Request k Review
pullRequestReviewR owner :: Name Owner
owner repo :: Name Repo
repo prid :: Id PullRequest
prid rid :: Id Review
rid =
    Paths -> QueryString -> Request k Review
forall (mt :: RW) a. Paths -> QueryString -> Request mt a
query
        [ "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
        , "pulls"
        , Id PullRequest -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id PullRequest
prid
        , "reviews"
        , Id Review -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Review
rid
        ]
        []

-- | A detailed review on a pull request given the repo owner, repo name, pull
-- request id and review id.
--
-- > pullRequestReview "thoughtbot" "factory_girl" (Id 301819) (Id 332)
pullRequestReview
    :: Name Owner
    -> Name Repo
    -> Id PullRequest
    -> Id Review
    -> IO (Either Error Review)
pullRequestReview :: Name Owner
-> Name Repo
-> Id PullRequest
-> Id Review
-> IO (Either Error Review)
pullRequestReview owner :: Name Owner
owner repo :: Name Repo
repo prid :: Id PullRequest
prid rid :: Id Review
rid =
    GenRequest 'MtJSON 'RO Review -> IO (Either Error Review)
forall (mt :: MediaType *) a.
ParseResponse mt a =>
GenRequest mt 'RO a -> IO (Either Error a)
executeRequest' (GenRequest 'MtJSON 'RO Review -> IO (Either Error Review))
-> GenRequest 'MtJSON 'RO Review -> IO (Either Error Review)
forall a b. (a -> b) -> a -> b
$ Name Owner
-> Name Repo
-> Id PullRequest
-> Id Review
-> GenRequest 'MtJSON 'RO Review
forall (k :: RW).
Name Owner
-> Name Repo -> Id PullRequest -> Id Review -> Request k Review
pullRequestReviewR Name Owner
owner Name Repo
repo Id PullRequest
prid Id Review
rid

-- | A detailed review on a pull request given the repo owner, repo name, pull
-- request id and review id. With authentication.
--
-- > pullRequestReview' (Just $ BasicAuth "github-username" "github-password")
-- > "thoughtbot" "factory_girl" (Id 301819) (Id 332)
pullRequestReview'
    :: Maybe Auth
    -> Name Owner
    -> Name Repo
    -> Id PullRequest
    -> Id Review
    -> IO (Either Error Review)
pullRequestReview' :: Maybe Auth
-> Name Owner
-> Name Repo
-> Id PullRequest
-> Id Review
-> IO (Either Error Review)
pullRequestReview' auth :: Maybe Auth
auth owner :: Name Owner
owner repo :: Name Repo
repo prid :: Id PullRequest
prid rid :: Id Review
rid =
    Maybe Auth
-> GenRequest 'MtJSON 'RO Review -> IO (Either Error Review)
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 Review -> IO (Either Error Review))
-> GenRequest 'MtJSON 'RO Review -> IO (Either Error Review)
forall a b. (a -> b) -> a -> b
$ Name Owner
-> Name Repo
-> Id PullRequest
-> Id Review
-> GenRequest 'MtJSON 'RO Review
forall (k :: RW).
Name Owner
-> Name Repo -> Id PullRequest -> Id Review -> Request k Review
pullRequestReviewR Name Owner
owner Name Repo
repo Id PullRequest
prid Id Review
rid

-- | Query the comments for a single pull request review.
-- see <https://developer.github.com/v3/pulls/reviews/#get-comments-for-a-single-review>
pullRequestReviewCommentsR
    :: Name Owner
    -> Name Repo
    -> Id PullRequest
    -> Id Review
    -> Request k [ReviewComment]
pullRequestReviewCommentsR :: Name Owner
-> Name Repo
-> Id PullRequest
-> Id Review
-> Request k [ReviewComment]
pullRequestReviewCommentsR owner :: Name Owner
owner repo :: Name Repo
repo prid :: Id PullRequest
prid rid :: Id Review
rid =
    Paths -> QueryString -> Request k [ReviewComment]
forall (mt :: RW) a. Paths -> QueryString -> Request mt a
query
        [ "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
        , "pulls"
        , Id PullRequest -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id PullRequest
prid
        , "reviews"
        , Id Review -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Review
rid
        , "comments"
        ]
        []

-- | All comments for a review on a pull request given the repo owner, repo
-- name, pull request id and review id.
--
-- > pullRequestReviewComments "thoughtbot" "factory_girl" (Id 301819) (Id 332)
pullRequestReviewCommentsIO
    :: Name Owner
    -> Name Repo
    -> Id PullRequest
    -> Id Review
    -> IO (Either Error [ReviewComment])
pullRequestReviewCommentsIO :: Name Owner
-> Name Repo
-> Id PullRequest
-> Id Review
-> IO (Either Error [ReviewComment])
pullRequestReviewCommentsIO owner :: Name Owner
owner repo :: Name Repo
repo prid :: Id PullRequest
prid rid :: Id Review
rid =
    GenRequest 'MtJSON 'RO [ReviewComment]
-> IO (Either Error [ReviewComment])
forall (mt :: MediaType *) a.
ParseResponse mt a =>
GenRequest mt 'RO a -> IO (Either Error a)
executeRequest' (GenRequest 'MtJSON 'RO [ReviewComment]
 -> IO (Either Error [ReviewComment]))
-> GenRequest 'MtJSON 'RO [ReviewComment]
-> IO (Either Error [ReviewComment])
forall a b. (a -> b) -> a -> b
$ Name Owner
-> Name Repo
-> Id PullRequest
-> Id Review
-> GenRequest 'MtJSON 'RO [ReviewComment]
forall (k :: RW).
Name Owner
-> Name Repo
-> Id PullRequest
-> Id Review
-> Request k [ReviewComment]
pullRequestReviewCommentsR Name Owner
owner Name Repo
repo Id PullRequest
prid Id Review
rid

-- | All comments for a review on a pull request given the repo owner, repo
-- name, pull request id and review id. With authentication.
--
-- > pullRequestReviewComments' (Just $ BasicAuth "github-username" "github-password") "thoughtbot" "factory_girl" (Id 301819) (Id 332)
pullRequestReviewCommentsIO'
    :: Maybe Auth
    -> Name Owner
    -> Name Repo
    -> Id PullRequest
    -> Id Review
    -> IO (Either Error [ReviewComment])
pullRequestReviewCommentsIO' :: Maybe Auth
-> Name Owner
-> Name Repo
-> Id PullRequest
-> Id Review
-> IO (Either Error [ReviewComment])
pullRequestReviewCommentsIO' auth :: Maybe Auth
auth owner :: Name Owner
owner repo :: Name Repo
repo prid :: Id PullRequest
prid rid :: Id Review
rid =
    Maybe Auth
-> GenRequest 'MtJSON 'RO [ReviewComment]
-> IO (Either Error [ReviewComment])
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 [ReviewComment]
 -> IO (Either Error [ReviewComment]))
-> GenRequest 'MtJSON 'RO [ReviewComment]
-> IO (Either Error [ReviewComment])
forall a b. (a -> b) -> a -> b
$ Name Owner
-> Name Repo
-> Id PullRequest
-> Id Review
-> GenRequest 'MtJSON 'RO [ReviewComment]
forall (k :: RW).
Name Owner
-> Name Repo
-> Id PullRequest
-> Id Review
-> Request k [ReviewComment]
pullRequestReviewCommentsR Name Owner
owner Name Repo
repo Id PullRequest
prid Id Review
rid