Commit 6b4e51d
authored
[Repo Assist] refactor(rust-guard): extract is_any_trusted_actor helper and collapse URL fallback loop (#4260)
🤖 *This is an automated pull request from Repo Assist.*
Closes #4252
## Root Cause
Two minor duplication issues in
`guards/github-guard/rust-guard/src/labels/`:
1. The three-predicate trust check `is_trusted_first_party_bot(x) ||
is_configured_trusted_bot(x, ctx) || is_trusted_user(x, ctx)` was
copy-pasted verbatim at **three call sites** (`helpers.rs:1282–1284`,
`helpers.rs:1479–1481`, `tool_rules.rs:98–100`). Adding a fourth trust
tier would require three matching edits.
2. `extract_repo_from_item` had three structurally identical `if let`
blocks differing only in the JSON field name (`repository_url`,
`html_url`, `url`). The same for-loop idiom is already used in
`extract_number_from_url` in the same file.
## Fix
**`helpers.rs`**
- Added `is_any_trusted_actor(username, ctx)` — a single helper that
combines the three predicates with a docstring explaining its semantics.
- Replaced both call sites in `helpers.rs` with one-liner
`is_any_trusted_actor` calls.
- Collapsed the three repeated `if let` URL-field blocks in
`extract_repo_from_item` into a `for field in &[...]` loop (same pattern
as `extract_number_from_url`).
**`tool_rules.rs`**
- Replaced the third call site with `is_any_trusted_actor`.
- Updated the import to use `is_any_trusted_actor` instead of the three
individual functions.
## Trade-offs
- Purely mechanical refactor; zero semantic change.
- `is_any_trusted_actor` is `pub(crate)` — callable within the crate but
not exported.
## Test Status
- ✅ `cargo build` — compiles without warnings
- ✅ `cargo test` — **317 / 317 tests pass**
- 2 files changed
Lines changed: 35 additions & 33 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
940 | 940 | | |
941 | 941 | | |
942 | 942 | | |
943 | | - | |
| 943 | + | |
| 944 | + | |
944 | 945 | | |
945 | 946 | | |
946 | 947 | | |
| |||
973 | 974 | | |
974 | 975 | | |
975 | 976 | | |
976 | | - | |
977 | | - | |
978 | | - | |
979 | | - | |
980 | | - | |
981 | | - | |
982 | | - | |
983 | | - | |
984 | | - | |
985 | | - | |
986 | | - | |
987 | | - | |
988 | | - | |
989 | | - | |
990 | | - | |
991 | | - | |
992 | | - | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
993 | 983 | | |
994 | 984 | | |
995 | 985 | | |
| |||
1278 | 1268 | | |
1279 | 1269 | | |
1280 | 1270 | | |
1281 | | - | |
1282 | | - | |
1283 | | - | |
1284 | | - | |
1285 | | - | |
| 1271 | + | |
1286 | 1272 | | |
1287 | 1273 | | |
1288 | 1274 | | |
| |||
1476 | 1462 | | |
1477 | 1463 | | |
1478 | 1464 | | |
1479 | | - | |
1480 | | - | |
1481 | | - | |
1482 | | - | |
| 1465 | + | |
1483 | 1466 | | |
1484 | 1467 | | |
1485 | 1468 | | |
| |||
1772 | 1755 | | |
1773 | 1756 | | |
1774 | 1757 | | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
1775 | 1766 | | |
1776 | 1767 | | |
1777 | 1768 | | |
| |||
1781 | 1772 | | |
1782 | 1773 | | |
1783 | 1774 | | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
1784 | 1789 | | |
1785 | 1790 | | |
1786 | 1791 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
| 13 | + | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
| 98 | + | |
102 | 99 | | |
103 | 100 | | |
104 | 101 | | |
| |||
0 commit comments