Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Reviewed
Development

Successfully merging this pull request may close these issues.

3 participants