/** * Check if the project id or identifier is valid. * * @param int|string $project_id * @return int|bool */ private function checkProject($project_id) { $project = $this->client->api('project')->show($project_id); if (!isset($project['project']['id'])) { return false; } return $project['project']['id']; }
/** * Load user data from API. * * @param $id */ public function loadUser($id, $reset = FALSE) { if (!isset($this->users[$id]) || $reset) { $user = $this->client->api('user')->show($id); if (!empty($user['user'])) { $this->users[$id] = new User($this, $user['user']); } } return $this->users[$id]; }
/** * iterates over a list of issues and deletes them using their Ids. * * @param array $issues The Issue List * @param \Redmine\Api\Issue $issueApi The Issue Api object, optional. * * @return void */ private function deleteIssueList(array $issues, \Redmine\Api\Issue $issueApi = null) { $issueApi = $issueApi ?: $this->client->api('issue'); /* @var $issueApi \Redmine\Api\Issue */ foreach ($issues['issues'] as $issue) { $issueApi->remove($issue['id']); } }
/** * Create follow up issue to given issue * * @param array $issue */ public function createAction($issue) { $redmineClient = new Redmine\Client($this->settings['Redmine']['url'], $this->settings['Redmine']['apiKey']); $id = $issue['related_id']; unset($issue['related_id']); $params = $issue; // get additional issue data and assign to new issue $res = $redmineClient->api('issue')->show($id); $params['project_id'] = Arrays::getValueByPath($res, 'issue.project.id'); $params['category_id'] = Arrays::getValueByPath($res, 'issue.category.id'); $newIssue = $redmineClient->api('issue')->create($params); // create relation $relation['issue_to_id'] = $id; $relation['relation_type'] = self::RELATION_TYPE; $json = json_encode(array('relation' => $relation)); $redmineClient->post('/issues/' . (string) $newIssue->id . '/relations.json', $json); $this->view->assign('value', json_decode(json_encode((array) $newIssue), 1)); }
/** * Factory method to be implemented from \RedmineCommand\AbstractCommand . * * * Must return an instance of \RedmineCommand\SlackResult . * * @see \RedmineCommand\AbstractCommand::executeImpl() * @return \RedmineCommand\SlackResult */ protected function executeImpl() { $log = $this->log; $result = new SlackResult(); $log->debug("CmdShow: Issues Id: " . implode(",", $this->cmd)); $client = new Client($this->config->redmine_url, $this->config->redmine_api_key); $resultText = "[requested by " . $this->post["user_name"] . "]"; if (empty($this->cmd)) { $resultText .= " Issue number required!"; } else { $resultText .= " Issue Details: "; } // Fetching issues and adding them as slack attachments $attachments = array(); $attachmentUnknown = null; foreach ($this->cmd as $issueId) { $log->debug("CmdShow: calling Redmine api for issue id #{$issueId}"); $issue = $client->api('issue')->show((int) $issueId); $attachment = new SlackResultAttachment(); if (!is_array($issue)) { if (strcmp($issue, "Syntax error") == 0) { if ($attachmentUnknown == null) { $attachmentUnknown = new SlackResultAttachment(); $attachmentUnknown->setTitle("Unknown Issues:"); $attachmentUnknown->setText(""); } $log->debug("CmdShow: #{$issueId} issue unknown!"); $attachmentUnknown->setText($attachmentUnknown->getText() . " {$issueId}"); } } else { $log->debug("CmdShow: #{$issueId} issue found!"); $attachment = Util::convertIssueToAttachment($this->config->getRedmineIssuesUrl(), $issueId, $issue); $attachments[] = $attachment; } } $result->setText($resultText); if ($attachmentUnknown != null) { $attachments[] = $attachmentUnknown; } $result->setAttachmentsArray($attachments); return $result; }
/** * @covers Redmine\Client * @test * @dataProvider getApiClassesProvider */ public function shouldGetApiInstance($apiName, $class) { $client = new Client('http://test.local', 'asdf'); $this->assertInstanceOf($class, $client->api($apiName)); }
function it_presents_a_summary_before_initiating_the_migration(Client $redmine, Project $project) { $project_detail = ['project' => ['name' => 'Redmine Project']]; $redmine->api('project')->willReturn($project); $project->show(34)->willReturn($project_detail); $mock = PHPMockery::mock('\\Ttf\\Remaim', 'fgets')->andReturn('y'); $phabricator_project = ['name' => 'Phabricator Project', 'id' => 78]; $policies = ['view' => 'PHID-foobar', 'edit' => 'PHID-barbaz']; $tasks = ['total_count' => [10]]; ob_start(); $this->presentSummary(34, $phabricator_project, $tasks, $policies)->shouldReturn(true); $output = ob_get_clean(); expect($output)->toBe(PHP_EOL . PHP_EOL . '####################' . PHP_EOL . '# Pre-flight check #' . PHP_EOL . '####################' . PHP_EOL . 'Redmine project named "Redmine Project" with ID 34.' . PHP_EOL . 'Target phabricator project named "Phabricator Project" with ID 78.' . PHP_EOL . 'View policy: PHID-foobar, Edit policy: PHID-barbaz' . PHP_EOL . '10 tickets to be migrated!' . PHP_EOL . PHP_EOL . 'OK to continue? [y/N]:' . PHP_EOL . '> '); }