diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/gitlab/api.rs | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/gitlab/api.rs b/src/gitlab/api.rs index 7f733b4c..3ddf4ec4 100644 --- a/src/gitlab/api.rs +++ b/src/gitlab/api.rs @@ -60,13 +60,17 @@ impl Api { } pub async fn get_group(&self, group_id: u64) -> Result<Group, Box<dyn std::error::Error>> { - let url = format!( - "{}/api/v4/groups/{}", - self.host.trim_end_matches('/'), - group_id - ); + self.get::<Group>(format!("/api/v4/groups/{}", group_id)) + .await + } - let group = self + async fn get<T: serde::de::DeserializeOwned>( + &self, + path: String, + ) -> Result<T, Box<dyn std::error::Error>> { + let url = format!("{}{}", self.host.trim_end_matches('/'), path); + + Ok(self .client .get(&url) .header("PRIVATE-TOKEN", &self.token) @@ -74,8 +78,6 @@ impl Api { .await? .error_for_status()? .json() - .await?; - - Ok(group) + .await?) } } |
