Skip to content

Commit

Permalink
Add support for check_run event.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Mar 9, 2020
1 parent 1f58724 commit a12e15a
Show file tree
Hide file tree
Showing 21 changed files with 612 additions and 8 deletions.
8 changes: 8 additions & 0 deletions github-tools.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ library
GitHub.Types.Base.Branch
GitHub.Types.Base.Change
GitHub.Types.Base.Changes
GitHub.Types.Base.CheckApp
GitHub.Types.Base.CheckCommit
GitHub.Types.Base.CheckOutput
GitHub.Types.Base.CheckRun
GitHub.Types.Base.CheckSuite
GitHub.Types.Base.Commit
GitHub.Types.Base.CommitComment
GitHub.Types.Base.CommitDetails
Expand All @@ -48,6 +53,7 @@ library
GitHub.Types.Base.Organization
GitHub.Types.Base.PageBuild
GitHub.Types.Base.PageBuildError
GitHub.Types.Base.Permissions
GitHub.Types.Base.PullRequest
GitHub.Types.Base.PullRequestLinks
GitHub.Types.Base.PullRequestRef
Expand All @@ -68,6 +74,8 @@ library
GitHub.Types.Base.Verification
GitHub.Types.Event
GitHub.Types.Events
GitHub.Types.Events.CheckRunEvent
GitHub.Types.Events.CheckSuiteEvent
GitHub.Types.Events.CommitCommentEvent
GitHub.Types.Events.CreateEvent
GitHub.Types.Events.DeleteEvent
Expand Down
5 changes: 5 additions & 0 deletions src/GitHub/Types/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import GitHub.Types.Base.Author as X
import GitHub.Types.Base.Branch as X
import GitHub.Types.Base.Change as X
import GitHub.Types.Base.Changes as X
import GitHub.Types.Base.CheckApp as X
import GitHub.Types.Base.CheckCommit as X
import GitHub.Types.Base.CheckOutput as X
import GitHub.Types.Base.CheckRun as X
import GitHub.Types.Base.CheckSuite as X
import GitHub.Types.Base.Commit as X
import GitHub.Types.Base.CommitComment as X
import GitHub.Types.Base.CommitDetails as X
Expand Down
82 changes: 82 additions & 0 deletions src/GitHub/Types/Base/CheckApp.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module GitHub.Types.Base.CheckApp where

import Control.Applicative ((<$>), (<*>))
import Data.Aeson (FromJSON (..), ToJSON (..),
object)
import Data.Aeson.Types (Value (..), (.:), (.=))
import Data.Text (Text)
import Test.QuickCheck.Arbitrary (Arbitrary (..))

import GitHub.Types.Base.Permissions
import GitHub.Types.Base.User

------------------------------------------------------------------------------
-- CheckApp

data CheckApp = CheckApp
{ checkAppCreatedAt :: Text
, checkAppDescription :: Text
, checkAppEvents :: [Text]
, checkAppExternalUrl :: Text
, checkAppHtmlUrl :: Text
, checkAppId :: Int
, checkAppName :: Text
, checkAppNodeId :: Text
, checkAppOwner :: User
, checkAppPermissions :: Permissions
, checkAppSlug :: Text
, checkAppUpdatedAt :: Text
} deriving (Eq, Show, Read)


instance FromJSON CheckApp where
parseJSON (Object x) = CheckApp
<$> x .: "created_at"
<*> x .: "description"
<*> x .: "events"
<*> x .: "external_url"
<*> x .: "html_url"
<*> x .: "id"
<*> x .: "name"
<*> x .: "node_id"
<*> x .: "owner"
<*> x .: "permissions"
<*> x .: "slug"
<*> x .: "updated_at"

parseJSON _ = fail "CheckApp"


instance ToJSON CheckApp where
toJSON CheckApp{..} = object
[ "created_at" .= checkAppCreatedAt
, "description" .= checkAppDescription
, "events" .= checkAppEvents
, "external_url" .= checkAppExternalUrl
, "html_url" .= checkAppHtmlUrl
, "id" .= checkAppId
, "name" .= checkAppName
, "node_id" .= checkAppNodeId
, "owner" .= checkAppOwner
, "permissions" .= checkAppPermissions
, "slug" .= checkAppSlug
, "updated_at" .= checkAppUpdatedAt
]


instance Arbitrary CheckApp where
arbitrary = CheckApp
<$> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
56 changes: 56 additions & 0 deletions src/GitHub/Types/Base/CheckCommit.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module GitHub.Types.Base.CheckCommit where

import Control.Applicative ((<$>), (<*>))
import Data.Aeson (FromJSON (..), ToJSON (..), object)
import Data.Aeson.Types (Value (..), (.:), (.=))
import Data.Text (Text)
import Test.QuickCheck.Arbitrary (Arbitrary (..))

import GitHub.Types.Base.Author

------------------------------------------------------------------------------
-- CheckCommit

