Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teams improvements #417

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samples/Organizations/Teams/CreateTeamFor.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ main = do
Github.createTeamFor'
(Github.OAuth token)
org
(Github.CreateTeam team (Just desc) (read repos :: [String]) Github.PermissionPull)
(Github.CreateTeam team (Just desc) (read repos :: [String]) Github.PrivacyClosed Github.PermissionPull)
_ ->
error "usage: CreateTeamFor <token> <org> <team_name> <description> <[\"repos\"]>"
case result of
Expand Down
2 changes: 1 addition & 1 deletion samples/Teams/EditTeam.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ main = do
(GitHub.OAuth $ fromString token)
GitHub.editTeamR
(GitHub.mkTeamId $ read team_id)
(GitHub.EditTeam (GitHub.mkTeamName $ fromString team_name) (Just $ fromString desc) GitHub.PermissionPull)
(GitHub.EditTeam (GitHub.mkTeamName $ fromString team_name) (Just $ fromString desc) Nothing Nothing)
_ ->
error "usage: EditTeam <token> <team_id> <team_name> <description>"
case result of
Expand Down
48 changes: 29 additions & 19 deletions src/GitHub/Data/Teams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ data SimpleTeam = SimpleTeam
, simpleTeamName :: !Text -- TODO (0.15.0): unify this and 'simpleTeamSlug' as in 'Team'.
, simpleTeamSlug :: !(Name Team)
, simpleTeamDescription :: !(Maybe Text)
, simpleTeamPrivacy :: !(Maybe Privacy)
, simpleTeamPrivacy :: !Privacy
, simpleTeamPermission :: !Permission
, simpleTeamMembersUrl :: !URL
, simpleTeamRepositoriesUrl :: !URL
Expand All @@ -66,7 +66,7 @@ data Team = Team
, teamName :: !Text
, teamSlug :: !(Name Team)
, teamDescription :: !(Maybe Text)
, teamPrivacy :: !(Maybe Privacy)
, teamPrivacy :: !Privacy
, teamPermission :: !Permission
, teamMembersUrl :: !URL
, teamRepositoriesUrl :: !URL
Expand All @@ -83,8 +83,8 @@ data CreateTeam = CreateTeam
{ createTeamName :: !(Name Team)
, createTeamDescription :: !(Maybe Text)
, createTeamRepoNames :: !(Vector (Name Repo))
-- , createTeamPrivacy :: Privacy
, createTeamPermission :: Permission
, createTeamPrivacy :: !Privacy
, createTeamPermission :: !Permission
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)

Expand All @@ -94,8 +94,8 @@ instance Binary CreateTeam
data EditTeam = EditTeam
{ editTeamName :: !(Name Team)
, editTeamDescription :: !(Maybe Text)
-- , editTeamPrivacy :: Privacy
, editTeamPermission :: !Permission
, editTeamPrivacy :: !(Maybe Privacy)
, editTeamPermission :: !(Maybe Permission)
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)

Expand Down Expand Up @@ -144,7 +144,7 @@ instance FromJSON SimpleTeam where
<*> o .: "name"
<*> o .: "slug"
<*> o .:?"description" .!= Nothing
<*> o .:?"privacy" .!= Nothing
<*> o .: "privacy"
<*> o .: "permission"
<*> o .: "members_url"
<*> o .: "repositories_url"
Expand All @@ -156,7 +156,7 @@ instance FromJSON Team where
<*> o .: "name"
<*> o .: "slug"
<*> o .:?"description" .!= Nothing
<*> o .:?"privacy" .!= Nothing
<*> o .: "privacy"
<*> o .: "permission"
<*> o .: "members_url"
<*> o .: "repositories_url"
Expand All @@ -165,19 +165,29 @@ instance FromJSON Team where
<*> 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 ]
toJSON (CreateTeam name desc repo_names privacy permission) =
object $ filter notNull
[ "name" .= name
, "description" .= desc
, "repo_names" .= repo_names
, "privacy" .= privacy
, "permission" .= permission
]
where
notNull (_, Null) = False
notNull (_, _) = True

instance ToJSON EditTeam where
toJSON (EditTeam name desc {-privacy-} permissions) =
object [ "name" .= name
, "description" .= desc
{-, "privacy" .= privacy-}
, "permissions" .= permissions ]
toJSON (EditTeam name desc privacy permission) =
object $ filter notNull
[ "name" .= name
, "description" .= desc
, "privacy" .= privacy
, "permission" .= permission
]
where
notNull (_, Null) = False
notNull (_, _) = True

instance FromJSON TeamMembership where
parseJSON = withObject "TeamMembership" $ \o -> TeamMembership
Expand Down