diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-09-04 08:04:48 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-09-04 13:30:59 +0100 |
| commit | 949c6459aa7683453a7160423b689ceadb08954b (patch) | |
| tree | 230c26ecb11b99916e5570e548673eb09ecf0a36 /src/repo_state.rs | |
| parent | a825311f2c55661aaab3a163bda9109295c96044 (diff) | |
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
Diffstat (limited to 'src/repo_state.rs')
| -rw-r--r-- | src/repo_state.rs | 40 |
1 files changed, 0 insertions, 40 deletions
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 @@ | |||
| 1 | use std::collections::HashMap; | ||
| 2 | |||
| 3 | use anyhow::{Context, Result}; | ||
| 4 | use git2::Oid; | ||
| 5 | |||
| 6 | pub struct RepoState { | ||
| 7 | pub identifier: String, | ||
| 8 | pub state: HashMap<String, String>, | ||
| 9 | pub event: nostr::Event, | ||
| 10 | } | ||
| 11 | |||
| 12 | impl RepoState { | ||
| 13 | pub fn try_from(mut state_events: Vec<nostr::Event>) -> Result<Self> { | ||
| 14 | state_events.sort_by_key(|e| e.created_at); | ||
| 15 | let event = state_events.first().context("no state events")?; | ||
| 16 | let mut state = HashMap::new(); | ||
| 17 | for tag in &event.tags { | ||
| 18 | if let Some(name) = tag.as_vec().first() { | ||
| 19 | if ["refs/heads/", "refs/tags", "HEAD"] | ||
| 20 | .iter() | ||
| 21 | .any(|s| name.starts_with(*s)) | ||
| 22 | { | ||
| 23 | if let Some(value) = tag.as_vec().get(1) { | ||
| 24 | if Oid::from_str(value).is_ok() || value.contains("ref: refs/") { | ||
| 25 | state.insert(name.to_owned(), value.to_owned()); | ||
| 26 | } | ||
| 27 | } | ||
| 28 | } | ||
| 29 | } | ||
| 30 | } | ||
| 31 | Ok(RepoState { | ||
| 32 | identifier: event | ||
| 33 | .identifier() | ||
| 34 | .context("existing event must have an identifier")? | ||
| 35 | .to_string(), | ||
| 36 | state, | ||
| 37 | event: event.clone(), | ||
| 38 | }) | ||
| 39 | } | ||
| 40 | } | ||