1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
use serde::{Deserialize, Serialize};
use crate::action::CommonAction;
use crate::build::ShortBuild;
use crate::client::{self, Result};
use crate::client_internals::Path;
use crate::job::ShortJob;
use crate::Jenkins;
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ShortQueueItem {
pub url: String,
#[cfg(not(feature = "extra-fields-visibility"))]
#[serde(flatten)]
pub(crate) extra_fields: Option<serde_json::Value>,
#[cfg(feature = "extra-fields-visibility")]
#[serde(flatten)]
pub extra_fields: Option<serde_json::Value>,
}
impl ShortQueueItem {
pub fn get_full_queue_item(&self, jenkins_client: &Jenkins) -> Result<QueueItem> {
let path = jenkins_client.url_to_path(&self.url);
if let Path::QueueItem { .. } = path {
Ok(jenkins_client.get(&path)?.json()?)
} else {
Err(client::Error::InvalidUrl {
url: self.url.clone(),
expected: client::error::ExpectedType::QueueItem,
}
.into())
}
}
}
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct QueueItem {
pub blocked: bool,
pub buildable: bool,
pub cancelled: Option<bool>,
pub id: u32,
pub in_queue_since: u64,
pub params: String,
pub stuck: bool,
pub task: ShortJob,
pub url: String,
pub why: Option<String>,
pub buildable_start_milliseconds: Option<u64>,
pub executable: Option<ShortBuild>,
pub actions: Vec<CommonAction>,
}
impl QueueItem {
pub fn refresh_item(self, jenkins_client: &Jenkins) -> Result<Self> {
let path = jenkins_client.url_to_path(&self.url);
if let Path::QueueItem { .. } = path {
Ok(jenkins_client.get(&path)?.json()?)
} else {
Err(client::Error::InvalidUrl {
url: self.url.clone(),
expected: client::error::ExpectedType::QueueItem,
}
.into())
}
}
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Queue {
pub items: Vec<QueueItem>,
}
impl Jenkins {
pub fn get_queue(&self) -> Result<Queue> {
Ok(self.get(&Path::Queue)?.json()?)
}
pub fn get_queue_item(&self, id: i32) -> Result<QueueItem> {
Ok(self.get(&Path::QueueItem { id })?.json()?)
}
}