Reduce error potentials in type label parsing

This commit is contained in:
Rahix 2025-12-09 15:33:57 +01:00
parent b66e8c8d9c
commit 6d6fffcb4a

View file

@ -111,22 +111,18 @@ fn element_from_issue(issue: &forgejo_api::structs::Issue) -> anyhow::Result<cra
let ty_labels: Vec<_> = labels let ty_labels: Vec<_> = labels
.iter() .iter()
.filter_map(|l| l.name.as_deref()) .filter_map(|l| l.name.as_deref())
.filter(|l| l.starts_with("Type/")) .filter_map(|l| l.strip_prefix("Type/"))
.collect(); .collect();
if ty_labels.len() == 0 { let ty = match &ty_labels[..] {
anyhow::bail!("Issue #{issue_number} has no type label!"); [ty] => ty.to_string(),
} [] => {
if ty_labels.len() > 1 { anyhow::bail!("Issue #{issue_number} has no type label!");
anyhow::bail!("Issue #{issue_number} has more than one type label!"); }
} [..] => {
anyhow::bail!("Issue #{issue_number} has more than one type label!");
let ty = ty_labels }
.first() };
.expect("TODO")
.strip_prefix("Type/")
.expect("TODO")
.to_owned();
let has_completed_label = labels let has_completed_label = labels
.iter() .iter()