forked from haskell-github/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTeams.hs
More file actions
251 lines (208 loc) · 7.91 KB
/
Copy pathTeams.hs
File metadata and controls
251 lines (208 loc) · 7.91 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
-----------------------------------------------------------------------------
-- |
-- License : BSD-3-Clause
-- Maintainer : Oleg Grenrus <oleg.grenrus@iki.fi>
--
module GitHub.Data.Teams where
import GitHub.Data.Definitions
import GitHub.Data.Id (Id)
import GitHub.Data.Name (Name)
import GitHub.Data.Repos (Repo)
import GitHub.Data.URL (URL)
import GitHub.Internal.Prelude
import Prelude ()
import qualified Data.Text as T
data Privacy
= PrivacyClosed
| PrivacySecret
deriving (Show, Data, Enum, Bounded, Typeable, Eq, Ord, Generic)
instance NFData Privacy where rnf = genericRnf
instance Binary Privacy
data Permission
= PermissionPull
| PermissionPush
| PermissionAdmin
deriving (Show, Data, Enum, Bounded, Typeable, Eq, Ord, Generic)
instance NFData Permission where rnf = genericRnf
instance Binary Permission
data AddTeamRepoPermission = AddTeamRepoPermission
{ addTeamRepoPermission :: !Permission
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData AddTeamRepoPermission where rnf = genericRnf
instance Binary AddTeamRepoPermission
data SimpleTeam = SimpleTeam
{ simpleTeamId :: !(Id Team)
, simpleTeamUrl :: !URL
, simpleTeamName :: !Text -- TODO (0.15.0): unify this and 'simpleTeamSlug' as in 'Team'.
, simpleTeamSlug :: !(Name Team)
, simpleTeamDescription :: !(Maybe Text)
, simpleTeamPrivacy :: !(Maybe Privacy)
, simpleTeamPermission :: !Permission
, simpleTeamMembersUrl :: !URL
, simpleTeamRepositoriesUrl :: !URL
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData SimpleTeam where rnf = genericRnf
instance Binary SimpleTeam
data Team = Team
{ teamId :: !(Id Team)
, teamUrl :: !URL
, teamName :: !Text
, teamSlug :: !(Name Team)
, teamDescription :: !(Maybe Text)
, teamPrivacy :: !(Maybe Privacy)
, teamPermission :: !Permission
, teamMembersUrl :: !URL
, teamRepositoriesUrl :: !URL
, teamMembersCount :: !Int
, teamReposCount :: !Int
, teamOrganization :: !SimpleOrganization
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData Team where rnf = genericRnf
instance Binary Team
data CreateTeam = CreateTeam
{ createTeamName :: !(Name Team)
, createTeamDescription :: !(Maybe Text)
, createTeamRepoNames :: !(Vector (Name Repo))
-- , createTeamPrivacy :: Privacy
, createTeamPermission :: Permission
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData CreateTeam where rnf = genericRnf
instance Binary CreateTeam
data EditTeam = EditTeam
{ editTeamName :: !(Name Team)
, editTeamDescription :: !(Maybe Text)
-- , editTeamPrivacy :: Privacy
, editTeamPermission :: !Permission
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData EditTeam where rnf = genericRnf
instance Binary EditTeam
data Role
= RoleMaintainer
| RoleMember
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData Role
instance Binary Role
data ReqState
= StatePending
| StateActive
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData ReqState where rnf = genericRnf
instance Binary ReqState
data TeamMembership = TeamMembership
{ teamMembershipUrl :: !URL
, teamMembershipRole :: !Role
, teamMembershipReqState :: !ReqState
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData TeamMembership where rnf = genericRnf
instance Binary TeamMembership
data CreateTeamMembership = CreateTeamMembership {
createTeamMembershipRole :: !Role
} deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData CreateTeamMembership where rnf = genericRnf
instance Binary CreateTeamMembership
-- JSON Instances
instance FromJSON SimpleTeam where
parseJSON = withObject "SimpleTeam" $ \o -> SimpleTeam
<$> o .: "id"
<*> o .: "url"
<*> o .: "name"
<*> o .: "slug"
<*> o .:?"description" .!= Nothing
<*> o .:?"privacy" .!= Nothing
<*> o .: "permission"
<*> o .: "members_url"
<*> o .: "repositories_url"
instance FromJSON Team where
parseJSON = withObject "Team" $ \o -> Team
<$> o .: "id"
<*> o .: "url"
<*> o .: "name"
<*> o .: "slug"
<*> o .:?"description" .!= Nothing
<*> o .:?"privacy" .!= Nothing
<*> o .: "permission"
<*> o .: "members_url"
<*> o .: "repositories_url"
<*> o .: "members_count"
<*> o .: "repos_count"
<*> o .: "organization"
instance ToJSON CreateTeam where
toJSON (CreateTeam name desc repo_names {-privacy-} permissions) =
object [ "name" .= name
, "description" .= desc
, "repo_names" .= repo_names
{-, "privacy" .= privacy-}
, "permissions" .= permissions ]
instance ToJSON EditTeam where
toJSON (EditTeam name desc {-privacy-} permissions) =
object [ "name" .= name
, "description" .= desc
{-, "privacy" .= privacy-}
, "permissions" .= permissions ]
instance FromJSON TeamMembership where
parseJSON = withObject "TeamMembership" $ \o -> TeamMembership
<$> o .: "url"
<*> o .: "role"
<*> o .: "state"
instance FromJSON CreateTeamMembership where
parseJSON = withObject "CreateTeamMembership" $ \o -> CreateTeamMembership
<$> o .: "role"
instance ToJSON CreateTeamMembership where
toJSON (CreateTeamMembership { createTeamMembershipRole = role }) =
object [ "role" .= role ]
instance FromJSON AddTeamRepoPermission where
parseJSON = withObject "AddTeamRepoPermission" $ \o -> AddTeamRepoPermission
<$> o .: "permission"
instance ToJSON AddTeamRepoPermission where
toJSON (AddTeamRepoPermission { addTeamRepoPermission = permission}) =
object [ "permission" .= permission ]
instance FromJSON Role where
parseJSON = withText "Role" $ \t -> case T.toLower t of
"maintainer" -> pure RoleMaintainer
"member" -> pure RoleMember
_ -> fail $ "Unknown Role: " <> T.unpack t
instance ToJSON Role where
toJSON RoleMaintainer = String "maintainer"
toJSON RoleMember = String "member"
instance FromJSON Permission where
parseJSON = withText "Permission" $ \t -> case T.toLower t of
"pull" -> pure PermissionPull
"push" -> pure PermissionPush
"admin" -> pure PermissionAdmin
_ -> fail $ "Unknown Permission: " <> T.unpack t
instance ToJSON Permission where
toJSON PermissionPull = "pull"
toJSON PermissionPush = "push"
toJSON PermissionAdmin = "admin"
instance FromJSON Privacy where
parseJSON = withText "Privacy" $ \t -> case T.toLower t of
"secret" -> pure PrivacySecret
"closed" -> pure PrivacyClosed
_ -> fail $ "Unknown Privacy: " <> T.unpack t
instance ToJSON Privacy where
toJSON PrivacySecret = String "secret"
toJSON PrivacyClosed = String "closed"
instance FromJSON ReqState where
parseJSON = withText "ReqState" $ \t -> case T.toLower t of
"active" -> pure StateActive
"pending" -> pure StatePending
_ -> fail $ "Unknown ReqState: " <> T.unpack t
instance ToJSON ReqState where
toJSON StateActive = String "active"
toJSON StatePending = String "pending"
-- | Filters members returned by their role in the team.
data TeamMemberRole
= TeamMemberRoleAll -- ^ all members of the team.
| TeamMemberRoleMaintainer -- ^ team maintainers
| TeamMemberRoleMember -- ^ normal members of the team.
deriving (Show, Eq, Ord, Enum, Bounded, Typeable, Data, Generic)