Compare commits

..

1 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
5 changed files with 32 additions and 140 deletions

View File

@ -15,9 +15,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Docs ### Docs
- add readme - add readme
### Fixed
- don't have to use user for basic auth
### Other ### Other
- move projects list into separate file - move projects list into separate file
- separate files - separate files

View File

@ -22,6 +22,7 @@ impl RootCommand {
let repositories = self.app.projects_list().get_projects().await?; let repositories = self.app.projects_list().get_projects().await?;
//let github_provider = self.app.github_provider();
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

@ -69,17 +69,6 @@ impl<'a> From<&'a GiteaUser> for &'a str {
#[derive(Debug, Serialize, Deserialize, PartialEq)] #[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct GiteaOrganisation(String); pub struct GiteaOrganisation(String);
impl From<GiteaOrganisation> for String {
fn from(value: GiteaOrganisation) -> Self {
value.0
}
}
impl<'a> From<&'a GiteaOrganisation> for &'a str {
fn from(value: &'a GiteaOrganisation) -> Self {
value.0.as_str()
}
}
impl Config { impl Config {
pub async fn from_file(file_path: &Path) -> anyhow::Result<Config> { pub async fn from_file(file_path: &Path) -> anyhow::Result<Config> {

View File

@ -23,7 +23,20 @@ impl GiteaProvider {
) -> anyhow::Result<Vec<super::Repository>> { ) -> anyhow::Result<Vec<super::Repository>> {
tracing::debug!("fetching gitea repositories for user"); tracing::debug!("fetching gitea repositories for user");
let config = self.get_config(api, access_token)?; let mut config = gitea_rs::apis::configuration::Configuration::new();
config.base_path = api.into();
match access_token {
Some(GiteaAccessToken::Env { env }) => {
let token =
std::env::var(env).context(format!("{env} didn't have a valid value"))?;
config.basic_auth = Some((user.into(), Some(token)));
}
Some(GiteaAccessToken::Direct(var)) => {
config.bearer_access_token = Some(var.to_owned());
}
None => {}
}
let mut repositories = Vec::new(); let mut repositories = Vec::new();
let mut page = 1; let mut page = 1;
@ -89,7 +102,20 @@ impl GiteaProvider {
) -> anyhow::Result<Vec<super::Repository>> { ) -> anyhow::Result<Vec<super::Repository>> {
tracing::debug!("fetching gitea repositories for user"); tracing::debug!("fetching gitea repositories for user");
let config = self.get_config(api, access_token)?; let mut config = gitea_rs::apis::configuration::Configuration::new();
config.base_path = api.into();
match access_token {
Some(GiteaAccessToken::Env { env }) => {
let token =
std::env::var(env).context(format!("{env} didn't have a valid value"))?;
config.basic_auth = Some((user.into(), Some(token)));
}
Some(GiteaAccessToken::Direct(var)) => {
config.bearer_access_token = Some(var.to_owned());
}
None => {}
}
let mut repositories = Vec::new(); let mut repositories = Vec::new();
let mut page = 1; let mut page = 1;
@ -143,109 +169,8 @@ impl GiteaProvider {
pub async fn list_repositories_for_organisation( pub async fn list_repositories_for_organisation(
&self, &self,
organisation: &str, organisation: &str,
api: &str,
access_token: Option<&GiteaAccessToken>,
) -> anyhow::Result<Vec<super::Repository>> { ) -> anyhow::Result<Vec<super::Repository>> {
let config = self.get_config(api, access_token)?; todo!()
let mut repositories = Vec::new();
let mut page = 1;
loop {
let mut repos = self
.list_repositories_for_organisation_with_page(organisation, &config, page)
.await?;
if repos.is_empty() {
break;
}
repositories.append(&mut repos);
page += 1;
}
let provider = &Self::get_domain(api)?;
Ok(repositories
.into_iter()
.map(|repo| super::Repository {
provider: provider.into(),
owner: repo
.owner
.map(|user| user.login.unwrap_or_default())
.unwrap_or_default(),
repo_name: repo.name.unwrap_or_default(),
ssh_url: repo
.ssh_url
.expect("ssh url to be set for gitea repository"),
})
.collect())
}
#[tracing::instrument(skip(self))]
pub async fn list_repositories_for_organisation_with_page(
&self,
organisation: &str,
config: &Configuration,
page: usize,
) -> anyhow::Result<Vec<gitea_rs::models::Repository>> {
let repos = gitea_rs::apis::organization_api::org_list_repos(
config,
organisation,
Some(page as i32),
None,
)
.await
.context("failed to fetch repos for users")?;
Ok(repos)
}
// fn get_config_from_user(
// &self,
// api: &str,
// user: &str,
// access_token: Option<&GiteaAccessToken>,
// ) -> anyhow::Result<Configuration> {
// let mut config = gitea_rs::apis::configuration::Configuration::new();
// config.base_path = api.into();
// match access_token {
// Some(GiteaAccessToken::Env { env }) => {
// let token =
// std::env::var(env).context(format!("{env} didn't have a valid value"))?;
// // config.basic_auth = Some((user.into(), Some(token)));
// config.basic_auth = Some(("".into(), Some(token)));
// }
// Some(GiteaAccessToken::Direct(var)) => {
// config.basic_auth = Some(("".into(), Some(var.to_owned())));
// }
// None => {}
// }
// Ok(config)
// }
fn get_config(
&self,
api: &str,
access_token: Option<&GiteaAccessToken>,
) -> anyhow::Result<Configuration> {
let mut config = gitea_rs::apis::configuration::Configuration::new();
config.base_path = api.into();
match access_token {
Some(GiteaAccessToken::Env { env }) => {
let token =
std::env::var(env).context(format!("{env} didn't have a valid value"))?;
config.basic_auth = Some(("".into(), Some(token)));
}
Some(GiteaAccessToken::Direct(var)) => {
config.bearer_access_token = Some(var.to_owned());
}
None => {}
}
Ok(config)
} }
} }

View File

@ -13,16 +13,6 @@ impl ProjectsList {
} }
pub async fn get_projects(&self) -> anyhow::Result<Vec<Repository>> { pub async fn get_projects(&self) -> anyhow::Result<Vec<Repository>> {
let mut repositories = Vec::new();
repositories.extend(self.get_gitea_projects().await?);
repositories.collect_unique();
Ok(repositories)
}
async fn get_gitea_projects(&self) -> anyhow::Result<Vec<Repository>> {
let gitea_provider = self.app.gitea_provider(); let gitea_provider = self.app.gitea_provider();
let mut repositories = Vec::new(); let mut repositories = Vec::new();
@ -50,20 +40,10 @@ impl ProjectsList {
repositories.append(&mut repos); repositories.append(&mut repos);
} }
for gitea_org in gitea.organisations.iter() {
let mut repos = gitea_provider
.list_repositories_for_organisation(
gitea_org.into(),
&gitea.url,
gitea.access_token.as_ref(),
)
.await?;
repositories.append(&mut repos);
}
} }
repositories.collect_unique();
Ok(repositories) Ok(repositories)
} }
} }