:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(review-hog): trigger reviews via pull_request_target (#71349)
Alex Lebedevb92384cd8e15
diff --git a/.github/workflows/review-hog.yml b/.github/workflows/review-hog.ymlindex 57a7dbdf3a4b..e1b052925841 100644--- a/.github/workflows/review-hog.yml+++ b/.github/workflows/review-hog.yml@@ -9,16 +9,19 @@# here — the only secret is the shared trigger token. Publishing happens server-side via the PostHog# GitHub App installation token.#-# Safety: `pull_request` (not `pull_request_target`) means fork PRs receive no secrets, so they cannot-# trigger; the `if:` also hard-gates forks; and applying the label needs write access.+# Safety: `pull_request_target` always runs the base branch's version of this file, so a PR cannot+# edit its own trigger, and it fires even when the PR has merge conflicts. It does expose secrets to+# fork PRs, so the `if:` hard-gates forks — safe because this job never checks out or runs PR code.name: ReviewHog+# Sanctioned use — no job checks out or runs PR code; see the Safety note above.+# nosemgrep: github-actions-pull-request-targeton:- pull_request:+ pull_request_target:types: [labeled]-# No GitHub permissions needed — the job only makes an outbound authenticated request; the review is-# fetched and published server-side via the PostHog GitHub App installation token.+# No GitHub permissions by default — the trigger job only makes an outbound authenticated request;+# the review is fetched and published server-side via the PostHog GitHub App installation token.permissions: {}concurrency:@@ -45,7 +48,7 @@ jobs:PR_NUMBER: ${{ github.event.pull_request.number }}run: |if [ -z "$REVIEWHOG_TRIGGER_TOKEN" ]; then- echo "::error::REVIEWHOG_TRIGGER_TOKEN secret is not set (or unavailable on a fork PR)." >&2+ echo "::error::REVIEWHOG_TRIGGER_TOKEN secret is not set." >&2exit 1fipayload="$(jq -n --arg repo "$REPO" --argjson pr "$PR_NUMBER" '{repo: $repo, pr_number: $pr}')"@@ -57,3 +60,27 @@ jobs:-H "Authorization: Bearer $REVIEWHOG_TRIGGER_TOKEN" \-H "Content-Type: application/json" \-d "$payload"++ # The trigger job skips bot-applied labels silently; explain why and strip the label so a+ # human can re-add it deliberately.+ bot-labeler-skip:+ name: Explain skipped bot label+ runs-on: ubuntu-latest+ timeout-minutes: 5+ permissions:+ issues: write+ if: >-+ github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name+ && github.event.sender.type == 'Bot'+ && github.event.label.name == 'reviewhog'+ steps:+ - name: Comment and strip label+ env:+ GH_TOKEN: ${{ github.token }}+ REPO: ${{ github.repository }}+ PR_NUMBER: ${{ github.event.pull_request.number }}+ run: |+ set -euo pipefail+ gh api -X POST "repos/$REPO/issues/$PR_NUMBER/comments" \+ -f body="ReviewHog reviews start only when a human adds the \`reviewhog\` label, so this bot-applied label was removed. Re-add it yourself to start a review."+ gh api -X DELETE "repos/$REPO/issues/$PR_NUMBER/labels/reviewhog"diff --git a/products/review_hog/ARCHITECTURE.md b/products/review_hog/ARCHITECTURE.mdindex e516ee27cc7d..3c39adcc4b35 100644--- a/products/review_hog/ARCHITECTURE.md+++ b/products/review_hog/ARCHITECTURE.md@@ -2157,12 +2157,16 @@ github-actions[bot] trick), and its Action carries **one** secret (no Anthropicthe review is **pinned to the reviewed `head_sha`** via `commit=repo_obj.get_commit(head_sha)`. Fork rejection isauthoritative in the **fetch activity** (`PRMetadata.is_fork`, non-retryable `ApplicationError` before the reportrow is created).-4. ✅ **The Action:** `.github/workflows/review-hog.yml` — `on: pull_request [labeled]`,+4. ✅ **The Action:** `.github/workflows/review-hog.yml` — `on: pull_request_target [labeled]`,`permissions: {}`, per-PR concurrency, `if:` gates (human-applied label + non-fork; any author — unmapped authors- resolve via the acting-user fallback), one `curl` with the bearer secret. `pull_request` (not- `pull_request_target`) ⇒ forks get no secret ⇒ can't trigger.+ resolve via the acting-user fallback), one `curl` with the bearer secret. `pull_request_target` runs the base+ branch's version of the file (a PR can't edit its own trigger) and fires even on conflicted PRs; it exposes+ secrets to fork PRs, so the non-fork `if:` gate is the fork barrier — safe because the job never runs PR code.+ Residual gap: stacked PRs whose base branch predates this file still dispatch nothing (no workflow on the base).+ A paired `bot-labeler-skip` job (Stamphog's pattern) turns the bot-labeler skip into feedback: it comments why+ and strips the label so a human can re-add it.**2026-07-14 update:** `synchronize` dropped (ADR 0002) — pushes no longer re-trigger; re-review = re-add the- label (or mark an already-labeled draft ready).+ label.5. ⏳ **Later (v2):** label lifecycle (strip-on-non-approval / keep-on-error / dismiss-stale-on-push). (`synchronize` /`ready_for_review` events are already wired in step 4.) Then **Stage 5b** (iterate-on-same-PR validation).diff --git a/products/review_hog/backend/reviewer/status_comment.py b/products/review_hog/backend/reviewer/status_comment.pyindex 25a40f2acd34..febf66f1bfe3 100644--- a/products/review_hog/backend/reviewer/status_comment.py+++ b/products/review_hog/backend/reviewer/status_comment.py@@ -175,6 +175,10 @@ def _find_marker_comment(installation_id=installation_id,endpoint="/repos/{owner}/{repo}/issues/{issue_number}/comments",):+ # Adopt only app-bot comments: anyone can paste the marker on a public repo, and the+ # returned id gets PATCHed — matching a stranger's comment would overwrite it.+ if (comment.get("user") or {}).get("type") != "Bot":+ continueif marker in (comment.get("body") or ""):return comment.get("id")return Nonediff --git a/products/review_hog/backend/tests/test_status_comment.py b/products/review_hog/backend/tests/test_status_comment.pyindex ca38c00695fe..7ca46cd1ec9a 100644--- a/products/review_hog/backend/tests/test_status_comment.py+++ b/products/review_hog/backend/tests/test_status_comment.py@@ -201,13 +201,16 @@ class TestEnsureStatusComment(BaseTest):self, mock_request: MagicMock, mock_paginated: MagicMock, mock_integration: MagicMock) -> None:# Crash between POST and saving the id: the marker scan must find the orphan, or every retry- # posts a duplicate status comment.+ # posts a duplicate status comment. It must only adopt app-bot comments — a human comment+ # carrying a pasted marker would otherwise get clobbered by the next edit._wire_auth(mock_integration)report = self._report()+ marker = status_marker(str(report.id))mock_paginated.return_value = iter([- {"id": 1, "body": "unrelated"},- {"id": 888, "body": f"hello\n{status_marker(str(report.id))}"},+ {"id": 1, "body": "unrelated", "user": {"login": "someone", "type": "User"}},+ {"id": 7, "body": f"pasted copy: {marker}", "user": {"login": "prankster", "type": "User"}},+ {"id": 888, "body": f"hello\n{marker}", "user": {"login": "posthog[bot]", "type": "Bot"}},])