Skip to content

feat(github): add GET_PREVIEW_DEPLOYMENT tool for deployment-based previews - #535

Merged
guitavano merged 2 commits into
mainfrom
guitavano/github-preview-deployment
Aug 13, 2026
Merged

feat(github): add GET_PREVIEW_DEPLOYMENT tool for deployment-based previews#535
guitavano merged 2 commits into
mainfrom
guitavano/github-preview-deployment

Conversation

@guitavano

@guitavano guitavano commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Problema

Alguns hosts publicam a URL de preview de uma PR só como um GitHub Deployment (deployment_status.environment_url) — não como target_url de commit-status nem como comentário de bot. O caso concreto é a VTEX FastStore WebOps: o preview (https://<hash>--<store>.preview.vtex.app) vive no deployment status de staging, e o pull_request_read do upstream não tem método de deployments. Resultado: o painel de PR do Studio não enxerga esses previews.

Correção

Adiciona a tool first-party GET_PREVIEW_DEPLOYMENT, espelhando exatamente o padrão do já-existente GET_CHECK_RUN (que preenche outro gap do upstream lendo a REST API com o token do próprio caller):

  • Lê a REST Deployments API (GET /repos/{owner}/{repo}/deployments?sha= + /deployments/{id}/statuses) com env.MESH_REQUEST_CONTEXT.authorization.
  • Varre os deployments do commit do mais novo pro mais antigo e retorna o environment_url do status success mais recente.
  • Retorna environmentUrl: null (não erro) quando há deployment mas nenhum publicou url ainda (deploy em andamento).
  • Filtro opcional por environment (ex.: staging).
  • Mesma validação de segmentos (anti path-injection), headers e mapeamento de erros de check-run.ts; sha validado como hex 7–40.

Registrada em github/server/tools/index.ts.

Testes

  • github/server/lib/deployment.test.ts — 12 casos (sucesso, skip até o próximo deployment, in-flight → empty, sem deployments → empty, filtro de environment, encode de segmentos, rejeição de path-injection em owner/repo/sha, token ausente, 403/404/5xx, body ilegível). bun test verde.
  • tsc --noEmit: sem novos erros (os existentes são do node_modules/@decocms/runtime, pré-existentes).

Próximo passo (outro repo)

PR companheiro no Studio (decocms/studio) liga essa tool como terceiro fallback de previewUrl em apps/api/src/tools/task-board/prs-get.ts, depois de commit-status e comentários. O host .preview.vtex.app já está no allow-list isTrustedPreviewHost.

🤖 Generated with Claude Code


Summary by cubic

Adds a first-party GET_PREVIEW_DEPLOYMENT tool to resolve a commit’s preview URL from GitHub Deployments, enabling previews that are published only as deployment-status environment_url. It scans candidate deployments’ statuses in parallel and surfaces environmentUrl as untrusted output.

  • Mirrors GET_CHECK_RUN: reads the REST Deployments API with env.MESH_REQUEST_CONTEXT.authorization, validates owner/repo/sha (and optional environment), and maps 401/403/404/5xx to stable errors. Registers the tool in github/server/tools/index.ts and adds unit tests.
  • Scans deployments newest-first; reads each deployment’s statuses concurrently (bounded), skips deployments whose status read fails, and returns the newest success with an environment_url, or environmentUrl: null while a deploy is in flight or no URL is published.
  • Security: environmentUrl is untrusted (set by the deployer); consumers must host-validate before showing or navigating.

Rollout

  • Call GET_PREVIEW_DEPLOYMENT with a token that grants deployments:read. No changes to existing preview sources.
  • Studio will adopt this as a third fallback after commit-status and comments. No migration required.

Written for commit a005f66. Summary will update on new commits.

Review in cubic

…eviews

Some hosts (VTEX FastStore WebOps) publish a PR's preview URL only as a
GitHub Deployment's deployment_status.environment_url — not as a
commit-status target_url and not as a bot comment. The upstream
pull_request_read has no deployments method, so those previews are
invisible to consumers like the Studio PR panel.

Add a first-party GET_PREVIEW_DEPLOYMENT tool mirroring GET_CHECK_RUN: it
reads the REST Deployments API with the caller's own token, scans a
commit's deployments newest-first, and returns the newest successful
status's environment_url (or null while a deploy is in-flight). Same
segment validation, header, and error-mapping shape as check-run.ts.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…l note

Review follow-ups on GET_PREVIEW_DEPLOYMENT:
- Scan candidate deployments' statuses concurrently (bounded by the slice)
  instead of a serial loop, so the in-flight case (deployments exist, none
  successful yet — exactly what this targets) costs one round-trip; a single
  deployment's status read failing now drops only that deployment, not the
  whole scan. Test added for that resilience.
- Document that environmentUrl is untrusted (set by the deployer, not
  host-validated here) in the tool description and output schema, so a direct
  agent caller doesn't treat it as a safe-to-navigate URL.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@guitavano
guitavano merged commit edabb0d into main Aug 13, 2026
2 checks passed
guitavano added a commit to decocms/studio that referenced this pull request Aug 13, 2026
…e) (#6033)

* feat(task-board): surface deployment-based PR previews (VTEX FastStore)

The PR panel lifts a preview URL from two sources — a commit-status
target_url and the deploy bot's PR comment. Some hosts publish it in
neither: VTEX FastStore WebOps records the preview only as a GitHub
Deployment's environment_url, so those PRs showed no preview button.

Add a third, last-resort source: when neither cheap source hits, resolve
the preview from the head commit's GitHub Deployments via the new github
MCP GET_PREVIEW_DEPLOYMENT tool (same connection/cache as GET_CHECK_RUN).
The head sha comes free from the combined-status response, and the result
passes the same isTrustedPreviewHost gate — .preview.vtex.app was already
allow-listed. The scan runs only when a preview is otherwise unknown, so
repos with a Vercel/Cloudflare/deco preview pay nothing.

Requires decocms/mcps#535 (adds GET_PREVIEW_DEPLOYMENT).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* refactor(task-board): address review — source head sha from the stable get.head.sha

Review follow-up on the deployment-preview fallback: derive the head sha
from the shared `pull_request_read get` response's head.sha (documented,
present regardless of CI) instead of get_status.sha, falling back to the
latter. get_status.sha was fragile — a PR with no CI, or a transient
get_status failure, left headSha null and silently skipped the deployment
lookup even when a deployment existed. The `get` is already fetched in the
same round-trip window and is now threaded into fetchPrStatusExtras.

Adds headShaFromPrGet + unit tests; TODO(e2e) note on the untested wiring.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant