Skip to content

Commit 124cddb

Browse files
committed
GitHubClient: Extract team_by_name() method
1 parent 08a3ad2 commit 124cddb

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

src/github.rs

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

28+
pub fn team_by_name(
29+
&self,
30+
org_name: &str,
31+
team_name: &str,
32+
auth: &AccessToken,
33+
) -> AppResult<GitHubTeam> {
34+
let url = format!("/orgs/{}/teams/{}", org_name, team_name);
35+
self.request(&url, auth)
36+
}
37+
2838
pub fn team_membership(
2939
&self,
3040
org_id: i32,
@@ -106,6 +116,18 @@ pub struct GithubUser {
106116
pub name: Option<String>,
107117
}
108118

119+
#[derive(Debug, Deserialize, Copy)]
120+
pub struct GitHubOrganization {
121+
pub id: i32, // unique GH id (needed for membership queries)
122+
}
123+
124+
#[derive(Debug, Deserialize)]
125+
pub struct GitHubTeam {
126+
pub id: i32, // unique GH id (needed for membership queries)
127+
pub name: Option<String>, // Pretty name
128+
pub organization: GitHubOrganization,
129+
}
130+
109131
#[derive(Debug, Deserialize)]
110132
pub struct GitHubTeamMembership {
111133
pub state: String,

src/models/team.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,10 @@ impl Team {
138138
)));
139139
}
140140

141-
#[derive(Deserialize)]
142-
struct GithubOrganization {
143-
id: i32, // unique GH id (needed for membership queries)
144-
}
145-
146-
#[derive(Deserialize)]
147-
struct GithubTeam {
148-
id: i32, // unique GH id (needed for membership queries)
149-
name: Option<String>, // Pretty name
150-
organization: GithubOrganization,
151-
}
152-
153-
let url = format!("/orgs/{}/teams/{}", org_name, team_name);
154141
let token = AccessToken::new(req_user.gh_access_token.clone());
155142
let team = app
156143
.github
157-
.request::<GithubTeam>(&url, &token)
144+
.team_by_name(org_name, team_name, &token)
158145
.map_err(|_| {
159146
cargo_err(&format_args!(
160147
"could not find the github team {}/{}",

0 commit comments

Comments
 (0)