Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[rust-guard] Collapse duplicated label promotion/demotion helpers

Chiusa Adatta ai principianti
#14,940 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

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
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust, wasm
Ambito
security

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

refactor rust-guard

🦀 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() or allow(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

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di github/gh-aw-mcpg

Tutte le issue di github/gh-aw-mcpg

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.