-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If gitlab throws error 500 try to resolve discussion (#557)
- Loading branch information
1 parent
23b5eec
commit 6af9925
Showing
10 changed files
with
278 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace DR\Review\Service\Api\Gitlab; | ||
|
||
use DR\Review\Controller\App\Review\ReviewController; | ||
use DR\Review\Entity\Review\Comment; | ||
use Psr\Log\LoggerAwareInterface; | ||
use Psr\Log\LoggerAwareTrait; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
|
||
class GitlabCommentFormatter implements LoggerAwareInterface | ||
{ | ||
use LoggerAwareTrait; | ||
|
||
public function __construct(private readonly string $appAbsoluteUrl, private readonly UrlGeneratorInterface $urlGenerator) | ||
{ | ||
} | ||
|
||
public function format(Comment $comment): string | ||
{ | ||
$url = $this->appAbsoluteUrl . $this->urlGenerator->generate(ReviewController::class, ['review' => $comment->getReview()]); | ||
|
||
$message = str_replace("\n", "\n<br>", $comment->getMessage()); | ||
|
||
return sprintf("%s\n<br>\n<br>*123view: %s*", $message, $url); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
tests/Unit/Service/Api/Gitlab/GitlabCommentFormatterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace DR\Review\Tests\Unit\Service\Api\Gitlab; | ||
|
||
use DR\Review\Controller\App\Review\ReviewController; | ||
use DR\Review\Entity\Review\CodeReview; | ||
use DR\Review\Entity\Review\Comment; | ||
use DR\Review\Service\Api\Gitlab\GitlabCommentFormatter; | ||
use DR\Review\Tests\AbstractTestCase; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
|
||
#[CoversClass(GitlabCommentFormatter::class)] | ||
class GitlabCommentFormatterTest extends AbstractTestCase | ||
{ | ||
private UrlGeneratorInterface&MockObject $urlGenerator; | ||
private GitlabCommentFormatter $formatter; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->urlGenerator = $this->createMock(UrlGeneratorInterface::class); | ||
$this->formatter = new GitlabCommentFormatter('https://example.com', $this->urlGenerator); | ||
} | ||
|
||
public function testFormat(): void | ||
{ | ||
$review = new CodeReview(); | ||
$comment = new Comment(); | ||
$comment->setMessage("foo\nbar"); | ||
$comment->setReview($review); | ||
|
||
$this->urlGenerator->expects(self::once()) | ||
->method('generate') | ||
->with(ReviewController::class, ['review' => $review]) | ||
->willReturn('/path/to/review'); | ||
|
||
static::assertSame("foo\n<br>bar\n<br>\n<br>*123view: https://example.com/path/to/review*", $this->formatter->format($comment)); | ||
} | ||
} |
Oops, something went wrong.