From 949c6459aa7683453a7160423b689ceadb08954b Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 4 Sep 2024 08:04:48 +0100 Subject: refactor: organise into lib and bin structure the make the code more readable this commit just moves the files, the next commit should fix the imports --- src/repo_state.rs | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 src/repo_state.rs (limited to 'src/repo_state.rs') diff --git a/src/repo_state.rs b/src/repo_state.rs deleted file mode 100644 index a5cebab..0000000 --- a/src/repo_state.rs +++ /dev/null @@ -1,40 +0,0 @@ -use std::collections::HashMap; - -use anyhow::{Context, Result}; -use git2::Oid; - -pub struct RepoState { - pub identifier: String, - pub state: HashMap, - pub event: nostr::Event, -} - -impl RepoState { - pub fn try_from(mut state_events: Vec) -> Result { - state_events.sort_by_key(|e| e.created_at); - let event = state_events.first().context("no state events")?; - let mut state = HashMap::new(); - for tag in &event.tags { - if let Some(name) = tag.as_vec().first() { - if ["refs/heads/", "refs/tags", "HEAD"] - .iter() - .any(|s| name.starts_with(*s)) - { - if let Some(value) = tag.as_vec().get(1) { - if Oid::from_str(value).is_ok() || value.contains("ref: refs/") { - state.insert(name.to_owned(), value.to_owned()); - } - } - } - } - } - Ok(RepoState { - identifier: event - .identifier() - .context("existing event must have an identifier")? - .to_string(), - state, - event: event.clone(), - }) - } -} -- cgit v1.2.3