azure_devops/work_items/methods/create.rs
1use super::super::models::{JsonPatchOperation, WorkItem};
2use super::super::WorkItemsClient;
3use crate::constants::ApiPath;
4use crate::error::Result;
5
6impl WorkItemsClient<'_> {
7 /// Create a new work item.
8 ///
9 /// # Arguments
10 ///
11 /// * `project` — The project name where the work item will be created.
12 /// * `work_item_type` — The work item type (e.g., `"Bug"`, `"Task"`, `"User Story"`).
13 /// * `patch_document` — A slice of [`JsonPatchOperation`] describing the
14 /// fields to set. Use [`JsonPatchOperation::add()`] to build operations.
15 ///
16 /// # Returns
17 ///
18 /// The newly created [`WorkItem`].
19 pub async fn create(
20 &self,
21 project: &str,
22 work_item_type: &str,
23 patch_document: &[JsonPatchOperation],
24 ) -> Result<WorkItem> {
25 let body = crate::work_items::helpers::serialize_patch(patch_document)?;
26 let p = ApiPath::work_item_create(project, work_item_type);
27 self.http.post_json_patch(&p, &[], &body).await
28 }
29}