File tree Expand file tree Collapse file tree 2 files changed +28
-14
lines changed Expand file tree Collapse file tree 2 files changed +28
-14
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,20 @@ impl GitHubClient {
25
25
self . request ( "/user" , auth)
26
26
}
27
27
28
+ pub fn team_membership (
29
+ & self ,
30
+ org_id : i32 ,
31
+ team_id : i32 ,
32
+ username : & str ,
33
+ auth : & AccessToken ,
34
+ ) -> AppResult < GitHubTeamMembership > {
35
+ let url = format ! (
36
+ "/organizations/{}/team/{}/memberships/{}" ,
37
+ org_id, team_id, username
38
+ ) ;
39
+ self . request ( & url, auth)
40
+ }
41
+
28
42
/// Does all the nonsense for sending a GET to Github. Doesn't handle parsing
29
43
/// because custom error-code handling may be desirable. Use
30
44
/// `parse_github_response` to handle the "common" processing of responses.
@@ -92,6 +106,11 @@ pub struct GithubUser {
92
106
pub name : Option < String > ,
93
107
}
94
108
109
+ #[ derive( Debug , Deserialize ) ]
110
+ pub struct GitHubTeamMembership {
111
+ pub state : String ,
112
+ }
113
+
95
114
pub fn team_url ( login : & str ) -> String {
96
115
let mut login_pieces = login. split ( ':' ) ;
97
116
login_pieces. next ( ) ;
Original file line number Diff line number Diff line change @@ -225,21 +225,16 @@ fn team_with_gh_id_contains_user(
225
225
// GET /organizations/:org_id/team/:team_id/memberships/:username
226
226
// check that "state": "active"
227
227
228
- #[ derive( Deserialize ) ]
229
- struct Membership {
230
- state : String ,
231
- }
232
-
233
- let url = format ! (
234
- "/organizations/{}/team/{}/memberships/{}" ,
235
- & github_org_id, & github_team_id, & user. gh_login
236
- ) ;
237
228
let token = AccessToken :: new ( user. gh_access_token . clone ( ) ) ;
238
- let membership = match app. github . request :: < Membership > ( & url, & token) {
239
- // Officially how `false` is returned
240
- Err ( ref e) if e. is :: < NotFound > ( ) => return Ok ( false ) ,
241
- x => x?,
242
- } ;
229
+ let membership =
230
+ match app
231
+ . github
232
+ . team_membership ( github_org_id, github_team_id, & user. gh_login , & token)
233
+ {
234
+ // Officially how `false` is returned
235
+ Err ( ref e) if e. is :: < NotFound > ( ) => return Ok ( false ) ,
236
+ x => x?,
237
+ } ;
243
238
244
239
// There is also `state: pending` for which we could possibly give
245
240
// some feedback, but it's not obvious how that should work.
You can’t perform that action at this time.
0 commit comments