Skip to content

Commit 1aafc53

Browse files
author
Zsolt Gál
committed
fix broken behats
1 parent 5f077d7 commit 1aafc53

File tree

7 files changed

+39
-30
lines changed

7 files changed

+39
-30
lines changed

features/bootstrap/fixtures/configuration.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,5 @@ project:
1616
transitions:
1717
- { command: resolve, transition: 'Resolve' }
1818

19-
# GitHub credentials - used to retrieve pull request data, including webhook statuses
20-
github:
21-
apiToken: topSecretToken # Required
22-
23-
extensions:
24-
class:
25-
- Technodelight\JiraGitHubExtension\Extension
19+
#extensions:
20+
# class:

src/Technodelight/Jira/Api/JiraRestApi/Api.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -940,9 +940,11 @@ private function collectAccountIds(array $jiraItem): array
940940
$fields = ['body', 'comment', 'value'];
941941
$accountIds = [];
942942
foreach ($jiraItem as $field => $value) {
943+
if (!in_array($field, $fields, true)) {
944+
continue;
945+
}
943946
$numOfMatches = preg_match_all('~(\[\~)(accountid:([^]]+))(\])~smu', $value, $matches);
944-
if (in_array($field, $fields, true)
945-
&& $numOfMatches > 0) {
947+
if ($numOfMatches > 0) {
946948
for ($i = 0; $i < $numOfMatches; $i++) {
947949
$accountIds[] = $matches[3][$i];
948950
}

src/Technodelight/Jira/Console/Argument/IssueKeyResolver/Guesser.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function __construct(
1717
private readonly BranchNameGeneratorConfiguration $branchConfig
1818
) {}
1919

20-
public function guessIssueKey($guessable, Branch $currentBranch = null): ?IssueKey
20+
public function guessIssueKey($guessable, ?Branch $currentBranch = null): ?IssueKey
2121
{
2222
$fromString = $this->fromString((string)$guessable);
2323
$fromUrl = $this->fromUrl($guessable);
@@ -42,9 +42,12 @@ private function fromString($string): ?IssueKey
4242
}
4343

4444
/** @SuppressWarnings(PHPMD.StaticAccess) */
45-
private function fromBranch(Branch $branch): ?IssueKey
45+
private function fromBranch(?Branch $branch): ?IssueKey
4646
{
4747
try {
48+
if ($branch === null) {
49+
return null;
50+
}
4851
$issueKey = $this->aliasConfig->aliasToIssueKey($branch->name());
4952
if ($issueKey !== $branch->name()) { // has an alias for complete branch name
5053
return IssueKey::fromString($issueKey);

src/Technodelight/Jira/Console/Command/Action/Issue/LogTime.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Technodelight\Jira\Console\Dashboard\WorklogFetcher;
2424
use Technodelight\Jira\Console\Input\Worklog\Comment as CommentInput;
2525
use Technodelight\Jira\Domain\Issue;
26+
use Technodelight\Jira\Domain\Issue\IssueKey;
2627
use Technodelight\Jira\Domain\Worklog;
2728
use Technodelight\Jira\Renderer\DashboardRenderer;
2829
use Technodelight\Jira\Renderer\Issue\Header as HeaderRenderer;
@@ -154,7 +155,7 @@ protected function interact(InputInterface $input, OutputInterface $output): voi
154155
$this->askForTimeToLog(
155156
$input,
156157
$output,
157-
$issueKeyOrWorklogId->issueKey() ? (string)$issueKeyOrWorklogId->issueKey() : '',
158+
$issueKeyOrWorklogId->issueKey(),
158159
$issueKeyOrWorklogId->worklog()
159160
)
160161
);
@@ -263,7 +264,7 @@ private function processNewWorklog(
263264
$issueKeyOrWorklogId->issueKey(),
264265
$timeSpent,
265266
$comment ?: 'Worked on issue ' . $issueKeyOrWorklogId->issueKey(),
266-
$this->dateResolver->argument($input)
267+
$this->dateResolver->argument($input)->toDateTime()->format(DateTime::ATOM)
267268
);
268269
$this->showSuccessMessages($output, $worklog);
269270

@@ -297,7 +298,7 @@ private function interactiveTimelog(InputInterface $input, OutputInterface $outp
297298
$issue->key(),
298299
$time,
299300
$comment ?: 'Worked on issue ' . $issue->key(),
300-
$this->dateResolver->argument($input)
301+
$this->dateResolver->argument($input)->toDateTime()->format(DateTime::ATOM)
301302
);
302303
$this->showSuccessMessages($output, $worklog);
303304
$timeLeft = $timeLeft - $worklog->timeSpentSeconds();
@@ -413,11 +414,11 @@ private function askIssueToChooseFrom(InputInterface $input, OutputInterface $ou
413414
private function askForTimeToLog(
414415
InputInterface $input,
415416
OutputInterface $output,
416-
string $issueKey,
417-
Worklog $worklog = null
417+
?IssueKey $issueKey,
418+
?Worklog $worklog = null
418419
): string {
419420
$question = new Question(
420-
$this->loggedTimeDialogText($issueKey, $worklog),
421+
$this->loggedTimeDialogText((string)$issueKey, $worklog),
421422
$worklog ? $this->dateHelper->secondsToHuman($worklog->timeSpentSeconds()) : '1d'
422423
);
423424
$question->setValidator(function ($answer) {
@@ -436,7 +437,7 @@ private function renderDashboard(InputInterface $input, OutputInterface $output)
436437
$this->dashboardRenderer->render(
437438
$output,
438439
$this->dashDataProvider->fetch(
439-
date('Y-m-d', strtotime($this->dateResolver->argument($input)))
440+
date('Y-m-d', strtotime($this->dateResolver->argument($input)->toDateTime()->format(DateTime::ATOM)))
440441
)
441442
);
442443
}

src/Technodelight/Jira/Helper/Wordwrap.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,17 @@
66

77
class Wordwrap
88
{
9+
public function __construct(private readonly TerminalDimensionProvider $dimensionProvider) {}
910

10-
public function __construct(private readonly TerminalDimensionProvider $dimensionProvider)
11-
{
12-
}
13-
14-
public function wrap($text, $width = null): string
11+
public function wrap(string $text, int $width = null): string
1512
{
1613
$termWidth = $width ?? ($this->dimensionProvider->width() ?: 80);
1714
$padding = ceil($termWidth * 0.1);
1815

19-
return wordwrap($text, $termWidth - $padding);
16+
return wordwrap($text, intval($termWidth - $padding));
2017
}
2118

22-
public function shorten($text, $length = 20): string
19+
public function shorten(string $text, int $length = 20): string
2320
{
2421
$wrapped = explode(PHP_EOL, wordwrap($text, $length));
2522
$firstLine = array_shift($wrapped);

src/Technodelight/Jira/Renderer/Issue/IssueRelations.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Technodelight\Jira\Renderer\Issue;
66

7+
use Symfony\Component\Console\Output\BufferedOutput;
78
use Symfony\Component\Console\Output\OutputInterface;
89
use Technodelight\Jira\Api\SymfonyRgbOutputFormatter\PaletteOutputFormatterStyle;
910
use Technodelight\Jira\Domain\Issue;
@@ -14,9 +15,10 @@
1415

1516
class IssueRelations implements IssueRenderer
1617
{
17-
public function __construct(private readonly TemplateHelper $templateHelper)
18-
{
19-
}
18+
public function __construct(
19+
private readonly TemplateHelper $templateHelper,
20+
private readonly Header $header
21+
) {}
2022

2123
public function render(OutputInterface $output, Issue $issue): void
2224
{
@@ -37,11 +39,12 @@ public function render(OutputInterface $output, Issue $issue): void
3739

3840
private function renderTasks(array $tasks, string $header): array
3941
{
42+
$count = count($tasks);
4043
$rows = [
41-
sprintf('<comment>%s:</comment> %s', $header, count($tasks) > 1 ? sprintf('(%d)', count($tasks)) : '')
44+
sprintf('<comment>%s:</comment> %s', $header, $count > 1 ? sprintf('(%d)', $count) : '')
4245
];
4346
foreach ($tasks as $task) {
44-
$content = $task instanceof IssueLink ? $this->renderLink($task) : $this->renderTasks($task, $header);
47+
$content = $task instanceof IssueLink ? $this->renderLink($task) : $this->renderIssue($task);
4548
$rows[] = $this->templateHelper->tabulate($content);
4649
}
4750
return $rows;
@@ -62,6 +65,13 @@ private function renderLink(IssueLink $link): string
6265
);
6366
}
6467

68+
private function renderIssue(Issue $issue): string
69+
{
70+
$output = new BufferedOutput();
71+
$this->header->render($output, $issue);
72+
return $output->fetch();
73+
}
74+
6575
private function formatStatus(Status $status): string
6676
{
6777
$style = new PaletteOutputFormatterStyle;

src/Technodelight/Jira/Resources/configs/renderers.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
<service id="technodelight.jira.renderer.issue.description" alias="technodelight.jira.renderer.issue.description.short" />
7777
<service id="technodelight.jira.renderer.issue.issue_relations" class="Technodelight\Jira\Renderer\Issue\IssueRelations">
7878
<argument type="service" id="technodelight.jira.template_helper" />
79+
<argument type="service" id="technodelight.jira.renderer.issue.header" />
7980
<tag name="issue_renderer" key="issue_relations" />
8081
</service>
8182
<service id="technodelight.jira.renderer.issue.versions" class="Technodelight\Jira\Renderer\Issue\Versions">

0 commit comments

Comments
 (0)