data CheckCommit = CheckCommit
{ checkCommitAuthor :: Author
, checkCommitCommitter :: Author
, checkCommitId :: Text
, checkCommitMessage :: Text
, checkCommitTimestamp :: Text
, checkCommitTreeId :: Text
} deriving (Eq, Show, Read)


instance FromJSON CheckCommit where
parseJSON (Object x) = CheckCommit
<$> x .: "author"
<*> x .: "committer"
<*> x .: "id"
<*> x .: "message"
<*> x .: "timestamp"
<*> x .: "tree_id"

parseJSON _ = fail "CheckCommit"


instance ToJSON CheckCommit where
toJSON CheckCommit{..} = object
[ "author" .= checkCommitAuthor
, "committer" .= checkCommitCommitter
, "id" .= checkCommitId
, "message" .= checkCommitMessage
, "timestamp" .= checkCommitTimestamp
, "tree_id" .= checkCommitTreeId
]


instance Arbitrary CheckCommit where
arbitrary = CheckCommit
<$> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
51 changes: 51 additions & 0 deletions src/GitHub/Types/Base/CheckOutput.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module GitHub.Types.Base.CheckOutput where

import Control.Applicative ((<$>), (<*>))
import Data.Aeson (FromJSON (..), ToJSON (..), object)
import Data.Aeson.Types (Value (..), (.:), (.=))
import Data.Text (Text)
import Data.Text.Arbitrary ()
import Test.QuickCheck.Arbitrary (Arbitrary (..))

------------------------------------------------------------------------------
-- CheckOutput

data CheckOutput = CheckOutput
{ checkOutputAnnotationsCount :: Int
, checkOutputAnnotationsUrl :: Text
, checkOutputSummary :: Text
, checkOutputText :: Maybe Text
, checkOutputTitle :: Text
} deriving (Eq, Show, Read)


instance FromJSON CheckOutput where
parseJSON (Object x) = CheckOutput
<$> x .: "annotations_count"
<*> x .: "annotations_url"
<*> x .: "summary"
<*> x .: "text"
<*> x .: "title"

parseJSON _ = fail "CheckOutput"


instance ToJSON CheckOutput where
toJSON CheckOutput{..} = object
[ "annotations_count" .= checkOutputAnnotationsCount
, "annotations_url" .= checkOutputAnnotationsUrl
, "summary" .= checkOutputSummary
, "text" .= checkOutputText
, "title" .= checkOutputTitle
]


instance Arbitrary CheckOutput where
arbitrary = CheckOutput
<$> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
95 changes: 95 additions & 0 deletions src/GitHub/Types/Base/CheckRun.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module GitHub.Types.Base.CheckRun where

import Control.Applicative ((<$>), (<*>))
import Data.Aeson (FromJSON (..), ToJSON (..),
object)
import Data.Aeson.Types (Value (..), (.:), (.=))
import Data.Text (Text)
import Test.QuickCheck.Arbitrary (Arbitrary (..))

import GitHub.Types.Base.CheckApp
import GitHub.Types.Base.CheckOutput
import GitHub.Types.Base.CheckSuite

------------------------------------------------------------------------------
-- CheckRun

data CheckRun = CheckRun
{ checkRunApp :: CheckApp
, checkRunCheckSuite :: CheckSuite
, checkRunCompletedAt :: Text
, checkRunConclusion :: Text
, checkRunDetailsUrl :: Text
, checkRunExternalId :: Text
, checkRunHeadSha :: Text
, checkRunHtmlUrl :: Text
, checkRunId :: Int
, checkRunName :: Text
, checkRunNodeId :: Text
, checkRunOutput :: CheckOutput
, checkRunStartedAt :: Text
, checkRunStatus :: Text
, checkRunUrl :: Text
} deriving (Eq, Show, Read)


instance FromJSON CheckRun where
parseJSON (Object x) = CheckRun
<$> x .: "app"
<*> x .: "check_suite"
<*> x .: "completed_at"
<*> x .: "conclusion"
<*> x .: "details_url"
<*> x .: "external_id"
<*> x .: "head_sha"
<*> x .: "html_url"
<*> x .: "id"
<*> x .: "name"
<*> x .: "node_id"
<*> x .: "output"
<*> x .: "started_at"
<*> x .: "status"
<*> x .: "url"

parseJSON _ = fail "CheckRun"


instance ToJSON CheckRun where
toJSON CheckRun{..} = object
[ "app" .= checkRunApp
, "check_suite" .= checkRunCheckSuite
, "completed_at" .= checkRunCompletedAt
, "conclusion" .= checkRunConclusion
, "details_url" .= checkRunDetailsUrl
, "external_id" .= checkRunExternalId
, "head_sha" .= checkRunHeadSha
, "html_url" .= checkRunHtmlUrl
, "id" .= checkRunId
, "name" .= checkRunName
, "node_id" .= checkRunNodeId
, "output" .= checkRunOutput
, "started_at" .= checkRunStartedAt
, "status" .= checkRunStatus
, "url" .= checkRunUrl
]


instance Arbitrary CheckRun where
arbitrary = CheckRun
<$> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
Loading

0 comments on commit a12e15a

Please sign in to comment.