Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ comfy-table = "7.2"
futures = "0.3"
base64 = "0.22"
mime_guess = "2.0"
uuid = { version = "1.23.3", features = ["v4"] }

[profile.release]
strip = true
Expand Down
74 changes: 73 additions & 1 deletion src/commands/ticket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ pub enum TicketCmd {
/// Comma-separated tags to remove
#[arg(long = "tags-remove")]
tags_remove: Option<String>,
/// Comma-separated Jira ticket keys (e.g. "TIO-817, TIO-818")
#[arg(long = "jira-tickets")]
jira_tickets: Option<String>,
},
/// Article subcommands
Article {
Expand All @@ -107,6 +110,18 @@ pub enum TicketCmd {
},
/// Get summary of ticket counts by state
Overview,
/// Create or update a shared draft (internal ID — see `ticket get` for the numeric ID)
SharedDraft {
id: String,
#[arg(long)]
body: String,
/// Article type (email or note; default: email)
#[arg(long, default_value = "email")]
r#type: String,
/// Mark as internal note (default: public reply)
#[arg(long)]
internal: bool,
},
}

#[derive(Subcommand)]
Expand Down Expand Up @@ -217,6 +232,7 @@ pub async fn run(cmd: TicketCmd, client: &ZammadClient, json: bool) -> Result<()
organization,
tags_add,
tags_remove,
jira_tickets,
} => {
update(
client,
Expand All @@ -230,9 +246,10 @@ pub async fn run(cmd: TicketCmd, client: &ZammadClient, json: bool) -> Result<()
organization,
tags_add,
tags_remove,
jira_tickets,
json,
)
.await
.await
}
TicketCmd::Article { cmd } => match cmd {
ArticleCmd::Add {
Expand All @@ -254,6 +271,12 @@ pub async fn run(cmd: TicketCmd, client: &ZammadClient, json: bool) -> Result<()
} => attachment_download(client, &id, article, attachment, all, &out, json).await,
},
TicketCmd::Overview => overview(client, json).await,
TicketCmd::SharedDraft {
id,
body,
r#type,
internal,
} => shared_draft(client, &id, body, r#type, internal, json).await,
}
}

Expand Down Expand Up @@ -563,6 +586,7 @@ async fn update(
organization: Option<String>,
tags_add: Option<String>,
tags_remove: Option<String>,
jira_tickets: Option<String>,
json: bool,
) -> Result<()> {
// Pending states require a `pending_time`; fail early with a clear message
Expand Down Expand Up @@ -610,6 +634,7 @@ async fn update(
insert_opt_str(&mut body, "title", title);
insert_opt_str(&mut body, "customer", customer);
insert_opt_str(&mut body, "organization", organization);
insert_opt_str(&mut body, "jira_tickets", jira_tickets);

let add_list = tags_add.as_deref().map(split_csv).unwrap_or_default();
let remove_list = tags_remove.as_deref().map(split_csv).unwrap_or_default();
Expand Down Expand Up @@ -756,6 +781,53 @@ async fn overview(client: &ZammadClient, json: bool) -> Result<()> {
Ok(())
}

/// Create or update a shared draft for a ticket.
///
/// PUT /api/v1/tickets/{ticket_id}/shared_draft
async fn shared_draft(
client: &ZammadClient,
id_str: &str,
body_text: String,
article_type: String,
internal: bool,
json: bool,
) -> Result<()> {
let resolved = resolve_ticket_id(client, id_str).await?;
let form_id = uuid::Uuid::new_v4().to_string();

let payload = serde_json::json!({
"form_id": form_id,
"new_article": {
"body": body_text,
"content_type": "text/html",
"type": article_type,
"internal": internal,
},
"ticket_attributes": {},
});

let value = client
.put(
&format!("/api/v1/tickets/{resolved}/shared_draft"),
Some(&payload),
)
.await?;

if json {
return output::emit_value(&value);
}

let draft_id = value
.get("shared_draft_id")
.and_then(|v| v.as_i64())
.unwrap_or_default();
let kind = if internal { "internal" } else { "public" };
output::print_message(&format!(
"Shared draft #{draft_id} saved on ticket {resolved} ({kind})"
));
Ok(())
}

/// Resolve a user-supplied ticket reference to an internal Zammad ID.
///
/// Accepts:
Expand Down
5 changes: 5 additions & 0 deletions src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ pub fn print_ticket_detail(t: &Ticket) {
"Organization:".bold(),
t.organization.as_deref().unwrap_or("-")
);
if let Some(jt) = &t.jira_tickets {
if !jt.is_empty() {
println!(" {} {}", "Jira Tickets:".bold(), jt.yellow());
}
}
if let Some(c) = &t.created_at {
println!(" {} {}", "Created:".bold(), c);
}
Expand Down
2 changes: 2 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub struct Ticket {
pub updated_at: Option<String>,
#[serde(default)]
pub article_count: Option<i64>,
#[serde(default)]
pub jira_tickets: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down