From 4a4d302ebf5bbe393d16f0c3c3dbd6fbc602d685 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sat, 16 Mar 2024 18:30:16 +0100 Subject: [PATCH 01/30] Store php_version in post meta --- src/class-restapi.php | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/class-restapi.php b/src/class-restapi.php index 0fb1566..20d7675 100644 --- a/src/class-restapi.php +++ b/src/class-restapi.php @@ -113,22 +113,40 @@ public static function add_results_callback( $data ) { ); } + $env = isset( $parameters['env'] ) ? json_decode( $parameters['env'], true ) : array(); + + $php_version = ''; + if ( isset( $env['php_version'] ) ) { + $parts = explode( '.', $env['php_version'] ); + $php_version = $parts[0] . '.' . $parts[1]; + } + $current_user = wp_get_current_user(); - $args = array( + // Check to see if the test result already exist. + $results = get_posts( array( 'post_parent' => $parent_id, 'post_type' => 'result', 'numberposts' => 1, 'author' => $current_user->ID, - ); - - // Check to see if the test result already exist. - $results = get_posts( $args ); + 'meta_query' => $php_version ? array( + array( + 'key' => 'php_version', + 'value' => $php_version, + ), + ) : array(), + ) ); if ( $results ) { $post_id = $results[0]->ID; } else { - $results = array( - 'post_title' => $current_user->user_login . ' - ' . $slug, + $post_title = $current_user->user_login . ' - ' . $slug; + + if ( $php_version ) { + $post_title .= '-' . $php_version; + } + + $args = array( + 'post_title' => $post_title, 'post_content' => '', 'post_status' => 'publish', 'post_author' => $current_user->ID, @@ -137,7 +155,7 @@ public static function add_results_callback( $data ) { ); // Store the results. - $post_id = wp_insert_post( $results, true ); + $post_id = wp_insert_post( $args, true ); } if ( is_wp_error( $post_id ) ) { @@ -149,6 +167,7 @@ public static function add_results_callback( $data ) { update_post_meta( $post_id, 'env', $env ); update_post_meta( $post_id, 'results', $results ); + update_post_meta( $post_id, 'php_version', $php_version ); self::maybe_send_email_notifications( $parent_id ); From 70871f5746ee291adb343685275da303d6a7a660 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sat, 16 Mar 2024 18:40:43 +0100 Subject: [PATCH 02/30] Use different way of displaying results --- parts/result-set-all.php | 77 ++++++++++++++++++++++++++ parts/result-set-single.php | 105 ++++++++++++++++++++++++++++++++++++ src/class-display.php | 14 ++--- 3 files changed, 189 insertions(+), 7 deletions(-) create mode 100644 parts/result-set-all.php create mode 100644 parts/result-set-single.php diff --git a/parts/result-set-all.php b/parts/result-set-all.php new file mode 100644 index 0000000..768f465 --- /dev/null +++ b/parts/result-set-all.php @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + post_name, 'r' ); + $query_args = array( + 'posts_per_page' => $posts_per_page, + 'post_type' => 'result', + 'post_parent' => $revision->ID, + 'orderby' => 'post_title', + 'order' => 'ASC', + ); + $report_query = new WP_Query( $query_args ); + + $hosts = []; + $num_hosts = 0; + $num_passed = 0; + $num_failed = 0; + + foreach ( $report_query->posts as $report ) : + $hosts[ $report->post_author ] ??= 0; + ++$hosts[ $report->post_author ]; + + $results = get_post_meta( $report->ID, 'results', true ); + + if ( 0 === (int) $results['failures'] && 0 === (int) $results['errors'] ) { + ++$num_passed; + } else { + ++$num_failed; + } + endforeach; + ?> + + + + + + + + + +
RevisionHostsPassedFailed➡️
+ + r + + + + + + + + + + + + + + View + +
diff --git a/parts/result-set-single.php b/parts/result-set-single.php new file mode 100644 index 0000000..5bd6849 --- /dev/null +++ b/parts/result-set-single.php @@ -0,0 +1,105 @@ +post_name, 'r' ); +?> + + + + + + + + + + + + + + + $posts_per_page, + 'post_type' => 'result', + 'post_parent' => $revision->ID, + 'orderby' => ['post_title' => 'ASC', 'author' => 'ASC', 'meta_value' => 'ASC'], +// 'meta_key' => 'php_version', + ); + $report_query = new WP_Query( $query_args ); + if ( ! empty( $report_query->posts ) ) : + + $prev_author = null; + + foreach ( $report_query->posts as $report ) : + $status = 'Errored'; + $status_title = 'No results found for test.'; + $results = get_post_meta( $report->ID, 'results', true ); + if ( isset( $results['failures'] ) && ! empty( $results['tests'] ) ) { + $status = 0 === (int) $results['failures'] && 0 === (int) $results['errors'] ? 'Passed' : 'Failed'; + $status_title = (int) $results['tests'] . ' tests, ' . (int) $results['failures'] . ' failed, ' . (int) $results['errors'] . ' errors'; + } + $host = 'Unknown'; + $user = get_user_by( 'id', $report->post_author ); + if ( $user ) { + $host = ''; + if ( ! empty( $user->user_url ) ) { + $host .= ''; + } + $host .= get_avatar( + $user->ID, + 18, + '', + '', + array( + 'extra_attr' => 'style="vertical-align: middle;margin-right:5px;"', + ) + ); + if ( ! empty( $user->user_url ) ) { + $host .= ''; + } + if ( ! empty( $user->user_url ) ) { + $host .= ''; + } + $host .= $user->display_name; + if ( ! empty( $user->user_url ) ) { + $host .= ''; + } + } + ?> + post_author ): ?> + + + + + + + + + + post_author; + endforeach; + else : + ?> + + + + + + + +
+ + r + +
StatusPHP VersionDatabase Version
+ +
ID ) ); ?>ID ) ); ?>
+ No reports for changeset. +
diff --git a/src/class-display.php b/src/class-display.php index a1429c6..1ec3039 100644 --- a/src/class-display.php +++ b/src/class-display.php @@ -74,7 +74,7 @@ public static function filter_the_content( $content ) { ); } else { $content = ptr_get_template_part( - 'result-set', + 'result-set-single', array( 'posts_per_page' => 500, 'revisions' => array( @@ -95,7 +95,7 @@ public static function render_results( $atts ) { $output = ''; $query_args = array( - 'posts_per_page' => 3, + 'posts_per_page' => 20, 'post_type' => 'result', 'post_parent' => 0, 'orderby' => 'post_name', @@ -121,7 +121,7 @@ public static function render_results( $atts ) { $output .= self::get_reporter_avatars(); } $output .= ptr_get_template_part( - 'result-set', + 'result-set-all', array( 'posts_per_page' => 50, 'revisions' => $rev_query->posts, @@ -142,7 +142,7 @@ public static function get_display_css() { ob_start(); ?>