Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions tools/jetpack-live-branches/jetpack-live-branches.user.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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' );
Expand Down Expand Up @@ -129,6 +131,21 @@
return { currentBranch, branchStatus };
}

/**
* Determine the PR's label names, from either PR page layout.
*
* @return {Set<string>} 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() );
} );
Comment on lines +140 to +145

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we're going to trust textContent, you could probably have simplified this a bit

Suggested change
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() );
} );
const labels = new Set(
$.map( $( '.js-issue-labels a.IssueLabel, section[aria-label="Labels"] a[href*="label%3A"]' ), e => e.textContent.trim() )
);

return labels;
}

/** Function. */
function doit() {
const markdownBody = document.querySelectorAll( markdownBodySelector )[ 0 ];
Expand Down Expand Up @@ -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( {
Expand Down
Loading