Пример #1
0
 /**
  * Prepare the response.
  *
  * @return  void
  *
  * @since   1.0
  * @throws  \Exception
  */
 protected function prepareResponse()
 {
     /* @type \JTracker\Application $application */
     $application = $this->getContainer()->get('app');
     $user = $application->getUser();
     $project = $application->getProject();
     if (!$user->id) {
         throw new \Exception('You are not allowed to test this item.');
     }
     $issueId = $application->input->getUint('issueId');
     $result = $application->input->getUint('result');
     if (!$issueId) {
         throw new \Exception('No issue ID received.');
     }
     $issueModel = new IssueModel($this->getContainer()->get('db'));
     $data = new \stdClass();
     $data->testResults = $issueModel->saveTest($issueId, $user->username, $result);
     $event = (new ActivityModel($this->getContainer()->get('db')))->addActivityEvent('test_item', 'now', $user->username, $project->project_id, $issueModel->getIssueNumberById($issueId), null, json_encode($result));
     $data->event = new \stdClass();
     foreach ($event as $k => $v) {
         $data->event->{$k} = $v;
     }
     $data->event->text = json_decode($data->event->text);
     $this->response->data = json_encode($data);
     $this->response->message = g11n3t('Test successfully added');
 }
Пример #2
0
 /**
  * Prepare the response.
  *
  * @return  void
  *
  * @since   1.0
  * @throws  \Exception
  */
 protected function prepareResponse()
 {
     /* @type \JTracker\Application $application */
     $application = $this->getContainer()->get('app');
     $user = $application->getUser();
     $project = $application->getProject();
     if (!$user->check('edit')) {
         throw new \Exception('You are not allowed to alter this item.');
     }
     $issueId = $application->input->getUint('issueId');
     if (!$issueId) {
         throw new \Exception('No issue ID received.');
     }
     $this->dispatcher = $application->getDispatcher();
     $this->addEventListener('tests');
     $this->setProjectGitHubBot($project);
     $data = new \stdClass();
     $result = new \stdClass();
     $result->user = $application->input->getUsername('user');
     $result->value = $application->input->getUint('result');
     $issueModel = new IssueModel($this->getContainer()->get('db'));
     $data->testResults = $issueModel->saveTest($issueId, $result->user, $result->value);
     $issueNumber = $issueModel->getIssueNumberById($issueId);
     $event = (new ActivityModel($this->getContainer()->get('db')))->addActivityEvent('alter_testresult', 'now', $user->username, $project->project_id, $issueNumber, null, json_encode($result));
     $this->triggerEvent('onTestAfterSubmit', ['issueNumber' => $issueNumber, 'data' => $data->testResults]);
     $data->event = new \stdClass();
     foreach ($event as $k => $v) {
         $data->event->{$k} = $v;
     }
     $data->event->text = json_decode($data->event->text);
     $this->response->data = json_encode($data);
     $this->response->message = g11n3t('Test successfully added');
 }
Пример #3
0
 /**
  * Prepare the response.
  *
  * @return  void
  *
  * @since   1.0
  * @throws  \Exception
  */
 protected function prepareResponse()
 {
     /* @type \JTracker\Application $application */
     $application = $this->getContainer()->get('app');
     $user = $application->getUser();
     $project = $application->getProject();
     if (!$user->id) {
         throw new \Exception('You are not allowed to test this item.');
     }
     $issueId = $application->input->getUint('issueId');
     $result = $application->input->getUint('result');
     $userComment = $application->input->get('comment', '', 'raw');
     $sha = $application->input->getCmd('sha');
     if (!$issueId) {
         throw new \Exception('No issue ID received.');
     }
     $this->dispatcher = $application->getDispatcher();
     $this->addEventListener('tests');
     $this->setProjectGitHubBot($project);
     $issueModel = new IssueModel($this->getContainer()->get('db'));
     $data = new \stdClass();
     $data->testResults = $issueModel->saveTest($issueId, $user->username, $result, $sha);
     $issueNumber = $issueModel->getIssueNumberById($issueId);
     $event = (new ActivityModel($this->getContainer()->get('db')))->addActivityEvent('test_item', 'now', $user->username, $project->project_id, $issueNumber, null, json_encode($result));
     $this->triggerEvent('onTestAfterSubmit', ['issueNumber' => $issueNumber, 'data' => $data->testResults]);
     $data->event = new \stdClass();
     foreach ($event as $k => $v) {
         $data->event->{$k} = $v;
     }
     $data->event->text = json_decode($data->event->text);
     $gitHubHelper = new GitHubHelper($this->getContainer()->get('gitHub'));
     // Create a comment to submitted on GitHub.
     switch ($result) {
         case 0:
             $comment = 'I have not tested this item.';
             break;
         case 1:
             $comment = 'I have tested this item :white_check_mark: successfully on ' . $sha;
             break;
         case 2:
             $comment = 'I have tested this item :red_circle: unsuccessfully on ' . $sha;
             break;
         default:
             throw new \UnexpectedValueException('Unexpected test result value.');
             break;
     }
     $comment .= $userComment ? '<br /><br />' . $userComment : '';
     $comment .= $gitHubHelper->getApplicationComment($application, $project, $issueNumber);
     $data->comment = $gitHubHelper->addComment($project, $issueNumber, $comment, $user->username, $this->getContainer()->get('db'));
     $this->response->data = json_encode($data);
     $this->response->message = g11n3t('Test successfully added');
 }
Пример #4
0
 /**
  * Prepare the response.
  *
  * @return  void
  *
  * @since   1.0
  * @throws  \Exception
  */
 protected function prepareResponse()
 {
     /* @type \JTracker\Application $application */
     $application = $this->getContainer()->get('app');
     $user = $application->getUser();
     if (!$user->id) {
         throw new \Exception('You are not allowed to test this item.');
     }
     $issueId = $application->input->getUint('issueId');
     $result = $application->input->getUint('result');
     if (!$issueId) {
         throw new \Exception('No issue ID received.');
     }
     $model = new IssueModel($this->getContainer()->get('db'));
     $this->response->data = json_encode($model->saveTest($issueId, $user->username, $result));
     $this->response->message = g11n3t('Test successfully added');
 }