Skip to content

Commit

Permalink
try fixing comment #4, improve issue relations rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Zsolt Gál committed Nov 15, 2023
1 parent d7333f7 commit e7f20a1
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Technodelight/Jira/Connector/HoaConsole/Aggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct(array $autocompleters = [])
$this->autocompleters = $autocompleters;
}

public function __invoke(string $buffer, int $offset = 0): array
public function __invoke(string $buffer): array
{
$words = explode(' ', $buffer);
$word = end($words);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ public function __construct(Issue $issue, Api $api)

public function complete(string $prefix): ?array
{
return $this->getAutocompletedValues($this->getMatchesForPrefix($this->issue, $prefix));
if (preg_match('/'. $this->getWordDefinition().'/', $prefix)) {
return $this->getAutocompletedValues($this->getMatchesForPrefix($this->issue, $prefix));
}

return null;
}

public function getWordDefinition(): string
{
return '\[~[^]]+|@[^]]+';
return '@[a-zA-Z]+';
}

private function getMatchesForPrefix(Issue $issue, $prefix): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Technodelight\Jira\Domain\Comment\CommentId;
use Technodelight\Jira\Console\Argument\IssueKeyResolver;
use Technodelight\Jira\Console\Input\Issue\Comment\Comment as CommentInput;
use Technodelight\Jira\Domain\Exception\NonNumericException;
use Technodelight\Jira\Renderer\Issue\Comment as CommentRenderer;
use Technodelight\Jira\Template\IssueRenderer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@ private function fetchPossibleIssuesCollection(): IssueCollection
private function fetchWordsList(Issue $issue): array
{
$list = $issue->comments();
$list[] = $issue->description();
$list[] = $issue->summary();
$list[] = $issue->description() ?? '';
$list[] = $issue->summary() ?? '';

return $this->collectWords($list);
}

private function collectWords(array $texts): array
{
$words = [];
foreach ($texts as $text) {
foreach (array_filter($texts) as $text) {
foreach ($this->collectAutocompletableWords($text) as $word) {
$words[] = $word;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Technodelight/Jira/Renderer/Issue/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function render(OutputInterface $output, Issue $issue): void
{
$output->writeln(
sprintf(
'<info>%s</info> %s %s %s <fg=black>(%s)</>',
'<info>%s</info> %s %s %s <fg=black>%s</>',
$issue->key(),
$this->formatStatus($issue->status()),
$this->formatIssueType($issue->issueType()),
Expand Down
16 changes: 14 additions & 2 deletions src/Technodelight/Jira/Renderer/Issue/IssueRelations.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace Technodelight\Jira\Renderer\Issue;

use Symfony\Component\Console\Output\OutputInterface;
use Technodelight\Jira\Api\SymfonyRgbOutputFormatter\PaletteOutputFormatterStyle;
use Technodelight\Jira\Domain\Issue;
use Technodelight\Jira\Domain\IssueLink;
use Technodelight\Jira\Domain\Status;
use Technodelight\Jira\Helper\TemplateHelper;
use Technodelight\Jira\Renderer\IssueRenderer;

Expand Down Expand Up @@ -51,8 +53,9 @@ private function renderTasks(array $tasks, $header)
private function renderRelatedTask(Issue $related)
{
return sprintf(
'<info>%s</> %s <fg=black>(%s)</>',
'<info>%s</> %s %s <fg=black>%s</>',
$related->issueKey(),
$this->formatStatus($related->status()),
$related->summary(),
$related->url()
);
Expand All @@ -61,12 +64,21 @@ private function renderRelatedTask(Issue $related)
private function renderLink(IssueLink $link)
{
return sprintf(
'<comment>%s</> <info>%s</> %s <fg=black>%s</> <fg=black>(%s)</>',
'<comment>%s</> <info>%s</> %s %s <fg=black>%s</> <fg=black>%s</>',
$link->isInward() ? $link->type()->inward() : $link->type()->outward(),
$link->isInward() ? $link->inwardIssue()->key() : $link->outwardIssue()->key(),
$this->formatStatus($link->isInward() ? $link->inwardIssue()->status() : $link->outwardIssue()->status()),
$link->isInward() ? $link->inwardIssue()->summary() : $link->outwardIssue()->summary(),
$link->id(),
$link->isInward() ? $link->inwardIssue()->url() : $link->outwardIssue()->url()
);
}

private function formatStatus(Status $status): string
{
$style = new PaletteOutputFormatterStyle;
$style->setForeground('black');
$style->setBackground($status->statusCategoryColor());
return $style->apply(sprintf(' %s ', $status));
}
}

0 comments on commit e7f20a1

Please sign in to comment.