-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathProjects.hs
More file actions
130 lines (109 loc) · 3.23 KB
/
Projects.hs
File metadata and controls
130 lines (109 loc) · 3.23 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
-----------------------------------------------------------------------------
-- |
-- License : BSD-3-Clause
-- Maintainer : Oleg Grenrus <oleg.grenrus@iki.fi>
--
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module GitHub.Data.Projects where
import GitHub.Data.Definitions
import GitHub.Data.Name
import GitHub.Data.Id (Id)
import GitHub.Data.URL (URL)
import GitHub.Internal.Prelude
import Prelude ()
import Data.Tagged (Tagged (..))
-- import qualified GitHub.Request as GH
import qualified Data.Text as T
data ProjectState = ProjectStateOpen | ProjectStateClosed
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData ProjectState where rnf = genericRnf
instance Binary ProjectState
instance FromJSON ProjectState where
parseJSON = withText "ProjecState" $ \t -> case T.toLower t of
"open" -> pure ProjectStateOpen
"closed" -> pure ProjectStateClosed
_ -> fail $ "Unknown ProjectState: " <> T.unpack t
data Project = Project
{
projectOwnerUrl:: !URL
, projectUrl:: !URL
, projectHtmlUrl:: !URL
, projectColumnsUrl:: !URL
, projectId :: !(Id Project)
, projectName :: !(Name Project)
, projectBody :: !(Maybe Text)
, projectNumber :: !Int
, projectState :: !ProjectState
, projectCreator :: !SimpleUser
, projectCreatedAt :: !UTCTime
, projectUpdatedAt :: !UTCTime
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData Project where rnf = genericRnf
instance Binary Project
instance FromJSON Project where
parseJSON = withObject "Project" $ \o -> Project
<$> o .: "owner_url"
<*> o .: "url"
<*> o .: "html_url"
<*> o .: "columns_url"
<*> o .: "id"
<*> o .: "name"
<*> o .:? "body"
<*> o .: "number"
<*> o .: "state"
<*> o .: "creator"
<*> o .: "created_at"
<*> o .: "updated_at"
data Column = Column
{
columnUrl :: !URL,
columnProjectUrl :: !URL,
columnCardsUrl :: !URL,
columnId :: !(Id Column),
columnName :: !(Name Column),
columnCreatedAt :: !UTCTime,
columntUpdatedAt :: !UTCTime
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData Column where rnf = genericRnf
instance Binary Column
instance FromJSON Column where
parseJSON = withObject "Column" $ \o ->
Column
<$> o .: "url"
<*> o .: "project_url"
<*> o .: "cards_url"
<*> o .: "id"
<*> o .: "name"
<*> o .: "created_at"
<*> o .: "updated_at"
data Card = Card
{ cardUrl :: !URL,
cardId :: !(Id Column),
cardNote:: !(Maybe T.Text),
cardCreator:: !(SimpleUser),
cardCreatedAt :: !UTCTime,
cardUpdatedAt :: !UTCTime,
archived:: !Bool,
cardColumnUrl:: !URL,
cardContentUrl:: !(Maybe URL),
cardProjectUrl:: !URL
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData Card where rnf = genericRnf
instance Binary Card
instance FromJSON Card where
parseJSON = withObject "Card" $ \o ->
Card
<$> o .: "url"
<*> o .: "id"
<*> o .:? "note"
<*> o .: "creator"
<*> o .: "created_at"
<*> o .: "updated_at"
<*> o .: "archived"
<*> o .: "column_url"
<*> o .:? "content_url"
<*> o .: "project_url"