Skip to content

Commit

Permalink
Merge pull request #127 from spryker-sdk/bugfix/sdk-2973-rating-calcu…
Browse files Browse the repository at this point in the history
…lation

SDK-2973: added integration branch name
  • Loading branch information
pavelmaksimov25 committed Jul 24, 2023
2 parents b5d1cae + 195bb24 commit 715fc75
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 15 deletions.
2 changes: 2 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore:
- "src/Transfer"
22 changes: 22 additions & 0 deletions src/Console/DiffGenerateConsole.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ class DiffGenerateConsole extends AbstractInstallerConsole
*/
protected const ARGUMENT_BRANCH_TO_COMPARE_DEFAULT = 'master';

/**
* @var string
*/
protected const ARGUMENT_INTEGRATION_BRANCH = 'integration-branch';

/**
* @var string
*/
protected const ARGUMENT_INTEGRATION_BRANCH_DESCRIPTION = 'Name of branch with integrated changes. By default it is `integrator/release-group-manifest-run`';

/**
* @var string
*/
protected const ARGUMENT_INTEGRATION_BRANCH_DEFAULT = 'integrator/release-group-manifest-run';

/**
* @var string
*/
Expand Down Expand Up @@ -76,6 +91,12 @@ protected function configure(): void
InputArgument::OPTIONAL,
static::ARGUMENT_BRANCH_TO_COMPARE_DESCRIPTION,
static::ARGUMENT_BRANCH_TO_COMPARE_DEFAULT,
)
->addArgument(
static::ARGUMENT_INTEGRATION_BRANCH,
InputArgument::OPTIONAL,
static::ARGUMENT_INTEGRATION_BRANCH_DESCRIPTION,
static::ARGUMENT_INTEGRATION_BRANCH_DEFAULT,
);
}

Expand Down Expand Up @@ -124,6 +145,7 @@ protected function buildCommandArgumentsTransfer(InputInterface $input): Integra
$transfer = parent::buildCommandArgumentsTransfer($input);
$transfer->setReleaseGroupId($this->getReleaseGroupIdOrFail($input));
$transfer->setBranchToCompare($input->getArgument(static::ARGUMENT_BRANCH_TO_COMPARE));
$transfer->setIntegrationBranch($input->getArgument(static::ARGUMENT_INTEGRATION_BRANCH));

return $transfer;
}
Expand Down
26 changes: 12 additions & 14 deletions src/Executor/ReleaseGroup/DiffGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@

