-----------------------------------------------------------------------------
-- |
-- License     :  BSD-3-Clause
-- Maintainer  :  Oleg Grenrus <oleg.grenrus@iki.fi>
--
-- The pull request review comments API as described at
-- <http://developer.github.com/v3/pulls/comments/>.
module GitHub.Endpoints.PullRequests.Comments (
    pullRequestCommentsR,
    pullRequestCommentR,
    createPullCommentR,
    createPullCommentReplyR,
    module GitHub.Data,
    ) where

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

-- | List comments on a pull request.
-- See <https://developer.github.com/v3/pulls/comments/#list-comments-on-a-pull-request>
pullRequestCommentsR :: Name Owner -> Name Repo -> IssueNumber -> FetchCount -> Request k (Vector Comment)
pullRequestCommentsR :: Name Owner
-> Name Repo
-> IssueNumber
-> FetchCount
-> Request k (Vector Comment)
pullRequestCommentsR Name Owner
user Name Repo
repo IssueNumber
prid =
    Paths -> QueryString -> FetchCount -> Request k (Vector Comment)
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
"pulls", IssueNumber -> Text
forall a. IsPathPart a => a -> Text
toPathPart IssueNumber
prid, Text
"comments"] []

-- | Query a single comment.
-- See <https://developer.github.com/v3/pulls/comments/#get-a-single-comment>
pullRequestCommentR :: Name Owner -> Name Repo -> Id Comment -> Request k Comment
pullRequestCommentR :: Name Owner -> Name Repo -> Id Comment -> Request k Comment
pullRequestCommentR Name Owner
user Name Repo
repo Id Comment
cid =
    Paths -> QueryString -> Request k Comment
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
"pulls", Text
"comments", Id Comment -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Comment
cid] []

-- | Create a comment.
--
-- See <https://developer.github.com/v3/pulls/comments/#create-a-comment>
createPullCommentR :: Name Owner -> Name Repo -> IssueNumber -> Text -> Text -> Int -> Text -> Request 'RW Comment
createPullCommentR :: Name Owner
-> Name Repo
-> IssueNumber
-> Text
-> Text
-> Int
-> Text
-> Request 'RW Comment
createPullCommentR Name Owner
user Name Repo
repo IssueNumber
iss Text
commit Text
path Int
position Text
body =
    CommandMethod -> Paths -> ByteString -> Request 'RW Comment
forall a. CommandMethod -> Paths -> ByteString -> Request 'RW a
command CommandMethod
Post Paths
parts (NewPullComment -> ByteString
forall a. ToJSON a => a -> ByteString
encode (NewPullComment -> ByteString) -> NewPullComment -> ByteString
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Int -> Text -> NewPullComment
NewPullComment Text
commit Text
path Int
position Text
body)
  where
    parts :: Paths
parts = [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
"pulls", IssueNumber -> Text
forall a. IsPathPart a => a -> Text
toPathPart IssueNumber
iss, Text
"comments"]

-- | Create a comment reply.
--
-- See <https://developer.github.com/v3/pulls/comments/#create-a-review-comment-reply>
createPullCommentReplyR :: Name Owner -> Name Repo -> IssueNumber -> Id Comment -> Text -> Request 'RW Comment
createPullCommentReplyR :: Name Owner
-> Name Repo
-> IssueNumber
-> Id Comment
-> Text
-> Request 'RW Comment
createPullCommentReplyR Name Owner
user Name Repo
repo IssueNumber
iss Id Comment
cid Text
body =
    CommandMethod -> Paths -> ByteString -> Request 'RW Comment
forall a. CommandMethod -> Paths -> ByteString -> Request 'RW a
command CommandMethod
Post Paths
parts (PullCommentReply -> ByteString
forall a. ToJSON a => a -> ByteString
encode (PullCommentReply -> ByteString) -> PullCommentReply -> ByteString
forall a b. (a -> b) -> a -> b
$ Text -> PullCommentReply
PullCommentReply Text
body)
  where
    parts :: Paths
parts = [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
"pulls", IssueNumber -> Text
forall a. IsPathPart a => a -> Text
toPathPart IssueNumber
iss
            , Text
"comments", Id Comment -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Comment
cid, Text
"replies"]