Skip to content

Commit

Permalink
SDK-4666: Add RG title in PR (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyspryker authored Nov 16, 2023
1 parent 7256049 commit 5b647bd
Showing 1 changed file with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class PullRequestDataGenerator
*/
protected const INTEGRATION_GUIDE_LENGTH = 500;

/**
* @var int
*/
protected const RELEASE_GROUP_TITLE_LENGTH = 50;

/**
* @var \Upgrade\Infrastructure\VersionControlSystem\Generator\ViolationBodyMessageBuilder
*/
Expand Down Expand Up @@ -95,7 +100,7 @@ public function buildBody(

return $this->buildHeaderText($stepsResponseDto, $releaseGroupId, $hasWarnings)
. PHP_EOL
. $this->buildReleaseGroupsTable($stepsResponseDto, $releaseGroupId)
. $this->buildReleaseGroupsTable($stepsResponseDto)
. PHP_EOL
. ($hasWarnings ? '## ' . $this->createErrorTitle($stepsResponseDto) . PHP_EOL : '')
. $warningsSection
Expand Down Expand Up @@ -156,47 +161,40 @@ protected function buildHeaderText(StepsResponseDto $stepsResponseDto, ?int $rel

/**
* @param \Upgrade\Application\Dto\StepsResponseDto $stepsResponseDto
* @param int|null $releaseGroupId
*
* @return string
*/
protected function buildReleaseGroupsTable(
StepsResponseDto $stepsResponseDto,
?int $releaseGroupId
): string {
protected function buildReleaseGroupsTable(StepsResponseDto $stepsResponseDto): string
{
if (count($stepsResponseDto->getAppliedReleaseGroups()) === 0) {
return '';
}

$shouldDisplayWarningColumn = $releaseGroupId !== null;
$shouldDisplayRatingColumn = $this->integratorExecutionValidator->isIntegratorShouldBeInvoked();
$shouldDisplayModuleOfferColumn = $this->shouldDisplayModuleOfferColumn($stepsResponseDto->getFilterResponseList());
$manifestRatingThreshold = $this->configurationProvider->getManifestsRatingThreshold();

$text = sprintf(
'| Release |%s%s%s',
$shouldDisplayRatingColumn ? ' Efforts saved by Upgrader |' : '',
$shouldDisplayWarningColumn ? ' Warnings detected? |' : '',
' Warnings detected? |',
$shouldDisplayModuleOfferColumn ? ' These new modules might be interesting for you |' : '',
) . PHP_EOL;

$text .= sprintf(
'| ------- |%s%s%s',
$shouldDisplayRatingColumn ? ' ---- |' : '',
$shouldDisplayWarningColumn ? ' ------------------ |' : '',
' ------------------ |',
$shouldDisplayModuleOfferColumn ? ' ------------------ |' : '',
) . PHP_EOL;

foreach ($stepsResponseDto->getAppliedReleaseGroups() as $appliedReleaseGroup) {
$text .= sprintf(
'| [%s](%s) |%s%s%s',
$appliedReleaseGroup->getId(),
$this->getReleaseGroupName($appliedReleaseGroup),
$appliedReleaseGroup->getLink(),
$shouldDisplayRatingColumn ? $this->buildRatingCell($appliedReleaseGroup, $manifestRatingThreshold) . ' |' : '',
$shouldDisplayWarningColumn ? $this->getReleaseGroupsTableWarningColumnText(
$stepsResponseDto,
$appliedReleaseGroup,
) . ' |' : '',
$this->getReleaseGroupsTableWarningColumnText($stepsResponseDto, $appliedReleaseGroup) . ' |',
$shouldDisplayModuleOfferColumn ? $this->buildModuleOfferCell($stepsResponseDto->getFilterResponseList(), $appliedReleaseGroup) . ' |' : '',
) . PHP_EOL;
}
Expand All @@ -221,6 +219,24 @@ protected function buildReleaseGroupsTable(
return $text;
}

/**
* @param \ReleaseApp\Infrastructure\Shared\Dto\ReleaseGroupDto $releaseGroupDto
*
* @return string
*/
protected function getReleaseGroupName(ReleaseGroupDto $releaseGroupDto): string
{
$name = trim((string)preg_replace(
'/^' . preg_quote((string)$releaseGroupDto->getJiraIssue(), '/') . '\b/i',
'',
$releaseGroupDto->getName(),
));

return mb_strlen($name) > static::RELEASE_GROUP_TITLE_LENGTH
? mb_substr($name, 0, static::RELEASE_GROUP_TITLE_LENGTH) . '...'
: $name;
}

/**
* @param \Upgrade\Application\Dto\StepsResponseDto $stepsResponseDto
*
Expand Down

0 comments on commit 5b647bd

Please sign in to comment.