diff --git a/pift.cron.inc b/pift.cron.inc index 4358c69..d734ebe 100644 --- a/pift.cron.inc +++ b/pift.cron.inc @@ -65,7 +65,7 @@ function pift_cron_retest() { * Complete failure: $response === FALSE * Success: $response = array('branches' => array(), 'files' => array()); * - Items in branches sub-arrays are - * array(nid/rid of project release node => test id on qa) + * array(label_id for project branch/tag => test id on qa) * - Items in files sub-arrays are * array(fid of file => test id on qa) * Failure: $response = array('response' => 3, 'errors' => array()): @@ -86,7 +86,7 @@ function pift_cron_queue_batch() { break; } elseif (isset($response['branches']) && isset($response['files'])) { - // Store branch test IDs using the client_identifier (branch NID). + // Store branch test IDs using the client_identifier (tag/branch versioncontrol label ID). foreach ($batch['branches'] as $branch) { if (isset($response['branches'][$branch['client_identifier']])) { pift_test_sent($response['branches'][$branch['client_identifier']], PIFT_TYPE_RELEASE, $branch['client_identifier']); @@ -122,7 +122,7 @@ function pift_cron_queue_batch() { * * Structure of 'branches' sub-arrays: * - 'project_identifier' => nid of project node associated with branch. - * - 'client_identifier' => nid of project release node associated with branch. + * - 'client_identifier' => versioncontrol label id associated with a project branch/tag. * - 'vcs_identifier' => git branch to be tested (7.x, 7.x-1.x, etc). * - 'dependency' => comma-delimited list of project dependencies * - 'plugin_argument' => array of extra information to be delivered to test @@ -164,7 +164,7 @@ function pift_cron_queue_batch_build() { pift_cron_queue_batch_build_branches($branches); // $branches is just an array of array(rid => TRUE) for each - // release branch which is to be tested. + // versioncontrol label_id correesponding to the branch which is to be tested. // Process the required branches and add related projects. pift_cron_queue_batch_build_branches_process($batch, $branches, $projects); @@ -201,12 +201,21 @@ function pift_cron_queue_batch_build_files(array &$batch, array &$branches) { 'file_url' => file_create_url($file['filepath']), ); - - $branch_info_result = db_fetch_array(db_query('SELECT prn.nid AS rid, prn.version_major, prn.tag + /* Release_nid to Label_id Notes: JJT + * TODO + * Since sandbox issues don't have a 'version' set, we can't key off of + * project_issue rid, like the original query does. In fact, we don't + * have anything to link us to a specific release. We need to first check + * if a release exists, and is set ... and if not, we don't queue the file. + * Can we do this with a join on the query? + * + * For now, just going to enable branch tests, not patch tests. + */ + $branch_info_result = db_fetch_array(db_query('SELECT prn.nid AS rid, prn.version_major, prn.tag FROM {project_issues} pi, {project_release_nodes} prn WHERE pi.nid = %d AND pi.rid = prn.nid', $issue_nid)); - $item['branch_identifier'] = $branch_info_result['rid']; + $item['branch_identifier'] = $branch_info_result['rid']; // Store branch as needed to be included with data. $branches[$branch_info_result['rid']] = FALSE; // Do not test unless commit found. @@ -255,6 +264,152 @@ function pift_cron_queue_batch_build_branches_process(array &$batch, array &$bra // Include branch data for all dependency branches and those that require review. $branches_implied = array(); foreach ($branches as $rid => $test) { + + /* Release_nid to Label_id Notes: JJT + * + * This section needs to be completely refactored. We now have label_id instead of branch $rid. + * + * Project identifier: label_id (vcs_labels) -> repo_id -> nid (versioncontrol_project_projects) + * client_identifier: label_id (vcs_labels) + * vcs_identifier: name (vcs_labels) + * link: if in vcs_release_labels, use release_nid. If not, use project_nid + */ + $result = db_query('SELECT l.label_id, l.name, p.nid + FROM {versioncontrol_labels} l, {versioncontrol_project_projects} p + WHERE l.repo_id = p.repo_id and l.label_id = %d', $rid); + + while ($branchlabel = db_fetch_array($result)) { + $item = array( + 'project_identifier' => $branchlabel['nid'], + 'client_identifier' => $branchlabel['label_id'], + 'vcs_identifier' => $branchlabel['name'], + 'dependency' => '', + 'plugin_argument' => array(), + 'test' => $test, + ); + } + if (empty($item)) { + watchdog('pift', 'Invalid release ID [' . $rid . '] for test ID [' . $test['test_id'] . '].', WATCHDOG_ERROR); + continue; + } + + // Attempt to get release nid ... if not, use project nid to generate link + $result = db_query('SELECT release_nid from {versioncontrol_release_labels} + WHERE label_id = %d', $item['client_identifier']); + if ($rnid = db_result($result)) { + $item['link'] = url('node/' . $rnid, array('absolute' => TRUE)); + } + else { + $item['link'] = url('node/' . $item['project_identifier'], array('absolute' => TRUE)); + } + + // Attempt to determine the Drupal core API version + // If a release node is available, load it and check taxonomy terms + if ($rnid && ($branch = node_load($rid))) { + $api = array(); + foreach ($branch->taxonomy as $tid => $term) { + if (in_array($tid, $api_versions)) { + $api['version'] = array_shift(explode('.', $term->name, 2)); + break; + } + } + } + // If no release node available, try to guess based on label name + else { + $key = array_shift(str_split($item['vcs_identifier'], 1)); + if (in_array($key, array('6', '7', '8'))) { + $api['version'] = $key; + } + else { + watchdog('pift', 'Unable to determine core Drupal version for project nid: [@nid] branch: [@name].', array('@nid' => $item['project_identifier'], '@name' => $item['vcs_identifier']), WATCHDOG_ERROR); + continue; + } + } + + // If the project is Drupal core then add the plugin argument, otherwise + // determine the compatible core branch and add it as a dependency. + + if (PIFT_PID == $item['project_identifier']) { + $item['plugin_argument']['drupal.core.version'] = $api['version']; + } + else { + // Load the Drupal core API release (branch) compatible with this branch. + switch ($api['version']) { + case '6': + // Label for D6.x: 56 + $item['dependency'] = array('56' => '56'); + break; + case '7': + // Label for D7.x: 60 + $item['dependency'] = array('60' => '60'); + break; + case '8': + // Label for D8.x: 110792 + $item['dependency'] = array('110792' => '110792'); + break; + } + + /* Release_nid to Label_id Notes: JJT + * dependency_list_get keys of branch nid, but currently doesn't work. + * Not fixing it here for sandboxes without releases + * Need to consider in project_dependency changes. + */ + // Cycle through dependencies and add the related branches to the implied + // branch list if they are not already being processed. + if (!empty($branch)) { + $dependencies = project_info_dependency_list_get($branch->nid); + + // @TODO: Remove the following line which eliminates the findings of above + // code. + // Currently the project_info tables are not properly built. Example: + // token_example in Examples 6.x-1.x has dependency per + // project_info_dependency on token, but that dependency_id (453016) is + // not in the project_info_module table. + $dependencies = array(); + + foreach ($dependencies as $dependency) { + // Get label for dependency release id + $result = db_query("Select label_id from {versioncontrol_release_labels} where release_nid = %d", $dependency['rid']); + if (!($label_id = db_result($result))) { + watchdog('pift', 'Unable to determine vcs label id for release nid: [@nid].', array('@nid' => $dependency['rid']), WATCHDOG_ERROR); + } + else { + $item['dependency'][$label_id] = $label_id; + } + } + + // Check for branches as dependencies that are not in the list of + // processed branches. + foreach ($item['dependency'] as $lid) { + // Add branch to implied list for post-processing. + if (!isset($branches[$lid])) { + $branches_implied[$lid] = FALSE; + } + } + } + + // Ensure that not depending on self. + unset($item['dependency'][$rid]); + + // Flatten array of dependencies and fill in modules list. + $item['dependency'] = implode(',', $item['dependency']); + + /* Release_nid to Label_id Notes: JJT + * module_list_get keys of branch nid, which won't work for sandboxes without releases. + * Project_dependency should fix this, so not dealing with it for now. + */ + $item['plugin_argument']['drupal.modules'] = array_keys(project_info_module_list_get($branch->nid)); + } + + // Add item information to the batch. + $batch['branches'][] = $item; + + // Add branch's project to list to be loaded. + $projects[$item['project_identifier']] = $item['project_identifier']; + } + + /* Original Code + // Load branch release node. if (!($branch = node_load($rid))) { watchdog('pift', 'Invalid release ID [' . $rid . '] for test ID [' . $test['test_id'] . '].', WATCHDOG_ERROR); @@ -337,6 +492,7 @@ function pift_cron_queue_batch_build_branches_process(array &$batch, array &$bra // Add branch's project to list to be loaded. $projects[$branch->project_release['pid']] = $branch->project_release['pid']; } + */ // Post-process any implied branches. if ($branches_implied && $depth == 0) {