Skip to content

Commit

Permalink
SDK-4712: Approved manifest rating (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
vol4onok authored Nov 23, 2023
1 parent 5a0ccc0 commit 260fd22
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 8 deletions.
22 changes: 22 additions & 0 deletions src/Console/DiffGenerateConsole.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ class DiffGenerateConsole extends AbstractInstallerConsole
*/
protected const ARGUMENT_INTEGRATION_BRANCH_DEFAULT = 'integrator/release-group-manifest-run';

/**
* @var string
*/
protected const ARGUMENT_DIFF_FILE_NAME = 'diff-file-name';

/**
* @var string
*/
protected const ARGUMENT_DIFF_FILE_NAME_DESCRIPTION = 'Name for the backet diff file. By default is `diff_to_display.diff`';

/**
* @var string
*/
protected const ARGUMENT_DIFF_FILE_NAME_DEFAULT = 'diff_to_display.diff';

/**
* @var string
*/
Expand Down Expand Up @@ -97,6 +112,12 @@ protected function configure(): void
InputArgument::OPTIONAL,
static::ARGUMENT_INTEGRATION_BRANCH_DESCRIPTION,
static::ARGUMENT_INTEGRATION_BRANCH_DEFAULT,
)
->addArgument(
static::ARGUMENT_DIFF_FILE_NAME,
InputArgument::OPTIONAL,
static::ARGUMENT_DIFF_FILE_NAME_DESCRIPTION,
static::ARGUMENT_DIFF_FILE_NAME_DEFAULT,
);
}

Expand Down Expand Up @@ -146,6 +167,7 @@ protected function buildCommandArgumentsTransfer(InputInterface $input): Integra
$transfer->setReleaseGroupId($this->getReleaseGroupIdOrFail($input));
$transfer->setBranchToCompare($input->getArgument(static::ARGUMENT_BRANCH_TO_COMPARE));
$transfer->setIntegrationBranch($input->getArgument(static::ARGUMENT_INTEGRATION_BRANCH));
$transfer->setDiffFileName($input->getArgument(static::ARGUMENT_DIFF_FILE_NAME));

return $transfer;
}
Expand Down
19 changes: 11 additions & 8 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 DIFF_TO_DISPLAY_FILE_NAME = 'diff_to_display.diff';

/**
* @var int
*/
Expand Down Expand Up @@ -104,7 +99,13 @@ public function generateDiff(
return;
}

