feat: clear unneccessary backend from kanban
runner nix smoke / nix label and flake smoke (push) Failing after 35s

This commit is contained in:
2026-09-28 00:24:44 +00:00
parent 0cbf267474
commit 54eb69d1c7
7 changed files with 84 additions and 427 deletions
-94
View File
@@ -1,13 +1,5 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
pub struct Label {
pub id: u64,
pub name: String,
#[serde(default)]
pub color: String,
}
#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
pub struct Issue {
pub id: u64,
@@ -15,8 +7,6 @@ pub struct Issue {
pub title: String,
#[serde(default)]
pub body: Option<String>,
#[serde(default)]
pub labels: Vec<Label>,
}
#[derive(Debug, Serialize, PartialEq, Eq)]
@@ -35,7 +25,6 @@ pub struct EditIssuePayload {
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ColumnSpec {
pub id: u64,
pub label: Option<Label>,
pub title: String,
}
@@ -64,93 +53,10 @@ pub struct MoveProjectIssuePayload {
pub sorting: Option<u64>,
}
#[derive(Debug, Serialize, PartialEq, Eq)]
pub struct ReplaceLabelsPayload {
pub labels: Vec<u64>,
}
pub fn extract_columns(labels: &[Label], prefix: &str) -> Vec<ColumnSpec> {
let mut columns: Vec<ColumnSpec> = labels
.iter()
.filter_map(|label| {
let title = label.name.strip_prefix(prefix)?;
if title.is_empty() {
None
} else {
Some(ColumnSpec {
id: label.id,
label: Some(label.clone()),
title: title.to_owned(),
})
}
})
.collect();
columns.sort_by(|left, right| left.title.cmp(&right.title));
columns
}
pub fn replacement_payload(
issue: &Issue,
column_prefix: &str,
target_label_id: u64,
) -> ReplaceLabelsPayload {
let mut labels: Vec<u64> = issue
.labels
.iter()
.filter(|label| !label.name.starts_with(column_prefix))
.map(|label| label.id)
.collect();
labels.push(target_label_id);
ReplaceLabelsPayload { labels }
}
#[cfg(test)]
mod tests {
use super::*;
fn label(id: u64, name: &str) -> Label {
Label {
id,
name: name.to_owned(),
color: String::new(),
}
}
#[test]
fn extracts_prefixed_columns_in_lexical_order() {
let labels = vec![
label(1, "bug"),
label(3, "kanban/Doing"),
label(2, "kanban/Todo"),
label(4, "kanban/"),
];
let columns = extract_columns(&labels, "kanban/");
assert_eq!(columns.len(), 2);
assert_eq!(columns[0].title, "Doing");
assert_eq!(columns[1].label.as_ref().expect("label").id, 2);
}
#[test]
fn replacement_removes_columns_and_preserves_other_labels() {
let issue = Issue {
id: 70,
number: 7,
title: "Fix it".to_owned(),
body: None,
labels: vec![label(1, "bug"), label(2, "kanban/Todo"), label(3, "urgent")],
};
let payload = replacement_payload(&issue, "kanban/", 9);
assert_eq!(payload.labels, vec![1, 3, 9]);
assert_eq!(
serde_json::to_value(payload).expect("serialize payload"),
serde_json::json!({"labels": [1, 3, 9]})
);
}
#[test]
fn deserializes_native_project_data_and_move_payload() {
let project: Project = serde_json::from_value(serde_json::json!({