use gossan_core::target::RepositoryTarget;
use gossan_core::{Config, ScanInput};
use gossan_keyhog_lite::{Chunk, ChunkMetadata};
use tempfile::tempdir;
use tracing::{info, warn};
pub async fn scan_repo(
target: &RepositoryTarget,
_config: &Config,
_input: &ScanInput,
) -> anyhow::Result<()> {
info!(url = %target.url, "starting in-memory git scan");
let dir = tempdir()?;
let url = target.url.to_string();
let dir_path = dir.path().to_path_buf();
let clone_result = tokio::task::spawn_blocking(move || -> anyhow::Result<()> {
let (_repo, _outcome) = gix::prepare_clone_bare(url.as_str(), &dir_path)
.map_err(|e| anyhow::anyhow!("failed to prepare clone: {e}"))?
.fetch_only(gix::progress::Discard, &gix::interrupt::IS_INTERRUPTED)
.map_err(|e| anyhow::anyhow!("clone failed: {e}"))?;
Ok(())
})
.await??;
let repo = gix::open(dir.path())?;
let head = repo.head()?.into_peeled_id()?;
let tree = head.object()?.into_commit().tree()?;
for entry in tree.decode()?.entries {
if entry.mode.is_tree() {
continue;
}
let obj = repo.find_object(entry.oid)?;
if obj.kind != gix::object::Kind::Blob {
continue;
}
let path = entry.filename.to_string();
let data = String::from_utf8_lossy(&obj.data);
let _chunk = Chunk {
data: data.to_string(),
metadata: ChunkMetadata {
source_type: "scm".into(),
path: Some(path.to_string()),
commit: Some(head.to_string()),
author: None,
date: None,
},
};
if path == "package.json" || path == "requirements.txt" || path == "composer.json" {
}
}
Ok(())
}