Changeset 6522
- Timestamp:
- 02/02/2018 02:28:06 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/src/class-restapi.php
r6262 r6522 151 151 update_post_meta( $post_id, 'results', $results ); 152 152 153 self::maybe_send_email_notifications( $parent_id ); 154 153 155 // Create the response object. 154 156 $response = new \WP_REST_Response( … … 166 168 return $response; 167 169 } 170 171 /** 172 * Maybe send an email notification if 'wpdevbot' has reported 173 * a success and others have reported failures. 174 */ 175 private static function maybe_send_email_notifications( $parent_id ) { 176 177 // 'wpdevbot' doesn't exist on this system, so nothing to compare. 178 $user = get_user_by( 'login', 'wpdevbot' ); 179 if ( ! $user ) { 180 return; 181 } 182 $wporgbot_id = $user->ID; 183 184 $args = array( 185 'post_parent' => $parent_id, 186 'post_type' => 'result', 187 'numberposts' => -1, 188 ); 189 $results = get_posts( $args ); 190 $wpdevbot_results = wp_filter_object_list( $results, array( 'post_author' => $wporgbot_id ) ); 191 // 'wpdevbot' hasn't reported yet 192 if ( empty( $wpdevbot_results ) ) { 193 return; 194 } 195 $wpdevbot_result = array_shift( $wpdevbot_results ); 196 // If 'wpdevbot' is failed, we already know the test failure 197 // and don't need to report host testing bots failures. 198 if ( self::is_failed_result( $wpdevbot_result ) ) { 199 return; 200 } 201 202 foreach ( $results as $result ) { 203 // Doesn't make sense to report wpdevbot to itself 204 if ( $wpdevbot_result->ID === $result->ID ) { 205 continue; 206 } 207 // If the test result is failed and we haven't yet sent an 208 // email notification, then let the reporter know. 209 if ( self::is_failed_result( $result ) 210 && ! get_post_meta( $result->ID, 'ptr_reported_failure', true ) ) { 211 $user = get_user_by( 'id', $result->post_author ); 212 if ( $user ) { 213 $subject = '[Host Test Results] Test failure for ' . $result->post_name; 214 $body = 'Hi there,' . PHP_EOL . PHP_EOL 215 . "We've detected a WordPress PHPUnit test failure on your hosting environment. Please review when you have a moment: " 216 . get_permalink( $result->ID ) . PHP_EOL . PHP_EOL 217 . 'Thanks,' . PHP_EOL . PHP_EOL 218 . 'WordPress.org Hosting Community'; 219 wp_mail( $user->user_email, $subject, $body ); 220 update_post_meta( $result->ID, 'ptr_reported_failure', true ); 221 } 222 } 223 } 224 225 } 226 227 /** 228 * Whether or not a given result is a failed result. 229 * 230 * @param WP_Post $post Result post object. 231 * @return boolean 232 */ 233 private static function is_failed_result( $post ) { 234 $is_failed = false; 235 $results = get_post_meta( $post->ID, 'results', true ); 236 if ( isset( $results['failures'] ) ) { 237 if ( 0 !== (int) $results['failures'] || 0 !== (int) $results['errors'] ) { 238 $is_failed = true; 239 } 240 } 241 return $is_failed; 242 } 243 168 244 }
Note: See TracChangeset
for help on using the changeset viewer.