Push to default branch attributes coverage to an unrelated fork PR with a same-named head branch
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 74/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Tranquilo
- Área
- ci-cd, testing-qa
Línea de trabajo
Empieza en la ruta de push de action.yml e inspecciona en upload_coverage.py la precedencia entre pull_request_number y ref. Reproduce el problema con un PR abierto de un fork cuyo head branch coincide con la rama a la que se ha hecho push y verifica que la búsqueda ya no seleccione ese fork. Se considera terminado cuando el push siga atribuyéndose a su rama y se registre la línea base de cobertura de la rama predeterminada.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Summary
On push events, the action associates an open PR via gh pr list --head "${{ github.ref_name }}". That matches by head-branch name across all repositories, so an open cross-repo (fork) PR whose head branch happens to be named the same as the pushed branch gets selected. Since upload_coverage.py prefers pull_request_number over ref, the push's coverage is filed under that unrelated PR instead of the branch, and the branch baseline is never recorded.
Impact
This reliably breaks the default branch baseline: if any contributor has an open PR from their fork's main branch (head branch main), every push to your main is attributed to that PR. The default-branch coverage never populates, so every other PR's coverage comment shows "Coverage data for the main branch is not yet available."
Root cause
action.yml (push path):
else
COMMIT_OID="${{ github.sha }}"
REF="${{ github.ref }}"
PR_NUMBER=$(gh pr list \
--repo "$GITHUB_REPOSITORY" \
--head "${{ github.ref_name }}" \ # not scoped to the base repo's own head branches
--state open \
--json number \
--jq '.[0].number // empty' 2>/dev/null || true)
fi
--repo only selects which repository's PR list to query; a fork PR is still part of that list (it targets the base repo, only its head branch lives in the fork). --head <branch> matches the head-branch name regardless of where the head lives, so a fork PR with head branch <branch> is returned. Then upload_coverage.py:
if pr_number:
payload["pull_request_number"] = int(pr_number)
elif ref:
payload["ref"] = ref
pull_request_number wins, so the ref (the branch) is dropped from the payload.
Reproduction
- The repo has an open PR from a fork whose head branch is named
main(headsomeuser:main→you:main). - A push to
main(the default branch) triggers the upload. - The action log shows:
Upload parameters
commit_oid: <sha>
ref: refs/heads/main
pr_number: <the unrelated fork PR number>
Coverage report uploaded successfully.
- Coverage is attributed to that PR; the
mainbaseline stays empty and PRs report "Coverage data for themainbranch is not yet available."
Confirmed that gh pr list --repo OWNER/REPO --head main --state open returns the fork PR (isCrossRepository: true), so the existing --repo argument does not prevent this.
Suggested fix
Scope the PR lookup to head branches in the base repository itself, so fork PRs aren't matched:
COMMIT_OID="${{ github.sha }}"
REF="${{ github.ref }}"
+ REPO_OWNER="${GITHUB_REPOSITORY%%/*}"
+ REPO_NAME="${GITHUB_REPOSITORY#*/}"
PR_NUMBER=$(gh pr list \
--repo "$GITHUB_REPOSITORY" \
--head "${{ github.ref_name }}" \
--state open \
- --json number \
- --jq '.[0].number // empty' 2>/dev/null || true)
+ --json number,headRepositoryOwner,headRepository \
+ --jq "[.[] | select(.headRepositoryOwner.login == \"$REPO_OWNER\" and .headRepository.name == \"$REPO_NAME\")] | .[0].number // empty" 2>/dev/null || true)
Alternatives: skip PR association entirely when the pushed ref is the default branch, or prefer ref over pull_request_number for push events.
Drafted by Claude (Anthropic AI assistant).
- Lenguaje dominante
- Python
- Estrellas
- 99
- Forks
- 20
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
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 actions/upload-code-coverage
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
actions/upload-code-coverage#18 · 1 comentario ·
-
Enable immutable releases Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 20/100
-
Please add a LICENSE file Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 45/100
actions/upload-code-coverage#20 · 1 comentario · 3 reacciones ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 58/100
actions/upload-code-coverage#16 · 2 comentarios · 5 reacciones ·
Todos los issues de actions/upload-code-coverage
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100