diff --git a/client/pifr_client.module b/client/pifr_client.module index 62064c6..ec49647 100644 --- a/client/pifr_client.module +++ b/client/pifr_client.module @@ -19,8 +19,7 @@ define('PIFR_CHART_REPOSITORY', variable_get('pifr_chart_repository', 'git://git define('PIFR_MULTIVARIATE_REPOSITORY', variable_get('pifr_multivariate_repository', 'git://git.drupal.org/project/multivariate.git')); define('PIFR_SIMPLETEST_REPOSITORY', variable_get('pifr_simpletest_repository', 'git://git.drupal.org/project/chart.git')); define('PIFR_MENU_REWRITE_REPOSITORY', variable_get('pifr_menu_rewrite_repository', 'git://git.drupal.org/project/menu_rewrite.git')); -define('PIFR_DRUPAL6_CURRENTBRANCH', '6.22'); -define('PIFR_DRUPAL7_CURRENTBRANCH', '7.x'); + /** * The location of the PHP executable to be used when running tests. diff --git a/client/pifr_client.review.inc b/client/pifr_client.review.inc index 58bdea4..a1afafe 100644 --- a/client/pifr_client.review.inc +++ b/client/pifr_client.review.inc @@ -1,7 +1,7 @@ 'fieldset', - '#title' => t('Test Type'), - ); - $form['testtype']['test'] = array( - '#type' => 'select', - '#title' => t('Select test plugin'), - '#options' => array( - 'simpletest' => t('SimpleTest'), - 'coder' => t('Code Review'), - ), - '#default_value' => 'pifr_simpletest', - '#description' => t('Represents the review plugin which will be invoked for this test.'), - ); - $form['testtype']['target'] = array( - '#type' => 'radios', - '#title' => t('Test Type'), - '#options' => array( - 'core' => 'Core', - 'branch' => 'Project Branch', - 'file' => 'File', - 'patch' => 'Patch', - ), - '#description' => t('Represents the object type which this code review will target.'), - '#default_value' => 'branch', - ); - $form['testtype']['selecttype'] = array( - '#type' => 'submit', - '#value' => t('Next >>'), - ); - - return $form; -} - -/** - * Client review form validation - */ -function pifr_client_review_form_validate($form, &$form_state) { - if (isset($form_state['storage']['plugin'])) { - switch ($form_state['storage']['plugin']) { - case 'coder': - // Coder Form Validation Steps - pifr_client_review_form_validate_coder($form, &$form_state); - break; - case 'simpletest': - default: - // Simpletest Form Validation Steps - pifr_client_review_form_validate_simpletest($form, &$form_state); - break; - } - } -} - -/** - * Client review form submission - */ -function pifr_client_review_form_submit($form, &$form_state) { - if ($form_state['clicked_button']['#id'] == 'edit-selecttype') { - // Handle plugin selection submission - $form_state['storage']['plugin'] = $form_state['values']['test']; - $form_state['storage']['target'] = $form_state['values']['target']; - } - else { - switch ($form_state['storage']['plugin']) { - case 'coder': - // Coder Form Submission Steps - pifr_client_review_form_submit_coder($form, $form_state); - break; - case 'simpletest': - default: - // Simpletest Form Submission Steps - pifr_client_review_form_submit_simpletest($form, $form_state); - break; - } - $form_state['rebuild'] = TRUE; - unset($form_state['storage']['plugin']); - - } -} - -/** - * Client simpletest review form. - */ -function pifr_client_review_form_simpletest(&$form_state) { $form = array(); $form['run'] = array( @@ -230,22 +131,14 @@ function pifr_client_review_form_simpletest(&$form_state) { } /** - * Validate the client simpletest review form. + * Run the pre-built tests. */ -function pifr_client_review_form_validate_simpletest($form, &$form_state) { - -} - -/** - * Submit the client simpletest review form. - */ -function pifr_client_review_form_submit_simpletest($form, &$form_state) { +function pifr_client_review_form_submit($form, &$form_state) { // Set the test variable so that the admin interface reacts accordingly. $test = pifr_client_review_pre_built_test($form_state['values']['type']); variable_set('pifr_client_test', $test); if ($review = pifr_client_review_load($test)) { - variable_set('pifr_client_test_start', time()); $review->run(); // Display test information. @@ -257,261 +150,7 @@ function pifr_client_review_form_submit_simpletest($form, &$form_state) { } /** - * Client coder review form. - */ -function pifr_client_review_form_coder(&$form_state) { - $form = array(); - - $form['runcoder'] = array( - '#type' => 'fieldset', - '#title' => t('Customize Coder Test Parameters'), - '#collapsible' => TRUE, - '#collapsed' => FALSE, - ); - - $form['runcoder']['version'] = array( - '#type' => 'select', - '#title' => t('Drupal Core Version'), - '#options' => array( - 'd6' => t('Drupal 6'), - 'd7' => t('Drupal 7'), - ), - '#default_value' => 'd7', - ); - - $reviews = array( - 'style' => t('Drupal Coding Standards'), - 'comment' => t('Drupal Commenting Standards'), - 'sql' => t('Drupal SQL Standards'), - 'security' => t('Drupal Security Standards'), - 'i18n' => t('Internationalization'), - 'coder_tough_love' => t('Coder Tough Love'), - ); - $form['runcoder']['reviews'] = array( - '#type' => 'checkboxes', - '#title' => t('Coder Reviews to run'), - '#options' => $reviews, - '#description' => t('Represents which Coder review components to enable for this test.'), - '#default_value' => array('style', 'comment', 'sql', 'security', 'i18n'), - ); - - $form['runcoder']['severity'] = array( - '#type' => 'radios', - '#title' => t('Coder Severity warning level'), - '#options' => array( - 'minor (most warnings)', - 'normal', - 'critical (fewest warnings)', - ), - '#default_value' => 1, - '#description' => t('Represents the severity level of errors which will be considered a failed test'), - ); - - switch ($form_state['storage']['target']) { - case 'core': - // No additional parameters required for a 'core' review - break; - default: - $form['branchtests'] = array( - '#type' => 'fieldset', - '#title' => t('Identify Review Target'), - '#collapsible' => FALSE, - ); - - $desc = t('Please enter the Git repository location for the project which contains the branch to test.'); - $desc .= ' ' . t('This may be a full project link such as git://git.drupal.org/project/drupal.git,'); - $desc .= ' ' . t('or a sandbox project link such as git://git.drupal.org/sandbox/username/12345678.git.'); - - $form['branchtests']['repository'] = array( - '#type' => 'textfield', - '#title' => t('Project Repository'), - '#description' => $desc, - ); - - $desc = t('Please indicate the branch for which you want to run the test.'); - $desc .= ' ' . t('This value must match an existing tag or branch within your Git repository.'); - $desc .= ' ' . t('(Valid entries are listed under the "tags" and "heads" labels on the project repository summary page.)'); - - $form['branchtests']['branch'] = array( - '#type' => 'textfield', - '#title' => t('Project Branch'), - '#description' => $desc, - ); - } - - // Add the 'file' or 'patch' form fields as needed - if ($form_state['storage']['target'] == 'file') { - - $desc = t('Please supply the name and path of the file (relative to the git project directory above) which you want code reviewed.'); - $desc .= ' ' . t('(For example, if you want to review the "needsreview.inc" file in your module "includes" directory, enter "includes/needsreview.inc".)'); - - $form['branchtests']['filename'] = array( - '#type' => 'textfield', - '#title' => t('Project File (Path + Name)'), - '#description' => $desc, - '#weight' => 5, - ); - } - elseif ($form_state['storage']['target'] == 'patch') { - $form['branchtests']['patchfile'] = array( - '#type' => 'file', - '#title' => t('Upload patch file'), - '#size' => 40, - ); - $form['#attributes']['enctype'] = "multipart/form-data"; - } - - - $form['op'] = array( - '#type' => 'submit', - '#value' => t('Run Test'), - ); - - return $form; -} - -/** - * Validate the client coder review form - */ -function pifr_client_review_form_validate_coder($form, &$form_state) { - // At least one coder review must be checked - if (count($form_state['values']['reviews']) < 1) { - form_set_error('reviews', 'Please select at least one coder review component'); - } - // Target-specific validation - - if (isset($form_state['storage']['target'])) { - switch ($form_state['storage']['target']) { - case 'patch': - if (isset($_FILES['files']) && is_uploaded_file($_FILES['files']['tmp_name']['patchfile'])) { - // Verify our local patches directory exists - $path = file_create_path("localpatches"); - file_check_directory($path, FILE_CREATE_DIRECTORY); - // Attempt to save the uploaded patch file - $file = file_save_upload('patchfile', array('pifr_client_validate_patchname' => array($_FILES['files'])), $path, FILE_EXISTS_REPLACE); - // Set error if file was not uploaded - if (!$file) { - form_set_error('patchfile', 'Error uploading patch file.'); - return; - } - // Set files to form_state for processing - $form_state['values']['file'] = $file; - } - default: - break; - } - } -} - -/** - * Validate patch file name - */ -function pifr_client_validate_patchname($files) { - if (substr($files->filename, strlen($files->filename) - 6, 6) != '.patch') { - return array('Invalid extension on patch file.'); - } - return array(); -} - -/** - * Submit the client coder review form - */ -function pifr_client_review_form_submit_coder($form, &$form_state) { - // Get the default arguments to be passed to client. - module_load_include('review.inc', 'pifr_server'); - $plugin = pifr_server_review_plugin_load('pifr_coder'); - $default = $plugin->argument_default_get(); - // Generate basic coder $test array - $test = array( - 'test_id' => 17, - 'review' => array( - 'plugin' => 'pifr_coder', - 'argument' => $default, - ), - 'vcs' => array( - 'main' => array( - 'repository' => array( - 'type' => 'git', - 'url' => variable_get('pifr_drupal_repository', 'git://git.drupal.org/project/drupal.git'), - ), - 'vcs_identifier' => variable_get('pifr_confirmation_vcs_id', '7.x'), - ), - 'dependencies' => array(), - ), - 'files' => array(), - ); - - // Update vcs_identifier - if ($form_state['values']['version'] == 'd6') { - $test['vcs']['main']['vcs_identifier'] = PIFR_DRUPAL6_CURRENTBRANCH; - $test['review']['argument']['drupal.core.version'] = 6; - } - elseif ($form_state['values']['version'] == 'd7') { - $test['vcs']['main']['vcs_identifier'] = PIFR_DRUPAL7_CURRENTBRANCH; - $test['review']['argument']['drupal.core.version'] = 7; - } - // Update with user-specific values - switch ($form_state['storage']['target']) { - case 'branch': - // Update the 'vcs' section with the project to be reviewed. - // No need to clone a full drupal install for code review! - $test['vcs']['main']['repository']['url'] = $form_state['values']['repository']; - $test['vcs']['main']['vcs_identifier'] = $form_state['values']['branch']; - break; - case 'file': - // Update the 'vcs' section with the project to be reviewed. - // No need to clone a full drupal install for code review! - $test['vcs']['main']['repository']['url'] = $form_state['values']['repository']; - $test['vcs']['main']['vcs_identifier'] = $form_state['values']['branch']; - $test['review']['argument']['test.files'][] = $form_state['values']['filename']; - break; - case 'patch': - $test['vcs']['main']['repository']['url'] = $form_state['values']['repository']; - $test['vcs']['main']['vcs_identifier'] = $form_state['values']['branch']; - // We stored the file in /localpatches in the files directory - $test['files'][] = file_create_url(file_create_path('localpatches') . '/' . $form_state['values']['file']->filename); - break; - default: - break; - } - - // Update coder.reviews - $test['review']['argument']['coder.reviews'] = $form_state['values']['reviews']; - - // Update coder.severity - switch ($form_state['values']['severity']) { - case 0: - $test['review']['argument']['coder.severity'] = SEVERITY_MINOR; - break; - case 1: - $test['review']['argument']['coder.severity'] = SEVERITY_NORMAL; - break; - case 2: - $test['review']['argument']['coder.severity'] = SEVERITY_CRITICAL; - break; - } - - variable_set('pifr_client_test', $test); - - if ($review = pifr_client_review_load($test)) { - variable_set('pifr_client_test_start', time()); - $review->run(); - - // Display test information. - drupal_set_message('Test: ' . pifr_client_review_export($test)); - drupal_set_message('Results: ' . pifr_client_review_export($review->get_result())); - - variable_del('pifr_client_test'); - variable_del('pifr_client_test_start'); - } - -} - - - - -/** - * Get a pre-built simpletest test, given the $type. + * Get a pre-built test, given the $type. * * @param string $type Test type, 'default', 'quick', 'fail', 'd6'. * @return array Pre-built test information array. @@ -547,7 +186,7 @@ function pifr_client_review_pre_built_test($type) { // Provide quickest test. if ($type == 'quick') { - $test['review']['argument']['simpletest.tests'] = array('NonDefaultBlockAdmin'); + $test['review']['argument']['tests'] = array('NonDefaultBlockAdmin'); } elseif ($type == 'fail') { $test['files'] = array( @@ -586,7 +225,7 @@ function pifr_client_review_pre_built_test($type) { 'type' => 'git', 'url' => variable_get('pifr_chart_repository', 'git://git.drupal.org/project/chart.git'), ), - 'vcs_identifier' => '6.x-1.3', // GITMIGRATION Fragile + 'vcs_identifier' => 'master', // GITMIGRATION Fragile ), ), ), diff --git a/client/review/db/mysql.inc b/client/review/db/mysql.inc index 5375fce..9cc0bb1 100644 --- a/client/review/db/mysql.inc +++ b/client/review/db/mysql.inc @@ -44,10 +44,8 @@ class pifr_client_db_interface_mysql implements pifr_client_db_interface { return FALSE; } $rows = array(); - if (!($result === TRUE)) { - while ($row = db_fetch_array($result)) { - $rows[] = $row; - } + while ($row = db_fetch_array($result)) { + $rows[] = $row; } db_set_active(); return $rows; diff --git a/client/review/db/pgsql.inc b/client/review/db/pgsql.inc index 982ad76..7be00ab 100644 --- a/client/review/db/pgsql.inc +++ b/client/review/db/pgsql.inc @@ -40,10 +40,8 @@ class pifr_client_db_interface_pgsql implements pifr_client_db_interface { if (db_set_active('pifr_checkout')) { $result = @db_query($sql); $rows = array(); - if (!($result === TRUE)) { - while ($row = db_fetch_array($result)) { - $rows[] = $row; - } + while ($row = db_fetch_array($result)) { + $rows[] = $row; } db_set_active(); return $rows; diff --git a/client/review/vcs/git.inc b/client/review/vcs/git.inc index dba74a7..167f2e2 100644 --- a/client/review/vcs/git.inc +++ b/client/review/vcs/git.inc @@ -119,8 +119,8 @@ class pifr_client_vcs_git extends pifr_client_vcs { */ public function apply($patch, $patch_level = 1, $check_only = FALSE) { $test_result = pifr_client_review::exec("git apply --check -p$patch_level $patch", TRUE); - if ($check_only) { - return ($test_result == 0); + if (!check_only) { + return (!$test_result != 0); } if ($test_result) { $this->patch_level = $patch_level; diff --git a/review/client.inc b/review/client.inc index 515c3a0..417da4e 100644 --- a/review/client.inc +++ b/review/client.inc @@ -151,9 +151,8 @@ abstract class pifr_client_review { require_once drupal_get_path('module', 'pifr_server') . '/pifr_server.review.inc'; $plugin = pifr_server_review_plugin_load($test['review']['plugin']); $plugin->init(); - - $pluginops = $plugin->operation_get_all(); - $this->operations = array_splice($pluginops, 0, -2); + + $this->operations = array_splice($plugin->operation_get_all(), 0, -2); $this->result_codes = array( 'fail' => count($this->operations) + 1, 'pass' => count($this->operations) + 2, diff --git a/review/coder/confirmation/fail.patch b/review/coder/confirmation/fail.patch index 80f1e54..3e87073 100644 --- a/review/coder/confirmation/fail.patch +++ b/review/coder/confirmation/fail.patch @@ -1,13 +1,3 @@ -From 856c1d5aaeeb21504e96b90ae3dda35c6464499d Mon Sep 17 00:00:00 2001 -From: Jeremy Thorson -Date: Fri, 1 Jul 2011 14:52:42 -0500 -Subject: [PATCH] New Coder Fail.Patch Confirmation file - ---- - coder.php | 10 ++++++++++ - 1 files changed, 10 insertions(+), 0 deletions(-) - create mode 100644 coder.php - diff --git a/coder.php b/coder.php new file mode 100644 index 0000000..9e7e776 diff --git a/review/coder/confirmation/pass.patch b/review/coder/confirmation/pass.patch index 126799c..ac020af 100644 --- a/review/coder/confirmation/pass.patch +++ b/review/coder/confirmation/pass.patch @@ -1,13 +1,3 @@ -From 65d3bf5cec9ca2f7f2388049b1824cc639664fbb Mon Sep 17 00:00:00 2001 -From: Jeremy Thorson -Date: Fri, 1 Jul 2011 14:44:19 -0500 -Subject: [PATCH] New Coder Confirmation Pass File. - ---- - coder.php | 5 +++++ - 1 files changed, 5 insertions(+), 0 deletions(-) - create mode 100644 coder.php - diff --git a/coder.php b/coder.php new file mode 100644 index 0000000..07b27be diff --git a/review/coder/pifr_coder.client.inc b/review/coder/pifr_coder.client.inc index f7f348f..2961f64 100644 --- a/review/coder/pifr_coder.client.inc +++ b/review/coder/pifr_coder.client.inc @@ -48,7 +48,7 @@ class pifr_client_review_pifr_coder extends pifr_client_review_pifr_drupal { // Get the review information for the selected reviews. $reviews = _coder_reviews(); foreach ($reviews as $key => $review) { - if (!in_array($key, $this->arguments['coder.reviews'], TRUE)) { + if (!in_array($key, $this->arguments['coder.reviews'])) { unset($reviews[$key]); } } @@ -64,11 +64,6 @@ class pifr_client_review_pifr_coder extends pifr_client_review_pifr_drupal { '#include_extensions' => _coder_get_reviews_extensions($php_extensions, $reviews), ); - // Update the Coder severity level if desired - if (!empty($this->arguments['coder.severity'])) { - $args['#severity'] = $this->arguments['coder.severity']; - } - // Cycle through all relevant files and perform review. $files = $this->syntax_ignore($this->file_list()); diff --git a/review/drupal/pifr_drupal.client.inc b/review/drupal/pifr_drupal.client.inc index 3633b56..cf82163 100644 --- a/review/drupal/pifr_drupal.client.inc +++ b/review/drupal/pifr_drupal.client.inc @@ -47,64 +47,59 @@ class pifr_client_review_pifr_drupal extends pifr_client_review { pifr_debug('Test(%test_id) request received:
%test
', array('%test_id' => $this->test['test_id'], '%test' => print_r($test, TRUE))); $this->log('core_url = [' . $this->core_url . ']; Test repository = [' . $this->test['vcs']['main']['repository']['url'] . ']'); - - - - if ($this->test['review']['plugin'] == 'pifr_simpletest') { - if ($this->test['vcs']['main']['repository']['url'] != $this->core_url) { - // Main repository is not core, so this must be a module test. Move the - // module repository (main) to the dependencies and find the core - // repository in the dependencies and move it to main. - $this->test['vcs']['dependencies'][] = $this->test['vcs']['main']; - - // Store the project name 'simpletest' for use when applying patches. - $this->project_directory = basename($this->test['vcs']['main']['repository']['url']); - $this->project_directory = preg_replace('/\.git$/', '', $this->project_directory); - $this->log('Project directory is [' . $this->project_directory . ']'); - - - foreach ($this->test['vcs']['dependencies'] as $key => $dependency) { - if ($dependency['repository']['url'] == $this->arguments['drupal.core.url']) { - $this->test['vcs']['main'] = $dependency; - unset($this->test['vcs']['dependencies'][$key]); - break; - } + if ($this->test['vcs']['main']['repository']['url'] != $this->core_url) { + // Main repository is not core, so this must be a module test. Move the + // module repository (main) to the dependencies and find the core + // repository in the dependencies and move it to main. + $this->test['vcs']['dependencies'][] = $this->test['vcs']['main']; + + // Store the project name 'simpletest' for use when applying patches. + $this->project_directory = basename($this->test['vcs']['main']['repository']['url']); + $this->project_directory = preg_replace('/\.git$/', '', $this->project_directory); + $this->log('Project directory is [' . $this->project_directory . ']'); + + + foreach ($this->test['vcs']['dependencies'] as $key => $dependency) { + if ($dependency['repository']['url'] == $this->arguments['drupal.core.url']) { + $this->test['vcs']['main'] = $dependency; + unset($this->test['vcs']['dependencies'][$key]); + break; } } + } - // Add SimpleTest as dependencies, unless it has already been added. - if ($this->test['review']['argument']['drupal.core.version'] == 6) { - $simpletest_url = variable_get('pifr_simpletest_repository', 'git://git.drupal.org/project/simpletest.git'); - $found = FALSE; - foreach ($this->test['vcs']['dependencies'] as $key => $dependency) { - if ($dependency['repository']['url'] == $simpletest_url) { - $found = TRUE; - break; - } - } - - if (!$found) { - // Since SimpleTest is not included in Drupal 6 it needs to be checked - // out from contrib. - $this->test['vcs']['dependencies'][] = array( - 'repository' => array( - 'type' => 'git', - 'url' => $simpletest_url, - ), - 'vcs_identifier' => '6.x-2.x', - ); + // Add SimpleTest as dependencies, unless it has already been added. + if ($this->test['review']['argument']['drupal.core.version'] == 6) { + $simpletest_url = variable_get('pifr_simpletest_repository', 'git://git.drupal.org/project/simpletest.git'); + $found = FALSE; + foreach ($this->test['vcs']['dependencies'] as $key => $dependency) { + if ($dependency['repository']['url'] == $simpletest_url) { + $found = TRUE; + break; } } - - // Set the dependency directory. - $this->arguments['test.directory.dependency'] = $this->module_directory; - - // If the main project is not Drupal core then all patches should be - // applied from the root of the primary dependency or project directory. - if (!empty($this->project_directory)) { - $this->arguments['test.directory.apply'] = $this->module_directory . '/' . $this->project_directory; + + if (!$found) { + // Since SimpleTest is not included in Drupal 6 it needs to be checked + // out from contrib. + $this->test['vcs']['dependencies'][] = array( + 'repository' => array( + 'type' => 'git', + 'url' => $simpletest_url, + ), + 'vcs_identifier' => '6.x-2.x', + ); } } + + // Set the dependency directory. + $this->arguments['test.directory.dependency'] = $this->module_directory; + + // If the main project is not Drupal core then all patches should be + // applied from the root of the primary dependency or project directory. + if (!empty($this->project_directory)) { + $this->arguments['test.directory.apply'] = $this->module_directory . '/' . $this->project_directory; + } } diff --git a/review/simpletest/pifr_simpletest.client.inc b/review/simpletest/pifr_simpletest.client.inc index e756085..4e0d4af 100644 --- a/review/simpletest/pifr_simpletest.client.inc +++ b/review/simpletest/pifr_simpletest.client.inc @@ -126,11 +126,6 @@ class pifr_client_review_pifr_simpletest extends pifr_client_review_pifr_drupal // @TODO: Temporary until #22336 is committed. $run_tests = file_exists('scripts/run-tests.sh') ? 'scripts/run-tests.sh' : 'core/scripts/run-tests.sh'; $url = escapeshellarg(url('', array('absolute' => TRUE)) . 'checkout'); - // Attempt to clear out any tables from previous runs - if (!$this->exec(PIFR_CLIENT_PHP . ' ./' . $run_tests . ' --php ' . PIFR_CLIENT_PHP . ' --clean')) { - $this->set_error(array('@reason' => t('failed during invocation of run-tests.sh --clean'))); - return; - } if (!$this->exec(PIFR_CLIENT_PHP . ' ./' . $run_tests . ' --concurrency ' . PIFR_CLIENT_CONCURRENCY . ' --php ' . PIFR_CLIENT_PHP . ' --url ' . $url . ' ' . $test_list)) { $this->set_error(array('@reason' => t('failed during invocation of run-tests.sh'))); @@ -296,9 +291,6 @@ class pifr_client_review_pifr_simpletest extends pifr_client_review_pifr_drupal * @return array Associative array of test info keyed by test case. */ protected function test_info_parse() { - if (!is_array($this->output)) { - $this->output = explode("\n", $this->output); - } $this->output = array_slice($this->output, 4); $group = 'Unknown'; $info = array();