From 746dd52030f6ed924ff4e53be53753432950951a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 7 Apr 2026 12:51:11 +0000 Subject: [PATCH] fix(rust-guard): replace to_lowercase() with eq_ignore_ascii_case, remove stale dead_code - Replace heap-allocating to_lowercase() + == in is_trusted_first_party_bot with zero-allocation eq_ignore_ascii_case, consistent with username_in_list - Remove six stale #[allow(dead_code)] attributes from lib.rs (invoke_backend, LogLevel, log_debug, log_info, log_warn, log_error are all actively used) Closes #3314 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../rust-guard/src/labels/helpers.rs | 19 +++++++++---------- guards/github-guard/rust-guard/src/lib.rs | 6 ------ 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/guards/github-guard/rust-guard/src/labels/helpers.rs b/guards/github-guard/rust-guard/src/labels/helpers.rs index 9944506a..641ab5aa 100644 --- a/guards/github-guard/rust-guard/src/labels/helpers.rs +++ b/guards/github-guard/rust-guard/src/labels/helpers.rs @@ -1292,16 +1292,15 @@ pub fn commit_integrity( /// - copilot-swe-agent: GitHub Copilot SWE agent (without [bot] suffix) /// - app/copilot-swe-agent: GitHub Copilot SWE agent (with app/ prefix, as returned by gh CLI) pub fn is_trusted_first_party_bot(username: &str) -> bool { - let lower = username.to_lowercase(); - lower == "dependabot[bot]" - || lower == "github-actions[bot]" - || lower == "github-actions" - || lower == "app/github-actions" - || lower == "github-merge-queue[bot]" - || lower == "copilot" - || lower == "copilot-swe-agent[bot]" - || lower == "copilot-swe-agent" - || lower == "app/copilot-swe-agent" + username.eq_ignore_ascii_case("dependabot[bot]") + || username.eq_ignore_ascii_case("github-actions[bot]") + || username.eq_ignore_ascii_case("github-actions") + || username.eq_ignore_ascii_case("app/github-actions") + || username.eq_ignore_ascii_case("github-merge-queue[bot]") + || username.eq_ignore_ascii_case("copilot") + || username.eq_ignore_ascii_case("copilot-swe-agent[bot]") + || username.eq_ignore_ascii_case("copilot-swe-agent") + || username.eq_ignore_ascii_case("app/copilot-swe-agent") } /// Check if a user is in the gateway-configured trusted bot list. diff --git a/guards/github-guard/rust-guard/src/lib.rs b/guards/github-guard/rust-guard/src/lib.rs index 5bd009f3..b6840caf 100644 --- a/guards/github-guard/rust-guard/src/lib.rs +++ b/guards/github-guard/rust-guard/src/lib.rs @@ -96,7 +96,6 @@ unsafe extern "C" fn host_log(_level: u32, _msg_ptr: u32, _msg_len: u32) { /// Call a backend tool and return the result /// This is a helper wrapper around call_backend with logging -#[allow(dead_code)] pub fn invoke_backend( tool_name: &str, args_json: &str, @@ -134,7 +133,6 @@ pub fn invoke_backend( /// Log levels matching the gateway's expectations #[repr(u32)] -#[allow(dead_code)] pub enum LogLevel { Debug = 0, Info = 1, @@ -153,22 +151,18 @@ fn log(level: LogLevel, msg: &str) { } } -#[allow(dead_code)] fn log_debug(msg: &str) { log(LogLevel::Debug, msg); } -#[allow(dead_code)] fn log_info(msg: &str) { log(LogLevel::Info, msg); } -#[allow(dead_code)] fn log_warn(msg: &str) { log(LogLevel::Warn, msg); } -#[allow(dead_code)] fn log_error(msg: &str) { log(LogLevel::Error, msg); }