diff --git a/modules/simplytest_tugboat/assets/simplytest_tugboat_status.js b/modules/simplytest_tugboat/assets/simplytest_tugboat_status.js index aaade81..7163704 100644 --- a/modules/simplytest_tugboat/assets/simplytest_tugboat_status.js +++ b/modules/simplytest_tugboat/assets/simplytest_tugboat_status.js @@ -31,6 +31,7 @@ }, 1000); $('.percentage', progressbar).html(data.percent + '%'); $('.message', progressbar).html(data.message); + $('.log', progressbar).html(data.instanceLog); if (data.percent == 100) { // Putting in an intentional delay to let the tugboat API return the URL and STM to process it. diff --git a/modules/simplytest_tugboat/simplytest_tugboat.instance_status.inc b/modules/simplytest_tugboat/simplytest_tugboat.instance_status.inc index a264472..7dfeca1 100644 --- a/modules/simplytest_tugboat/simplytest_tugboat.instance_status.inc +++ b/modules/simplytest_tugboat/simplytest_tugboat.instance_status.inc @@ -249,6 +249,11 @@ function simplytest_tugboat_status_progress_page($id) { '#percent' => $state['percent'], '#message' => $state['message'], ), + 'log' => array( + '#prefix' => '
', + '#suffix' => '
', + '#markup' => "", + ), ); } } @@ -332,6 +337,7 @@ function simplytest_tugboat_status_state($instance_id) { $status_code = FALSE; $percent = 0; $message = t('No instance status found...'); + $log = ''; if (!empty($statuses)) { $instance_status = array_pop($statuses); @@ -341,6 +347,7 @@ function simplytest_tugboat_status_state($instance_id) { $status_code = $status['code']; $percent = simplytest_tugboat_status_running_percentage($status['code']); $message = $status['message']; + $log = _simplytest_tugboat_get_log($instance_id); } } @@ -348,6 +355,7 @@ function simplytest_tugboat_status_state($instance_id) { 'code' => $status_code, 'percent' => $percent, 'message' => $message, + 'instanceLog' => $log, ]; } diff --git a/modules/simplytest_tugboat/simplytest_tugboat.module b/modules/simplytest_tugboat/simplytest_tugboat.module index b6d7a65..3b64732 100644 --- a/modules/simplytest_tugboat/simplytest_tugboat.module +++ b/modules/simplytest_tugboat/simplytest_tugboat.module @@ -222,6 +222,45 @@ function _simplytest_tugboat_launch_instance($submission) { simplytest_tugboat_status_goto($ref); } +/** + * Get instance log. + * + * @param $instance_id + */ +function _simplytest_tugboat_get_log($instance_id) { + $tugboat_repo = variable_get('tugboat_repository_id'); + + $return_data = array(); + $error_string = ''; + + // Check branch existence and status. + $state = simplytest_tugboat_status_state($instance_id); + + if ($state['code'] === FALSE) { + return; + } + // Get preview ID. + $context = simplytest_tugboat_context_load($instance_id); + + // Load the ID of the correct base preview ID. + $preview_id = simplytest_tugboat_load_preview_id($context, FALSE); + + // Run the tugboat command. + $command = "log $preview_id"; + watchdog('message', $command); + $return_status = _tugboat_execute($command, $return_data, $error_string); + $log = array(); + foreach ($return_data as $log_entry) { + $color = 'white'; + if ($log_entry['level'] == 'stderr') { + $color = 'red'; + } + $message = '

' . $log_entry['message'] . '

'; + $log[] = $message; + } + return $log; +} + /** * Call tugboat and start spawning the new instance. * @@ -254,7 +293,7 @@ function _simplytest_tugboat_execute_tugboat($instance_id) { simplytest_tugboat_status_update($instance_id, SIMPLYTEST_STATUS_PREPARE); // Load the ID of the correct base preview ID. - $base_preview_id = simplytest_tugboat_load_preview_id($context); + $base_preview_id = simplytest_tugboat_load_preview_id($context, TRUE); watchdog('message', 'Trying to load base preview ' . $base_preview_id); @@ -294,8 +333,12 @@ function _simplytest_tugboat_execute_tugboat($instance_id) { * @param $context * @return string */ -function simplytest_tugboat_load_preview_id($context) { - $branch_name = 'base-' . $context; +function simplytest_tugboat_load_preview_id($context, $base = TRUE) { + if ($base) { + $branch_name = 'base-' . $context; + } else { + $branch_name = $context; + } $previews = array(); $error_string = ''; $return_status = _tugboat_execute("ls previews", $previews, $error_string); @@ -306,11 +349,22 @@ function simplytest_tugboat_load_preview_id($context) { $max_id = NULL; // Find the most recent preview ID for the base. - $acceptable_states = array( - 'ready', - 'suspended', - 'refreshing', - ); + if ($base) { + $acceptable_states = array( + 'ready', + 'suspended', + 'refreshing', + ); + } else { + $acceptable_states = array( + 'building', + 'pending', + 'new', + 'ready', + 'suspended', + 'refreshing', + ); + } $repo = variable_get('simplytest_tugboat_github_repo'); $ns = variable_get('simplytest_tugboat_github_ns'); $repo_filter = 'https://github.com/' . $ns . '/' . $repo; @@ -329,9 +383,15 @@ function simplytest_tugboat_load_preview_id($context) { // Throw error if ID not found if (empty($max_id)) { - watchdog('simplytest_tugboat', 'No base preview for: %sid', array( - '%sid' => $context, - ), WATCHDOG_ERROR); + if ($base) { + watchdog('simplytest_tugboat', 'No base preview for: %sid', array( + '%sid' => $context, + ), WATCHDOG_ERROR); + } else { + watchdog('simplytest_tugboat', 'No preview for: %sid', array( + '%sid' => $context, + ), WATCHDOG_ERROR); + } } return $max_id; }