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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
use crate::{Jira, Result, Version, VersionCreationBody, VersionMoveAfterBody, VersionUpdateBody};
pub struct Versions {
jira: Jira,
}
impl Versions {
pub fn new(jira: &Jira) -> Self {
Self { jira: jira.clone() }
}
/// Fetch all versions associated to the given project
///
/// See [jira docs](https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-project-projectIdOrKey-versions-get)
/// for more information
pub fn project_versions(&self, project_id_or_key: &str) -> Result<Vec<Version>> {
self.jira
.get("api", &format!("/project/{project_id_or_key}/versions"))
}
/// Create a new version
///
/// See [jira docs](https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-version-post)
/// for more information
pub fn create<T: Into<String>>(&self, project_id: u64, name: T) -> Result<Version> {
let name = name.into();
self.jira
.post("api", "/version", VersionCreationBody { project_id, name })
}
/// Move a version after another version
///
/// See [jira docs](https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-version-id-move-post)
/// for more information
pub fn move_after<T: Into<String>>(&self, version: &Version, after: T) -> Result<Version> {
self.jira.post(
"api",
&format!("/version/{}/move", version.id),
VersionMoveAfterBody {
after: after.into(),
},
)
}
/// Release a new version: modify the version by turning the released boolean to true
///
/// See [jira docs](https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-version-id-put)
/// for more information
pub fn release(
&self,
version: &Version,
move_unfixed_issues_to: Option<&Version>,
) -> Result<()> {
if version.released {
// already released
Ok(())
} else {
self.jira
.put::<Version, _>(
"api",
&format!("/version/{}", version.id),
VersionUpdateBody {
released: true,
archived: false,
move_unfixed_issues_to: move_unfixed_issues_to.map(|v| v.self_link.clone()),
},
)
.map(|_v| ())
}
}
/// Delete a version
///
/// See [jira docs](https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-project-versions/#api-rest-api-2-version-id-delete)
/// for more information
pub fn delete<I>(&self, id: I) -> Result<()>
where
I: Into<String>,
{
self.jira
.delete::<crate::EmptyResponse>("api", &format!("/version/{}", id.into()))?;
Ok(())
}
}
#[cfg(feature = "async")]
use crate::r#async::Jira as AsyncJira;
#[cfg(feature = "async")]
pub struct AsyncVersions {
jira: AsyncJira,
}
#[cfg(feature = "async")]
impl AsyncVersions {
pub fn new(jira: &AsyncJira) -> Self {
Self { jira: jira.clone() }
}
/// Fetch all versions associated to the given project
///
/// See [jira docs](https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-project-projectIdOrKey-versions-get)
/// for more information
pub async fn project_versions(&self, project_id_or_key: &str) -> Result<Vec<Version>> {
self.jira
.get("api", &format!("/project/{project_id_or_key}/versions"))
.await
}
/// Create a new version
///
/// See [jira docs](https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-version-post)
/// for more information
pub async fn create<T: Into<String>>(&self, project_id: u64, name: T) -> Result<Version> {
let name = name.into();
self.jira
.post("api", "/version", VersionCreationBody { project_id, name })
.await
}
/// Move a version after another version
///
/// See [jira docs](https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-version-id-move-post)
/// for more information
pub async fn move_after<T: Into<String>>(
&self,
version: &Version,
after: T,
) -> Result<Version> {
self.jira
.post(
"api",
&format!("/version/{}/move", version.id),
VersionMoveAfterBody {
after: after.into(),
},
)
.await
}
/// Release a new version: modify the version by turning the released boolean to true
///
/// See [jira docs](https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-version-id-put)
/// for more information
pub async fn release(
&self,
version: &Version,
move_unfixed_issues_to: Option<&Version>,
) -> Result<()> {
if version.released {
// already released
Ok(())
} else {
self.jira
.put::<Version, _>(
"api",
&format!("/version/{}", version.id),
VersionUpdateBody {
released: true,
archived: false,
move_unfixed_issues_to: move_unfixed_issues_to.map(|v| v.self_link.clone()),
},
)
.await
.map(|_v| ())
}
}
/// Delete a version
///
/// See [jira docs](https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-project-versions/#api-rest-api-2-version-id-delete)
/// for more information
pub async fn delete<I>(&self, id: I) -> Result<()>
where
I: Into<String>,
{
self.jira
.delete::<crate::EmptyResponse>("api", &format!("/version/{}", id.into()))
.await?;
Ok(())
}
}