-----------------------------------------------------------------------------
-- |
-- License     :  BSD-3-Clause
-- Maintainer  :  Oleg Grenrus <oleg.grenrus@iki.fi>
--
-- The Github issue comments API from
-- <http://developer.github.com/v3/issues/comments/>.
module GitHub.Endpoints.Issues.Comments (
    commentR,
    commentsR,
    createCommentR,
    deleteCommentR,
    editCommentR,
    module GitHub.Data,
    ) where

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

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

-- | List comments on an issue.
-- See <https://developer.github.com/v3/issues/comments/#list-comments-on-an-issue>
commentsR :: Name Owner -> Name Repo -> IssueNumber -> FetchCount -> Request k (Vector IssueComment)
commentsR :: forall (k :: RW).
Name Owner
-> Name Repo
-> IssueNumber
-> FetchCount
-> Request k (Vector IssueComment)
commentsR Name Owner
user Name Repo
repo IssueNumber
iid =
    Paths
-> QueryString -> FetchCount -> Request k (Vector IssueComment)
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
"issues", IssueNumber -> Text
forall a. IsPathPart a => a -> Text
toPathPart IssueNumber
iid, Text
"comments"] []

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

-- | Edit a comment.
-- See <https://developer.github.com/v3/issues/comments/#edit-a-comment>
editCommentR :: Name Owner -> Name Repo -> Id Comment -> Text -> Request 'RW Comment
editCommentR :: Name Owner
-> Name Repo -> Id Comment -> Text -> Request 'RW Comment
editCommentR Name Owner
user Name Repo
repo Id Comment
commid Text
body =
    CommandMethod -> Paths -> ByteString -> Request 'RW Comment
forall a. CommandMethod -> Paths -> ByteString -> Request 'RW a
command CommandMethod
Patch Paths
parts (EditComment -> ByteString
forall a. ToJSON a => a -> ByteString
encode (EditComment -> ByteString) -> EditComment -> ByteString
forall a b. (a -> b) -> a -> b
$ Text -> EditComment
EditComment 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
"issues", Text
"comments", Id Comment -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Comment
commid]

-- | Delete a comment.
-- See <https://developer.github.com/v3/issues/comments/#delete-a-comment>
deleteCommentR :: Name Owner -> Name Repo -> Id Comment -> GenRequest 'MtUnit 'RW ()
deleteCommentR :: Name Owner -> Name Repo -> Id Comment -> GenRequest 'MtUnit 'RW ()
deleteCommentR Name Owner
user Name Repo
repo Id Comment
commid =
    CommandMethod -> Paths -> ByteString -> GenRequest 'MtUnit 'RW ()
forall (mt :: MediaType (*)) a.
CommandMethod -> Paths -> ByteString -> GenRequest mt 'RW a
Command CommandMethod
Delete Paths
parts ByteString
forall a. Monoid a => a
mempty
  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
"issues", Text
"comments", Id Comment -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Comment
commid]