module GitHub.Types.Events where
import Control.Applicative
import Control.Monad
import Data.Aeson
import Data.Aeson.Types
import Data.Text
import GitHub.Types.Base
import GitHub.Types.Repository
data Event
= CommitCommentEventType CommitCommentEvent
| DeploymentEventType DeploymentEvent
| DeploymentStatusEventType DeploymentStatusEvent
deriving (Eq, Show)
eventParser :: Text -> Value -> Parser Event
eventParser "commit_comment" x = CommitCommentEventType <$> parseJSON x
eventParser "deployment" x = DeploymentEventType <$> parseJSON x
eventParser "deployment_status" x = DeploymentStatusEventType <$> parseJSON x
eventParser _ _ = mzero
data CommitCommentEvent = CommitCommentEvent
{ commitCommentEventRepository :: Repository
} deriving (Eq, Show)
instance FromJSON CommitCommentEvent where
parseJSON (Object x) = CommitCommentEvent
<$> x .: "repository"
parseJSON _ = mzero
data DeploymentEvent = DeploymentEvent
{ deploymentEventId :: Int
, deploymentEventSha :: Text
, deploymentEventName :: Text
, deploymentEventPayload :: Value
, deploymentEventEnvironment :: Text
, deploymentEventDescription :: Maybe Text
, deploymentEventRepository :: Repository
} deriving (Eq, Show)
instance FromJSON DeploymentEvent where
parseJSON (Object x) = DeploymentEvent
<$> x .: "id"
<*> x .: "sha"
<*> x .: "name"
<*> x .: "payload"
<*> x .: "environment"
<*> x .: "description"
<*> x .: "repository"
parseJSON _ = mzero
data DeploymentStatusEvent = DeploymentStatusEvent
{ deploymentStatusEventState :: State
, deploymentStatusEventTargetUrl :: Maybe Text
, deploymentStatusEventDeployment :: Deployment
, deploymentStatusEventDescription :: Maybe Text
} deriving (Eq, Show)
instance FromJSON DeploymentStatusEvent where
parseJSON (Object x) = DeploymentStatusEvent
<$> x .: "state"
<*> x .: "target_url"
<*> x .: "deployment"
<*> x .: "description"
parseJSON _ = mzero