git.iko.soy/typeable/compaREST
on master help sign in
173 lines 4.4 kB history raw
1module GitHub.Data.Checks
2 ( Check (..),
3 CheckStatus (..),
4 CheckConclusion (..),
5 CheckOutput (..),
6 CheckAnnotation (..),
7 CheckAnnotationLevel (..),
8 CheckImage (..),
9 CheckAction (..),
10 )
11where
13import Data.Aeson
14import Data.Aeson.Types
15import Data.Text (Text)
16import Data.Vector (Vector)
17import GHC.Generics (Generic)
18import GitHub
19import GitHub.Internal.Prelude (UTCTime)
21data Check = Check
22 { checkName :: !(Name Check)
23 , checkSha :: !(Name Commit)
24 , checkDetailsURL :: !(Maybe URL)
25 , checkExternalId :: !(Maybe (Id Check))
26 , checkStatus :: !(Maybe CheckStatus)
27 , checkStartedAt :: !(Maybe UTCTime)
28 , checkConclusion :: !(Maybe CheckConclusion)
29 , checkCompletedAt :: !(Maybe UTCTime)
30 , checkOutput :: !(Maybe CheckOutput)
31 , checkActions :: !(Maybe (Vector CheckAction))
32 }
33 deriving stock (Show, Eq, Ord, Generic)
35instance ToJSON Check where
36 toJSON (Check n sha durl eid s sa c ca o a) =
37 object'
38 [ "name" .= n
39 , "head_sha" .= sha
40 , "details_url" .= durl
41 , "external_id" .= eid
42 , "status" .= s
43 , "started_at" .= sa
44 , "conclusion" .= c
45 , "completed_at" .= ca
46 , "output" .= o
47 , "actions" .= a
48 ]
50data CheckStatus
51 = CheckQueued
52 | CheckInProgress
53 | CheckCompleted
54 deriving stock (Show, Enum, Bounded, Eq, Ord, Generic)
56instance ToJSON CheckStatus where
57 toJSON CheckQueued = String "queued"
58 toJSON CheckInProgress = String "in_progress"
59 toJSON CheckCompleted = String "completed"
61data CheckConclusion
62 = CheckActionRequired
63 | CheckCancelled
64 | CheckFailure
65 | CheckNeutral
66 | CheckSuccess
67 | CheckSkipped
68 | CheckStale
69 | CheckTimedOut
70 deriving stock (Show, Enum, Bounded, Eq, Ord, Generic)
72instance ToJSON CheckConclusion where
73 toJSON CheckActionRequired = String "action_required"
74 toJSON CheckCancelled = String "cancelled"
75 toJSON CheckFailure = String "failure"
76 toJSON CheckNeutral = String "neutral"
77 toJSON CheckSuccess = String "success"
78 toJSON CheckSkipped = String "skipped"
79 toJSON CheckStale = String "stale"
80 toJSON CheckTimedOut = String "timed_out"
82data CheckOutput = CheckOutput
83 { checkTitle :: !Text
84 , checkSummary :: !Text
85 , checkText :: !(Maybe Text)
86 , checkAnnotations :: !(Maybe (Vector CheckAnnotation))
87 , checkImages :: !(Maybe (Vector CheckImage))
88 }
89 deriving stock (Show, Eq, Ord, Generic)
91instance ToJSON CheckOutput where
92 toJSON (CheckOutput t s txt a i) =
93 object'
94 [ "title" .= t
95 , "summary" .= s
96 , "text" .= txt
97 , "annotations" .= a
98 , "images" .= i
99 ]
101data CheckAnnotation = CheckAnnotation
102 { checkPath :: !Text
103 , checkStartLine :: !Int
104 , checkEndLine :: !Int
105 , checkStartColumn :: !(Maybe Int)
106 , checkEndColumn :: !(Maybe Int)
107 , checkAnnotationLevel :: !CheckAnnotationLevel
108 , checkMessage :: !Text
109 , checkTitle :: !(Maybe Text)
110 , checkRawDetails :: !(Maybe Text)
111 }
112 deriving stock (Show, Eq, Ord, Generic)
114instance ToJSON CheckAnnotation where
115 toJSON (CheckAnnotation p sl el sc ec al m t rd) =
116 object'
117 [ "path" .= p
118 , "start_line" .= sl
119 , "end_line" .= el
120 , "start_column" .= sc
121 , "end_column" .= ec
122 , "annotation_level" .= al
123 , "message" .= m
124 , "title" .= t
125 , "raw_details" .= rd
126 ]
128data CheckAnnotationLevel
129 = NoticeAnnotation
130 | WarningAnnotation
131 | FailureAnnotation
132 deriving stock (Show, Enum, Bounded, Eq, Ord, Generic)
134instance ToJSON CheckAnnotationLevel where
135 toJSON NoticeAnnotation = String "notice"
136 toJSON WarningAnnotation = String "warning"
137 toJSON FailureAnnotation = String "failure"
139data CheckImage = CheckImage
140 { checkImageAlt :: !Text
141 , checkImageURL :: !URL
142 , checkImageCaption :: !(Maybe Text)
143 }
144 deriving stock (Show, Eq, Ord, Generic)
146instance ToJSON CheckImage where
147 toJSON (CheckImage a url c) =
148 object'
149 [ "alt" .= a
150 , "image_url" .= url
151 , "caption" .= c
152 ]
154data CheckAction = CheckAction
155 { checkActionLabel :: !Text
156 , checkActionDescription :: !Text
157 , checkActionIdentifier :: !Text
158 }
159 deriving stock (Show, Eq, Ord, Generic)
161instance ToJSON CheckAction where
162 toJSON (CheckAction l d i) =
163 object'
164 [ "label" .= l
165 , "description" .= d
166 , "identifier" .= i
167 ]
169object' :: [Pair] -> Value
170object' = object . filter notNull
171 where
172 notNull (_, Null) = False
173 notNull (_, _) = True