Skip to content
This repository was archived by the owner on Jun 30, 2021. It is now read-only.

Add run filtering#73

Open
jakubsacha wants to merge 6 commits into
masterfrom
add-run-filtering
Open

Add run filtering#73
jakubsacha wants to merge 6 commits into
masterfrom
add-run-filtering

Conversation

@jakubsacha
Copy link
Copy Markdown
Contributor

This pull request adds possibility to use --job and --stage options during local rumi execution.

@jakubsacha
Copy link
Copy Markdown
Contributor Author

Blocked by: symfony/symfony#22244

Comment thread src/Commands/CacheStoreCommand.php Outdated
/** @var ConfigReader $configReader */
$configReader = $this->container->get('trivago.rumi.services.config_reader');
/** @var ConfigReaderInterface $configReader */
$configReader = $this->container->get('trivago.rumi.services.config_reader_filter_decorator');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could config_reader_filter_decorator be injected directly here instead of getting a service via container->get ?

* @var ConfigReader
* @var ConfigReaderFilterDecorator
*/
private $configReader;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't that be also renamed to $configReaderFilterDecorator?

Comment thread src/Commands/RunCommand.php Outdated

if ($input->getOption(self::STAGE_FILTER)) {
$this->configReader->setStageFilter($input->getOption(self::STAGE_FILTER));
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a bit more "elegant" way of setting the filter?

{
foreach($this->stages as $k => $s){
if ($s === $stage) {
unset ($this->stages[$k]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be space between unset and brackets maybe removed ?

return $config;
}

public function setStageFilter($stageFilter)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

annotation is missing

Copy link
Copy Markdown

@adriferracuti adriferracuti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far, just minor things and a suggestion :)

*/
public function remove(JobConfig $job)
{
foreach ($this->jobs as $k=>$j) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$k => $j

}

/**
* @param null $jobFilter
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@param string $jobFilter

*/
private $configReader;
/**
* @var null
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@var null|string

*/
private $stageFilter;
/**
* @var null
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@var null|string

if (strpos(mb_strtolower($stage->getName()), $this->stageFilter) === false ){
$stagesCollection->remove($stage);
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could move this logic to the collection itself, by adding, for example, a filterByStage($stageFilter) method

if (!count($stage->getJobs()->getIterator())) {
$stagesCollection->remove($stage);
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could move this logic to the collection itself, by adding, for example, a removeEmptyStages() method

Comment thread src/Services/ConfigReaderInterface.php Outdated
{
/**
* @param $workingDir
* @param $configFile
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

types are missing

//given
$config = [
'stage1Name' => []
'stage1Name' => [],
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intended? :)

Copy link
Copy Markdown
Contributor

@Fleshgrinder Fleshgrinder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very inconsistent style, and you should avoid mocking in the tests, especially because you never leave architectural boundaries. Test execution would be faster, and it would tell you more about your software.

Mocks are a code smell

— Greg Young

Comment thread src/Commands/CacheStoreCommand.php Outdated
$output->writeln('<error>' . $e->getMessage() . '</error>');

return -1;
return $e->getCode() != 0 ? $e->getCode() : -1;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • -1 is not a valid exit code, returning that to the shell is a bad idea: http://www.tldp.org/LDP/abs/html/exitcodes.html
  • Avoid type unsafe comparison by all means (=== instead of ==).
  • Use positive conditions, they are generally easier to understand.
  • This does exactly what you need: 😉
return (int) $e->getCode() !== 0;

try {
/** @var ConfigReader $configReader */
/** @var ConfigReaderInterface $configReader */
$configReader = $this->container->get('trivago.rumi.services.config_reader');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid this kind of inline IDE comments and install the Symfony extension for PhpStorm instead.

{
try {
if (trim($input->getArgument('volume')) != '') {
if (trim($input->getArgument('volume')) !== '') {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't Symfony trim the arguments anyways?

return '';
}

return $this->workingDir . '/';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This working directory code is 1:1 the same as in RunCommand: trait?

return '';
}
return (string)$this->input->getOption(RunCommand::JOB_FILTER);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to create your own extended input instead of using so many procedural constants. It would also allow you to decouple yourself from the Symfony console component, and it would make your code much simpler.


interface JobFilterParametersInterface
{
public function getJobFilter(): string;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public in an interface is plain wrong, it cannot be anything else.


$this->container->set('trivago.rumi.services.config_reader', $this->configReader->reveal());

$this->SUT = new CacheStoreCommand(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your style is extremely inconsistent: all upper prop, really?

public function testGivenCiFileDoesNotExist_WhenCacheStoreRun_ThenItSkipsExecution()
{
// given
$this->configReader->getRunConfig()->willThrow(new \RuntimeException('', ReturnCodes::RUMI_YML_DOES_NOT_EXIST));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create your own exception instead of using procedural constants.

@jakubsacha jakubsacha force-pushed the add-run-filtering branch from ee173e4 to 870074e Compare May 10, 2017 13:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants