Compare commits

..

2 Commits

Author SHA1 Message Date
cuddle-please
3ecc46ca94 chore(release): 0.2.0
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2024-09-13 18:09:48 +00:00
02845e5e11
refactor: move projects list into separate file
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
2024-09-13 20:09:19 +02:00
4 changed files with 64 additions and 31 deletions

View File

@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- add readme - add readme
### Other ### Other
- move projects list into separate file
- separate files - separate files
- move config out - move config out
- remove unused libraries - remove unused libraries

View File

@ -3,6 +3,7 @@ use crate::{
git_provider::{ git_provider::{
gitea::GiteaProviderApp, github::GitHubProviderApp, GitProvider, VecRepositoryExt, gitea::GiteaProviderApp, github::GitHubProviderApp, GitProvider, VecRepositoryExt,
}, },
projects_list::ProjectsListApp,
}; };
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -19,38 +20,9 @@ impl RootCommand {
pub async fn execute(&mut self) -> anyhow::Result<()> { pub async fn execute(&mut self) -> anyhow::Result<()> {
tracing::debug!("executing"); tracing::debug!("executing");
let repositories = self.app.projects_list().get_projects().await?;
//let github_provider = self.app.github_provider(); //let github_provider = self.app.github_provider();
let gitea_provider = self.app.gitea_provider();
let mut repositories = Vec::new();
for gitea in self.app.config.providers.gitea.iter() {
if let Some(user) = &gitea.current_user {
let mut repos = gitea_provider
.list_repositories_for_current_user(
user,
&gitea.url,
gitea.access_token.as_ref(),
)
.await?;
repositories.append(&mut repos);
}
for gitea_user in gitea.users.iter() {
let mut repos = gitea_provider
.list_repositories_for_user(
gitea_user.into(),
&gitea.url,
gitea.access_token.as_ref(),
)
.await?;
repositories.append(&mut repos);
}
}
repositories.collect_unique();
for repo in &repositories { for repo in &repositories {
tracing::info!("repo: {}", repo.to_rel_path().display()); tracing::info!("repo: {}", repo.to_rel_path().display());
} }

View File

@ -9,6 +9,7 @@ mod app;
mod commands; mod commands;
mod config; mod config;
mod git_provider; mod git_provider;
mod projects_list;
#[derive(Parser)] #[derive(Parser)]
#[command(author, version, about, long_about = Some("Navigate git projects at the speed of thought"))] #[command(author, version, about, long_about = Some("Navigate git projects at the speed of thought"))]

View File

@ -0,0 +1,59 @@
use crate::{
app::App,
git_provider::{gitea::GiteaProviderApp, Repository, VecRepositoryExt},
};
pub struct ProjectsList {
app: &'static App,
}
impl ProjectsList {
pub fn new(app: &'static App) -> Self {
Self { app }
}
pub async fn get_projects(&self) -> anyhow::Result<Vec<Repository>> {
let gitea_provider = self.app.gitea_provider();
let mut repositories = Vec::new();
for gitea in self.app.config.providers.gitea.iter() {
if let Some(user) = &gitea.current_user {
let mut repos = gitea_provider
.list_repositories_for_current_user(
user,
&gitea.url,
gitea.access_token.as_ref(),
)
.await?;
repositories.append(&mut repos);
}
for gitea_user in gitea.users.iter() {
let mut repos = gitea_provider
.list_repositories_for_user(
gitea_user.into(),
&gitea.url,
gitea.access_token.as_ref(),
)
.await?;
repositories.append(&mut repos);
}
}
repositories.collect_unique();
Ok(repositories)
}
}
pub trait ProjectsListApp {
fn projects_list(&self) -> ProjectsList;
}
impl ProjectsListApp for &'static App {
fn projects_list(&self) -> ProjectsList {
ProjectsList::new(self)
}
}