| 492 | } |
| 493 | |
| 494 | fn add_hook_to_groups( |
| 495 | groups: &mut Vec<Value>, |
| 496 | command: &str, |
| 497 | status_message: Option<&str>, |
| 498 | timeout_sec: Option<u64>, |
| 499 | ) -> bool { |
| 500 | if groups.iter().any(|group| group_has_command(group, command)) { |
| 501 | return false; |
| 502 | } |
| 503 | |
| 504 | let mut entry = Map::new(); |
| 505 | entry.insert("type".to_string(), Value::String("command".to_string())); |
| 506 | entry.insert("command".to_string(), Value::String(command.to_string())); |
| 507 | if let Some(message) = status_message { |
| 508 | entry.insert( |
| 509 | "statusMessage".to_string(), |
| 510 | Value::String(message.to_string()), |
| 511 | ); |
| 512 | } |
| 513 | if let Some(timeout) = timeout_sec { |
| 514 | entry.insert("timeout".to_string(), Value::Number(timeout.into())); |
| 515 | } |
| 516 | |
| 517 | let mut group = Map::new(); |
| 518 | group.insert( |
| 519 | "hooks".to_string(), |
| 520 | Value::Array(vec![Value::Object(entry)]), |
| 521 | ); |
| 522 | groups.push(Value::Object(group)); |
| 523 | true |
| 524 | } |
| 525 | |
| 526 | fn group_has_command(group: &Value, command: &str) -> bool { |
| 527 | group |