[rust-guard] Collapse duplicated label promotion/demotion helpers
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 64/100
Direzione di ricerca
Inizia in guards/github-guard/rust-guard/src/labels/helpers.rs dalle quattro funzioni apply_label e dagli helper has_promotion_label/has_demotion_label, poi controlla i re-export in labels/mod.rs. Introduci i due helper condivisi promote/demote mantenendo le stringhe di log identiche byte per byte. È completato quando cargo test passa senza modifiche, la build wasm32-wasip1 ha successo e gli helper sono pub(crate) se usati solo internamente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
🦀 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
- Lingua principale
- Go
- Stelle
- 181
- Fork
- 53
- Merge medio
- 7h 8m
- PR unite (30g)
- 215
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di github/gh-aw-mcpg
-
automation mcp-gateway test
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 8/100
github/gh-aw-mcpg#15068 ·
I maintainer di solito rispondono entro 1 giorno
-
Support per-server custom CA certificates for HTTP MCP upstreamsForse già presa @lpcox l’ha presa oggi. Apertaenhancement from-gh-aw
github/gh-aw-mcpg#15065 · 1 reazione · 2 assegnatari ·
I maintainer di solito rispondono entro 1 giorno
-
Smoke Copilot - Issue GroupAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 5/100
github/gh-aw-mcpg#15055 ·
I maintainer di solito rispondono entro 1 giorno
-
Verify hashes for the Serena package installationForse già presa @lpcox l’ha presa 1 giorno fa. Aperta
github/gh-aw-mcpg#14993 · 1 reazione · 2 assegnatari ·
I maintainer di solito rispondono entro 1 giorno
-
automation repo-assist
Difficoltà 5/5 Più di una settimana Idoneità per principianti 15/100
github/gh-aw-mcpg#14238 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di github/gh-aw-mcpg
Issue simili
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:session-state issue-rating: 🦞 diamond lobster no-stale P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
openclaw/wacli#503 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 81/100
apache/rocketmq-dashboard#6895 ·
I maintainer di solito rispondono entro 3 giorni
-
agent-butler-finding chore
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
jordansmall/spindrift#5466 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
open-telemetry/opentelemetry-go-compile-instrumentation#1507 ·
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 87/100
777genius/agent-notifications#490 ·
I maintainer di solito rispondono entro 1 giorno