Skip to content

Commit

Permalink
[#jira] Handle invalid ticket IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
larowlan committed Jan 21, 2019
1 parent eb7539a commit 5e1bc55
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Commands/Start.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ protected function execute(InputInterface $input, OutputInterface $output) {
else {
$connector_id = $this->connector->spotConnector($ticket_id, $input, $output);
}
if (!$connector_id) {
throw new \InvalidArgumentException('No such ticket was found in any backends.');
}
if ($alias = $this->connector->loadAlias($ticket_id, $connector_id)) {
$ticket_id = $alias;
}
Expand Down
25 changes: 24 additions & 1 deletion src/Commands/Visit.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$output->writeln('<error>No active ticket, please use tl visit {ticket_id} to specifiy a ticket.</error>');
return;
}
$url = $this->connector->ticketUrl($issue_number, isset($data) ? $data->connector_id : $this->connector->spotConnector($issue_number, $input, $output));
$url = $this->connector->ticketUrl($issue_number, isset($data) ? $data->connector_id : $this->getConnector($input, $output, $issue_number));
$this->open($url, $output);
}

Expand Down Expand Up @@ -94,4 +94,27 @@ protected function open($url, OutputInterface $output) {
}
}

/**
* Gets connector ID.
* @param \Symfony\Component\Console\Input\InputInterface $input
* Input.
* @param \Symfony\Component\Console\Output\OutputInterface $output
* Output.
* @param mixed $issue_number
* Issue number.
*
* @return string
* Connector ID.
*
* @throws \InvalidArgumentException
* When no such ticket exists.
*/
protected function getConnector(InputInterface $input, OutputInterface $output, $issue_number) {
$connector_id = $this->connector->spotConnector($issue_number, $input, $output);
if (!$connector_id) {
throw new \InvalidArgumentException('No such ticket was found in any backends.');
}
return $connector_id;
}

}

0 comments on commit 5e1bc55

Please sign in to comment.