Esempio n. 1
0
 public function handle2()
 {
     $enabled = ['aa', 'bb', 'zz', 'cc'];
     $enabled2 = ['zz', 'vv'];
     $disabled = ['bb'];
     $merge = array_diff(array_unique(array_merge($enabled, $enabled2)), $disabled);
     $api = new Api('https://projects.radic.nl', new \chobie\Jira\Api\Authentication\Basic(env('JIRA_USERNAME'), env('JIRA_PASSWORD')));
     $walker = new Walker($api);
     $walker->push('project = "Codex"');
     $p = $api->getProjects();
     $issueTypes = $api->getIssueTypes();
     $a = 'a';
 }
Esempio n. 2
0
 /**
  * Get versions of a project.
  *
  * @param string  $project_key    Project key.
  * @param integer $cache_duration Cache duration.
  *
  * @return array|false
  */
 public function getVersions($project_key, $cache_duration = 0)
 {
     $cache_key = __METHOD__ . '(' . $project_key . ')';
     $cached_value = $this->cache->fetch($cache_key);
     if ($cached_value === false) {
         $cached_value = parent::getVersions($project_key);
         $this->cache->save($cache_key, $cached_value, $cache_duration);
     }
     return $cached_value;
 }
Esempio n. 3
0
 /**
  * Make API request
  *
  * @param string $method
  * @param string $url
  * @param array  $data
  * @param bool   $asJson
  * @param bool   $isFile
  * @param bool   $debug
  * @return JiraLib\Api\Result
  */
 public function api($method = Api::REQUEST_GET, $url = '', $data = array(), $asJson = false, $isFile = false, $debug = false)
 {
     $result = parent::api($method, $url, $data, true, $isFile, $debug);
     if ($result) {
         $this->processErrors($result);
         if (!$asJson) {
             $result = new Api\Result($result);
         }
     }
     return $result;
 }
Esempio n. 4
0
 /**
  * Add a comment in JIRA with the commit hash
  * @param Commit $commit The commit for which we're running the Git Hook
  * @throws GitHookException if requirement fails
  */
 public function run(Commit $commit)
 {
     /** @var \Bart\GitHook\GitHookConfig $hConfigs */
     $hConfigs = Diesel::create('\\Bart\\GitHook\\GitHookConfig', $commit);
     // Apply template to produce desired comment for JIRA issue
     $template = $hConfigs->jiraCommentTemplate();
     $count = preg_match_all('/\\%s/', $template);
     $this->logger->debug("Loaded jira template --{$template}-- and found {$count} token(s)");
     $vsprintf_args = [];
     if ($count !== false) {
         $vsprintf_args = array_fill(0, $count, $commit->revision());
     }
     $comment = vsprintf($template, $vsprintf_args);
     $jiraIssues = $commit->jiras();
     $this->logger->debug('Found ' . count($jiraIssues) . " jira issue(s) in {$commit}");
     foreach ($jiraIssues as $jira) {
         $this->logger->debug("Adding comment to jira {$jira}");
         $this->jiraClient->addComment($jira->id(), $comment);
     }
 }
Esempio n. 5
0
 /**
  * {@inheritDoc}
  **/
 public function changeStatus($id, $status, $comment = '')
 {
     static $statusTransitions = [];
     if (empty($statusTransitions)) {
         $transitions = $this->api->getTransitions($id, [])->getResult()['transitions'];
         $statusTransitions = [];
         foreach ($transitions as $transition) {
             $statusTransitions[$transition['to']['id']] = $transition['id'];
         }
     }
     $statusId = $this->convertStatusToId($status);
     $params = ['transition' => ['id' => $statusTransitions[$statusId]]];
     try {
         $this->api->transition($id, $params);
         $this->api->addComment($id, $comment);
     } catch (\Exception $ex) {
         return false;
     }
     return true;
 }
Esempio n. 6
0
 public function testGetPriorities()
 {
     $response = file_get_contents(__DIR__ . '/resources/api_priority.json');
     $this->expectClientCall(Api::REQUEST_GET, '/rest/api/2/priority', array(), $response);
     $actual = $this->api->getPriorities();
     $response_decoded = json_decode($response, true);
     $expected = array('1' => $response_decoded[0], '5' => $response_decoded[1]);
     $this->assertEquals($expected, $actual);
     // Second time we call the method the results should be cached and not trigger an API Request.
     $this->client->sendRequest(Api::REQUEST_GET, '/rest/api/2/priority', array(), self::ENDPOINT, $this->credential)->shouldNotBeCalled();
     $this->assertEquals($expected, $this->api->getPriorities(), 'Calling twice did not yield the same results');
 }
Esempio n. 7
0
 /**
  * Checks if current position is valid.
  *
  * @return boolean The return value will be casted to boolean and then evaluated.
  *                 Returns true on success or false on failure.
  * @throws \Exception When "Walker::push" method wasn't called.
  * @throws Api\UnauthorizedException When it happens.
  * @link   http://php.net/manual/en/iterator.valid.php
  */
 public function valid()
 {
     if (is_null($this->jql)) {
         throw new \Exception('you have to call Jira_Walker::push($jql, $fields) at first');
     }
     if (!$this->executed) {
         try {
             $result = $this->api->search($this->getQuery(), $this->key(), $this->perPage, $this->fields);
             $this->setResult($result);
             $this->executed = true;
             if ($result->getTotal() == 0) {
                 return false;
             }
             return true;
         } catch (Api\UnauthorizedException $e) {
             throw $e;
         } catch (\Exception $e) {
             error_log($e->getMessage());
             return false;
         }
     } else {
         if ($this->offset >= $this->max && $this->key() < $this->total) {
             try {
                 $result = $this->api->search($this->getQuery(), $this->key(), $this->perPage, $this->fields);
                 $this->setResult($result);
                 return true;
             } catch (Api\UnauthorizedException $e) {
                 throw $e;
             } catch (\Exception $e) {
                 error_log($e->getMessage());
                 return false;
             }
         } else {
             if (($this->startAt - 1) * $this->perPage + $this->offset < $this->total) {
                 return true;
             } else {
                 return false;
             }
         }
     }
 }
Esempio n. 8
0
 /**
  * @param $jira
  */
 private function addLabels($jira)
 {
     $params = ['fields' => ['labels' => self::$labels]];
     $this->jiraClient->editIssue($jira->id(), $params);
 }
Esempio n. 9
0
 /**
  * query issues
  *
  * @param $jql
  * @param $startAt
  * @param $maxResult
  * @param string $fields
  *
  * @return \chobie\Jira\Api\Result
  */
 public function search($jql, $startAt = 0, $maxResult = 20, $fields = '*navigable')
 {
     return parent::search($jql, $startAt, $maxResult, $fields);
 }