[rust-guard] Collapse duplicated label promotion/demotion helpers
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 64/100
Línea de trabajo
Empieza en guards/github-guard/rust-guard/src/labels/helpers.rs en las cuatro funciones apply_label y en los auxiliares has_promotion_label/has_demotion_label, luego revisa los re-exports en labels/mod.rs. Introduce los dos auxiliares compartidos promote/demote manteniendo las cadenas de log byte a byte idénticas. Está terminado cuando cargo test pasa sin cambios, la compilación wasm32-wasip1 tiene éxito y los auxiliares son pub(crate) si solo se usan internamente.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
🦀 Rust Guard Improvement Report
Improvement 1: Collapse four near-identical label promotion/demotion functions
Category: Duplication
File(s): guards/github-guard/rust-guard/src/labels/helpers.rs
Effort: Small (< 15 min)
Risk: Low
Problem
apply_approval_label_promotion (~L488), apply_refusal_label_demotion (~L512), apply_promotion_label_promotion (~L565) and apply_demotion_label_demotion (~L593) share the same skeleton: detect a label, log [integrity] {type}:{repo}#{n} promoted/demoted ..., then max_integrity(.., writer_integrity) or cap_integrity(.., none_integrity), else return integrity unchanged. Only the matched label, the log suffix and the direction differ. Any change to the logging format or semantics must be made four times.
Suggested Change
Introduce two small direction helpers and have the four functions delegate to them.
Before
fn apply_demotion_label_demotion(item, resource_type, repo_full_name, integrity, ctx) -> Vec<String> {
if has_demotion_label(item, ctx) {
let number = item_number(item);
crate::log_info(&format!("[integrity] {}:{}#{} demoted to none (built-in demotion-label '{}')", ...));
cap_integrity(repo_full_name, &integrity, &none_integrity(repo_full_name, ctx), ctx)
} else { integrity }
}
// ...same shape x3
After
fn promote_to_writer(item: &Value, rt: &str, repo: &str, integrity: Vec<String>, ctx: &PolicyContext, reason: &str) -> Vec<String> {
crate::log_info(&format!("[integrity] {rt}:{repo}#{} promoted to approved ({reason})", item_number(item)));
max_integrity(repo, &integrity, &writer_integrity(repo, ctx), ctx)
}
fn demote_to_none(item: &Value, rt: &str, repo: &str, integrity: Vec<String>, ctx: &PolicyContext, reason: &str) -> Vec<String> {
crate::log_info(&format!("[integrity] {rt}:{repo}#{} demoted to none ({reason})", item_number(item)));
cap_integrity(repo, &integrity, &none_integrity(repo, ctx), ctx)
}
fn apply_demotion_label_demotion(item: &Value, rt: &str, repo: &str, integrity: Vec<String>, ctx: &PolicyContext) -> Vec<String> {
if has_demotion_label(item, ctx) {
demote_to_none(item, rt, repo, integrity, ctx, &format!("built-in demotion-label '{}'", ctx.demotion_label))
} else { integrity }
}
Log messages stay byte-identical, so behavior and existing tests are unchanged.
Why This Matters
Removes ~40 lines of duplicated logic and keeps precedence/logging semantics in one place.
Improvement 2: Downscope has_promotion_label / has_demotion_label
Category: API Surface
File(s): labels/helpers.rs (L554, L560)
Effort: Small (< 15 min)
Risk: Low
Problem
Both are pub but are only called inside helpers.rs and from sibling-module tests (re-exported in labels/mod.rs L58). Neighbouring helpers were already downscoped to pub(crate) in earlier runs.
Suggested Change
pub(crate) fn has_promotion_label(...)
pub(crate) fn has_demotion_label(...)
Verify with cargo build --target wasm32-wasip1 and cargo test.
Codebase Health Summary
- Total Rust files: 10
- Total lines: ~23,200
- Areas analyzed: helpers.rs, labels/mod.rs, lib.rs, constants usage, dead-code/unwrap scan (no production
unwrap()orallow(dead_code)found) - Areas with little left: string-literal constants (heavily mined in prior runs)
Generated by Rust Guard Improver • Run: 38711785474
Generated by Rust Guard Improver · copilot · auto · 27.4 AIC · ⊞ 11.4K · ◷
- expires on Oct 22, 2026, 9:20 AM UTC
- Lenguaje dominante
- Go
- Estrellas
- 181
- Forks
- 53
- Merge medio
- 7 h 27 min
- PR fusionados (30 d)
- 204
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Incluye un Dockerfile o un archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de github/gh-aw-mcpg
-
automation mcp-gateway test
Dificultad 2/5 1-3 horas Aptitud para principiantes 8/100
github/gh-aw-mcpg#14956 ·
Los mantenedores suelen responder en 1 día
-
agentic-workflows
Dificultad 4/5 3-5 días Aptitud para principiantes 15/100
github/gh-aw-mcpg#14953 ·
Los mantenedores suelen responder en 1 día
-
Smoke Copilot - Issue GroupAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 5/100
github/gh-aw-mcpg#14943 ·
Los mantenedores suelen responder en 1 día
-
agentic-workflows
Dificultad 4/5 1-2 días Aptitud para principiantes 14/100
github/gh-aw-mcpg#14939 ·
Los mantenedores suelen responder en 1 día
-
automation integrity-audit
Dificultad 3/5 Medio día Aptitud para principiantes 15/100
github/gh-aw-mcpg#14937 ·
Los mantenedores suelen responder en 1 día
Todos los issues de github/gh-aw-mcpg
Issues similares
-
documentation hacktoberfest priority: low skill: good first issue status: ready for dev
Dificultad 2/5 Medio día Aptitud para principiantes 85/100
hyperledger-labs/fabric-smart-client#2142 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
numberly/vault-db-injector#107 ·
Los mantenedores suelen responder en 1 día
-
area/import kind/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
[DOC] Wrong sg_egress_ports range in the Terraform Databricks Guide for AWS Hub & Spoke with Network FirewallPosiblemente ocupada @akhil9tiet la tomó hoy. Abiertodocs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
databricks/terraform-provider-databricks#6080 · 1 comentario ·
Los mantenedores suelen responder en 3 días
-
kind/documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
kubernetes-sigs/dra-driver-nvidia-gpu#1569 ·
Los mantenedores suelen responder en 1 día