Example #1
0
 /**
  * @param $ticketId
  * @param $repository
  * @param $assignee
  * @return bool
  * @throws \Zendesk\API\MissingParametersException
  * @throws \Zendesk\API\ResponseException
  * @internal param $ticket
  */
 public function createIssue($ticketId, $repository, $assignee)
 {
     $this->logger->debug(sprintf('entering issue creation for ticket #%s in repo %s', $ticketId, $repository));
     if ($this->isKnownTicket($ticketId)) {
         throw new \InvalidArgumentException('this ticket is already known, cant create twice');
     }
     try {
         $ticket = $this->zClient->ticket($ticketId)->find();
     } catch (\Exception $e) {
         $this->logger->error($this->zClient->getDebug()->lastResponseHeaders);
         return false;
     }
     if (!is_object($ticket->ticket)) {
         throw new \InvalidArgumentException('unable to find zendesk ticket with id ' . $ticketId);
     }
     try {
         $issueDatas = $this->formatIssueDatas($ticket->ticket, $assignee);
         $username = isset($this->config['github_organization']) ? $this->config['github_organization'] : $this->config['github_username'];
         $issue = $this->gClient->issue()->create($username, $repository, $issueDatas);
         if (isset($issue['number'])) {
             $this->updateTicketAfterIssueCreation($ticketId, $issue, $repository);
             $this->persistCreatedTicket($ticketId, $issue['number'], $repository);
             return true;
         } else {
             $this->logger->error('unable to find issue number from github payload');
             throw new \Exception('unable to find created issue Id');
         }
     } catch (\Exception $e) {
         $this->logger->error($e->getMessage());
         return false;
     }
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function getIssues(array $criteria = ['state' => 'open'])
 {
     list($username, $repo) = explode('/', $this->getName());
     $pager = new ResultPager($this->client);
     $issues = $pager->fetchAll($this->client->issue(), 'all', [$username, $repo, $criteria]);
     $newIssues = [];
     foreach ($issues as $issue) {
         $newIssues[] = new GithubIssue($issue);
     }
     return $newIssues;
 }
Example #3
0
 public function it_returns_Issue_objects_on_getIssues(Client $client, Issue $api, HttpClient $http, Response $response)
 {
     $client->issue()->willReturn($api);
     $client->getHttpClient()->willReturn($http);
     $api->getPerPage()->willReturn(5);
     $api->setPerPage(Argument::any())->willReturn();
     $http->getLastResponse()->willReturn($response);
     $response->getHeader('Link')->willReturn(null);
     $api->all('foo', 'bar', ['state' => 'open'])->willReturn([['number' => 1], ['number' => 5]]);
     $result = $this->getIssues();
     $result->shouldBeArray();
     $result->shouldHaveCount(2);
     $result[0]->shouldHaveType('Rs\\Issues\\Github\\GithubIssue');
     $result[0]->getId()->shouldBe(1);
     $result[1]->shouldHaveType('Rs\\Issues\\Github\\GithubIssue');
     $result[1]->getId()->shouldBe(5);
 }
Example #4
0
 public function deleteMilestone($repository, $number)
 {
     $this->assertAuthenticated();
     $array = explode('/', $repository, 2);
     $this->github->issue()->milestones()->remove($array[0], $array[1], $number);
 }