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

Repo: add permissions field #476

Merged
merged 3 commits into from
Apr 2, 2022
Merged
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
21 changes: 21 additions & 0 deletions src/GitHub/Data/Repos.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,26 @@ data Repo = Repo
, repoPushedAt :: !(Maybe UTCTime) -- ^ this is Nothing for new repositories
, repoCreatedAt :: !(Maybe UTCTime)
, repoUpdatedAt :: !(Maybe UTCTime)
, repoPermissions :: !(Maybe RepoPermissions) -- ^ Repository permissions as they relate to the authenticated user.
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)

instance NFData Repo where rnf = genericRnf
instance Binary Repo

-- | Repository permissions, as they relate to the authenticated user.
--
-- Returned by for example 'GitHub.Endpoints.Repos.currentUserReposR'
data RepoPermissions = RepoPermissions
{ repoPermissionAdmin :: !Bool
, repoPermissionPush :: !Bool
, repoPermissionPull :: !Bool
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)

instance NFData RepoPermissions where rnf = genericRnf
instance Binary RepoPermissions

data RepoRef = RepoRef
{ repoRefOwner :: !SimpleOwner
, repoRefRepo :: !(Name Repo)
Expand Down Expand Up @@ -214,6 +228,7 @@ instance FromJSON Repo where
<*> o .:? "pushed_at"
<*> o .:? "created_at"
<*> o .:? "updated_at"
<*> o .:? "permissions"

instance ToJSON NewRepo where
toJSON (NewRepo { newRepoName = name
Expand Down Expand Up @@ -273,6 +288,12 @@ instance ToJSON EditRepo where
, "archived" .= archived
]

instance FromJSON RepoPermissions where
parseJSON = withObject "RepoPermissions" $ \o -> RepoPermissions
<$> o .: "admin"
<*> o .: "push"
<*> o .: "pull"

instance FromJSON RepoRef where
parseJSON = withObject "RepoRef" $ \o -> RepoRef
<$> o .: "owner"
Expand Down
6 changes: 3 additions & 3 deletions src/GitHub/Endpoints/Repos.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ repoPublicityQueryString RepoPublicityPublic = [("type", Just "public")]
repoPublicityQueryString RepoPublicityPrivate = [("type", Just "private")]

-- | List your repositories.
-- See <https://developer.github.com/v3/repos/#list-your-repositories>
-- See <https://docs.github.com/en/rest/reference/repos#list-repositories-for-the-authenticated-user>
currentUserReposR :: RepoPublicity -> FetchCount -> Request k (Vector Repo)
currentUserReposR publicity =
pagedQuery ["user", "repos"] qs
where
qs = repoPublicityQueryString publicity

-- | List user repositories.
-- See <https://developer.github.com/v3/repos/#list-user-repositories>
-- See <https://docs.github.com/en/rest/reference/repos#list-repositories-for-a-user>
userReposR :: Name Owner -> RepoPublicity -> FetchCount -> Request k(Vector Repo)
userReposR user publicity =
pagedQuery ["users", toPathPart user, "repos"] qs
where
qs = repoPublicityQueryString publicity

-- | List organization repositories.
-- See <https://developer.github.com/v3/repos/#list-organization-repositories>
-- See <https://docs.github.com/en/rest/reference/repos#list-organization-repositories>
organizationReposR
:: Name Organization
-> RepoPublicity
Expand Down