From 5189111f5e0d9030dd5ff823a63f21b19bab81f6 Mon Sep 17 00:00:00 2001 From: iphydf Date: Fri, 16 Dec 2016 18:13:05 +0000 Subject: [PATCH] Add support for commit_comment event. --- web/GitHub/Types/Base.hs | 52 ++++++++++++++++++++++++++++++++++++++ web/GitHub/Types/Events.hs | 18 ++++++++++--- 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/web/GitHub/Types/Base.hs b/web/GitHub/Types/Base.hs index c3ff338..c58f47e 100644 --- a/web/GitHub/Types/Base.hs +++ b/web/GitHub/Types/Base.hs @@ -12,6 +12,58 @@ import Data.Text (Text) +------------------------------------------------------------------------------ +-- CommitComment + +data CommitComment = CommitComment + { commitCommentUrl :: Text + , commitCommentHtmlUrl :: Text + , commitCommentId :: Int + , commitCommentUser :: User + , commitCommentPosition :: Maybe Int + , commitCommentLine :: Maybe Int + , commitCommentPath :: Maybe Text + , commitCommentCommitId :: Text + , commitCommentCreatedAt :: DateTime + , commitCommentUpdatedAt :: DateTime + , commitCommentBody :: Text + } deriving (Eq, Show, Read) + + +instance FromJSON CommitComment where + parseJSON (Object x) = CommitComment + <$> x .: "url" + <*> x .: "html_url" + <*> x .: "id" + <*> x .: "user" + <*> x .: "position" + <*> x .: "line" + <*> x .: "path" + <*> x .: "commit_id" + <*> x .: "created_at" + <*> x .: "updated_at" + <*> x .: "body" + + parseJSON _ = fail "CommitComment" + + +instance ToJSON CommitComment where + toJSON CommitComment{..} = object + [ "url" .= commitCommentUrl + , "html_url" .= commitCommentHtmlUrl + , "id" .= commitCommentId + , "user" .= commitCommentUser + , "position" .= commitCommentPosition + , "line" .= commitCommentLine + , "path" .= commitCommentPath + , "commit_id" .= commitCommentCommitId + , "created_at" .= commitCommentCreatedAt + , "updated_at" .= commitCommentUpdatedAt + , "body" .= commitCommentBody + ] + + + ------------------------------------------------------------------------------ -- IssueComment diff --git a/web/GitHub/Types/Events.hs b/web/GitHub/Types/Events.hs index 300b6bc..a6c0c4a 100644 --- a/web/GitHub/Types/Events.hs +++ b/web/GitHub/Types/Events.hs @@ -194,18 +194,30 @@ webhookPayloadParser eventType x = -- CommitCommentEvent data CommitCommentEvent = CommitCommentEvent - { commitCommentEventComment :: Value + { commitCommentEventAction :: Text + , commitCommentEventComment :: CommitComment + , commitCommentEventRepository :: Repository + , commitCommentEventSender :: User + , commitCommentEventOrganization :: Organization } deriving (Eq, Show, Read) instance FromJSON CommitCommentEvent where parseJSON (Object x) = CommitCommentEvent - <$> x .: "comment" + <$> x .: "action" + <*> x .: "comment" + <*> x .: "repository" + <*> x .: "sender" + <*> x .: "organization" parseJSON _ = fail "CommitCommentEvent" instance ToJSON CommitCommentEvent where toJSON CommitCommentEvent{..} = object - [ "comment" .= commitCommentEventComment + [ "action" .= commitCommentEventAction + , "comment" .= commitCommentEventComment + , "repository" .= commitCommentEventRepository + , "sender" .= commitCommentEventSender + , "organization" .= commitCommentEventOrganization ]