diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/repo_state.rs | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/src/lib/repo_state.rs b/src/lib/repo_state.rs index 8eba1af..04f3cf2 100644 --- a/src/lib/repo_state.rs +++ b/src/lib/repo_state.rs | |||
| @@ -36,24 +36,7 @@ impl RepoState { | |||
| 36 | } | 36 | } |
| 37 | } | 37 | } |
| 38 | } | 38 | } |
| 39 | // Include a HEAD if one isn't listed to prevent errors when users git config | 39 | add_head(&mut state); |
| 40 | // default branch isn't in the state event | ||
| 41 | if !state.contains_key("HEAD") { | ||
| 42 | if state.contains_key("refs/heads/master") { | ||
| 43 | state.insert("HEAD".to_string(), "ref: refs/heads/master".to_string()); | ||
| 44 | } else if state.contains_key("refs/heads/main") { | ||
| 45 | state.insert("HEAD".to_string(), "ref: refs/heads/main".to_string()); | ||
| 46 | } else if let Some(tag) = event | ||
| 47 | .tags | ||
| 48 | .iter() | ||
| 49 | .find(|t| t.len() > 1 && t.as_slice()[0].starts_with("refs/heads/")) | ||
| 50 | { | ||
| 51 | state.insert( | ||
| 52 | "HEAD".to_string(), | ||
| 53 | format!("ref: {}", tag.clone().to_vec()[0]), | ||
| 54 | ); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | Ok(RepoState { | 40 | Ok(RepoState { |
| 58 | identifier: event | 41 | identifier: event |
| 59 | .tags | 42 | .tags |
| @@ -67,9 +50,10 @@ impl RepoState { | |||
| 67 | 50 | ||
| 68 | pub async fn build( | 51 | pub async fn build( |
| 69 | identifier: String, | 52 | identifier: String, |
| 70 | state: HashMap<String, String>, | 53 | mut state: HashMap<String, String>, |
| 71 | signer: &Arc<dyn NostrSigner>, | 54 | signer: &Arc<dyn NostrSigner>, |
| 72 | ) -> Result<Self> { | 55 | ) -> Result<Self> { |
| 56 | add_head(&mut state); | ||
| 73 | let mut tags = vec![Tag::identifier(identifier.clone())]; | 57 | let mut tags = vec![Tag::identifier(identifier.clone())]; |
| 74 | for (name, value) in &state { | 58 | for (name, value) in &state { |
| 75 | tags.push(Tag::custom(nostr_sdk::TagKind::Custom(name.into()), vec![ | 59 | tags.push(Tag::custom(nostr_sdk::TagKind::Custom(name.into()), vec![ |
| @@ -89,3 +73,17 @@ impl RepoState { | |||
| 89 | }) | 73 | }) |
| 90 | } | 74 | } |
| 91 | } | 75 | } |
| 76 | |||
| 77 | // Include a HEAD if one isn't listed to prevent errors when users git config | ||
| 78 | // default branch isn't in the state event | ||
| 79 | fn add_head(state: &mut HashMap<String, String>) { | ||
| 80 | if !state.contains_key("HEAD") { | ||
| 81 | if state.contains_key("refs/heads/master") { | ||
| 82 | state.insert("HEAD".to_string(), "ref: refs/heads/master".to_string()); | ||
| 83 | } else if state.contains_key("refs/heads/main") { | ||
| 84 | state.insert("HEAD".to_string(), "ref: refs/heads/main".to_string()); | ||
| 85 | } else if let Some(k) = state.keys().find(|k| k.starts_with("refs/heads/")) { | ||
| 86 | state.insert("HEAD".to_string(), format!("ref: {k}")); | ||
| 87 | } | ||
| 88 | } | ||
| 89 | } | ||