Skip to content

Commit 944c935

Browse files
Copilotlpcox
andauthored
Fix: remove #[cfg(test)] from has_promotion/demotion_label; eliminate duplicate logic
Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/c19d9291-dcb0-41e7-9ecb-1ba67bde60ee Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
1 parent d893732 commit 944c935

2 files changed

Lines changed: 3 additions & 22 deletions

File tree

guards/github-guard/rust-guard/src/labels/helpers.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,6 @@ fn apply_approval_label_promotion(
367367

368368
/// Check whether a content item carries the configured built-in promotion label
369369
/// (case-insensitive). Returns `false` when `promotion_label` is empty (feature disabled).
370-
#[cfg(test)]
371370
pub fn has_promotion_label(item: &Value, ctx: &PolicyContext) -> bool {
372371
if ctx.promotion_label.is_empty() {
373372
return false;
@@ -380,7 +379,6 @@ pub fn has_promotion_label(item: &Value, ctx: &PolicyContext) -> bool {
380379

381380
/// Check whether a content item carries the configured built-in demotion label
382381
/// (case-insensitive). Returns `false` when `demotion_label` is empty (feature disabled).
383-
#[cfg(test)]
384382
pub fn has_demotion_label(item: &Value, ctx: &PolicyContext) -> bool {
385383
if ctx.demotion_label.is_empty() {
386384
return false;
@@ -400,14 +398,7 @@ fn apply_promotion_label_promotion(
400398
integrity: Vec<String>,
401399
ctx: &PolicyContext,
402400
) -> Vec<String> {
403-
if ctx.promotion_label.is_empty() {
404-
return integrity;
405-
}
406-
let label_names = extract_github_label_names(item);
407-
if label_names
408-
.iter()
409-
.any(|name| ctx.promotion_label.eq_ignore_ascii_case(name))
410-
{
401+
if has_promotion_label(item, ctx) {
411402
let number = item.get(field_names::NUMBER).and_then(|v| v.as_u64()).unwrap_or(0);
412403
crate::log_info(&format!(
413404
"[integrity] {}:{}#{} promoted to approved (built-in promotion-label '{}')",
@@ -429,14 +420,7 @@ fn apply_demotion_label_demotion(
429420
integrity: Vec<String>,
430421
ctx: &PolicyContext,
431422
) -> Vec<String> {
432-
if ctx.demotion_label.is_empty() {
433-
return integrity;
434-
}
435-
let label_names = extract_github_label_names(item);
436-
if label_names
437-
.iter()
438-
.any(|name| ctx.demotion_label.eq_ignore_ascii_case(name))
439-
{
423+
if has_demotion_label(item, ctx) {
440424
let number = item.get(field_names::NUMBER).and_then(|v| v.as_u64()).unwrap_or(0);
441425
crate::log_info(&format!(
442426
"[integrity] {}:{}#{} demoted to none (built-in demotion-label '{}')",

guards/github-guard/rust-guard/src/labels/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ pub use helpers::{
5050
};
5151
#[cfg(test)]
5252
pub use helpers::has_approval_label;
53-
#[cfg(test)]
54-
pub use helpers::has_demotion_label;
55-
#[cfg(test)]
56-
pub use helpers::has_promotion_label;
53+
pub use helpers::{has_demotion_label, has_promotion_label};
5754
#[cfg(test)]
5855
pub use helpers::secret_label;
5956

0 commit comments

Comments
 (0)