Skip to content

Website: Preview the PR specified by the referer header#1762

Closed
adamziel wants to merge 1 commit intotrunkfrom
referer-based-pr-preview
Closed

Website: Preview the PR specified by the referer header#1762
adamziel wants to merge 1 commit intotrunkfrom
referer-based-pr-preview

Conversation

@adamziel
Copy link
Collaborator

Enables easy linking to Playground PRs from WordPress and Gutenberg GitHub PRs without interpolating the PR number in the link.

This PR adds a https://playground.wordpress.net/preview-referrer-pr.php script that looks at the Referer header, extracts the repo and the PR number from it, and redirects to the relevant PR previewer.

Testing instructions

  1. Run the script on a HTTPS domain (or use my link: https://adamadam.blog/referer.php)
  2. Link to that script from a WordPress develop and a Gutenberg PR
  3. Click those links
  4. Confirm you were redirected to /wordpress.html or /gutenberg.html with a proper ?pr= query parameter

Props to @gziolo for the idea

Enables easy linking to Playground PRs from WordPress and Gutenberg
GitHub PRs without interpolating the PR number in the link.

This PR adds a https://playground.wordpress.net/preview-referrer-pr.php script
that looks at the Referer header, extracts the repo and the PR number
from it, and redirects to the relevant PR previewer.

 ## Testing instructions

1. Run the script on a HTTPS domain (or use my link: https://adamadam.blog/referer.php)
2. Link to that script from a WordPress develop and a Gutenberg PR
3. Click those links
4. Confirm you were redirected to /wordpress.html or /gutenberg.html
   with a proper `?pr=` query parameter

Props to @gziolo for the idea

if (preg_match('/github\.com\/WordPress\/gutenberg\/pull\/(?<prNumber>\d+)/i', $referrer, $matches)) {
$prNumber = $matches['prNumber'];
header('Location: ./gutenberg.html?pr=' . $prNumber);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with #1761 would it be helpful to cut out the redirect and launch /?core-pr=${prNumber}?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my first thought, too, but /gutenberg.html will tell you when the artifact isn't ready yet while a direct link would just not load the PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a possible enhancement for #1761 down the line 😉

@gziolo
Copy link
Member

gziolo commented Sep 16, 2024

Nice! I tried to put the link https://adamadam.blog/referer.php in my PR: WordPress/gutenberg#65273. However, it didn't work correctly.

@adamziel adamziel force-pushed the trunk branch 2 times, most recently from 680cd19 to 2e376d2 Compare October 4, 2024 09:24
@adamziel adamziel self-assigned this Dec 17, 2024
@ajitbohra
Copy link
Member

Tested and it redirects as mentioned

pr-referrer.mp4

@adamziel can you confirm screen recording shows expected result?

@adamziel
Copy link
Collaborator Author

@ajitbohra it does, thank you for testing! Would you be able to confirm the result is reliable across browsers and different levels of privacy settings? I wonder why it failed for @gziolo

@adamziel
Copy link
Collaborator Author

This PR seems stale so I'll close it. Feel free to reopen at any point but also no pressure – it can stay closed and that's fine.

@adamziel adamziel closed this Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

No open projects
Status: Reviewed

Development

Successfully merging this pull request may close these issues.

4 participants