Compare commits
2 Commits
5a792db905
...
3ecc46ca94
Author | SHA1 | Date | |
---|---|---|---|
|
3ecc46ca94 | ||
02845e5e11 |
@ -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
|
||||||
|
@ -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());
|
||||||
}
|
}
|
||||||
|
@ -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"))]
|
||||||
|
59
crates/gitnow/src/projects_list.rs
Normal file
59
crates/gitnow/src/projects_list.rs
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user