Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelmaksimov25 committed Nov 6, 2023
2 parents b6575d6 + 8139bbd commit 8f9bd4a
Show file tree
Hide file tree
Showing 19 changed files with 197 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@ class ReleaseAppConstant
* @var string
*/
public const RELEASE_GROUP_LINK_PATTERN = '%s/release-group/%s';

/**
* @var string
*/
public const RELEASE_HISTORY_PATH = 'release-history';
}
56 changes: 54 additions & 2 deletions src/ReleaseApp/Application/Service/ReleaseAppService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace ReleaseApp\Application\Service;

use DateTimeInterface;
use ReleaseApp\Application\Configuration\ConfigurationProviderInterface;
use ReleaseApp\Application\Configuration\ReleaseAppConstant;
use ReleaseApp\Domain\Client\ReleaseAppClientInterface;
use ReleaseApp\Domain\Client\Request\UpgradeAnalysisRequest;
use ReleaseApp\Domain\Client\Request\UpgradeInstructionsRequest;
Expand All @@ -24,12 +27,21 @@ class ReleaseAppService implements ReleaseAppServiceInterface
*/
protected ReleaseAppClientInterface $releaseAppClient;

/**
* @var \ReleaseApp\Application\Configuration\ConfigurationProviderInterface
*/
protected ConfigurationProviderInterface $configurationProvider;

/**
* @param \ReleaseApp\Domain\Client\ReleaseAppClientInterface $releaseAppClient
* @param \ReleaseApp\Application\Configuration\ConfigurationProviderInterface $configurationProvider
*/
public function __construct(ReleaseAppClientInterface $releaseAppClient)
{
public function __construct(
ReleaseAppClientInterface $releaseAppClient,
ConfigurationProviderInterface $configurationProvider
) {
$this->releaseAppClient = $releaseAppClient;
$this->configurationProvider = $configurationProvider;
}

/**
Expand Down Expand Up @@ -63,6 +75,46 @@ public function getReleaseGroup(UpgradeReleaseGroupInstructionsRequest $upgradeR
return $response->getReleaseGroup();
}

/**
* @param string|null $sort
* @param string|null $direction
* @param \DateTimeInterface|null $releasedFrom
* @param bool $projectOnly
*
* @return string
*/
public function getReleaseHistoryLink(
?string $sort = null,
?string $direction = null,
?DateTimeInterface $releasedFrom = null,
bool $projectOnly = false
): string {
$queryParams = [];

if ($sort) {
$queryParams['sort'] = $sort;
}
if ($direction) {
$queryParams['direction'] = $direction;
}
if ($projectOnly) {
$queryParams['project_only'] = $projectOnly;
}

if ($releasedFrom instanceof DateTimeInterface) {
$queryParams['released_from[day]'] = $releasedFrom->format('d');
$queryParams['released_from[month]'] = $releasedFrom->format('m');
$queryParams['released_from[year]'] = $releasedFrom->format('Y');
}

return sprintf(
'%s/%s?%s',
$this->configurationProvider->getReleaseAppUrl(),
ReleaseAppConstant::RELEASE_HISTORY_PATH,
http_build_query($queryParams),
);
}

/**
* @param \ReleaseApp\Domain\Entities\Collection\UpgradeAnalysisModuleVersionCollection $moduleVersionCollection
*
Expand Down
16 changes: 16 additions & 0 deletions src/ReleaseApp/Application/Service/ReleaseAppServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace ReleaseApp\Application\Service;

use DateTimeInterface;
use ReleaseApp\Domain\Client\Request\UpgradeAnalysisRequest;
use ReleaseApp\Domain\Client\Request\UpgradeReleaseGroupInstructionsRequest;
use ReleaseApp\Domain\Entities\Collection\UpgradeInstructionsReleaseGroupCollection;
Expand All @@ -29,4 +30,19 @@ public function getNewReleaseGroupsSortedByReleaseDate(UpgradeAnalysisRequest $u
* @return \ReleaseApp\Domain\Entities\UpgradeInstructionsReleaseGroup
*/
public function getReleaseGroup(UpgradeReleaseGroupInstructionsRequest $upgradeReleaseGroupInstructionsRequest): UpgradeInstructionsReleaseGroup;

/**
* @param string|null $sort
* @param string|null $direction
* @param \DateTimeInterface|null $releasedFrom
* @param bool $projectOnly
*
* @return string
*/
public function getReleaseHistoryLink(
?string $sort = null,
?string $direction = null,
?DateTimeInterface $releasedFrom = null,
bool $projectOnly = false
): string;
}
18 changes: 18 additions & 0 deletions src/ReleaseApp/Infrastructure/Service/ReleaseAppService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace ReleaseApp\Infrastructure\Service;

