feat(integrations): add Azure work item state management and UI tweaks

Add support for listing and setting Azure DevOps work item states from the
integration layer. New helpers build and validate JSON-patch payloads and
expose two Tauri commands so the frontend can enumerate available states
and apply state changes. The Issue Center now loads Azure states and can
change an issue's state; dialog dismiss controls and related CSS were
consolidated and board UI feedback was simplified for clarity.

- Add Tauri commands to list and set Azure work item states.
- Load and present Azure states in Issue Center and allow state changes.
- Unify dialog dismiss attributes and refine hover/focus styling.
This commit is contained in:
2026-09-11 08:43:06 +02:00
parent c42f8eb352
commit d0dd79354a
12 changed files with 151 additions and 66 deletions
+65 -15
View File
@@ -10,6 +10,56 @@ fn completed_state(value: &Value) -> Result<String,String> {
if states.len()!=1 {return Err("No unique completed state is configured for this work item type. Open the issue in Azure to select its state.".into());}
Ok(states[0].into())
}
fn azure_issue_context(client: &Client, base: &str, username: &str, token: &str, project: &str, number: u64) -> Result<(reqwest::Url, Value, Value), String> {
let mut url = comment_url("azure-devops", base, project, number)?;
url.path_segments_mut().map_err(|_| "Invalid Azure URL.")?.pop();
url.set_query(Some("api-version=7.1"));
let item = read(request(client, reqwest::Method::GET, url.clone(), "azure-devops", username, token)?.send().map_err(|e| e.to_string())?, "azure-devops")?;
let kind = value_string(&item, &["fields", "System.WorkItemType"]);
if kind.is_empty() { return Err("Azure returned no work item type.".into()); }
let mut states_url = reqwest::Url::parse(&normalized_base_url(base)?).map_err(|e| e.to_string())?;
states_url.path_segments_mut().map_err(|_| "Invalid Azure URL.")?.pop_if_empty().extend([project, "_apis", "wit", "workitemtypes", &kind, "states"]);
states_url.set_query(Some("api-version=7.1"));
let states = read(request(client, reqwest::Method::GET, states_url, "azure-devops", username, token)?.send().map_err(|e| e.to_string())?, "azure-devops")?;
Ok((url, item, states))
}
fn azure_state_patch(item: &Value, states: &Value, state: &str) -> Result<Value, String> {
if state.is_empty() || !states["value"].as_array().into_iter().flatten().any(|entry| entry["name"].as_str() == Some(state)) {
return Err("This state is not configured for the work item type.".into());
}
let rev = item["rev"].as_u64().ok_or("Azure returned no revision.")?;
Ok(json!([{"op":"test","path":"/rev","value":rev},{"op":"add","path":"/fields/System.State","value":state}]))
}
fn set_azure_state(client: &Client, url: reqwest::Url, item: &Value, states: &Value, username: &str, token: &str, state: &str) -> Result<String, String> {
let payload = azure_state_patch(item, states, state)?;
if item["fields"]["System.State"] == state { return Ok(state.into()); }
let result = read(request(client, reqwest::Method::PATCH, url, "azure-devops", username, token)?.header("Content-Type", "application/json-patch+json").json(&payload).send().map_err(|e| e.to_string())?, "azure-devops")?;
let actual = value_string(&result, &["fields", "System.State"]);
if actual != state { return Err("Azure did not confirm the requested state.".into()); }
Ok(actual)
}
#[tauri::command]
pub async fn list_azure_issue_states(base_url: String, username: String, token: String, repository: String, number: u64) -> Result<Vec<String>, String> {
tauri::async_runtime::spawn_blocking(move || {
let (_, _, states) = azure_issue_context(&comment_client()?, &base_url, &username, &token, &repository, number)?;
let names: Vec<String> = states["value"].as_array().into_iter().flatten().filter_map(|entry| entry["name"].as_str()).filter(|name| !name.is_empty()).map(str::to_owned).collect();
if names.is_empty() { return Err("Azure returned no work item states.".into()); }
Ok(names)
}).await.map_err(|e| e.to_string())?
}
#[tauri::command]
pub async fn set_azure_issue_state(base_url: String, username: String, token: String, repository: String, number: u64, state: String) -> Result<String, String> {
tauri::async_runtime::spawn_blocking(move || {
let client = comment_client()?;
let (url, item, states) = azure_issue_context(&client, &base_url, &username, &token, &repository, number)?;
set_azure_state(&client, url, &item, &states, &username, &token, &state)
}).await.map_err(|e| e.to_string())?
}
#[tauri::command]
pub async fn close_integration_issue(provider:String,base_url:String,username:String,token:String,repository:String,number:u64) -> Result<String,String> {
tauri::async_runtime::spawn_blocking(move || {
@@ -17,21 +67,9 @@ pub async fn close_integration_issue(provider:String,base_url:String,username:St
let mut url=comment_url(&provider,&base_url,&repository,number)?;
url.path_segments_mut().map_err(|_|"Invalid issue URL.")?.pop();
if provider=="azure-devops" {
url.set_query(Some("api-version=7.1"));
let item=read(request(&client,reqwest::Method::GET,url.clone(),&provider,&username,&token)?.send().map_err(|e|e.to_string())?,&provider)?;
let kind=value_string(&item,&["fields","System.WorkItemType"]);
let mut states_url=reqwest::Url::parse(&normalized_base_url(&base_url)?).map_err(|e|e.to_string())?;
states_url.path_segments_mut().map_err(|_|"Invalid Azure URL.")?.pop_if_empty().extend([&repository,"_apis","wit","workitemtypes",&kind,"states"]);
states_url.set_query(Some("api-version=7.1"));
let states=read(request(&client,reqwest::Method::GET,states_url,&provider,&username,&token)?.send().map_err(|e|e.to_string())?,&provider)?;
let state=completed_state(&states)?;
if item["fields"]["System.State"]==state {return Ok(state);}
let rev=item["rev"].as_u64().ok_or("Azure returned no revision.")?;
let payload=json!([{"op":"test","path":"/rev","value":rev},{"op":"add","path":"/fields/System.State","value":state}]);
let result=read(request(&client,reqwest::Method::PATCH,url,&provider,&username,&token)?.header("Content-Type","application/json-patch+json").json(&payload).send().map_err(|e|e.to_string())?,&provider)?;
let actual=value_string(&result,&["fields","System.State"]);
if actual!=state {return Err("Azure did not confirm the completed state.".into());}
Ok(actual)
let (url, item, states) = azure_issue_context(&client, &base_url, &username, &token, &repository, number)?;
let state = completed_state(&states)?;
set_azure_state(&client, url, &item, &states, &username, &token, &state)
} else {
let gitlab=provider.starts_with("gitlab");
let method=if gitlab {reqwest::Method::PUT}else{reqwest::Method::PATCH};
@@ -45,6 +83,18 @@ pub async fn close_integration_issue(provider:String,base_url:String,username:St
}
#[cfg(test)] mod tests {
use super::*;
#[test] fn state_changes_validate_custom_states_and_guard_revision() {
let item = json!({"rev":17,"fields":{"System.State":"New"}});
let states = json!({"value":[{"name":"Ready for QA"},{"name":"Active"}]});
let patch = azure_state_patch(&item, &states, "Ready for QA").unwrap();
assert_eq!(patch, json!([
{"op":"test","path":"/rev","value":17},
{"op":"add","path":"/fields/System.State","value":"Ready for QA"}
]));
assert!(azure_state_patch(&item, &states, "Closed").is_err());
assert!(azure_state_patch(&item, &states, "").is_err());
assert!(azure_state_patch(&json!({}), &states, "Active").is_err());
}
#[test] fn uses_custom_completed_state_and_rejects_ambiguous_configuration() {
assert_eq!(completed_state(&json!({"value":[{"name":"Review","category":"Resolved"},{"name":"Delivered","category":"Completed"}]})).unwrap(),"Delivered");
assert!(completed_state(&json!({"value":[]})).is_err());
+3 -1
View File
@@ -36,7 +36,7 @@ use git::{
use integrations::{
create_integration_review_request, list_integration_repository_branches,
add_integration_review_comment, get_integration_review_details, list_integration_repositories, list_integration_review_requests, open_in_browser,
run_integration_review_action, list_integration_issues, get_integration_board, list_integration_boards, move_integration_board_card, list_integration_issue_comments, add_integration_issue_comment, close_integration_issue,
run_integration_review_action, list_integration_issues, get_integration_board, list_integration_boards, move_integration_board_card, list_integration_issue_comments, add_integration_issue_comment, close_integration_issue, list_azure_issue_states, set_azure_issue_state,
};
use std::path::{Path, PathBuf};
use std::sync::Mutex;
@@ -449,6 +449,8 @@ async fn main() {
list_integration_issue_comments,
add_integration_issue_comment,
close_integration_issue,
list_azure_issue_states,
set_azure_issue_state,
get_integration_review_details,
add_integration_review_comment,
run_integration_review_action,