Also return HEAD when calculating HOC

This commit is contained in:
Valentin Brandl 2019-04-29 20:40:05 +02:00
parent fd6f58ca9c
commit 34e2942f5f
No known key found for this signature in database
GPG Key ID: 30D341DD34118D7D

View File

@ -100,7 +100,7 @@ fn pull(path: impl AsRef<Path>) -> Result<(), Error> {
Ok(()) Ok(())
} }
fn hoc(repo: &str, repo_dir: &str, cache_dir: &str) -> Result<u64, Error> { fn hoc(repo: &str, repo_dir: &str, cache_dir: &str) -> Result<(u64, String), Error> {
let repo_dir = format!("{}/{}", repo_dir, repo); let repo_dir = format!("{}/{}", repo_dir, repo);
let cache_dir = format!("{}/{}.json", cache_dir, repo); let cache_dir = format!("{}/{}.json", cache_dir, repo);
let cache_dir = Path::new(&cache_dir); let cache_dir = Path::new(&cache_dir);
@ -125,7 +125,7 @@ fn hoc(repo: &str, repo_dir: &str, cache_dir: &str) -> Result<u64, Error> {
]; ];
let cache = CacheState::read_from_file(&cache_dir, &head)?; let cache = CacheState::read_from_file(&cache_dir, &head)?;
match &cache { match &cache {
CacheState::Current(res) => return Ok(*res), CacheState::Current(res) => return Ok((*res, head)),
CacheState::Old(cache) => { CacheState::Old(cache) => {
arg.push(format!("{}..HEAD", cache.head)); arg.push(format!("{}..HEAD", cache.head));
} }
@ -150,10 +150,10 @@ fn hoc(repo: &str, repo_dir: &str, cache_dir: &str) -> Result<u64, Error> {
}) })
.sum(); .sum();
let cache = cache.calculate_new_cache(count, head); let cache = cache.calculate_new_cache(count, (&head).into());
cache.write_to_file(cache_dir)?; cache.write_to_file(cache_dir)?;
Ok(cache.count) Ok((cache.count, head))
} }
fn remote_exists(url: &str) -> Result<bool, Error> { fn remote_exists(url: &str) -> Result<bool, Error> {
@ -179,7 +179,7 @@ fn calculate_hoc(
repo.remote_set_url("origin", &url)?; repo.remote_set_url("origin", &url)?;
} }
pull(&path)?; pull(&path)?;
let hoc = hoc(&service_path, &state.repos, &state.cache)?; let (hoc, _) = hoc(&service_path, &state.repos, &state.cache)?;
let badge_opt = BadgeOptions { let badge_opt = BadgeOptions {
subject: "Hits-of-Code".to_string(), subject: "Hits-of-Code".to_string(),
color: "#007ec6".to_string(), color: "#007ec6".to_string(),