Repository navigation
Expand file tree
/
Copy pathRepos.hs
More file actions
337 lines (295 loc) · 12.2 KB
/
Copy pathRepos.hs
File metadata and controls
337 lines (295 loc) · 12.2 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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
-----------------------------------------------------------------------------
-- |
-- License : BSD-3-Clause
-- Maintainer : Oleg Grenrus <oleg.grenrus@iki.fi>
--
-- The Github Repos API, as documented at
-- <http://developer.github.com/v3/repos/>
module GitHub.Endpoints.Repos (
-- * Querying repositories
currentUserRepos,
currentUserReposR,
userRepos,
userRepos',
userReposR,
organizationRepos,
organizationRepos',
organizationReposR,
repository,
repository',
repositoryR,
contributors,
contributors',
contributorsR,
contributorsWithAnonymous,
contributorsWithAnonymous',
languagesFor,
languagesFor',
languagesForR,
tagsFor,
tagsFor',
tagsForR,
branchesFor,
branchesFor',
branchesForR,
-- ** Create
createRepo',
createRepoR,
createOrganizationRepo',
createOrganizationRepoR,
forkExistingRepo',
forkExistingRepoR,
-- ** Edit
editRepo,
editRepoR,
-- ** Delete
deleteRepo,
deleteRepoR,
-- * Data
module GitHub.Data,
) where
import GitHub.Data
import GitHub.Internal.Prelude
import GitHub.Request
import Prelude ()
repoPublicityQueryString :: RepoPublicity -> QueryString
repoPublicityQueryString RepoPublicityAll = [("type", Just "all")]
repoPublicityQueryString RepoPublicityOwner = [("type", Just "owner")]
repoPublicityQueryString RepoPublicityMember = [("type", Just "member")]
repoPublicityQueryString RepoPublicityPublic = [("type", Just "public")]
repoPublicityQueryString RepoPublicityPrivate = [("type", Just "private")]
-- | List your repositories.
currentUserRepos :: Auth -> RepoPublicity -> IO (Either Error (Vector Repo))
currentUserRepos auth publicity =
executeRequest auth $ currentUserReposR publicity FetchAll
-- | List your repositories.
-- See <https://developer.github.com/v3/repos/#list-your-repositories>
currentUserReposR :: RepoPublicity -> FetchCount -> Request k (Vector Repo)
currentUserReposR publicity =
pagedQuery ["user", "repos"] qs
where
qs = repoPublicityQueryString publicity
-- | The repos for a user, by their login. Can be restricted to just repos they
-- own, are a member of, or publicize. Private repos will return empty list.
--
-- > userRepos "mike-burns" All
userRepos :: Name Owner -> RepoPublicity -> IO (Either Error (Vector Repo))
userRepos = userRepos' Nothing
-- | The repos for a user, by their login.
-- With authentication.
--
-- > userRepos' (Just $ BasicAuth "github-username" "github-password") "mike-burns" All
userRepos'
:: Maybe Auth
-> Name Owner
-> RepoPublicity
-> IO (Either Error (Vector Repo))
userRepos' auth user publicity =
executeRequestMaybe auth $ userReposR user publicity FetchAll
-- | List user repositories.
-- See <https://developer.github.com/v3/repos/#list-user-repositories>
userReposR :: Name Owner -> RepoPublicity -> FetchCount -> Request k(Vector Repo)
userReposR user publicity =
pagedQuery ["users", toPathPart user, "repos"] qs
where
qs = repoPublicityQueryString publicity
-- | The repos for an organization, by the organization name.
--
-- > organizationRepos "thoughtbot"
organizationRepos :: Name Organization -> IO (Either Error (Vector Repo))
organizationRepos org = organizationRepos' Nothing org RepoPublicityAll
-- | The repos for an organization, by the organization name.
-- With authentication.
--
-- > organizationRepos (Just $ BasicAuth "github-username" "github-password") "thoughtbot" All
organizationRepos'
:: Maybe Auth
-> Name Organization
-> RepoPublicity
-> IO (Either Error (Vector Repo))
organizationRepos' auth org publicity =
executeRequestMaybe auth $ organizationReposR org publicity FetchAll
-- | List organization repositories.
-- See <https://developer.github.com/v3/repos/#list-organization-repositories>
organizationReposR
:: Name Organization
-> RepoPublicity
-> FetchCount
-> Request k (Vector Repo)
organizationReposR org publicity =
pagedQuery ["orgs", toPathPart org, "repos"] qs
where
qs = repoPublicityQueryString publicity
-- | Details on a specific repo, given the owner and repo name.
--
-- > repository "mike-burns" "github"
repository :: Name Owner -> Name Repo -> IO (Either Error Repo)
repository = repository' Nothing
-- | Details on a specific repo, given the owner and repo name.
-- With authentication.
--
-- > repository' (Just $ BasicAuth "github-username" "github-password") "mike-burns" "github"
repository' :: Maybe Auth -> Name Owner -> Name Repo -> IO (Either Error Repo)
repository' auth user repo =
executeRequestMaybe auth $ repositoryR user repo
-- | Query single repository.
-- See <https://developer.github.com/v3/repos/#get>
repositoryR :: Name Owner -> Name Repo -> Request k Repo
repositoryR user repo =
query ["repos", toPathPart user, toPathPart repo] []
-- | Create a new repository.
--
-- > createRepo' (BasicAuth (user, password)) (newRepo "some_repo") {newRepoHasIssues = Just False}
createRepo' :: Auth -> NewRepo -> IO (Either Error Repo)
createRepo' auth nrepo =
executeRequest auth $ createRepoR nrepo
-- | Create a new repository.
-- See <https://developer.github.com/v3/repos/#create>
createRepoR :: NewRepo -> Request 'RW Repo
createRepoR nrepo =
command Post ["user", "repos"] (encode nrepo)
-- | Fork an existing repository.
forkExistingRepo' :: Auth -> Name Owner -> Name Repo -> Maybe (Name Owner) -> IO (Either Error Repo)
forkExistingRepo' auth owner repo morg =
executeRequest auth $ forkExistingRepoR owner repo morg
-- | Fork an existing repository.
-- See <https://developer.github.com/v3/repos/forks/#create-a-fork>
-- TODO: The third paramater (an optional Organisation) is not used yet.
forkExistingRepoR :: Name Owner -> Name Repo -> Maybe (Name Owner) -> Request 'RW Repo
forkExistingRepoR owner repo _morg =
command Post ["repos", toPathPart owner, toPathPart repo, "forks" ] mempty
-- | Create a new repository for an organization.
--
-- > createOrganizationRepo (BasicAuth (user, password)) "thoughtbot" (newRepo "some_repo") {newRepoHasIssues = Just False}
createOrganizationRepo' :: Auth -> Name Organization -> NewRepo -> IO (Either Error Repo)
createOrganizationRepo' auth org nrepo =
executeRequest auth $ createOrganizationRepoR org nrepo
-- | Create a new repository for an organization.
-- See <https://developer.github.com/v3/repos/#create>
createOrganizationRepoR :: Name Organization -> NewRepo -> Request 'RW Repo
createOrganizationRepoR org nrepo =
command Post ["orgs", toPathPart org, "repos"] (encode nrepo)
-- | Edit an existing repository.
--
-- > editRepo (BasicAuth (user, password)) "some_user" "some_repo" def {editDescription = Just "some description"}
editRepo
:: Auth
-> Name Owner -- ^ owner
-> Name Repo -- ^ repository name
-> EditRepo
-> IO (Either Error Repo)
editRepo auth user repo body =
executeRequest auth $ editRepoR user repo body
-- | Edit an existing repository.
-- See <https://developer.github.com/v3/repos/#edit>
editRepoR :: Name Owner -> Name Repo -> EditRepo -> Request 'RW Repo
editRepoR user repo body =
command Patch ["repos", toPathPart user, toPathPart repo] (encode b)
where
-- if no name is given, use curent name
b = body {editName = editName body <|> Just repo}
-- | The contributors to a repo, given the owner and repo name.
--
-- > contributors "thoughtbot" "paperclip"
contributors :: Name Owner -> Name Repo -> IO (Either Error (Vector Contributor))
contributors = contributors' Nothing
-- | The contributors to a repo, given the owner and repo name.
-- With authentication.
--
-- > contributors' (Just $ BasicAuth "github-username" "github-password") "thoughtbot" "paperclip"
contributors' :: Maybe Auth -> Name Owner -> Name Repo -> IO (Either Error (Vector Contributor))
contributors' auth user repo =
executeRequestMaybe auth $ contributorsR user repo False FetchAll
-- | List contributors.
-- See <https://developer.github.com/v3/repos/#list-contributors>
contributorsR
:: Name Owner
-> Name Repo
-> Bool -- ^ Include anonymous
-> FetchCount
-> Request k (Vector Contributor)
contributorsR user repo anon =
pagedQuery ["repos", toPathPart user, toPathPart repo, "contributors"] qs
where
qs | anon = [("anon", Just "true")]
| otherwise = []
-- | The contributors to a repo, including anonymous contributors (such as
-- deleted users or git commits with unknown email addresses), given the owner
-- and repo name.
--
-- > contributorsWithAnonymous "thoughtbot" "paperclip"
contributorsWithAnonymous :: Name Owner -> Name Repo -> IO (Either Error (Vector Contributor))
contributorsWithAnonymous = contributorsWithAnonymous' Nothing
-- | The contributors to a repo, including anonymous contributors (such as
-- deleted users or git commits with unknown email addresses), given the owner
-- and repo name.
-- With authentication.
--
-- > contributorsWithAnonymous' (Just $ BasicAuth "github-username" "github-password") "thoughtbot" "paperclip"
contributorsWithAnonymous' :: Maybe Auth -> Name Owner -> Name Repo -> IO (Either Error (Vector Contributor))
contributorsWithAnonymous' auth user repo =
executeRequestMaybe auth $ contributorsR user repo True FetchAll
-- | The programming languages used in a repo along with the number of
-- characters written in that language. Takes the repo owner and name.
--
-- > languagesFor "mike-burns" "ohlaunch"
languagesFor :: Name Owner -> Name Repo -> IO (Either Error Languages)
languagesFor = languagesFor' Nothing
-- | The programming languages used in a repo along with the number of
-- characters written in that language. Takes the repo owner and name.
-- With authentication.
--
-- > languagesFor' (Just $ BasicAuth "github-username" "github-password") "mike-burns" "ohlaunch"
languagesFor' :: Maybe Auth -> Name Owner -> Name Repo -> IO (Either Error Languages)
languagesFor' auth user repo =
executeRequestMaybe auth $ languagesForR user repo
-- | List languages.
-- See <https://developer.github.com/v3/repos/#list-languages>
languagesForR :: Name Owner -> Name Repo -> Request k Languages
languagesForR user repo =
query ["repos", toPathPart user, toPathPart repo, "languages"] []
-- | The git tags on a repo, given the repo owner and name.
--
-- > tagsFor "thoughtbot" "paperclip"
tagsFor :: Name Owner -> Name Repo -> IO (Either Error (Vector Tag))
tagsFor = tagsFor' Nothing
-- | The git tags on a repo, given the repo owner and name.
-- With authentication.
--
-- > tagsFor' (Just $ BasicAuth "github-username" "github-password") "thoughtbot" "paperclip"
tagsFor' :: Maybe Auth -> Name Owner -> Name Repo -> IO (Either Error (Vector Tag))
tagsFor' auth user repo =
executeRequestMaybe auth $ tagsForR user repo FetchAll
-- | List tags.
-- See <https://developer.github.com/v3/repos/#list-tags>
tagsForR :: Name Owner -> Name Repo -> FetchCount -> Request k (Vector Tag)
tagsForR user repo =
pagedQuery ["repos", toPathPart user, toPathPart repo, "tags"] []
-- | The git branches on a repo, given the repo owner and name.
--
-- > branchesFor "thoughtbot" "paperclip"
branchesFor :: Name Owner -> Name Repo -> IO (Either Error (Vector Branch))
branchesFor = branchesFor' Nothing
-- | The git branches on a repo, given the repo owner and name.
-- With authentication.
--
-- > branchesFor' (Just $ BasicAuth "github-username" "github-password") "thoughtbot" "paperclip"
branchesFor' :: Maybe Auth -> Name Owner -> Name Repo -> IO (Either Error (Vector Branch))
branchesFor' auth user repo =
executeRequestMaybe auth $ branchesForR user repo FetchAll
-- | List branches.
-- See <https://developer.github.com/v3/repos/#list-branches>
branchesForR :: Name Owner -> Name Repo -> FetchCount -> Request k (Vector Branch)
branchesForR user repo =
pagedQuery ["repos", toPathPart user, toPathPart repo, "branches"] []
-- | Delete an existing repository.
--
-- > deleteRepo (BasicAuth (user, password)) "thoughtbot" "some_repo"
deleteRepo :: Auth -> Name Owner -> Name Repo -> IO (Either Error ())
deleteRepo auth user repo =
executeRequest auth $ deleteRepoR user repo
-- | Delete a repository,.
-- See <https://developer.github.com/v3/repos/#delete-a-repository>
deleteRepoR :: Name Owner -> Name Repo -> GenRequest 'MtUnit 'RW ()
deleteRepoR user repo =
Command Delete ["repos", toPathPart user, toPathPart repo] mempty