Merge pull request woocommerce/woocommerce-beta-tester#48 from woocommerce/fix/46

Don't make external requests
This commit is contained in:
Claudiu Lodromanean 2018-07-12 09:29:07 -07:00 committed by GitHub
commit 2ec8452074
4 changed files with 37 additions and 46 deletions

View File

@ -38,7 +38,8 @@ class WC_Beta_Tester_Admin_Assets {
'wc_beta_tester_version_info_params',
array(
'version' => $version,
'description' => WC_Beta_Tester::instance()->get_github_release_information( $version )->body,
/* translators: %s: Release version number */
'description' => sprintf( __( 'Release of version %s', 'woocommerce-beta-tester' ), $version ),
)
);

View File

@ -28,13 +28,38 @@ class WC_Beta_Tester_Admin_Menus {
* @return string
*/
protected function get_ticket_template() {
$bug_tpl = wp_remote_retrieve_body( wp_remote_get( 'https://raw.githubusercontent.com/woocommerce/woocommerce/master/.github/ISSUE_TEMPLATE/Bug_report.md' ) );
ob_start();
?>
**Describe the bug**
A clear and concise description of what the bug is. Please be as descriptive as possible; issues lacking detail, or for any other reason than to report a bug, may be closed without action.
$begin = strpos( $bug_tpl, '**Describe the bug**' );
if ( $begin ) {
$bug_tpl = substr( $bug_tpl, $begin );
}
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Expected behavior**
A clear and concise description of what you expected to happen.
**Isolating the problem (mark completed items with an [x]):**
- [ ] I have deactivated other plugins and confirmed this bug occurs when only WooCommerce plugin is active.
- [ ] This bug happens with a default WordPress theme active, or [Storefront](https://woocommerce.com/storefront/).
- [ ] I can reproduce this bug consistently using the steps above.
**WordPress Environment**
<details>
```
Copy and paste the system status report from **WooCommerce > System Status** in WordPress admin.
```
</details>
<?php
$bug_tpl = ob_get_clean();
return $bug_tpl;
}

View File

@ -287,8 +287,6 @@ class WC_Beta_Tester {
return $response;
}
$github_release_data = $this->get_github_release_information( $new_version );
if ( $this->is_beta_version( $new_version ) ) {
$warning = __( '<h1><span>&#9888;</span>This is a beta release<span>&#9888;</span></h1>', 'woocommerce-beta-tester' );
}
@ -301,10 +299,9 @@ class WC_Beta_Tester {
$response->version = $new_version;
$response->download_link = $this->get_download_url( $new_version );
$response->sections['changelog'] = make_clickable( wpautop( $github_release_data->body ) );
$response->sections['changelog'] .= sprintf(
'<p><a target="_blank" href="%s">' . __( 'Read more on GitHub', 'woocommerce-beta-tester' ) . '</a></p>',
'https://github.com/woocommerce/woocommerce/releases/tag/' . $response->version
$response->sections['changelog'] = sprintf(
'<p><a target="_blank" href="%s">' . __( 'Read the changelog and find out more about the release on GitHub.', 'woocommerce-beta-tester' ) . '</a></p>',
'https://github.com/woocommerce/woocommerce/blob/' . $response->version . '/readme.txt'
);
foreach ( $response->sections as $key => $section ) {
@ -353,40 +350,6 @@ class WC_Beta_Tester {
}
}
/**
* Gets release information from GitHub.
*
* @param string $version Version number.
* @return bool|string False on error, description otherwise
*/
public function get_github_release_information( $version ) {
$url = 'https: //api.github.com/repos/woocommerce/woocommerce/releases/tags/' . $version;
$github_data = get_site_transient( md5( $url ) . '_github_data' );
if ( $this->overrule_transients() || empty( $github_data ) ) {
$github_data = wp_remote_get( $url, array(
'sslverify' => false,
) );
if ( is_wp_error( $github_data ) ) {
return false;
}
$github_data = json_decode( $github_data['body'] );
if ( empty( $github_data ) ) {
return false;
}
$github_data = $github_data;
// Refresh every 6 hours.
set_site_transient( md5( $url ) . '_github_data', $github_data, HOUR_IN_SECONDS * 6 );
}
return $github_data;
}
/**
* Return true if version string is a beta version.
*

View File

@ -8,6 +8,8 @@
* Author URI: http://woocommerce.com/
* Requires at least: 4.4
* Tested up to: 4.9
* WC requires at least: 3.0.0
* WC tested up to: 3.5.0
* Text Domain: woocommerce-beta-tester
*
* @package WC_Beta_Tester