grp_core/common/repos/
list.rs1use futures::{Stream, StreamExt};
2
3use crate::animation::Animation;
4use crate::config::Config;
5use crate::platform::Platform;
6use crate::error::structs::Error;
7use crate::common::structs::{Context, Repo, RequestType};
8
9impl Platform {
10 pub async fn list_repos<T: Into<String>, A: Animation + ?Sized>(&self,
13 owner: Option<T>,
14 config: &Config,
15 animation: &Box<A>
16 ) -> Result<impl Stream<Item = Result<Vec<Repo>, Error>>, Error> {
17 let owner = owner.map(|o| o.into());
18 let owner = owner.unwrap_or(config.user.clone());
19
20 animation.change_message("getting user type");
21 let user_type = self.get_user_type(&owner, &config).await?;
22
23 let url = self.url_list_repos(&user_type, &config.endpoint).await;
24
25 let context = Context {
26 request_type: RequestType::List,
27 owner: Some(user_type.get_user().name),
28 repo: None,
29 additional: None,
30 };
31
32 animation.change_message("fetching repositories...");
33
34 Ok(
35 self.pagginate(url, &config, context)
36 .map(|result| {
37 self.get_repos(result)
38 })
39 )
40 }
41
42 pub fn get_repos(&self, response: Result<String, Error>) -> Result<Vec<Repo>, Error> {
43 match response {
44 Ok(rs) => Repo::from_text_array(&rs, &self),
45 Err(e) => Err(e),
46 }
47 }
48}