$this->storeDiff($releaseGroupId, $commandArgumentsTransfer->getBranchToCompareOrFail(), $commandArgumentsTransfer->getIntegrationBranchOrFail(), $inputOutput);
$this->storeDiff(
$releaseGroupId,
$commandArgumentsTransfer->getBranchToCompareOrFail(),
$commandArgumentsTransfer->getIntegrationBranchOrFail(),
$commandArgumentsTransfer->getDiffFileNameOrFail(),
$inputOutput,
);
$this->gitClean($currentBranchName);
} catch (GitException $exception) {
throw new RuntimeException(
Expand All @@ -123,6 +124,7 @@ public function generateDiff(
* @param int $releaseGroupId
* @param string $branchToCompare
* @param string $integrationBranch
* @param string $diffFileName
* @param \SprykerSdk\Integrator\Dependency\Console\InputOutputInterface $inputOutput
*
* @throws \RuntimeException
Expand All @@ -133,6 +135,7 @@ protected function storeDiff(
int $releaseGroupId,
string $branchToCompare,
string $integrationBranch,
string $diffFileName,
InputOutputInterface $inputOutput
): void {
if ($this->gitRepository->hasChanges()) {
Expand All @@ -149,9 +152,9 @@ protected function storeDiff(
$gitDiffOutput = $this->gitRepository->getDiff('origin/' . $branchToCompare, $integrationBranch);
}

$this->bucketFileStorage->addFile($releaseGroupId . DIRECTORY_SEPARATOR . static::DIFF_TO_DISPLAY_FILE_NAME, $gitDiffOutput);
$this->bucketFileStorage->addFile($releaseGroupId . DIRECTORY_SEPARATOR . $diffFileName, $gitDiffOutput);
$inputOutput->writeln($gitDiffOutput, InputOutputInterface::VERBOSE);
$inputOutput->writeln(sprintf('%s was uploaded to the bucket', static::DIFF_TO_DISPLAY_FILE_NAME));
$inputOutput->writeln(sprintf('%s was uploaded to the bucket', $diffFileName));
}

/**
Expand Down
40 changes: 40 additions & 0 deletions src/Transfer/IntegratorCommandArgumentsTransfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ class IntegratorCommandArgumentsTransfer
*/
public const INTEGRATION_BRANCH = 'integrationBranch';

/**
* @var string
*/
public const DIFF_FILE_NAME = 'diffFileName';

/**
* @var string
*/
Expand Down Expand Up @@ -78,6 +83,11 @@ class IntegratorCommandArgumentsTransfer
*/
protected ?string $integrationBranch = null;

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

/**
* @var array<\SprykerSdk\Integrator\Transfer\ModuleTransfer>
*/
Expand Down Expand Up @@ -235,6 +245,36 @@ public function getIntegrationBranchOrFail(): string
return (string)$this->integrationBranch;
}

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

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

/**
* @return string
*/
public function getDiffFileNameOrFail(): string
{
if ($this->diffFileName === null) {
$this->throwNullValueException(static::DIFF_FILE_NAME);
}

return (string)$this->diffFileName;
}

/**
* @return string|null
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,57 @@

class DiffGenerateConsoleTest extends TestCase
{
/**
* @return void
*/
public function testBuildCommandArgumentsTransfer(): void
{
// Arrange
$verboseOption = new InputOption('verboseOption', null, InputOutputInterface::DEBUG);
$inputDefinition = new InputDefinition();
$inputDefinition->addOption($verboseOption);
$console = new DiffGenerateConsole();
$arguments = [
'branch-to-compare' => 'test1',
'integration-branch' => 'test2',
'diff-file-name' => 'test3',
'release-group-id' => 10,
];
$options = [
'format' => 'yaml',
'dry' => true,
];
foreach ($options as $key => $value) {
$option = (new InputOption($key, null, InputOption::VALUE_OPTIONAL));
$option->setDefault($value);
$inputDefinition->addOption($option);
}
foreach ($arguments as $key => $value) {
$arg = (new InputArgument($key));
$arg->setDefault($value);
$inputDefinition->addArgument($arg);
}
$input = new ArrayInput([], $inputDefinition);

// Act
/** @var \SprykerSdk\Integrator\Transfer\IntegratorCommandArgumentsTransfer $integratorCommandArgumentsTransfer */
$integratorCommandArgumentsTransfer = $this->invokeMethod(
$console,
'buildCommandArgumentsTransfer',
[
$input, $this->buildOutput(), null,
],
);

// Assert
$this->assertSame('test1', $integratorCommandArgumentsTransfer->getBranchToCompare());
$this->assertSame('test2', $integratorCommandArgumentsTransfer->getIntegrationBranch());
$this->assertSame('test3', $integratorCommandArgumentsTransfer->getDiffFileName());
$this->assertSame(10, $integratorCommandArgumentsTransfer->getReleaseGroupId());
$this->assertSame('yaml', $integratorCommandArgumentsTransfer->getFormat());
$this->assertTrue($integratorCommandArgumentsTransfer->getIsDry());
}

/**
* @return void
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ public function createCommandArgumentsTransfer(bool $isDry = false, array $Modul
$transfer->setReleaseGroupId(1);
$transfer->setBranchToCompare('master');
$transfer->setIntegrationBranch('integration-branch');
$transfer->setDiffFileName('diff_file.diff');

return $transfer;
}
Expand Down

0 comments on commit 260fd22

Please sign in to comment.