%d'. $where, time() - $interval, $rid)); } function drupalorg_versioncontrol_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { if (isset($node->type) && $node->type == 'project_project') { // Quick one-off to ensure path aliases are correct. if (in_array($op, array('insert', 'update')) && !empty($node->project['sandbox'])) { // Clear existing alias for the sandbox, it's guaranteed to be wrong. path_set_alias("node/$node->nid"); // Set the one with the git_username $user = user_load($node->uid); path_set_alias("node/$node->nid", "sandbox/{$user->git_username}/{$node->project['uri']}", NULL, isset($node->language) ? $node->language : ''); } $function = 'drupalorg_versioncontrol_nodeapi_' . $op; if (function_exists($function)) { return $function($node, $a3, $a4); } } } function drupalorg_versioncontrol_nodeapi_insert(&$node, $a3 = NULL, $a4 = NULL) { if ($node->project['sandbox']) { $user = user_load($node->uid); $top_path = "sandbox/{$user->git_username}/{$node->project['uri']}"; } else { $top_path = "project/{$node->project['uri']}"; } $repo_root = variable_get('drupalorg_git_basedir', '/var/git') . '/repositories/' . $top_path . '.git'; $description = 'For more information about this repository, visit the project page at ' . url('node/' . $node->nid, array('absolute' => TRUE)); $data = new stdClass(); $data->name = $node->project['uri']; $data->root = $repo_root; $data->vcs = 'git'; $data->plugins = array( 'auth_handler' => 'account', // We can't rely on the $conf default for this b/c vc_project doesn't respect it ); $data->project_nid = $node->nid; $data->update_method = 1; $backend = versioncontrol_get_backends('git'); $repo = $backend->buildEntity('repo', $data); // Grab the auth handler just so we know the class is loaded. $repo->getAuthHandler(); $auth_data = array( 'access' => VersioncontrolAuthHandlerMappedAccounts::ALL, 'branch_create' => VersioncontrolAuthHandlerMappedAccounts::DENY, 'branch_update' => VersioncontrolAuthHandlerMappedAccounts::DENY, 'branch_delete' => VersioncontrolAuthHandlerMappedAccounts::DENY, 'tag_create' => VersioncontrolAuthHandlerMappedAccounts::DENY, 'tag_update' => VersioncontrolAuthHandlerMappedAccounts::DENY, 'tag_delete' => VersioncontrolAuthHandlerMappedAccounts::DENY, 'per-label' => array() ); $job = array( 'operation' => array( // Create the repo on disk. 'init' => array(), // Save repo record to db, creating a repo_id. 'save' => array(), // Save user auth data. 'setUserAuthData' => array($node->uid, $auth_data), // Set the project description. 'setDescription' => array($description), ), 'repository' => $repo, ); drupal_queue_include(); $queue = DrupalQueue::get('versioncontrol_repomgr'); if (!$queue->createItem($job)) { $error_info = array( '%nid' => $node->nid, '%op' => $op, ); drupal_set_message(t('An error occurred while attempting to enqueue your repository for creation. Please file an issue in the infrastructure queue.'), 'error'); watchdog('drupalorg_versioncontrol', t("Failed to enqueue Git repository creation job for node '%nid'.", $error_info)); } else { drupal_set_message(t('The Git repository for this project has been enqueued for creation. It should be available in a few seconds.')); } } function drupalorg_versioncontrol_nodeapi_delete(&$node, $a3 = NULL, $a4 = NULL) { if (!$node->versioncontrol_project['repo'] instanceof VersioncontrolGitRepository) { watchdog('drupalorg_versioncontrol', 'No repo found for project %title when deleting node.', array('%title' => $node->title), WATCHDOG_WARNING); return; } $repo = $node->versioncontrol_project['repo']; $job = array( 'operation' => 'delete', 'repository' => $repo, ); drupal_queue_include(); $queue = DrupalQueue::get('versioncontrol_repomgr'); if (!$queue->createItem($job)) { $error_info = array( '%nid' => $node->nid, ); drupal_set_message(t('Failed to enqueue Git repository for deletion.'), 'error'); watchdog('drupalorg_versioncontrol', t("Failed to enqueue repository deletion job for node '%nid'.", $error_info)); } else { drupal_set_message(t('Git repository enqueued for deletion.')); } } /** * Implements hook_project_promote_sandbox(). * * Project has been promoted to a full project, relocate it on disk. */ function drupalorg_versioncontrol_project_promote_sandbox($project) { if (empty($project->versioncontrol_project['repo']) || !$project->versioncontrol_project['repo'] instanceof VersioncontrolGitRepository) { watchdog('drupalorg_versioncontrol', t("Trying to enqueue sandbox promotion job for node '%nid', but no repo attached to node.", $error_info)); return; } $repo = $project->versioncontrol_project['repo']; // Update the name to the new project shortname. $repo->name = $project->project['uri']; // Just in case, until dbtng fixes hook_query_alter(). $repo->project_nid = $project->nid; $job = array( 'operation' => array( // Relocate the repo on disk and update the repo root. 'move' => array(variable_get('drupalorg_git_basedir', '/var/git') . '/repositories/project/' . $project->project['uri'] . '.git'), // The repository needs to be reinit-ed with project hooks, replacing the old sandbox hooks. // FIXME replacing the config file means we lose any custom settings. Make this more robust. 'reInit' => array(array('hooks', 'config')), // Update the description 'setDescription' => array('For more information about this repository, visit the project page at ' . url('node/' . $project->nid, array('absolute' => TRUE))), // Save the updated repo entry to the db. 'save' => array(), ), 'repository' => $repo, ); drupal_queue_include(); $queue = DrupalQueue::get('versioncontrol_repomgr'); if (!$queue->createItem($job)) { watchdog('drupalorg_versioncontrol', t("Failed to enqueue promotion of sandbox '%shortname'.", array('%shortname' => $project->uri))); } } /** * Implements views hook_views_default_views_alter(). */ function drupalorg_versioncontrol_views_default_views_alter(&$views) { // Link #123 pattern on operation messages to issues at drupal.org $views_with_tracker_url = array( // versioncontrol default views (commitlog) 'commitlog_repository_commits', 'commitlog_individual_commit', 'commitlog_global_commits', 'commitlog_user_commits', // versioncontrol_git default views 'vc_git_individual_commit', // versioncontrol_project default views 'vc_git_project_commit_view', 'vc_git_project_global_commits', 'vc_git_project_user_commits', 'vc_project_commit_view', 'vc_project_global_commits', 'vc_project_user_commits', ); foreach ($views_with_tracker_url as $view_name) { if (isset($views[$view_name])) { if (isset($views[$view_name]->display['default']->display_options['fields']['message']['issue_tracker_url'])) { $views[$view_name]->display['default']->display_options['fields']['message']['issue_tracker_url'] = 'http://drupal.org/node/%issue_id'; } // Use views_litepager and remove inner file listings, except on individual commit views. if ($view_name != 'commitlog_individual_commit' && $view_name != 'vc_git_individual_commit') { if (isset($views[$view_name]->display['default']->display_options)) { $views[$view_name]->display['default']->display_options['use_pager'] = 'lite'; } if (isset($views[$view_name]->display['default']->display_options['fields']['view'])) { unset($views[$view_name]->display['default']->display_options['fields']['view']); } } } } } /** * Implements hook_form_alter(). */ function drupalorg_versioncontrol_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'project_release_node_form' && !empty($form['error']) && !empty($form['retry'])) { $project = $form['project']['#value']; $msg = '' . t('No valid branches or tags found.') . ''; $msg .= '
' . t('Your release needs to have a tag or branch that follows the naming conventions and have no other release attached to it.') . '
'; $msg .= '' . t('Valid release tag examples:') . '
'; $examples = array('7.x-1.2', '7.x-2.0-alpha2', '7.x-2.0-beta3'); $msg .= theme('item_list', $examples); $msg .= '' . t('Valid release branch examples:') . '
'; $examples = array('7.x-1.x', '6.x-2.x'); $msg .= theme('item_list', $examples); $msg .= '' . t('For more help, see Creating a Tag or Branch in Git or the Git instructions page for your project.', array('@git_instructions_url' => url('node/' . $project->nid . '/git-instructions'))) . '
'; $msg .= '' . t('Once you have added a valid branch or tag, try again.', array('@retry' => url('node/add/project_release/' . $project->nid))) . '
'; $form['error']['#value'] = $msg; unset($form['retry']); } }