Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions scripts/lint_notification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Format sphinx-lint diagnostics for the translation team's Telegram alert."""

import os
import re
import subprocess
import sys
from pathlib import Path
from urllib.parse import quote


def main(log, output):
repo = os.environ["PYDOC_REPO"].rstrip("/")
run = os.environ["GITHUB_RUN_ID"]
version = os.environ["PYDOC_VERSION"]
checkout = Path("cpython/Doc/locales") / os.environ["PYDOC_LANGUAGE"] / "LC_MESSAGES"
revision = subprocess.check_output(
["git", "-C", str(checkout), "rev-parse", "HEAD"], universal_newlines=True
).strip()
header = f"❌ *{version} lint* ([execução {run}]({repo}/actions/runs/{run}))"
footer = "Mais diagnósticos no log da execução."
message = header
found = False
for line in sorted(set(log.read_text(encoding="utf-8").splitlines())):
match = re.fullmatch(r"(.+?\.po):(\d+):\s+(.+\(.*\))", line)
if not match:
continue
found = True
filename, lineno, diagnostic = match.groups()
path = Path(filename)
if path.is_absolute():
path = path.relative_to(checkout.resolve())
url = f"{repo}/blob/{revision}/{quote(path.as_posix())}#L{lineno}"
detail = f"{path}:{lineno}: {diagnostic}".replace("`", "\\`")
block = f"\n\n```\n{detail}\n```\n[Abrir linha {lineno}]({url})"
# Count the unparsed text conservatively, including Markdown and emoji.
if len((message + block + "\n\n" + footer).encode("utf-16-le")) // 2 > 4096:
message += "\n\n" + footer
break
message += block
if not found:
sys.exit("No sphinx-lint diagnostics found")
output.write_text(message, encoding="utf-8")


if __name__ == "__main__":
main(Path(sys.argv[1]), Path(sys.argv[2]))
10 changes: 4 additions & 6 deletions scripts/prepmsg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@ URL="${PYDOC_REPO}/actions/runs/${GITHUB_RUN_ID}"
input="$1"
output="$2"

if [[ "${GITHUB_JOB}" == "lint" ]]; then
exec python3 "$(dirname "$0")/lint_notification.py" "$input" "$output"
fi

touch aux
if [[ "${GITHUB_JOB}" == "build" ]]; then
grep 'cpython/Doc/.*WARNING:' "$input" | \
sed 's|.*/cpython/Doc/||' | \
uniq | \
sed 's|^|```\n|;s|$|\n```\n|' \
> aux
elif [[ "${GITHUB_JOB}" == "lint" ]]; then
grep -P '^.*\.po:\d+:\s+.*\(.*\)$' "$input" | \
sed 's|.*/cpython/Doc/||' | \
sort -u | \
sed 's|^|```\n|;s|$|\n```\n|' \
> aux
else
die "Unexpected job name ${GITHUB_JOB}"
fi
Expand Down