Inheritance: implements Iterator
Example #1
0
 /**
  * {@inheritDoc}
  **/
 public function getIssues($statuses, $offset = 0, $limit = 500, $sort = 'id')
 {
     $statusIds = $this->convertStatusesToIds($statuses);
     $walker = new Issues\Walker($this->api);
     $statusFilter = implode(' OR ', array_map(function ($id) {
         return 'status = ' . $id;
     }, $statusIds));
     $walker->push("{$statusFilter} ORDER BY {$sort}");
     $result = [];
     foreach ($walker as $issue) {
         $branches = [];
         $date = '20990101';
         foreach ($issue->getFields() as $fieldName => $value) {
             $matches = [];
             if (is_string($fieldName) && preg_match("/Branch \\((.*)\\)/", $fieldName, $matches) && !empty($value)) {
                 $branch = trim($value);
                 $branches[$matches[1]] = $branch;
                 $currentDate = substr($branch, 4, 8);
                 //get date from the branch
                 if ($currentDate < $date) {
                     $date = $currentDate;
                 }
             }
         }
         $result[$issue->getKey()] = ['id' => $issue->getKey(), 'author' => $issue->getReporter()['displayName'], 'asignee' => $issue->getAssignee()['displayName'], 'subject' => $issue->getSummary(), 'status' => $this->statusIdsFlipped[$issue->getStatus()['id']], 'date' => empty($branches) ? null : date('Y-m-d', strtotime($date)), 'branches' => $branches, 'issueTracker' => $this];
     }
     return $result;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $api = $this->getContainer()->get('git_automation.jira_api');
     $permanentBranches = ['dev', 'master', 'facebook'];
     $branches = $this->git->branches();
     $branches = array_filter(array_map(function ($val) use($permanentBranches) {
         $val = trim($val);
         if (in_array($val, $permanentBranches)) {
             return false;
         }
         $val = preg_replace("/_.*/i", "", $val);
         if (strpos($val, '-') > 1 && strpos($val, '-') < strlen($val) - 1) {
             return $val;
         }
         return false;
     }, $branches));
     $walker = new Walker($api);
     $query = 'key IN ("' . implode('","', $branches) . '")';
     $walker->push($query);
     /** @var \chobie\Jira\Issue $issue */
     $deleted = [];
     foreach ($walker as $issue) {
         $closedStatuses = ["approved", "awaiting for check", "closed (won't fix)", "closed success"];
         if (in_array(strtolower($issue->getStatus()['name']), $closedStatuses)) {
             $output->writeln($issue->getKey() . ' is closed ');
             $this->git->branchDelete($issue->getKey(), true);
             $deleted[] = $issue->getKey();
         } else {
             $output->writeln($issue->getKey() . ' is ' . $issue->getStatus()['name']);
         }
     }
     if (!empty($deleted)) {
         $this->git->deleteRemoteBranches($deleted);
     }
 }
Example #3
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $api = new Api(getenv('JIRA_URL'), new Basic(getenv('JIRA_USERNAME'), getenv('JIRA_PASSWORD')));
     $search = $input->getArgument('search');
     $walker = new Walker($api);
     $walker->push("text ~ '{$search}' ORDER BY status ASC");
     $rows = $this->buildRows($walker);
     $table = new Table($output);
     $table->setHeaders(['Key', 'Summary', 'Status', 'Link'])->setRows($rows)->render();
 }
Example #4
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';
 }
Example #5
0
 /**
  * Returns issues.
  *
  * @param string  $jql               JQL.
  * @param string  $link_name         Link name.
  * @param integer $link_direction    Link direction.
  * @param array   $link_project_keys Link project keys.
  *
  * @return array
  */
 public function getIssues($jql, $link_name, $link_direction, array $link_project_keys)
 {
     $this->_buildCustomFieldsMap();
     $walker = new Walker($this->jiraApi);
     $walker->push($jql, implode(',', $this->_getQueryFields()));
     $ret = array();
     foreach ($walker as $issue) {
         foreach ($link_project_keys as $link_project_key) {
             $linked_issue = $this->_getLinkedIssue($issue, $link_name, $link_direction, $link_project_key);
             if (is_object($linked_issue) && $this->isAlreadyProcessed($issue, $linked_issue)) {
                 continue;
             }
             $ret[] = array($issue, $linked_issue, $link_project_key);
         }
     }
     return $ret;
 }
 public function register(Application $app)
 {
     $app['jira.api.client'] = $app->share(function ($app) {
         return new JiraGuzzleClient($app['jira.oauth.client']);
     });
     if (empty($this->config['basic_auth'])) {
         $auth = new Anonymous();
     } else {
         $auth = new Basic($this->config['basic_auth']['username'], $this->config['basic_auth']['password']);
     }
     $app['jira.api'] = $app->share(function ($app) use($auth) {
         $client = new Api($this->config['base_url'], $auth, $app['jira.api.client']);
         return $client;
     });
     $app['jira.api.walker'] = $app->protect(function ($jql) use($app) {
         $walker = new Walker($app['jira.api']);
         $walker->push($jql, "*navigable");
         return $walker;
     });
 }