Skip to content
Merged
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
1 change: 1 addition & 0 deletions .cspell/dicts/project.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ MYPRJ
NEWKEY
burndown
splitn
hexdigit
56 changes: 56 additions & 0 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,32 @@ pub trait BacklogApi {
fn get_project_statuses(&self, _key: &str) -> Result<Vec<ProjectStatus>> {
unimplemented!()
}
fn add_project_status(&self, _key: &str, _name: &str, _color: &str) -> Result<ProjectStatus> {
unimplemented!()
}
fn update_project_status(
&self,
_key: &str,
_status_id: u64,
_params: &[(String, String)],
) -> Result<ProjectStatus> {
unimplemented!()
}
fn delete_project_status(
&self,
_key: &str,
_status_id: u64,
_substitute_status_id: u64,
) -> Result<ProjectStatus> {
unimplemented!()
}
fn reorder_project_statuses(
&self,
_key: &str,
_status_ids: &[u64],
) -> Result<Vec<ProjectStatus>> {
unimplemented!()
}
fn get_project_issue_types(&self, _key: &str) -> Result<Vec<ProjectIssueType>> {
unimplemented!()
}
Expand Down Expand Up @@ -398,6 +424,36 @@ impl BacklogApi for BacklogClient {
self.get_project_statuses(key)
}

fn add_project_status(&self, key: &str, name: &str, color: &str) -> Result<ProjectStatus> {
self.add_project_status(key, name, color)
}

fn update_project_status(
&self,
key: &str,
status_id: u64,
params: &[(String, String)],
) -> Result<ProjectStatus> {
self.update_project_status(key, status_id, params)
}

fn delete_project_status(
&self,
key: &str,
status_id: u64,
substitute_status_id: u64,
) -> Result<ProjectStatus> {
self.delete_project_status(key, status_id, substitute_status_id)
}

fn reorder_project_statuses(
&self,
key: &str,
status_ids: &[u64],
) -> Result<Vec<ProjectStatus>> {
self.reorder_project_statuses(key, status_ids)
}

fn get_project_issue_types(&self, key: &str) -> Result<Vec<ProjectIssueType>> {
self.get_project_issue_types(key)
}
Expand Down
77 changes: 77 additions & 0 deletions src/api/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,83 @@ impl BacklogClient {
})
}

pub fn add_project_status(&self, key: &str, name: &str, color: &str) -> Result<ProjectStatus> {
let params = vec![
("name".to_string(), name.to_string()),
("color".to_string(), color.to_string()),
];
let value = self.post_form(&format!("/projects/{}/statuses", key), &params)?;
serde_json::from_value(value.clone()).map_err(|e| {
anyhow::anyhow!(
"Failed to deserialize add project status response: {}\nRaw JSON:\n{}",
e,
serde_json::to_string_pretty(&value).unwrap_or_else(|_| value.to_string())
)
})
}

pub fn update_project_status(
&self,
key: &str,
status_id: u64,
params: &[(String, String)],
) -> Result<ProjectStatus> {
let value =
self.patch_form(&format!("/projects/{}/statuses/{}", key, status_id), params)?;
serde_json::from_value(value.clone()).map_err(|e| {
anyhow::anyhow!(
"Failed to deserialize update project status response: {}\nRaw JSON:\n{}",
e,
serde_json::to_string_pretty(&value).unwrap_or_else(|_| value.to_string())
)
})
}

pub fn delete_project_status(
&self,
key: &str,
status_id: u64,
substitute_status_id: u64,
) -> Result<ProjectStatus> {
let params = vec![(
"substituteStatusId".to_string(),
substitute_status_id.to_string(),
)];
let value = self.delete_form(
&format!("/projects/{}/statuses/{}", key, status_id),
&params,
)?;
serde_json::from_value(value.clone()).map_err(|e| {
anyhow::anyhow!(
"Failed to deserialize delete project status response: {}\nRaw JSON:\n{}",
e,
serde_json::to_string_pretty(&value).unwrap_or_else(|_| value.to_string())
)
})
}

pub fn reorder_project_statuses(
&self,
key: &str,
status_ids: &[u64],
) -> Result<Vec<ProjectStatus>> {
let params: Vec<(String, String)> = status_ids
.iter()
.map(|id| ("statusId[]".to_string(), id.to_string()))
.collect();
let value = self.patch_form(
&format!("/projects/{}/statuses/updateDisplayOrder", key),
&params,
)?;
serde_json::from_value(value.clone()).map_err(|e| {
anyhow::anyhow!(
"Failed to deserialize reorder project statuses response: {}\nRaw JSON:\n{}",
e,
serde_json::to_string_pretty(&value).unwrap_or_else(|_| value.to_string())
)
})
}

pub fn add_project_user(&self, key: &str, user_id: u64) -> Result<ProjectUser> {
let params = vec![("userId".to_string(), user_id.to_string())];
let value = self.post_form(&format!("/projects/{}/users", key), &params)?;
Expand Down
Loading