public function do_execute() { /* Prepare variables */ try { $project_id = $this->getProvidedArgument('projectid'); $project_row = TBGProjectsTable::getTable()->getById($project_id, false); TBGContext::setScope(new TBGScope($project_row[TBGProjectsTable::SCOPE])); $project = new TBGProject($project_id, $project_row); } catch (Exception $e) { throw $e; $this->cliEcho("The project with the ID " . $this->getProvidedArgument('projectid') . " does not exist\n", 'red', 'bold'); exit; } $author = $this->getProvidedArgument('author'); $new_rev = $this->getProvidedArgument('revno'); $commit_msg = $this->getProvidedArgument('log'); $changed = $this->getProvidedArgument('changed'); $old_rev = $this->getProvidedArgument('oldrev', null); $date = $this->getProvidedArgument('date', null); $branch = $this->getProvidedArgument('branch', null); if (TBGSettings::get('access_method_' . $project->getKey()) == TBGVCSIntegration::ACCESS_HTTP) { $this->cliEcho("This project uses the HTTP access method, and so access via the CLI has been disabled\n", 'red', 'bold'); exit; } if ($old_rev === null && !is_integer($new_rev)) { $this->cliEcho("Error: if only the new revision is specified, it must be a number so that old revision can be calculated from it (by substracting 1 from new revision number)."); } else { if ($old_rev === null) { $old_rev = $new_rev - 1; } } $output = TBGVCSIntegration::processCommit($project, $commit_msg, $old_rev, $new_rev, $date, $changed, $author, $branch); $this->cliEcho($output); }
public function runAddCommitGitorious(TBGRequest $request) { TBGContext::getResponse()->setContentType('text/plain'); TBGContext::getResponse()->renderHeaders(); $passkey = TBGContext::getRequest()->getParameter('passkey'); $project_id = urldecode(TBGContext::getRequest()->getParameter('project_id')); $project = TBGContext::factory()->TBGProject($project_id); // Validate access if (!$project) { echo 'Error: The project with the ID ' . $project_id . ' does not exist'; exit; } if (TBGSettings::get('access_method_' . $project->getID(), 'vcs_integration') == TBGVCSIntegration::ACCESS_DIRECT) { echo 'Error: This project uses the CLI access method, and so access via HTTP has been disabled'; exit; } if (TBGSettings::get('access_passkey_' . $project->getID(), 'vcs_integration') != $passkey) { echo 'Error: The passkey specified does not match the passkey specified for this project'; exit; } // Validate data $data = html_entity_decode(TBGContext::getRequest()->getParameter('payload', null, false)); if (empty($data) || $data == null) { die('Error: No payload was provided'); } $entries = json_decode($data); if ($entries == null) { die('Error: The payload could not be decoded'); } $entries = json_decode($data); $previous = $entries->before; // Branch is stored in the ref $ref = $entries->ref; $parts = explode('/', $ref); if (count($parts) == 3) { $branch = $parts[2]; } else { $branch = null; } // Parse each commit individually foreach (array_reverse($entries->commits) as $commit) { $email = $commit->author->email; $author = $commit->author->name; $new_rev = $commit->id; $old_rev = $previous; $commit_msg = $commit->message; $time = strtotime($commit->timestamp); // Add commit echo TBGVCSIntegration::processCommit($project, $commit_msg, $old_rev, $previous, $time, "", $author, $branch); $previous = $new_rev; exit; } }