Skip to content

Say in the PR preview where a ticket's edits go while the PR is checked out - #674

Open
huzaifaalmesbah wants to merge 2 commits into
WordPress:trunkfrom
huzaifaalmesbah:fix/672-pr-preview-ticket-edits
Open

huzaifaalmesbah wants to merge 2 commits into
WordPress:trunkfrom
huzaifaalmesbah:fix/672-pr-preview-ticket-edits

Conversation

@huzaifaalmesbah

@huzaifaalmesbah huzaifaalmesbah commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Why

Applying a pull request to a ticket that has your own edits makes those edits disappear from the checkout. Nothing in the preview says where they go, so it looks like the app destroyed them (#672). They are safe: the switch to pr/N parks them in the ticket branch's "Work in progress" commit, and Revert this PR brings them back. The contributor just isn't told before clicking Apply and rebuild.

What changes

The Apply PR #N preview now says where the edits go, before they go:

Your edits to 1 file stay with ticket #60001 and come back when you revert this PR.

  • git:preview-pr now also returns setAside: { ref, files } when the current branch is a ticket or issue branch. The count comes from collectUnsubmittedFiles, measured from the branch point with the parked WIP included. That is the same number the ticket card's changes note shows, and exactly what the checkout takes out of the files.
  • describePrPreview turns it into the sentence (ticket or issue, singular or plural). It says nothing when there are no edits or the preview is from trunk.
  • Revert does not always come back here. recordPrHead keeps the returnTo from the first time a PR was tried. If PR First stab at supporting Gutenberg projects  #7 was first tried from ticket A and is now tried from ticket B, Revert this PR returns to A. In that case the sentence says the edits "come back when you return to it" and does not promise revert.
  • The count only feeds a sentence. On a ticket branch with no recorded branch point (migration records none for a branch that already existed, and so does linking one the registry has never seen), the preview goes without the sentence rather than failing. The checkout works there, so the preview must too.

Not changed: the banner after checkout. The issue asks for the "PR #N is applied" banner to repeat where the edits are. It already does: describePrCheckout gives it "Your ticket changes are saved separately and return when you revert this PR.", and gutenberg-site.spec.js asserts that line is visible for issues. So this PR leaves the banner alone. The renderer still doesn't read parked from the checkout result, because nothing needs it now.

How to test this

Platforms: any. Nothing here depends on the platform.

The reported path is covered by a journey: npx playwright test --project=journeys tests/e2e/journeys/pr-checkout.spec.js -g "keeps ticket work". It links ticket 60001, edits a file, opens the preview for PR #7, and now asserts the sentence before clicking Apply and rebuild. I ran it against trunk's src/ and it fails on exactly that assertion. It passes on this branch.

By hand, on a real wordpress-develop site (what the journey cannot reach):

Starting state: a site with a linked ticket.

  1. Edit a file in the checkout, e.g. src/wp-admin/css/install.css.
  2. Under Apply a patch or PR, enter a PR number that does not touch that file and press its apply button. Expected: the Apply PR #N dialog lists the PR's files and says "Your edits to 1 file stay with ticket # and come back when you revert this PR."
  3. Click Apply and rebuild. Expected: install.css no longer has your edit, and the banner says the ticket changes are saved separately.
  4. Click Revert this PR. Expected: your edit to install.css is back.
  5. Repeat step 2 on trunk (no ticket linked). Expected: no sentence about edits.

What must not have happened:

  • The preview must not fail or show an error where it opened before. That includes a ticket linked to a branch the app did not create.
  • The count must be the same number the ticket card shows for its changes, not a smaller "uncommitted only" count.

Risks and limitations

  • The preview now does one worktree walk against the branch point, after the PR fetch it already waits on. It is the same walk the card's changes note runs when the window gets focus. I did not measure it on a full wordpress-develop checkout.
  • Not run by hand on a real wordpress-develop clone. The journey uses the app's fake site and origin.

Related

Fixes #672


Design decisions and alternatives considered
  • Counting in main, not reusing the renderer's worktreeDirty. The card's count is already in renderer state and would avoid a walk. But it can be null while a probe runs, or stale after a switch. The preview is a decision point, so it counts at the moment it is shown. The number is the same either way, because both come from collectUnsubmittedFiles.
  • Two wordings, not one. The issue's sentence promises that revert brings the edits back. That is only true when the PR's recorded returnTo is the current ticket. Rather than make the preview wrong in that case, it says something true in both.
  • The banner is left alone. See "What changes". Its existing line already does what the issue asks after checkout.
Review outcome (required — see AGENTS.md)

1 [fix here] · 0 [follow-up]. Fixed: 1 of 1.

  • [fix here] The preview could fail where it used to succeed. collectUnsubmittedFiles throws through patchBaseOid when the ticket branch has no recorded baseOid, which is reachable through migration and through linking an existing branch. The preview would then show the raw error and block applying any PR. Fixed: the count is optional (the same pattern as the discard handlers), and the new ipc-wiring test git:preview-pr still previews from a ticket branch with no recorded branch point fails without the fix.

  • Review: completed. A fresh subagent did the judgement pass against .github/instructions/code-review.instructions.md on the working tree over base trunk @ 7ee3ead. It checked the count's correctness, that returnTo agrees with git:checkout-pr, the "Return to saved copy" path, performance, i18n, cross-platform and test layers. npm run lint clean; npm test 2101 pass / 0 fail / 2 skipped; journeys pr-checkout.spec.js, gutenberg-site.spec.js, apply-card.spec.js pass.

  • Since review: the [fix here] above and its test were applied before committing (head adb4165). Re-ran lint, npm test and the PR journeys on it. No other change.

Implementation notes
  • src/main.js: git:preview-pr returns setAside.
  • src/renderer/pr-checkout.cjs: setAsideSentence and describePrPreview({ setAside, returnTo, noun }) give setAsideNote. The four strings use _n with positional placeholders and translator comments.
  • src/renderer/apply-card.cjs and components/apply-card.jsx: previewWords carries setAsideNote, and the dialog shows it under the file list.
  • Tests: pr-checkout-renderer.test.cjs (wording: ticket, issue, singular, revert elsewhere, none), apply-card.test.cjs (carried through previewWords), ipc-wiring.test.cjs (count against the branch point, null on trunk, no branch point), and pr-checkout.spec.js (the reported path).
Screenshots or recording

The Apply PR #7 dialog from the pr-checkout.spec.js journey, with ticket 60001 and one edited file.

Before (trunk) After
Apply PR #7 dialog on trunk: the headline and the file list, nothing about the ticket's edit Apply PR #7 dialog with this change: the same, plus the sentence saying where the ticket's edit goes

…ed out

Checking out a pull request from a ticket with edits parks them in the
ticket branch's WIP commit and takes them out of the files, and the
preview said nothing of it: the edits looked destroyed. git:preview-pr
now counts the ticket's edits the way its card does, against the branch
point, and the preview says "Your edits to N files stay with ticket #X
and come back when you revert this PR". When revert goes elsewhere,
because the PR was first tried from another ticket, it says they come
back when you return to the ticket instead of promising revert does it.

The count only feeds that sentence, so a ticket branch with no recorded
branch point previews without it rather than failing.

Fixes WordPress#672.
@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Repository: WordPress/contributor-toolkit/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9ec3e659-d8d8-4037-bcc9-81e7da72cf56

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

huzaifaalmesbah added a commit to huzaifaalmesbah/contributor-toolkit that referenced this pull request Oct 9, 2026
huzaifaalmesbah added a commit to huzaifaalmesbah/contributor-toolkit that referenced this pull request Oct 9, 2026
@ryanwelcher

Copy link
Copy Markdown
Collaborator

This conflicts with trunk since #702 (the "could not download the latest trunk" note, #701). Both changes touch the same lines, and the fix is to keep both:

I merged trunk locally this way and the full unit suite passes. Could you merge or rebase onto trunk and push?

…icket-edits

# Conflicts:
#	src/main.js
#	src/renderer/index.jsx
#	src/renderer/pr-checkout.cjs
#	tests/unit/apply-card.test.cjs
#	tests/unit/ipc-wiring.test.cjs
@huzaifaalmesbah

Copy link
Copy Markdown
Member Author

Thanks, @ryanwelcher! I merged trunk in f132bad and resolved the conflicts the way you described, so both setAside and measuredFromSite reach the preview, and setAsideNote and trunkNote both show. Both pairs of git:preview-pr tests (#672 and #701) are kept. The full unit suite passes and lint is clean.

This branch has not been deployed

No deployments
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.

Say where a ticket's edits go when a pull request is checked out

2 participants