class DiffGenerator implements DiffGeneratorInterface
{
/**
* @var string
*/
protected const INTEGRATOR_RESULT_BRANCH_NAME = 'integrator/release-group-manifest-run';

/**
* @var string
*/
Expand Down Expand Up @@ -100,7 +95,7 @@ public function generateDiff(
try {
$dry = $commandArgumentsTransfer->getIsDryOrFail();
if (!$dry) {
$this->prepareBranch();
$this->prepareBranch($commandArgumentsTransfer->getIntegrationBranchOrFail());
}

$this->manifestExecutor->applyManifestList([], $unappliedManifests, $inputOutput, $commandArgumentsTransfer);
Expand All @@ -109,7 +104,7 @@ public function generateDiff(
return;
}

$this->storeDiff($releaseGroupId, $commandArgumentsTransfer->getBranchToCompareOrFail(), $inputOutput);
$this->storeDiff($releaseGroupId, $commandArgumentsTransfer->getBranchToCompareOrFail(), $commandArgumentsTransfer->getIntegrationBranchOrFail(), $inputOutput);
$this->gitClean($currentBranchName);
} catch (GitException $exception) {
throw new RuntimeException(
Expand All @@ -127,6 +122,7 @@ public function generateDiff(
/**
* @param int $releaseGroupId
* @param string $branchToCompare
* @param string $integrationBranch
* @param \SprykerSdk\Integrator\Dependency\Console\InputOutputInterface $inputOutput
*
* @throws \RuntimeException
Expand All @@ -136,6 +132,7 @@ public function generateDiff(
protected function storeDiff(
int $releaseGroupId,
string $branchToCompare,
string $integrationBranch,
InputOutputInterface $inputOutput
): void {
if ($this->gitRepository->hasChanges()) {
Expand All @@ -144,12 +141,12 @@ protected function storeDiff(
}

try {
$gitDiffOutput = $this->gitRepository->getDiff($branchToCompare, static::INTEGRATOR_RESULT_BRANCH_NAME);
$gitDiffOutput = $this->gitRepository->getDiff($branchToCompare, $integrationBranch);
} catch (GitException $e) {
if ($e->getCode() !== static::GIT_ERROR_CODE_BRANCH_NOT_EXISTS) {
throw $e;
}
$gitDiffOutput = $this->gitRepository->getDiff('origin/' . $branchToCompare, static::INTEGRATOR_RESULT_BRANCH_NAME);
$gitDiffOutput = $this->gitRepository->getDiff('origin/' . $branchToCompare, $integrationBranch);
}

$this->bucketFileStorage->addFile($releaseGroupId . DIRECTORY_SEPARATOR . static::DIFF_TO_DISPLAY_FILE_NAME, $gitDiffOutput);
Expand All @@ -158,14 +155,16 @@ protected function storeDiff(
}

/**
* @param string $integrationBranch
*
* @return void
*/
protected function prepareBranch(): void
protected function prepareBranch(string $integrationBranch): void
{
if (in_array(static::INTEGRATOR_RESULT_BRANCH_NAME, (array)$this->gitRepository->getBranches())) {
$this->gitRepository->deleteBranch(static::INTEGRATOR_RESULT_BRANCH_NAME);
if (in_array($integrationBranch, (array)$this->gitRepository->getBranches())) {
$this->gitRepository->deleteBranch($integrationBranch);
}
$this->gitRepository->createBranch(static::INTEGRATOR_RESULT_BRANCH_NAME, true);
$this->gitRepository->createBranch($integrationBranch, true);
}

/**
Expand All @@ -176,6 +175,5 @@ protected function prepareBranch(): void
protected function gitClean(string $currentBranchName): void
{
$this->gitRepository->checkout($currentBranchName);
$this->gitRepository->deleteBranch(static::INTEGRATOR_RESULT_BRANCH_NAME);
}
}
40 changes: 40 additions & 0 deletions src/Transfer/IntegratorCommandArgumentsTransfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class IntegratorCommandArgumentsTransfer
*/
public const BRANCH_TO_COMPARE = 'branchToCompare';

/**
* @var string
*/
public const INTEGRATION_BRANCH = 'integrationBranch';

/**
* @var string
*/
Expand Down Expand Up @@ -68,6 +73,11 @@ class IntegratorCommandArgumentsTransfer
*/
protected ?string $branchToCompare = null;

/**
* @var string|null
*/
protected ?string $integrationBranch = null;

/**
* @var array<\SprykerSdk\Integrator\Transfer\ModuleTransfer>
*/
Expand Down Expand Up @@ -195,6 +205,36 @@ public function getReleaseGroupIdOrFail(): int
return (int)$this->releaseGroupId;
}

/**
* @return string|null
*/
public function getIntegrationBranch(): ?string
{
return $this->integrationBranch;
}

/**
* @param string|null $integrationBranch
*
* @return void
*/
public function setIntegrationBranch(?string $integrationBranch): void
{
$this->integrationBranch = $integrationBranch;
}

/**
* @return string
*/
public function getIntegrationBranchOrFail(): string
{
if ($this->integrationBranch === null) {
$this->throwNullValueException(static::INTEGRATION_BRANCH);
}

return (string)$this->integrationBranch;
}

/**
* @return string|null
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public function testRunReleaseGroupManifestExecutionSuccess(): void
$manifestExecutor = new DiffGenerator($reader, $fileStorageMock, $executorMock, $gitMock);

// Assert
$gitMock->expects($this->atLeastOnce())->method('getBranches')->willReturn('master');
$gitMock->expects($this->atLeastOnce())->method('getBranches')->willReturn(['integration-branch']);
$gitMock->expects($this->atLeastOnce())->method('deleteBranch')->with('integration-branch');
$gitMock->expects($this->atLeastOnce())->method('checkout');
$gitMock->expects($this->once())->method('commit');
$fileStorageMock->expects($this->once())->method('addFile');
Expand Down Expand Up @@ -206,6 +207,7 @@ public function createCommandArgumentsTransfer(bool $isDry = false, array $Modul
$transfer = parent::createCommandArgumentsTransfer($isDry, $ModuleTransfers);
$transfer->setReleaseGroupId(1);
$transfer->setBranchToCompare('master');
$transfer->setIntegrationBranch('integration-branch');

return $transfer;
}
Expand Down

0 comments on commit 715fc75

Please sign in to comment.