Skip to content

Commit 16d5350

Browse files
authored
Repo: add permissions field (#476)
Adds field `repoPermissions` to `Repo` record.
1 parent 3a26d2f commit 16d5350

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/GitHub/Data/Repos.hs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,26 @@ data Repo = Repo
6161
, repoPushedAt :: !(Maybe UTCTime) -- ^ this is Nothing for new repositories
6262
, repoCreatedAt :: !(Maybe UTCTime)
6363
, repoUpdatedAt :: !(Maybe UTCTime)
64+
, repoPermissions :: !(Maybe RepoPermissions) -- ^ Repository permissions as they relate to the authenticated user.
6465
}
6566
deriving (Show, Data, Typeable, Eq, Ord, Generic)
6667

6768
instance NFData Repo where rnf = genericRnf
6869
instance Binary Repo
6970

71+
-- | Repository permissions, as they relate to the authenticated user.
72+
--
73+
-- Returned by for example 'GitHub.Endpoints.Repos.currentUserReposR'
74+
data RepoPermissions = RepoPermissions
75+
{ repoPermissionAdmin :: !Bool
76+
, repoPermissionPush :: !Bool
77+
, repoPermissionPull :: !Bool
78+
}
79+
deriving (Show, Data, Typeable, Eq, Ord, Generic)
80+
81+
instance NFData RepoPermissions where rnf = genericRnf
82+
instance Binary RepoPermissions
83+
7084
data RepoRef = RepoRef
7185
{ repoRefOwner :: !SimpleOwner
7286
, repoRefRepo :: !(Name Repo)
@@ -214,6 +228,7 @@ instance FromJSON Repo where
214228
<*> o .:? "pushed_at"
215229
<*> o .:? "created_at"
216230
<*> o .:? "updated_at"
231+
<*> o .:? "permissions"
217232

218233
instance ToJSON NewRepo where
219234
toJSON (NewRepo { newRepoName = name
@@ -273,6 +288,12 @@ instance ToJSON EditRepo where
273288
, "archived" .= archived
274289
]
275290

291+
instance FromJSON RepoPermissions where
292+
parseJSON = withObject "RepoPermissions" $ \o -> RepoPermissions
293+
<$> o .: "admin"
294+
<*> o .: "push"
295+
<*> o .: "pull"
296+
276297
instance FromJSON RepoRef where
277298
parseJSON = withObject "RepoRef" $ \o -> RepoRef
278299
<$> o .: "owner"

src/GitHub/Endpoints/Repos.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,23 @@ repoPublicityQueryString RepoPublicityPublic = [("type", Just "public")]
4343
repoPublicityQueryString RepoPublicityPrivate = [("type", Just "private")]
4444

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

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

6161
-- | List organization repositories.
62-
-- See <https://developer.github.com/v3/repos/#list-organization-repositories>
62+
-- See <https://docs.github.com/en/rest/reference/repos#list-organization-repositories>
6363
organizationReposR
6464
:: Name Organization
6565
-> RepoPublicity

0 commit comments

Comments
 (0)