diff --git a/tools/jetpack-live-branches/jetpack-live-branches.user.js b/tools/jetpack-live-branches/jetpack-live-branches.user.js index bc4a8aaa3ac40..b38a80c5d3cf6 100644 --- a/tools/jetpack-live-branches/jetpack-live-branches.user.js +++ b/tools/jetpack-live-branches/jetpack-live-branches.user.js @@ -1,12 +1,14 @@ // ==UserScript== // @name Jetpack Live Branches // @namespace https://wordpress.com/ -// @version 1.11 +// @version 1.12 // @description Adds links to PRs pointing to Jurassic Ninja sites for live-testing a changeset // @require https://code.jquery.com/jquery-3.3.1.min.js // @match https://github.com/Automattic/jetpack/pull/* // ==/UserScript== +/* global jQuery */ + ( function() { const $ = jQuery.noConflict(); doit(); @@ -19,81 +21,158 @@ $( '.gh-header-meta .State' ) .text() .trim() === 'Merged'; - const base = 'https://jurassic.ninja/create?'; - const query = `jetpack-beta&branch=${ branch }&wp-debug-log`; - let link = base + query; - const canLiveTestText = `
-

Jetpack Live Branches

-

${ link }

- -
`; - const branchIsForkedText = - '
' + - '

Jetpack Live Branches

' + - "

This branch can't be tested live because it comes from a forked version of this repo.

" + - '
'; - const branchIsMergedText = - '
' + - '

Jetpack Live Branches

' + - '

This branch is already merged.

' + - '
'; + if ( ! branchIsForked && ! branchIsMerged ) { - appendHtml( markdownBody, canLiveTestText ); + const link = getLink(); + const contents = ` +

Settings

+ ${ getOptionsList( + [ + { + label: 'A shortlived site', + name: 'shortlived', + }, + { + checked: true, + label: 'WP_DEBUG and WP_DEBUG_LOG set to true', + name: 'wp-debug-log', + }, + { + label: 'Multisite based on subdomains', + name: 'subdomain_multisite', + }, + { + label: 'Multisite based on subdirectories', + name: 'subdir_multisite', + }, + { + label: 'Pre-generate content', + name: 'content', + }, + { + label: 'xmlrpc.php unavailable', + name: 'blockxmlrpc', + }, + ], + 100 + ) } +

Plugins

+ ${ getOptionsList( + [ + { + label: 'WordPress Beta Tester', + name: 'wordpress-beta-tester', + }, + { + label: 'Gutenberg', + name: 'gutenberg', + }, + { + label: 'Classic Editor', + name: 'classic-editor', + }, + { + label: 'WooCommerce', + name: 'woocommerce', + }, + { + label: 'WooCommerce Beta Tester', + name: 'woocommerce-beta-tester', + }, + { + label: 'Config Constants', + name: 'config-constants', + }, + { + label: 'Code Snippets', + name: 'code-snippets', + }, + { + label: 'WP Rollback', + name: 'wp-rollback', + }, + { + label: 'WP Downgrade', + name: 'wp-downgrade', + }, + { + label: 'WP Super Cache', + name: 'wp-super-cache', + }, + { + label: 'WP Log Viewer', + name: 'wp-log-viewer', + }, + { + label: 'WP Job Manager', + name: 'wp-job-manager', + }, + ], + 33 + ) } +

+ + ${ link } + +

+ `; + appendHtml( markdownBody, contents ); } else if ( ! branchIsMerged ) { - appendHtml( markdownBody, branchIsForkedText ); + appendHtml( + markdownBody, + "

This branch can't be tested live because it comes from a forked version of this repo.

" + ); } else { - appendHtml( markdownBody, branchIsMergedText ); + appendHtml( markdownBody, '

This branch is already merged.

' ); + } + + function getLink() { + const query = [ 'jetpack-beta', `branch=${ branch }` ]; + $( '#jetpack-live-branches input[type=checkbox]:checked' ).each( ( i, input ) => { + query.push( input.name ); + } ); + return `https://jurassic.ninja/create?${ query.join( '&' ) }`; + } + + function getOption( { checked = false, label, name }, columnWidth ) { + return ` +
  • + +
  • + `; } - function appendHtml( el, str ) { - const div = document.createElement( 'div' ); + function getOptionsList( options, columnWidth ) { + return ` + + `; + } + + function appendHtml( el, contents ) { const $el = $( el ); - $( div ).append( str ); - $el.append( - $( div ) - .children() - .get( 0 ) + const liveBranches = $( '
    ' ).append( + `

    Jetpack Live Branches

    ${ contents }` ); - + $el.append( liveBranches ); $el.find( 'input[type=checkbox]' ).change( toggle ); } function toggle( e ) { e.stopPropagation(); e.preventDefault(); - const $link = $( '#jetpack-beta-branch-link' ); - const $this = $( this ); - const name = $this.attr( 'name' ); - const checked = $this.is( ':checked' ); - - const query_array = $link - .attr( 'href' ) - .split( '?' )[ 1 ] - .split( '&' ); - - if ( checked ) { - query_array.push( name ); - link = base + query_array.join( '&' ); - } else { - link = - base + - query_array - .filter( function( item ) { - return item !== name; - } ) - .join( '&' ); - } - $link.attr( 'href', link ); - $link.text( link ); + const link = getLink(); + $( '#jetpack-beta-branch-link' ) + .attr( 'href', link ) + .text( link ); } } } )();