@@ -185,152 +185,8 @@ impl GitHubApi {
185
185
}
186
186
Ok ( result)
187
187
}
188
-
189
- pub ( crate ) fn repo ( & self , org : & str , repo : & str ) -> Result < Option < Repo > , Error > {
190
- let resp = self
191
- . prepare ( true , Method :: GET , & format ! ( "repos/{}/{}" , org, repo) ) ?
192
- . send ( ) ?;
193
- match resp. status ( ) {
194
- reqwest:: StatusCode :: OK => Ok ( Some ( resp. json ( ) ?) ) ,
195
- reqwest:: StatusCode :: NOT_FOUND => Ok ( None ) ,
196
- _ => Err ( resp. error_for_status ( ) . unwrap_err ( ) . into ( ) ) ,
197
- }
198
- }
199
-
200
- pub ( crate ) fn repo_teams ( & self , org : & str , repo : & str ) -> Result < Vec < Team > , Error > {
201
- let resp = self
202
- . prepare ( true , Method :: GET , & format ! ( "repos/{}/{}/teams" , org, repo) ) ?
203
- . send ( ) ?;
204
- Ok ( resp. error_for_status ( ) ?. json ( ) ?)
205
- }
206
-
207
- pub ( crate ) fn repo_collaborators (
208
- & self ,
209
- org : & str ,
210
- repo : & str ,
211
- ) -> Result < Vec < RepoCollaborator > , Error > {
212
- let resp = self
213
- . prepare (
214
- true ,
215
- Method :: GET ,
216
- & format ! ( "repos/{org}/{repo}/collaborators?affiliation=direct" ) ,
217
- ) ?
218
- . send ( ) ?;
219
-
220
- Ok ( resp. error_for_status ( ) ?. json ( ) ?)
221
- }
222
-
223
- pub ( crate ) fn protected_branches ( & self , org : & str , repo : & str ) -> Result < Vec < Branch > , Error > {
224
- let resp = self
225
- . prepare (
226
- true ,
227
- Method :: GET ,
228
- & format ! ( "repos/{}/{}/branches?protected=true" , org, repo) ,
229
- ) ?
230
- . send ( ) ?;
231
- Ok ( resp. error_for_status ( ) ?. json ( ) ?)
232
- }
233
-
234
- pub ( crate ) fn branch_protection (
235
- & self ,
236
- org : & str ,
237
- repo : & str ,
238
- branch : & str ,
239
- ) -> Result < BranchProtection , Error > {
240
- let resp = self
241
- . prepare (
242
- true ,
243
- Method :: GET ,
244
- & format ! ( "repos/{}/{}/branches/{}/protection" , org, repo, branch) ,
245
- ) ?
246
- . send ( ) ?;
247
- Ok ( resp. error_for_status ( ) ?. json ( ) ?)
248
- }
249
188
}
250
189
251
190
fn user_node_id ( id : u64 ) -> String {
252
191
base64:: encode ( format ! ( "04:User{id}" ) )
253
192
}
254
-
255
- #[ derive( serde:: Deserialize , Debug ) ]
256
- pub ( crate ) struct Repo {
257
- pub ( crate ) description : Option < String > ,
258
- pub ( crate ) homepage : Option < String > ,
259
- }
260
-
261
- #[ derive( serde:: Deserialize , Debug ) ]
262
- pub ( crate ) struct Team {
263
- pub ( crate ) name : String ,
264
- pub ( crate ) permission : Permission ,
265
- }
266
-
267
- #[ derive( serde:: Deserialize , Debug ) ]
268
- pub ( crate ) struct Permission ( String ) ;
269
-
270
- impl Permission {
271
- pub ( crate ) fn as_toml ( & self ) -> & str {
272
- match self . 0 . as_str ( ) {
273
- "push" => "write" ,
274
- s => s,
275
- }
276
- }
277
- }
278
-
279
- #[ derive( serde:: Serialize , serde:: Deserialize , Debug , Eq , PartialEq , Copy , Clone ) ]
280
- #[ serde( rename_all = "snake_case" ) ]
281
- pub ( crate ) enum TeamPrivacy {
282
- Closed ,
283
- Secret ,
284
- }
285
-
286
- #[ derive( serde:: Deserialize , Debug ) ]
287
- pub ( crate ) struct Branch {
288
- pub ( crate ) name : String ,
289
- }
290
-
291
- #[ derive( serde:: Deserialize , Debug ) ]
292
- pub ( crate ) struct BranchProtection {
293
- pub ( crate ) required_status_checks : Option < StatusChecks > ,
294
- pub ( crate ) required_pull_request_reviews : Option < RequiredReviews > ,
295
- }
296
-
297
- #[ derive( serde:: Deserialize , Debug ) ]
298
- pub ( crate ) struct StatusChecks {
299
- pub ( crate ) contexts : Vec < String > ,
300
- }
301
-
302
- #[ derive( serde:: Deserialize , Debug ) ]
303
- pub ( crate ) struct RequiredReviews {
304
- pub ( crate ) dismiss_stale_reviews : bool ,
305
- }
306
-
307
- #[ derive( serde:: Deserialize , Debug ) ]
308
- pub ( crate ) struct RepoCollaborator {
309
- #[ serde( alias = "login" ) ]
310
- pub ( crate ) name : String ,
311
- pub ( crate ) permissions : Permissions ,
312
- }
313
-
314
- #[ derive( serde:: Deserialize , Debug ) ]
315
- pub ( crate ) struct Permissions {
316
- triage : bool ,
317
- push : bool ,
318
- maintain : bool ,
319
- admin : bool ,
320
- }
321
-
322
- impl Permissions {
323
- pub ( crate ) fn highest ( & self ) -> & str {
324
- if self . admin {
325
- "admin"
326
- } else if self . maintain {
327
- "maintain"
328
- } else if self . push {
329
- "write"
330
- } else if self . triage {
331
- "triage"
332
- } else {
333
- "read"
334
- }
335
- }
336
- }
0 commit comments