use DateTimeInterface;
use ReleaseApp\Application\Service\ReleaseAppService as ApplicationReleaseAppService;
use ReleaseApp\Domain\Client\Request\UpgradeAnalysisRequest;
use ReleaseApp\Domain\Client\Request\UpgradeReleaseGroupInstructionsRequest;
Expand Down Expand Up @@ -66,4 +67,21 @@ public function getReleaseGroup(UpgradeReleaseGroupInstructionsRequest $upgradeR

return new ReleaseAppResponse($releaseGroupCollection);
}

/**
* @param string|null $sort
* @param string|null $direction
* @param \DateTimeInterface|null $releasedFrom
* @param bool $projectOnly
*
* @return string
*/
public function getReleaseHistoryLink(
?string $sort = null,
?string $direction = null,
?DateTimeInterface $releasedFrom = null,
bool $projectOnly = false
): string {
return $this->releaseApp->getReleaseHistoryLink($sort, $direction, $releasedFrom, $projectOnly);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace ReleaseApp\Infrastructure\Service;

use DateTimeInterface;
use ReleaseApp\Domain\Client\Request\UpgradeAnalysisRequest;
use ReleaseApp\Domain\Client\Request\UpgradeReleaseGroupInstructionsRequest;
use ReleaseApp\Infrastructure\Shared\Dto\ReleaseAppResponse;
Expand All @@ -28,4 +29,19 @@ public function getNewReleaseGroups(UpgradeAnalysisRequest $upgradeAnalysisReque
* @return \ReleaseApp\Infrastructure\Shared\Dto\ReleaseAppResponse
*/
public function getReleaseGroup(UpgradeReleaseGroupInstructionsRequest $upgradeReleaseGroupInstructionsRequest): ReleaseAppResponse;

/**
* @param string|null $sort
* @param string|null $direction
* @param \DateTimeInterface|null $releasedFrom
* @param bool $projectOnly
*
* @return string
*/
public function getReleaseHistoryLink(
?string $sort = null,
?string $direction = null,
?DateTimeInterface $releasedFrom = null,
bool $projectOnly = false
): string;
}
17 changes: 17 additions & 0 deletions src/ReleaseApp/Infrastructure/Shared/Dto/ReleaseGroupDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace ReleaseApp\Infrastructure\Shared\Dto;

use DateTimeInterface;
use ReleaseApp\Infrastructure\Shared\Dto\Collection\ModuleDtoCollection;

class ReleaseGroupDto
Expand All @@ -33,6 +34,11 @@ class ReleaseGroupDto
*/
protected string $name;

/**
* @var \DateTimeInterface
*/
protected DateTimeInterface $released;

/**
* @var string
*/
Expand Down Expand Up @@ -77,6 +83,7 @@ class ReleaseGroupDto
* @param int $id
* @param string $name
* @param \ReleaseApp\Infrastructure\Shared\Dto\Collection\ModuleDtoCollection $moduleCollection
* @param \DateTimeInterface $released
* @param bool $containsProjectChanges
* @param string $link
* @param int $rating
Expand All @@ -89,6 +96,7 @@ public function __construct(
int $id,
string $name,
ModuleDtoCollection $moduleCollection,
DateTimeInterface $released,
bool $containsProjectChanges,
string $link,
int $rating,
Expand All @@ -99,6 +107,7 @@ public function __construct(
) {
$this->id = $id;
$this->name = $name;
$this->released = $released;
$this->link = $link;
$this->moduleCollection = $moduleCollection;
$this->containsProjectChanges = $containsProjectChanges;
Expand Down Expand Up @@ -274,4 +283,12 @@ public function getManualActionNeeded(): bool
{
return $this->manualActionNeeded;
}

/**
* @return \DateTimeInterface
*/
public function getReleased(): DateTimeInterface
{
return $this->released;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ protected function mapReleaseGroupDto(UpgradeInstructionsReleaseGroup $releaseGr
$releaseGroup->getId(),
$releaseGroup->getName(),
$this->buildModuleTransferCollection($releaseGroup),
$releaseGroup->getReleased(),
$releaseGroup->hasProjectChanges(),
$this->getReleaseGroupLink($releaseGroup->getId()),
$releaseGroup->getRating(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Upgrade\Infrastructure\VersionControlSystem\Generator;

use ReleaseApp\Application\Service\ReleaseAppServiceInterface;
use ReleaseApp\Infrastructure\Shared\Dto\ReleaseGroupDto;
use Upgrade\Application\Dto\IntegratorResponseDto;
use Upgrade\Application\Dto\ReleaseGroupFilterResponseDto;
Expand Down Expand Up @@ -42,19 +43,27 @@ class PullRequestDataGenerator
*/
protected IntegratorExecutionValidatorInterface $integratorExecutionValidator;

/**
* @var \ReleaseApp\Application\Service\ReleaseAppServiceInterface $releaseApp
*/
protected ReleaseAppServiceInterface $releaseApp;

/**
* @param \Upgrade\Infrastructure\VersionControlSystem\Generator\ViolationBodyMessageBuilder $violationBodyMessageBuilder
* @param \Upgrade\Application\Provider\ConfigurationProviderInterface $configurationProvider
* @param \Upgrade\Application\Strategy\Common\IntegratorExecutionValidatorInterface $integratorExecutionValidator
* @param \ReleaseApp\Application\Service\ReleaseAppServiceInterface $releaseApp
*/
public function __construct(
ViolationBodyMessageBuilder $violationBodyMessageBuilder,
ConfigurationProviderInterface $configurationProvider,
IntegratorExecutionValidatorInterface $integratorExecutionValidator
IntegratorExecutionValidatorInterface $integratorExecutionValidator,
ReleaseAppServiceInterface $releaseApp
) {
$this->violationBodyMessageBuilder = $violationBodyMessageBuilder;
$this->configurationProvider = $configurationProvider;
$this->integratorExecutionValidator = $integratorExecutionValidator;
$this->releaseApp = $releaseApp;
}

/**
Expand All @@ -74,7 +83,7 @@ public function buildBody(

return $this->buildHeaderText($stepsResponseDto, $releaseGroupId)
. PHP_EOL
. $this->buildReleaseGroupsTable($this->configurationProvider, $stepsResponseDto, $releaseGroupId)
. $this->buildReleaseGroupsTable($stepsResponseDto, $releaseGroupId)
. PHP_EOL
. (trim($warningsSection) !== '' ? '## Warnings' . PHP_EOL : '')
. $warningsSection
Expand Down Expand Up @@ -129,14 +138,12 @@ protected function buildHeaderText(StepsResponseDto $stepsResponseDto, ?int $rel
}

/**
* @param \Upgrade\Application\Provider\ConfigurationProviderInterface $upgradeConfigurationProvider
* @param \Upgrade\Application\Dto\StepsResponseDto $stepsResponseDto
* @param int|null $releaseGroupId
*
* @return string
*/
protected function buildReleaseGroupsTable(
ConfigurationProviderInterface $upgradeConfigurationProvider,
StepsResponseDto $stepsResponseDto,
?int $releaseGroupId
): string {
Expand Down Expand Up @@ -184,6 +191,16 @@ protected function buildReleaseGroupsTable(
$text .= PHP_EOL;
}

/** @var \ReleaseApp\Infrastructure\Shared\Dto\ReleaseGroupDto $firstAppliedRG */
$firstAppliedRG = $stepsResponseDto->getAppliedReleaseGroups()[0] ?? null;
if ($firstAppliedRG) {
$text .= sprintf(
'There are also [releases](%s), that did not include any modules, please check them out.',
$this->releaseApp->getReleaseHistoryLink('released', 'asc', $firstAppliedRG->getReleased(), true),
);
$text .= PHP_EOL;
}

return $text;
}

Expand Down
26 changes: 26 additions & 0 deletions tests/ReleaseApp/Infrastructure/Service/ReleaseAppServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace ReleaseApp\Infrastructure\Service;

use DateTime;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use ReleaseApp\Domain\Client\Request\UpgradeAnalysisRequest;
Expand Down Expand Up @@ -52,6 +53,7 @@ public function testGetNewReleaseGroupsSuccess(): void
new ModuleDto('spryker/mail-extension', '1.0.0', 'major'),
new ModuleDto('spryker/symfony-mailer', '1.0.2', 'major'),
]),
DateTime::createFromFormat("Y-m-d\TH:i:s.uO", '2022-11-13T18:12:50.000000+0000'),
true,
'https://api.release.spryker.com/release-group/4395',
100,
Expand Down Expand Up @@ -84,6 +86,7 @@ public function testGetReleaseGroupSuccess(): void
new ModuleDto('spryker/shipment-types-backend-api', '0.1.0', 'minor'),
new ModuleDto('spryker/shipment-type', '0.1.1', 'patch'),
]),
DateTime::createFromFormat("Y-m-d\TH:i:s.uO", '2023-05-23T14:26:52.000000+0000'),
true,
'https://api.release.spryker.com/release-group/4821',
100,
Expand All @@ -102,6 +105,29 @@ public function testGetReleaseGroupSuccess(): void
);
}

