Пример #1
0
 /**
  * Method to insert data for an issue from GitHub
  *
  * @return  boolean  True on success
  *
  * @since   1.0
  */
 protected function insertData()
 {
     // Figure out the state based on the action
     $action = $this->hookData->action;
     $status = $this->processStatus($action);
     $parsedText = $this->parseText($this->data->body);
     // Prepare the dates for insertion to the database
     $dateFormat = $this->db->getDateFormat();
     $opened = new Date($this->data->created_at);
     $modified = new Date($this->data->updated_at);
     $data = array();
     $data['issue_number'] = $this->data->number;
     $data['title'] = $this->data->title;
     $data['description'] = $parsedText;
     $data['description_raw'] = $this->data->body;
     $data['status'] = is_null($status) ? 1 : $status;
     $data['opened_date'] = $opened->format($dateFormat);
     $data['opened_by'] = $this->data->user->login;
     $data['modified_date'] = $modified->format($dateFormat);
     $data['modified_by'] = $this->hookData->sender->login;
     $data['project_id'] = $this->project->project_id;
     $data['has_code'] = 1;
     $data['build'] = $this->data->base->ref;
     // Add the closed date if the status is closed
     if ($this->data->closed_at) {
         $closed = new Date($this->data->closed_at);
         $data['closed_date'] = $closed->format($dateFormat);
         $data['closed_by'] = $this->hookData->sender->login;
     }
     // If the title has a [# in it, assume it's a JoomlaCode Tracker ID
     if (preg_match('/\\[#([0-9]+)\\]/', $this->data->title, $matches)) {
         $data['foreign_number'] = $matches[1];
     } elseif (preg_match('/tracker_item_id=([0-9]+)/', $this->data->body, $matches)) {
         $data['foreign_number'] = $matches[1];
     }
     // Process labels for the item
     $data['labels'] = $this->processLabels($this->data->number);
     $model = new IssueModel($this->db);
     try {
         $model->setProject(new TrackerProject($this->db, $this->project))->add($data);
     } catch (\Exception $e) {
         $this->logger->error(sprintf('Error adding GitHub pull request %s/%s #%d to the tracker: %s', $this->project->gh_user, $this->project->gh_project, $this->data->number, $e->getMessage()));
         $this->getContainer()->get('app')->close();
     }
     // Get a table object for the new record to process in the event listeners
     $table = (new IssuesTable($this->db))->load($model->getState()->get('issue_id'));
     $this->triggerEvent('onPullAfterCreate', $table, array('action' => $action));
     // Pull the user's avatar if it does not exist
     $this->pullUserAvatar($this->data->user->login);
     // Add a reopen record to the activity table if the action is reopened
     if ($action == 'reopened') {
         $this->addActivityEvent('reopen', $data['modified_date'], $this->hookData->sender->login, $this->project->project_id, $this->data->number);
     }
     // Add a close record to the activity table if the status is closed
     if ($this->data->closed_at) {
         $this->addActivityEvent('close', $data['closed_date'], $this->hookData->sender->login, $this->project->project_id, $this->data->number);
     }
     // Store was successful, update status
     $this->logger->info(sprintf('Added GitHub pull request %s/%s #%d (Database ID #%d) to the tracker.', $this->project->gh_user, $this->project->gh_project, $this->data->number, $table->id));
     return true;
 }