#!/usr/bin/env python3
"""Read the review comments on a Tangled pull (top-level discussion comments).
WHY: the appview has no read API for pull comments, and eyeballing the pull page
HTML per comment is slow. This fetches the pull (or a specific round) and prints
every top-level comment as author / time / body — so acting on operator review
notes is one command, not a WebFetch guess.
Same session-cookie auth as tangled_pr.py (cookie from the encrypted store,
tangled.cookie). Read-only: it never posts.
USAGE:
tangled_comments.py --owner notplants-bot.bsky.social --repo lichen.page.review --pull 75
tangled_comments.py ... --pull 75 --round 2 # a specific round's page
tangled_comments.py ... --pull 75 --json # machine-readable
"""
import argparse, html, json, os, re, sys, urllib.request
BASE = "https://tangled.org"
def load_cookie():
"""Cookie from the encrypted store (tangled.cookie) — see engine/README.md (Secrets)."""
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import secrets as _store
c = _store.get("tangled.cookie")
if not c:
sys.exit("no tangled.cookie in the secret store — add it with: sops /secrets/store.yaml")
return c
def fetch(url, cookie):
req = urllib.request.Request(url, headers={"Cookie": cookie, "User-Agent": "tangled-pr-bot"})
return urllib.request.urlopen(req, timeout=60).read().decode()
def _text(fragment):
"""Strip tags from a body fragment down to readable plaintext."""
t = re.sub(r"(?is)
", "\n", fragment)
t = re.sub(r"(?is)