示例#1
0
 /**
  * Add a comment on GitHub.
  *
  * @param   TrackerProject  $project      The project.
  * @param   integer         $issueNumber  The issue number.
  * @param   string          $comment      The comment to add.
  * @param   string          $userName     The username.
  * @param   DatabaseDriver  $database     The database driver object.
  *
  * @return  Comment  The GitHub comment object
  *
  * @throws \DomainException
  *
  * @since  1.0
  */
 public function addComment(TrackerProject $project, $issueNumber, $comment, $userName, DatabaseDriver $database)
 {
     $data = new Comment();
     if ($project->gh_user && $project->gh_project) {
         $gitHubResponse = $this->gitHub->issues->comments->create($project->gh_user, $project->gh_project, $issueNumber, $comment);
         if (!isset($gitHubResponse->id)) {
             throw new \DomainException('Invalid response from GitHub');
         }
         $data->created_at = $gitHubResponse->created_at;
         $data->opened_by = $gitHubResponse->user->login;
         $data->comment_id = $gitHubResponse->id;
         $data->text_raw = $gitHubResponse->body;
         $data->text = $this->gitHub->markdown->render($comment, 'gfm', $project->gh_user . '/' . $project->gh_project);
     } else {
         $date = new Date();
         $data->created_at = $date->format($database->getDateFormat());
         $data->opened_by = $userName;
         $data->comment_id = '???';
         $data->text_raw = $comment;
         $data->text = $this->gitHub->markdown->render($comment, 'markdown');
     }
     (new ActivityModel($database))->addActivityEvent('comment', $data->created_at, $data->opened_by, $project->project_id, $issueNumber, $data->comment_id, $data->text, $data->text_raw);
     $data->activities_id = $database->insertid();
     $date = new Date($data->created_at);
     $data->created_at = $date->format('j M Y');
     return $data;
 }
 /**
  * Add a new event and store it to the database.
  *
  * @param   string   $event       The event name.
  * @param   string   $dateTime    Date and time.
  * @param   string   $userName    User name.
  * @param   integer  $projectId   Project id.
  * @param   integer  $itemNumber  THE item number.
  * @param   integer  $commentId   The comment id
  * @param   string   $text        The parsed html comment text.
  * @param   string   $textRaw     The raw comment text.
  *
  * @return  $this
  *
  * @since   1.0
  */
 protected function addActivityEvent($event, $dateTime, $userName, $projectId, $itemNumber, $commentId = null, $text = '', $textRaw = '')
 {
     $data = array();
     $date = new Date($dateTime);
     $data['created_date'] = $date->format($this->db->getDateFormat());
     $data['event'] = $event;
     $data['user'] = $userName;
     $data['project_id'] = (int) $projectId;
     $data['issue_number'] = (int) $itemNumber;
     $data['gh_comment_id'] = (int) $commentId;
     $data['text'] = $text;
     $data['text_raw'] = $textRaw;
     try {
         $activity = new ActivitiesTable($this->db);
         $activity->save($data);
     } catch (\Exception $exception) {
         $this->logger->info(sprintf('Error storing %s activity to the database (ProjectId: %d, ItemNo: %d): %s', $event, $projectId, $itemNumber, $exception->getMessage()));
         $this->getContainer()->get('app')->close();
     }
     return $this;
 }
示例#3
0
 /**
  * Tests the Joomla\Database\DatabaseDriver::getDateFormat method.
  *
  * @return  void
  *
  * @since   1.0
  */
 public function testGetDateFormat()
 {
     $this->assertThat($this->instance->getDateFormat(), $this->equalTo('Y-m-d H:i:s'));
 }