Skip to content

Commit 08a3ad2

Browse files
committed
GitHubClient: Extract team_membership() method
1 parent 561eb48 commit 08a3ad2

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

src/github.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ impl GitHubClient {
2525
self.request("/user", auth)
2626
}
2727

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+
2842
/// Does all the nonsense for sending a GET to Github. Doesn't handle parsing
2943
/// because custom error-code handling may be desirable. Use
3044
/// `parse_github_response` to handle the "common" processing of responses.
@@ -92,6 +106,11 @@ pub struct GithubUser {
92106
pub name: Option<String>,
93107
}
94108

109+
#[derive(Debug, Deserialize)]
110+
pub struct GitHubTeamMembership {
111+
pub state: String,
112+
}
113+
95114
pub fn team_url(login: &str) -> String {
96115
let mut login_pieces = login.split(':');
97116
login_pieces.next();

src/models/team.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -225,21 +225,16 @@ fn team_with_gh_id_contains_user(
225225
// GET /organizations/:org_id/team/:team_id/memberships/:username
226226
// check that "state": "active"
227227

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-
);
237228
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+
};
243238

244239
// There is also `state: pending` for which we could possibly give
245240
// some feedback, but it's not obvious how that should work.

0 commit comments

Comments
 (0)