Skip to content

Traduccion array

Traduccion array #1094

Workflow file for this run

name: Agrega comentario a PR
on:
pull_request_target:
permissions:
contents: read
pull-requests: read
jobs:
define-comment:
name: Entradas sin traducción
runs-on: ubuntu-22.04
outputs:
any_changed: ${{ steps.changed-files.outputs.any_changed }}
comment: ${{ steps.create-pr-comment.outputs.comment }}
steps:
# Obtener únicamente los archivos del repositorio original
- uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.base.sha }}
path: base-branch
persist-credentials: false
- name: Preparar Python v3.13
uses: actions/setup-python@v7
with:
python-version: "3.13"
cache: "pip"
cache-dependency-path: base-branch/requirements-own.txt
# Obtener los archivos .po modificados mediante la API
- name: Obtiene lista de archivos con cambios
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
with:
files: |
**/*.po
- name: Instalar dependencias
if: steps.changed-files.outputs.any_changed == 'true'
run: |
python -m pip install -r base-branch/requirements-own.txt
# Descargar los archivos modificados como datos, sin ejecutar su código
- name: Descargar archivos PO de la Pull Request
if: steps.changed-files.outputs.any_changed == 'true'
env:
GH_TOKEN: ${{ github.token }}
GH_REPOSITORY: ${{ github.repository }}
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
CHANGED_PO_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
python - <<'PY'
import base64
import json
import os
import pathlib
import urllib.parse
import urllib.request
repository = os.environ["GH_REPOSITORY"]
commit = os.environ["PR_HEAD_SHA"]
token = os.environ["GH_TOKEN"]
files = os.environ["CHANGED_PO_FILES"].splitlines()
api_url = os.environ["GITHUB_API_URL"]
for filename in files:
path = pathlib.PurePosixPath(filename)
if path.is_absolute() or ".." in path.parts:
raise ValueError(f"Ruta no permitida: {filename}")
if path.suffix != ".po":
raise ValueError(f"Archivo no permitido: {filename}")
url = (
f"{api_url}/repos/{repository}/contents/"
f"{urllib.parse.quote(filename, safe='/')}"
f"?ref={commit}"
)
request = urllib.request.Request(
url,
headers={
"Authorization": f"Bearer {token}",
"Accept": "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28",
},
)
with urllib.request.urlopen(request) as response:
data = json.loads(response.read())
if data.get("encoding") != "base64":
raise ValueError(f"Formato inesperado: {filename}")
destination = pathlib.Path("pr-files") / filename
destination.parent.mkdir(parents=True, exist_ok=True)
destination.write_bytes(
base64.b64decode(data["content"])
)
PY
- name: Calcular entradas faltantes
if: steps.changed-files.outputs.any_changed == 'true'
id: create-pr-comment
env:
CHANGED_PO_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
cd pr-files
mapfile -t PO_FILES <<< "$CHANGED_PO_FILES"
{
echo 'comment<<EOF'
python ../base-branch/scripts/list_missing_entries.py --github-mode "${PO_FILES[@]}"
echo EOF
} >> "$GITHUB_OUTPUT"
write-comment:
runs-on: ubuntu-22.04
needs: [define-comment]
if: needs.define-comment.outputs.any_changed == 'true'
permissions:
issues: write
pull-requests: write
steps:
- name: Agregar comentario con entradas faltantes
uses: thollander/actions-comment-pull-request@v3
with:
message: ${{ needs.define-comment.outputs.comment }}
comment-tag: missing-entries