Skip to content
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.

Retrieve WCPay Dev Tools plugin zip from the private repo #286

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions features/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ function ( $options_page ) {
'text' => __( 'Licensing API OAuth2 token to provision Jetpack products with. Leave blank to disable.', 'jurassic-ninja' ),
'sanitize' => false,
),
'wcpay_dev_tools_github_token' => array(
'id' => 'wcpay_dev_tools_github_token',
'title' => __( 'GitHub Token for WooPayments Dev Tool Private Repo', 'jurassic-ninja' ),
'text' => __( 'Set a fined-grain GitHub token with read-only access to retrieve the latest commit from the repo directly.', 'jurassic-ninja' ),
'sanitize' => false,
),
'add_gutenberg_by_default' => array(
'id' => 'add_gutenberg_by_default',
'title' => __( 'Add Gutenberg to every launched WordPress', 'jurassic-ninja' ),
Expand Down
41 changes: 38 additions & 3 deletions features/woocommerce-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,48 @@ function ( $s ) use ( $cmd ) {
);
}

/**
* Gets the zip link for the WooCommerce Payments Dev Tools plugin from the private GitHub repo.
*
* @return string|null The zip link. Null if it can not be retrieved.
*/
function get_private_wcpay_dev_tools_zipball_link(): ?string {
$response = wp_remote_head(
'https://api.github.com/repos/Automattic/woocommerce-payments-dev-tools-ci/zipball/trunk',
array(
'headers' => array(
'Authorization' => 'Bearer ' . settings( 'wcpay_dev_tools_github_token', '' ),
),
)
);

$status = wp_remote_retrieve_response_code( $response );
$location = wp_remote_retrieve_header( $response, 'location' );

if ( 302 === $status
&& is_string( $location ) &&
wp_http_validate_url( $location )
) {
return $location;
}

push_error(
new \WP_Error(
'wcpay_dev_tools_private_repo',
__( 'Can not retrieve the WooCommerce Payments Dev Tools private repo. The GitHub fined-grain token may be invalid.', 'jurassic-ninja' )
)
);
return null;
}
/**
* Installs and activates the WooCommerce Payments Dev Tools plugin on the site.
*/
function add_woocommerce_payments_dev_tools() {
$woocommerce_payments_dev_tools_plugin_url = 'https://github.com/Automattic/woocommerce-payments-dev-tools-ci/releases/latest/download/woocommerce-payments-dev-tools-trunk.zip';
// We install the trunk version of the plugin.
$cmd = "wp plugin install $woocommerce_payments_dev_tools_plugin_url --activate";
$private_repo_url = get_private_wcpay_dev_tools_zipball_link();
$public_repo_url = 'https://github.com/Automattic/woocommerce-payments-dev-tools-ci/releases/latest/download/woocommerce-payments-dev-tools-trunk.zip';

$install_url = $private_repo_url ?? $public_repo_url;
$cmd = "wp plugin install $install_url --activate";

add_filter(
'jurassic_ninja_feature_command',
Expand Down
2 changes: 1 addition & 1 deletion lib/error-stuff.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function errors() {
/**
* Push an error to the stack of errors that will be shown on the admin notices
*
* @param WP_Error $err An error to be shown in the admin notice.
* @param \WP_Error $err An error to be shown in the admin notice.
*/
function push_error( $err ) {
global $jurassic_ninja_errors;
Expand Down
Loading