Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto Apto para principiantes
#14,940 0 comentarios 0 reacciones 0 asignados Ver en GitHub

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
Tipo de issue
Refactorización
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust, wasm
Área
security

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

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
Lenguaje dominante
Go
Estrellas
181
Forks
53
Merge medio
7 h 27 min
PR fusionados (30 d)
204

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de github/gh-aw-mcpg

Todos los issues de github/gh-aw-mcpg

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.