forked from haskell-github/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatuses.hs
More file actions
112 lines (95 loc) · 3.25 KB
/
Statuses.hs
File metadata and controls
112 lines (95 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
module GitHub.Data.Statuses where
import GitHub.Data.Definitions
import GitHub.Data.Name (Name)
import GitHub.Data.Id (Id)
import GitHub.Data.URL (URL)
import GitHub.Internal.Prelude
import Prelude ()
import GitHub.Data.GitData (Commit)
import GitHub.Data.Repos (RepoRef)
import qualified Data.Text as T
data StatusState
= StatusPending
| StatusSuccess
| StatusError
| StatusFailure
deriving (Show, Data, Enum, Bounded, Typeable, Eq, Ord, Generic)
instance NFData StatusState where rnf = genericRnf
instance Binary StatusState
instance FromJSON StatusState where
parseJSON = withText "StatusState" $ \t -> case T.toLower t of
"pending" -> pure StatusPending
"success" -> pure StatusSuccess
"error" -> pure StatusError
"failure" -> pure StatusFailure
_ -> fail $ "Unknown StatusState: " <> T.unpack t
instance ToJSON StatusState where
toJSON StatusPending = String "pending"
toJSON StatusSuccess = String "success"
toJSON StatusError = String "error"
toJSON StatusFailure = String "failure"
data Status = Status
{ statusCreatedAt :: !UTCTime
, statusUpdatedAt :: !UTCTime
, statusState :: !StatusState
, statusTargetUrl :: !(Maybe URL)
, statusDescription :: !(Maybe Text)
, statusId :: !(Id Status)
, statusUrl :: !URL
, statusContext :: !(Maybe Text)
, statusCreator :: !(Maybe SimpleUser)
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance FromJSON Status where
parseJSON = withObject "Status" $ \o -> Status
<$> o .: "created_at"
<*> o .: "updated_at"
<*> o .: "state"
<*> o .:? "target_url"
<*> o .:? "description"
<*> o .: "id"
<*> o .: "url"
<*> o .:? "context"
<*> o .:? "creator"
data NewStatus = NewStatus
{ newStatusState :: !StatusState
, newStatusTargetUrl :: !(Maybe URL)
, newStatusDescription :: !(Maybe Text)
, newStatusContext :: !(Maybe Text)
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData NewStatus where rnf = genericRnf
instance Binary NewStatus
instance ToJSON NewStatus where
toJSON (NewStatus s t d c) = object $ filter notNull $
[ "state" .= s
, "target_url" .= t
, "description" .= d
, "context" .= c
]
where
notNull (_, Null) = False
notNull (_, _) = True
data CombinedStatus = CombinedStatus
{ combinedStatusState :: !StatusState
, combinedStatusSha :: !(Name Commit)
, combinedStatusTotalCount :: !Int
, combinedStatusStatuses :: !(Vector Status)
, combinedStatusRepository :: !RepoRef
, combinedStatusCommitUrl :: !URL
, combinedStatusUrl :: !URL
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance FromJSON CombinedStatus where
parseJSON = withObject "CombinedStatus" $ \o -> CombinedStatus
<$> o .: "state"
<*> o .: "sha"
<*> o .: "total_count"
<*> o .: "statuses"
<*> o .: "repository"
<*> o .: "commit_url"
<*> o .: "url"