/** * Method to insert data for an issue from GitHub * * @return void * * @since 1.0 */ protected function insertIssue() { // Try to render the description with GitHub markdown $parsedText = $this->parseText($this->hookData->issue->body); // Prepare the dates for insertion to the database $dateFormat = $this->db->getDateFormat(); $opened = new Date($this->hookData->issue->created_at); $modified = new Date($this->hookData->issue->updated_at); $data = array(); $data['issue_number'] = $this->hookData->issue->number; $data['title'] = $this->hookData->issue->title; $data['description'] = $parsedText; $data['description_raw'] = $this->hookData->issue->body; $data['status'] = $this->hookData->issue->state == 'open' ? 1 : 10; $data['opened_date'] = $opened->format($dateFormat); $data['opened_by'] = $this->hookData->issue->user->login; $data['modified_date'] = $modified->format($dateFormat); $data['project_id'] = $this->project->project_id; $data['build'] = $this->hookData->repository->default_branch; // Add the closed date if the status is closed if ($this->hookData->issue->closed_at) { $closed = new Date($this->hookData->issue->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->hookData->issue->title, $matches)) { $data['foreign_number'] = $matches[1]; } elseif (preg_match('/tracker_item_id=([0-9]+)/', $this->hookData->issue->body, $matches)) { $data['foreign_number'] = $matches[1]; } // Process labels for the item $data['labels'] = $this->processLabels($this->hookData->issue->number); try { $table = new IssuesTable($this->db); $table->save($data); } catch (\Exception $e) { $this->logger->error(sprintf('Error adding GitHub issue %s/%s #%d to the tracker: %s', $this->project->gh_user, $this->project->gh_project, $this->hookData->issue->number, $e->getMessage())); $this->getContainer()->get('app')->close(); } $this->triggerEvent('onCommentAfterCreateIssue', $table); // Pull the user's avatar if it does not exist $this->pullUserAvatar($this->hookData->issue->user->login); // Add a close record to the activity table if the status is closed if ($this->hookData->issue->closed_at) { $this->addActivityEvent('close', $data['closed_date'], $this->hookData->sender->login, $this->project->project_id, $this->hookData->issue->number); } // Store was successful, update status $this->logger->info(sprintf('Added GitHub issue %s/%s #%d to the tracker.', $this->project->gh_user, $this->project->gh_project, $this->hookData->issue->number)); }
/** * Add the item. * * @param array $src The source. * * @return $this * * @since 1.0 */ public function add(array $src) { // Store the issue $table = new IssuesTable($this->db); $table->save($src); // Store the saved issue id for category. $state = $this->getState(); $state->set('issue_id', $table->id); $this->setState($state); /* @todo see issue #194 Store the activity $table = new ActivitiesTable($this->db); $src['event'] = 'open'; $src['user'] = $src['opened_by']; $table->save($src);*/ return $this; }
/** * Updates a pull request title to include the JoomlaCode ID if it exists * * @param object $hookData Hook data payload * @param Github $github Github object * @param Logger $logger Logger object * @param object $project Object containing project data * @param IssuesTable $table Table object * * @return void * * @since 1.0 */ protected function updatePullTitle($hookData, Github $github, Logger $logger, $project, IssuesTable $table) { // If the title already has the ID in it, then no need to do anything here if (preg_match('/\\[#([0-9]+)\\]/', $hookData->pull_request->title, $matches)) { return; } // If we don't have a foreign ID, we can't do anything here if (is_null($table->foreign_number)) { return; } // Define the new title $title = '[#' . $table->foreign_number . '] ' . $table->title; try { $github->pulls->edit($project->gh_user, $project->gh_project, $hookData->pull_request->number, $title); // Post the new label on the object $logger->info(sprintf('Updated the title for GitHub pull request %s/%s #%d', $project->gh_user, $project->gh_project, $hookData->pull_request->number)); } catch (\DomainException $e) { $logger->error(sprintf('Error updating the title for GitHub pull request %s/%s #%d - %s', $project->gh_user, $project->gh_project, $hookData->pull_request->number, $e->getMessage())); // Don't change the title locally return; } // Update the local title now try { $data = ['title' => $title]; $table->save($data); } catch (\Exception $e) { $logger->error(sprintf('Error updating the title for issue %s/%s #%d on the tracker: %s', $project->gh_user, $project->gh_project, $hookData->issue->number, $e->getMessage())); } }
/** * Method to update data for an issue from GitHub * * @return boolean True on success * * @since 1.0 */ protected function updateData() { // Figure out the state based on the action $action = $this->hookData->action; $status = $this->processStatus($action); // Try to render the description with GitHub markdown $parsedText = $this->parseText($this->hookData->issue->body); // Prepare the dates for insertion to the database $dateFormat = $this->db->getDateFormat(); $modified = new Date($this->hookData->issue->updated_at); // Only update fields that may have changed, there's no API endpoint to show that so make some guesses $data = array(); $data['title'] = $this->hookData->issue->title; $data['description'] = $parsedText; $data['description_raw'] = $this->hookData->issue->body; if (!is_null($status)) { $data['status'] = $status; } $data['modified_date'] = $modified->format($dateFormat); $data['modified_by'] = $this->hookData->sender->login; // Add the closed date if the status is closed if ($this->hookData->issue->closed_at) { $closed = new Date($this->hookData->issue->closed_at); $data['closed_date'] = $closed->format($dateFormat); } // Process labels for the item $data['labels'] = $this->processLabels($this->hookData->issue->number); try { $table = new IssuesTable($this->db); $table->load(array('issue_number' => $this->hookData->issue->number, 'project_id' => $this->project->project_id)); $table->save($data); } catch (\Exception $e) { $this->logger->error(sprintf('Error updating GitHub issue %s/%s #%d in the tracker: %s', $this->project->gh_user, $this->project->gh_project, $this->hookData->issue->number, $e->getMessage())); $this->getContainer()->get('app')->close(); } $this->triggerEvent('onIssueAfterUpdate', $table); // Add a reopen record to the activity table if the status is closed if ($action == 'reopened') { $this->addActivityEvent('reopen', $this->hookData->issue->updated_at, $this->hookData->sender->login, $this->project->project_id, $this->hookData->issue->number); } // Add a close record to the activity table if the status is closed if ($this->hookData->issue->closed_at) { $this->addActivityEvent('close', $this->hookData->issue->closed_at, $this->hookData->sender->login, $this->project->project_id, $this->hookData->issue->number); } // Store was successful, update status $this->logger->info(sprintf('Updated GitHub issue %s/%s #%d to the tracker.', $this->project->gh_user, $this->project->gh_project, $this->hookData->issue->number)); return true; }