pub mod jira;
pub mod secrets;
pub use secrets::SecretsManager;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum IntegrationKind {
CustomCommands,
Jira,
}
impl Default for IntegrationKind {
fn default() -> Self {
IntegrationKind::CustomCommands
}
}
impl IntegrationKind {
pub fn display_name(&self) -> &'static str {
match self {
IntegrationKind::CustomCommands => "Custom Commands",
IntegrationKind::Jira => "Jira Cloud",
}
}
pub fn cycle_next(&self) -> Self {
match self {
IntegrationKind::CustomCommands => IntegrationKind::Jira,
IntegrationKind::Jira => IntegrationKind::CustomCommands,
}
}
}
pub struct IntegrationOutput {
pub success: bool,
pub messages: Vec<String>,
pub worklog_id: Option<String>,
}
pub fn log_work(
kind: &IntegrationKind,
jira_url: &str,
jira_email: &str,
api_token: &str,
issue_key: &str,
time_spent: &str,
started: &str,
description: &str,
) -> Option<IntegrationOutput> {
match kind {
IntegrationKind::CustomCommands => None,
IntegrationKind::Jira => {
Some(jira::log_work(jira_url, jira_email, api_token, issue_key, time_spent, started, description)
.unwrap_or_else(|e| IntegrationOutput {
success: false,
messages: vec![format!("[JIRA] Error: {}", e)],
worklog_id: None,
}))
}
}
}
pub fn delete_work(
kind: &IntegrationKind,
jira_url: &str,
jira_email: &str,
api_token: &str,
issue_key: &str,
worklog_id: &str,
) -> Option<IntegrationOutput> {
match kind {
IntegrationKind::CustomCommands => None,
IntegrationKind::Jira => {
Some(jira::delete_work(jira_url, jira_email, api_token, issue_key, worklog_id)
.unwrap_or_else(|e| IntegrationOutput {
success: false,
messages: vec![format!("[JIRA] Error: {}", e)],
worklog_id: None,
}))
}
}
}
pub fn fetch_issue_summary(
kind: &IntegrationKind,
jira_url: &str,
jira_email: &str,
api_token: &str,
issue_key: &str,
) -> Option<Result<String, String>> {
match kind {
IntegrationKind::CustomCommands => None,
IntegrationKind::Jira => {
Some(jira::fetch_issue_summary(jira_url, jira_email, api_token, issue_key)
.map_err(|e| format!("[JIRA] Error fetching {}: {}", issue_key, e)))
}
}
}
pub fn open_issue(
kind: &IntegrationKind,
jira_url: &str,
issue_key: &str,
) -> Option<IntegrationOutput> {
match kind {
IntegrationKind::CustomCommands => None,
IntegrationKind::Jira => {
Some(jira::open_issue(jira_url, issue_key)
.unwrap_or_else(|e| IntegrationOutput {
success: false,
messages: vec![format!("[JIRA] Error: {}", e)],
worklog_id: None,
}))
}
}
}