/**
* @return void
*/
public function testGetReleaseHistoryLink(): void
{
// Arrange
$container = static::bootKernel()->getContainer();
$container->set(HttpRequestExecutor::class, $this->createRequestExecutorMock());

$sort = 'date';
$direction = 'asc';
$released = new DateTime('2021-01-01');

// Act
$result = $container->get(ReleaseAppService::class)->getReleaseHistoryLink($sort, $direction, $released, true);

// Assert
$this->assertSame(
'https://api.release.spryker.com/release-history?sort=date&direction=asc&project_only=1&released_from%5Bday%5D=01&released_from%5Bmonth%5D=01&released_from%5Byear%5D=2021',
$result,
);
}

/**
* @return \ReleaseApp\Infrastructure\Client\HttpRequestExecutor
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace UpgradeTest\Application\Strategy\Common\Step;

use DateTime;
use PHPUnit\Framework\TestCase;
use ReleaseApp\Application\Configuration\ReleaseAppConstant;
use ReleaseApp\Infrastructure\Shared\Dto\Collection\ModuleDtoCollection;
Expand Down Expand Up @@ -74,7 +75,7 @@ public function testRunShouldPassModulesInExecutor(): void
{
// Arrange
$module = new ModuleDto('spryker/acl', '1.1.1', ReleaseAppConstant::MODULE_TYPE_MAJOR);
$releaseGroup = new ReleaseGroupDto(1, 'RG', new ModuleDtoCollection([$module]), false, '', 100);
$releaseGroup = new ReleaseGroupDto(1, 'RG', new ModuleDtoCollection([$module]), new DateTime(), false, '', 100);
$stepsResponseDto = new StepsResponseDto(true);
$stepsResponseDto->addAppliedReleaseGroup($releaseGroup);

Expand All @@ -99,7 +100,7 @@ public function testRunShouldNotPassModulesInExecutorWhenNotSpecifiedReleaseGrou
{
// Arrange
$module = new ModuleDto('spryker/acl', '1.1.1', ReleaseAppConstant::MODULE_TYPE_MAJOR);
$releaseGroup = new ReleaseGroupDto(1, 'RG', new ModuleDtoCollection([$module]), false, '', 100);
$releaseGroup = new ReleaseGroupDto(1, 'RG', new ModuleDtoCollection([$module]), new DateTime(), false, '', 100);
$stepsResponseDto = new StepsResponseDto(true);
$stepsResponseDto->addAppliedReleaseGroup($releaseGroup);

Expand Down
Loading

0 comments on commit 8f9bd4a

Please sign in to comment.