{-# LANGUAGE CPP #-}
-----------------------------------------------------------------------------
-- |
-- License     :  BSD-3-Clause
-- Maintainer  :  Oleg Grenrus <oleg.grenrus@iki.fi>
--
-- The repo commits API as described on
-- <http://developer.github.com/v3/repos/comments/>.
module GitHub.Endpoints.Repos.Comments (
    commentsFor,
    commentsFor',
    commentsForR,
    commitCommentsFor,
    commitCommentsFor',
    commitCommentsForR,
    commitCommentFor,
    commitCommentFor',
    commitCommentForR,
    module GitHub.Data,
    ) where

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

-- | All the comments on a Github repo.
--
-- > commentsFor "thoughtbot" "paperclip"
commentsFor :: Name Owner -> Name Repo -> IO (Either Error (Vector Comment))
commentsFor :: Name Owner -> Name Repo -> IO (Either Error (Vector Comment))
commentsFor = Maybe Auth
-> Name Owner -> Name Repo -> IO (Either Error (Vector Comment))
commentsFor' Maybe Auth
forall a. Maybe a
Nothing

-- | All the comments on a Github repo.
-- With authentication.
--
-- > commentsFor "thoughtbot" "paperclip"
commentsFor' :: Maybe Auth -> Name Owner -> Name Repo -> IO (Either Error (Vector Comment))
commentsFor' :: Maybe Auth
-> Name Owner -> Name Repo -> IO (Either Error (Vector Comment))
commentsFor' auth :: Maybe Auth
auth user :: Name Owner
user repo :: Name Repo
repo =
    Maybe Auth
-> GenRequest 'MtJSON 'RO (Vector Comment)
-> IO (Either Error (Vector Comment))
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 Comment)
 -> IO (Either Error (Vector Comment)))
-> GenRequest 'MtJSON 'RO (Vector Comment)
-> IO (Either Error (Vector Comment))
forall a b. (a -> b) -> a -> b
$ Name Owner
-> Name Repo
-> FetchCount
-> GenRequest 'MtJSON 'RO (Vector Comment)
forall (k :: RW).
Name Owner -> Name Repo -> FetchCount -> Request k (Vector Comment)
commentsForR Name Owner
user Name Repo
repo FetchCount
FetchAll

-- | List commit comments for a repository.
-- See <https://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository>
commentsForR :: Name Owner -> Name Repo -> FetchCount -> Request k (Vector Comment)
commentsForR :: Name Owner -> Name Repo -> FetchCount -> Request k (Vector Comment)
commentsForR user :: Name Owner
user repo :: Name Repo
repo =
    Paths -> QueryString -> FetchCount -> Request k (Vector Comment)
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, "comments"] []

-- | Just the comments on a specific SHA for a given Github repo.
--
-- > commitCommentsFor "thoughtbot" "paperclip" "41f685f6e01396936bb8cd98e7cca517e2c7d96b"
commitCommentsFor :: Name Owner -> Name Repo -> Name Commit -> IO (Either Error (Vector Comment))
commitCommentsFor :: Name Owner
-> Name Repo -> Name Commit -> IO (Either Error (Vector Comment))
commitCommentsFor = Maybe Auth
-> Name Owner
-> Name Repo
-> Name Commit
-> IO (Either Error (Vector Comment))
commitCommentsFor' Maybe Auth
forall a. Maybe a
Nothing

-- | Just the comments on a specific SHA for a given Github repo.
-- With authentication.
--
-- > commitCommentsFor "thoughtbot" "paperclip" "41f685f6e01396936bb8cd98e7cca517e2c7d96b"
commitCommentsFor' :: Maybe Auth -> Name Owner -> Name Repo -> Name Commit -> IO (Either Error (Vector Comment))
commitCommentsFor' :: Maybe Auth
-> Name Owner
-> Name Repo
-> Name Commit
-> IO (Either Error (Vector Comment))
commitCommentsFor' auth :: Maybe Auth
auth user :: Name Owner
user repo :: Name Repo
repo sha :: Name Commit
sha =
    Maybe Auth
-> GenRequest 'MtJSON 'RO (Vector Comment)
-> IO (Either Error (Vector Comment))
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 Comment)
 -> IO (Either Error (Vector Comment)))
-> GenRequest 'MtJSON 'RO (Vector Comment)
-> IO (Either Error (Vector Comment))
forall a b. (a -> b) -> a -> b
$ Name Owner
-> Name Repo
-> Name Commit
-> FetchCount
-> GenRequest 'MtJSON 'RO (Vector Comment)
forall (k :: RW).
Name Owner
-> Name Repo
-> Name Commit
-> FetchCount
-> Request k (Vector Comment)
commitCommentsForR Name Owner
user Name Repo
repo Name Commit
sha FetchCount
FetchAll

-- | List comments for a single commit.
-- See <https://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit>
commitCommentsForR :: Name Owner -> Name Repo -> Name Commit -> FetchCount -> Request k (Vector Comment)
commitCommentsForR :: Name Owner
-> Name Repo
-> Name Commit
-> FetchCount
-> Request k (Vector Comment)
commitCommentsForR user :: Name Owner
user repo :: Name Repo
repo sha :: Name Commit
sha =
    Paths -> QueryString -> FetchCount -> Request k (Vector Comment)
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, "commits", Name Commit -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Commit
sha, "comments"] []

-- | A comment, by its ID, relative to the Github repo.
--
-- > commitCommentFor "thoughtbot" "paperclip" "669575"
commitCommentFor :: Name Owner -> Name Repo -> Id Comment -> IO (Either Error Comment)
commitCommentFor :: Name Owner -> Name Repo -> Id Comment -> IO (Either Error Comment)
commitCommentFor = Maybe Auth
-> Name Owner
-> Name Repo
-> Id Comment
-> IO (Either Error Comment)
commitCommentFor' Maybe Auth
forall a. Maybe a
Nothing

-- | A comment, by its ID, relative to the Github repo.
--
-- > commitCommentFor "thoughtbot" "paperclip" "669575"
commitCommentFor' :: Maybe Auth -> Name Owner -> Name Repo -> Id Comment -> IO (Either Error Comment)
commitCommentFor' :: Maybe Auth
-> Name Owner
-> Name Repo
-> Id Comment
-> IO (Either Error Comment)
commitCommentFor' auth :: Maybe Auth
auth user :: Name Owner
user repo :: Name Repo
repo cid :: Id Comment
cid =
    Maybe Auth
-> GenRequest 'MtJSON 'RO Comment -> IO (Either Error Comment)
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 Comment -> IO (Either Error Comment))
-> GenRequest 'MtJSON 'RO Comment -> IO (Either Error Comment)
forall a b. (a -> b) -> a -> b
$ Name Owner
-> Name Repo -> Id Comment -> GenRequest 'MtJSON 'RO Comment
forall (k :: RW).
Name Owner -> Name Repo -> Id Comment -> Request k Comment
commitCommentForR Name Owner
user Name Repo
repo Id Comment
cid

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