MCPcopy Create free account
hub / github.com/3eif/gitmotion / clone_repository

Function clone_repository

api/src/main.rs:452–497  ·  view source on GitHub ↗
(
    repo_url: &str,
    temp_dir: &Path,
    github_token: Option<&str>,
)

Source from the content-addressed store, hash-verified

450}
451
452fn clone_repository(
453 repo_url: &str,
454 temp_dir: &Path,
455 github_token: Option<&str>,
456) -> Result<(), GourceError> {
457 log_message(
458 log::Level::Info,
459 &format!("Cloning repository: {}", repo_url),
460 None,
461 );
462
463 let mut url = Url::parse(repo_url).map_err(|_| GourceError::InvalidUrl)?;
464
465 if let Some(token) = github_token {
466 url.set_username("oauth2")
467 .map_err(|_| GourceError::InvalidUrl)?;
468 url.set_password(Some(token))
469 .map_err(|_| GourceError::InvalidUrl)?;
470 }
471
472 let child = Command::new("git")
473 .arg("clone")
474 .arg(url.as_str())
475 .arg(temp_dir)
476 .stdout(Stdio::piped())
477 .stderr(Stdio::piped())
478 .spawn()
479 .map_err(|_| GourceError::CloneFailed)?;
480
481 let output = child
482 .wait_with_output()
483 .map_err(|_| GourceError::CloneFailed)?;
484
485 if !output.status.success() {
486 let error_message = String::from_utf8_lossy(&output.stderr);
487 log_message(
488 log::Level::Error,
489 &format!("Git clone failed: {}", error_message),
490 None,
491 );
492 return Err(GourceError::CloneFailed);
493 }
494
495 log_message(log::Level::Info, "Successfully cloned repository", None);
496 Ok(())
497}
498
499fn count_days_and_commits(
500 repo_path: &Path,

Callers 1

process_gourceFunction · 0.85

Calls 1

log_messageFunction · 0.85

Tested by

no test coverage detected