fetch repos

This commit is contained in:
Kasper Juul Hermansen 2022-11-21 21:44:36 +01:00
parent 1879ad00ee
commit 30d9410e9f
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
4 changed files with 13 additions and 15 deletions

6
'
View File

@ -1,6 +0,0 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "apiVersion")]
pub enum Schema {}

View File

@ -40,6 +40,7 @@ pub async fn execute_subcommand(args: &ArgMatches) -> eyre::Result<()> {
} => {
tracing::debug!(name, "running action");
tracing::info!("fetching repos");
let mut repo_clones = Vec::with_capacity(select.repositories.len());
for repo in select.repositories {
let gp = service_register.git_provider.clone();

View File

@ -1,3 +1,5 @@
use std::path::PathBuf;
use git2::{Cred, RemoteCallbacks};
use crate::storage::DynStorageEngine;
@ -16,11 +18,12 @@ impl GitHubGitProvider {
#[async_trait::async_trait]
impl GitProvider for GitHubGitProvider {
async fn clone_from_url(&self, url: String) -> eyre::Result<()> {
async fn clone_from_url(&self, url: String) -> eyre::Result<PathBuf> {
tracing::debug!(url, "allocating dir");
let dir = self.storage_engine.allocate_dir().await?;
tokio::task::spawn_blocking(move || {
let dirpath = dir.clone().path();
let _ = tokio::task::spawn_blocking(move || {
let mut callbacks = RemoteCallbacks::new();
callbacks.credentials(|url, username_from_url, _allowed_types| {
tracing::debug!(username_from_url, url, "pulling key from ssh-agent");
@ -33,17 +36,17 @@ impl GitProvider for GitHubGitProvider {
let mut builder = git2::build::RepoBuilder::new();
builder.fetch_options(fo);
let path = dir.path();
tracing::debug!(
url,
path = path.as_os_str().to_string_lossy().to_string(),
path = dirpath.as_os_str().to_string_lossy().to_string(),
"clone git repo"
);
builder.clone(url.as_str(), path.as_path())
builder.clone(url.as_str(), dirpath.as_path())
})
.await??;
Ok(())
tracing::debug!("done pulling repo");
Ok(dir.path())
}
}

View File

@ -1,4 +1,4 @@
use std::sync::Arc;
use std::{path::PathBuf, sync::Arc};
use async_trait::async_trait;
@ -6,7 +6,7 @@ pub mod github;
#[async_trait]
pub trait GitProvider {
async fn clone_from_url(&self, url: String) -> eyre::Result<()>;
async fn clone_from_url(&self, url: String) -> eyre::Result<PathBuf>;
}
pub type DynGitProvider = Arc<dyn GitProvider + Send + Sync>;