Skip to content

fix(admin): preview-aware banner + relabelled posts links + Check-for-Preview fix - #1170

Merged
Adam-S-Daniel merged 2 commits into
mainfrom
fix/admin-preview-links-banner
May 19, 2026
Merged

fix(admin): preview-aware banner + relabelled posts links + Check-for-Preview fix#1170
Adam-S-Daniel merged 2 commits into
mainfrom
fix/admin-preview-links-banner

Conversation

@Adam-S-Daniel

Copy link
Copy Markdown
Owner

Problem

On https://adamdaniel.ai/admin/#/collections/posts and the edit-post screen, three things were wrong for unpublished-draft posts (exemplified by “Safely Keep Your Agent Iterating Autonomously With Gitleaks and PR Comments”, PR #941):

  1. The Posts-list links were bare/internal-looking: preview-pr941, PR #941.
  2. The edit screen’s “View page on site:” banner linked the production URL (https://adamdaniel.ai/blog/<slug>/) even though the post isn’t merged → 404 for the whole draft lifecycle.
  3. The edit screen was stuck on “Check for Preview” forever even though the preview env was already serving.

Root cause of (3)

decap-cms 3.12.2’s github backend implements getDeployPreview as GET /repos/.../commits/<pr-head-sha>/status and surfaces the first commit status whose context matches backend.preview_context. The repo only ever registered a GitHub Deployment (environment: preview-pr-<N>) — which admin/deploy-status-pill.js reads, but Decap’s editor never does. (The decapcms.org “polls /deployments?ref=” docs describe the Netlify backend, not github.) No matching commit status ⇒ permanent “Check for Preview”.

Changes

admin/posts-list-enhance.js

  • preview-pr<N> ↗“preview draft ↗” (URL unchanged: https://preview-pr<N>.adamdaniel.ai/blog/<slug>/)
  • PR #<N>“view draft changes”, now pointing at the PR’s GitHub Files-changed diff (…/pull/<N>/files)
  • new “view published changes” → the merged PR’s /files diff, derived from the last main commit’s associatedPullRequests (added to the existing batched GraphQL query — still three calls total). Visibility exactly per spec: unpublished draft → no (no merged PR on main); published → yes; published + draft changes → yes, rendered before “preview draft”.

admin/live-url-banner.js — when the open entry has an open editorial-workflow PR, the banner swaps the host to that PR’s preview env (preview-pr<N>.adamdaniel.ai), exactly the URL the list surfaces; no open PR → current origin (genuinely live). Reuses the list’s shared PR cache / operator Decap token; no token / API error → degrades to the prior behaviour. The published: false placeholder is untouched (so cms-link-crawler’s known-bug allowlist still holds).

.github/workflows/deploy-preview.yml — adds statuses: write and a step that publishes a deploy/preview commit status (state: success, target_url = preview root) on the PR head SHA. Decap runs that target_url through its preview_path builder, so the editor’s button resolves to “View Preview”https://preview-pr<N>.adamdaniel.ai/blog/<slug>/.

admin/config.yml / config-local.yml / config-test.yml — pin backend.preview_context: deploy/preview (explicit, auditable; survives patch-preview-config.sh, which only rewrites site_url/display_url/branch).

Docs/testsAGENTS.md brought in sync (banner preview-origin, posts-list links, the two-signals contract); e2e/cms-posts-list-enhance.spec.js gains a pure-fs lock for all of the above; e2e/select-specs.js runs that spec on deploy-preview.yml changes too.

Verification

  • node --check clean on modified JS; all YAML valid.
  • cms-posts-list-enhance.spec.js 17/17; plus cms-config, cms-permalink-contract, deploy-preview-cms-slug, preview-bot-comment, deploy-commit-metadata, cms-native-view-live, sitemap, select-specs.test.jsno existing static contract regressed.
  • workflow-path-audit: deploy-preview.yml’s trigger/paths-ignore is unchanged and still correct — the new step consumes no new repo path (pure github-script on context+env, same dependency surface as the adjacent Deployment-registration step); deploy-preview is intentionally not a required check, so workflow-level paths-ignore remains the right pattern (no always-run+early-skip refactor needed).

Rollout note

The “Check for Preview” fix takes effect on future preview deploys — the commit status is set per deploy and is not backfilled, so an already-open PR only gets it on its next push.

🤖 Generated with Claude Code

…-Preview fix

Posts list (admin/posts-list-enhance.js):
- rename "preview-pr<N> ↗" → "preview draft ↗" (URL unchanged)
- rename "PR #<N>" → "view draft changes", point at the PR /files diff
- add "view published changes" → the merged PR's /files diff, derived
  from the last main commit's associatedPullRequests (one batched
  GraphQL query). Shown only when the post is actually live on main
  (an unpublished draft has no merged PR); rendered before
  "preview draft" when both are present.

Edit screen banner (admin/live-url-banner.js):
- when the open entry is an unmerged editorial-workflow draft, swap the
  host to its per-PR preview env (preview-pr<N>.adamdaniel.ai) instead
  of linking the prod URL that 404s for the whole draft lifecycle.
  Reuses posts-list-enhance's PR cache / operator token; degrades to
  the current origin with no token or on API error.

"Check for Preview" stuck forever (root cause):
- decap-cms 3.12.2's github backend reads GET /commits/<sha>/status and
  matches backend.preview_context — it never reads the GitHub
  Deployment we register. deploy-preview.yml now also publishes a
  deploy/preview commit status (state=success, target_url=preview root)
  and admin/config*.yml pin backend.preview_context to it, so the
  editor resolves to "View Preview" → the post's preview URL.

Tests: e2e/cms-posts-list-enhance.spec.js gains a pure-fs lock for all
of the above; e2e/select-specs.js runs it on deploy-preview.yml too.

Local-only branch per request — not pushed.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@github-actions github-actions Bot added the cms/draft Content draft — not ready for publish label May 19, 2026
@github-actions

github-actions Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

🗑️ Preview environment cleaned up.

@github-actions

github-actions Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

Visual Regression Video

Video regression.mp4
Preview preview-pr1170.adamdaniel.ai
Commit 211f781
Visually different 0 page(s)
Potentially affected by changes 2 page(s)
New 0 page(s)
Visually identical 7 page(s)

Auto-approved. No visual regressions detected — the required regression check passed without manual review.

Video regenerates automatically on every push to this PR.

@github-actions

github-actions Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

E2E tests passing on 211f781

Cleared by the most recent green run.

@Adam-S-Daniel
Adam-S-Daniel enabled auto-merge (squash) May 19, 2026 23:20
@Adam-S-Daniel
Adam-S-Daniel merged commit f387108 into main May 19, 2026
26 checks passed
@github-actions github-actions Bot added the not-decap-created PR was not created by Decap CMS (head branch is not cms/<col>/<slug>) label May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cms/draft Content draft — not ready for publish not-decap-created PR was not created by Decap CMS (head branch is not cms/<col>/<slug>)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant