1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct IssueLinkType {
6 pub id: String,
7 pub name: String,
8 pub inward: String,
9 pub outward: String,
10}
11
12#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct LinkedIssue {
14 pub id: String,
15 pub key: String,
16 pub summary: String,
17 pub status: String,
18 pub priority: Option<String>,
19 pub issue_type: String,
20}
21
22#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct IssueLink {
24 pub id: String,
25 #[serde(rename = "type")]
26 pub link_type: IssueLinkType,
27 #[serde(rename = "inwardIssue")]
28 pub inward_issue: Option<LinkedIssue>,
29 #[serde(rename = "outwardIssue")]
30 pub outward_issue: Option<LinkedIssue>,
31}
32
33impl LinkedIssue {
34 pub fn from_value(value: &Value) -> Option<Self> {
35 let id = value.get("id")?.as_str()?.to_string();
36 let key = value.get("key")?.as_str()?.to_string();
37 let fields = value.get("fields")?;
38
39 let summary = fields.get("summary")?.as_str()?.to_string();
40 let status = fields
41 .get("status")
42 .and_then(|s| s.get("name"))
43 .and_then(|v| v.as_str())
44 .unwrap_or("Unknown")
45 .to_string();
46 let priority = fields
47 .get("priority")
48 .and_then(|p| p.get("name"))
49 .and_then(|v| v.as_str())
50 .map(|s| s.to_string());
51 let issue_type = fields
52 .get("issuetype")
53 .and_then(|i| i.get("name"))
54 .and_then(|v| v.as_str())
55 .unwrap_or("Unknown")
56 .to_string();
57
58 Some(Self {
59 id,
60 key,
61 summary,
62 status,
63 priority,
64 issue_type,
65 })
66 }
67}
68
69impl IssueLink {
70 pub fn from_value(value: &Value) -> Option<Self> {
71 let id = value.get("id")?.as_str()?.to_string();
72 let type_val = value.get("type")?;
73 let link_type = IssueLinkType {
74 id: type_val.get("id")?.as_str()?.to_string(),
75 name: type_val.get("name")?.as_str()?.to_string(),
76 inward: type_val.get("inward")?.as_str()?.to_string(),
77 outward: type_val.get("outward")?.as_str()?.to_string(),
78 };
79
80 let inward_issue = value.get("inwardIssue").and_then(LinkedIssue::from_value);
81 let outward_issue = value.get("outwardIssue").and_then(LinkedIssue::from_value);
82
83 Some(Self {
84 id,
85 link_type,
86 inward_issue,
87 outward_issue,
88 })
89 }
90}