Skip to content

Commit 73b5b0c

Browse files
committed
GitHubClient: Extract org_by_name() method
1 parent 124cddb commit 73b5b0c

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/github.rs

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

28+
pub fn org_by_name(&self, org_name: &str, auth: &AccessToken) -> AppResult<GitHubOrganization> {
29+
let url = format!("/orgs/{}", org_name);
30+
self.request(&url, auth)
31+
}
32+
2833
pub fn team_by_name(
2934
&self,
3035
org_name: &str,
@@ -116,9 +121,10 @@ pub struct GithubUser {
116121
pub name: Option<String>,
117122
}
118123

119-
#[derive(Debug, Deserialize, Copy)]
124+
#[derive(Debug, Deserialize)]
120125
pub struct GitHubOrganization {
121126
pub id: i32, // unique GH id (needed for membership queries)
127+
pub avatar_url: Option<String>,
122128
}
123129

124130
#[derive(Debug, Deserialize)]

src/models/team.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,7 @@ impl Team {
155155
return Err(cargo_err("only members of a team can add it as an owner"));
156156
}
157157

158-
#[derive(Deserialize)]
159-
struct Org {
160-
avatar_url: Option<String>,
161-
}
162-
163-
let url = format!("/orgs/{}", org_name);
164-
let org = app.github.request::<Org>(&url, &token)?;
158+
let org = app.github.org_by_name(org_name, &token)?;
165159

166160
NewTeam::new(
167161
&login.to_lowercase(),

0 commit comments

Comments
 (0)