You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
rust-guard: extract first_matching_label helper and add label-check unit tests (#8047)
`first_matching_approval_label` and `first_matching_refusal_label` were
near-identical — differing only in which `PolicyContext` field they
accessed. Adds a shared private helper and direct unit tests for all
four label-check functions.
## Refactor: extract `first_matching_label`
Replaces the duplicated body in both functions with a single helper that
takes the label list directly:
```rust
fn first_matching_label<'a>(item: &'a Value, label_list: &[String]) -> Option<&'a str> {
if label_list.is_empty() {
return None;
}
extract_github_label_names(item)
.into_iter()
.find(|name| label_list.iter().any(|l| l.eq_ignore_ascii_case(name)))
}
fn first_matching_approval_label<'a>(item: &'a Value, ctx: &PolicyContext) -> Option<&'a str> {
first_matching_label(item, &ctx.approval_labels)
}
fn first_matching_refusal_label<'a>(item: &'a Value, ctx: &PolicyContext) -> Option<&'a str> {
first_matching_label(item, &ctx.refusal_labels)
}
```
## Tests: direct unit tests for label-check helpers in `helpers.rs`
Adds 10 tests covering `has_approval_label`, `has_refusal_label`,
`has_promotion_label`, and `has_demotion_label`:
- Case-insensitive matching
- Empty list / empty string → feature disabled (`false`)
- Missing `labels` field on the item → `false`
0 commit comments