/**
  * Add a Github repository
  *
  * @return void
  * @return null
  **/
 function add()
 {
     if (!Repository::canAdd($this->logged_user, $this->active_project)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $repository_data = $this->request->post('repository');
     if (!is_array($repository_data)) {
         $repository_data = array('visibility' => $this->active_project->getDefaultVisibility());
     }
     // if
     if ($this->request->isSubmitted()) {
         $repository_data['name'] = trim($repository_data['name']) == '' ? $repository_data['url'] : $repository_data['name'];
         $this->active_repository->setAttributes($repository_data);
         $this->active_repository->setBody(clean(array_var($repository_data, 'url', null)));
         $this->active_repository->setProjectId($this->active_project->getId());
         $this->active_repository->setCreatedBy($this->logged_user);
         $this->active_repository->setState(STATE_VISIBLE);
         $result = $this->active_repository->testRepositoryConnection();
         if ($result === true) {
             $save = $this->active_repository->save();
             if ($save && !is_error($save)) {
                 flash_success(lang('Project repository ":name" has been added successfully'), array('name' => $this->active_repository->getName()));
                 $this->redirectToUrl(github_module_url($this->active_project));
             } else {
                 $save->errors['-- any --'] = $save->errors['body'];
                 $this->smarty->assign('errors', $save);
             }
             //if
         } else {
             $errors = new ValidationErrors();
             $errors->addError(lang('Failed to connect to repository: :message', array('message' => $result)));
             $this->smarty->assign('errors', $errors);
         }
         // if
     }
     // if
     $this->smarty->assign(array('repository_data' => $repository_data));
 }
/**
 * Handle on prepare project overview event
 *
 * @param NamedList $tabs
 * @param User $logged_user
 * @param Project $project
 * @return null
 */
function github_handle_on_project_tabs(&$tabs, &$logged_user, &$project)
{
    $tabs->add('github', array('text' => lang('Github'), 'url' => github_module_url($project)));
}