From 60c27c0e6cfcb9bb93a383e2f292b64c15467a30 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Thu, 12 Nov 2026 10:19:18 +0100 Subject: [PATCH] Live Branches: Support GitHub's new pull request page layout GitHub now serves some users a React-based PR page that has no `.pull-discussion-timeline` wrapper, so the script found no PR body and rendered nothing. Labels moved as well, into a sidebar section of Primer tokens without the `IssueLabel` class or `data-name` attribute, which would have left every plugin unchecked by default. Match the PR body and labels in both layouts. The new selectors key on `aria-label` rather than the layout's hashed class names, which are unlikely to survive GitHub's next build. Branch and state already come from the embedded JSON, which both layouts provide. --- .../jetpack-live-branches.user.js | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/tools/jetpack-live-branches/jetpack-live-branches.user.js b/tools/jetpack-live-branches/jetpack-live-branches.user.js index 7173c144c55c..1daf47865d7a 100644 --- a/tools/jetpack-live-branches/jetpack-live-branches.user.js +++ b/tools/jetpack-live-branches/jetpack-live-branches.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name Jetpack Live Branches // @namespace https://wordpress.com/ -// @version 1.38 +// @version 1.39 // @description Adds links to PRs pointing to Jurassic Ninja sites for live-testing a changeset // @grant GM_xmlhttpRequest // @connect betadownload.jetpack.me @@ -15,7 +15,9 @@ ( function () { const $ = jQuery.noConflict(); - const markdownBodySelector = '.pull-discussion-timeline .markdown-body'; + // GitHub serves two PR page layouts: the classic timeline, and a React one with hashed class names. + const markdownBodySelector = + '.pull-discussion-timeline .markdown-body, section[aria-label="Description"] .markdown-body'; let pluginsList = null; const style = document.createElement( 'style' ); @@ -129,6 +131,21 @@ return { currentBranch, branchStatus }; } + /** + * Determine the PR's label names, from either PR page layout. + * + * @return {Set} Label names. + */ + function getPRLabels() { + const labels = new Set( + $.map( $( '.js-issue-labels a.IssueLabel' ), e => $( e ).data( 'name' ) ) + ); + $( 'section[aria-label="Labels"] a[href*="label%3A"]' ).each( ( i, e ) => { + labels.add( e.textContent.trim() ); + } ); + return labels; + } + /** Function. */ function doit() { const markdownBody = document.querySelectorAll( markdownBodySelector )[ 0 ]; @@ -176,9 +193,7 @@ const plugins = []; if ( Object.hasOwn( body, 'plugins' ) ) { - const labels = new Set( - $.map( $( '.js-issue-labels a.IssueLabel' ), e => $( e ).data( 'name' ) ) - ); + const labels = getPRLabels(); Object.keys( body.plugins ).forEach( k => { const data = body.plugins[ k ]; plugins.push( {