Add run filtering#73
Conversation
|
Blocked by: symfony/symfony#22244 |
| /** @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'); |
There was a problem hiding this comment.
Could config_reader_filter_decorator be injected directly here instead of getting a service via container->get ?
| * @var ConfigReader | ||
| * @var ConfigReaderFilterDecorator | ||
| */ | ||
| private $configReader; |
There was a problem hiding this comment.
Shouldn't that be also renamed to $configReaderFilterDecorator?
|
|
||
| if ($input->getOption(self::STAGE_FILTER)) { | ||
| $this->configReader->setStageFilter($input->getOption(self::STAGE_FILTER)); | ||
| } |
There was a problem hiding this comment.
Is there a bit more "elegant" way of setting the filter?
| { | ||
| foreach($this->stages as $k => $s){ | ||
| if ($s === $stage) { | ||
| unset ($this->stages[$k]); |
There was a problem hiding this comment.
should be space between unset and brackets maybe removed ?
| return $config; | ||
| } | ||
|
|
||
| public function setStageFilter($stageFilter) |
There was a problem hiding this comment.
annotation is missing
adriferracuti
left a comment
There was a problem hiding this comment.
Looks good so far, just minor things and a suggestion :)
| */ | ||
| public function remove(JobConfig $job) | ||
| { | ||
| foreach ($this->jobs as $k=>$j) { |
| } | ||
|
|
||
| /** | ||
| * @param null $jobFilter |
| */ | ||
| private $configReader; | ||
| /** | ||
| * @var null |
| */ | ||
| private $stageFilter; | ||
| /** | ||
| * @var null |
| if (strpos(mb_strtolower($stage->getName()), $this->stageFilter) === false ){ | ||
| $stagesCollection->remove($stage); | ||
| } | ||
| } |
There was a problem hiding this comment.
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); | ||
| } | ||
| } |
There was a problem hiding this comment.
You could move this logic to the collection itself, by adding, for example, a removeEmptyStages() method
| { | ||
| /** | ||
| * @param $workingDir | ||
| * @param $configFile |
| //given | ||
| $config = [ | ||
| 'stage1Name' => [] | ||
| 'stage1Name' => [], |
| $output->writeln('<error>' . $e->getMessage() . '</error>'); | ||
|
|
||
| return -1; | ||
| return $e->getCode() != 0 ? $e->getCode() : -1; |
There was a problem hiding this comment.
-1is 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'); |
There was a problem hiding this comment.
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')) !== '') { |
There was a problem hiding this comment.
Doesn't Symfony trim the arguments anyways?
| return ''; | ||
| } | ||
|
|
||
| return $this->workingDir . '/'; |
There was a problem hiding this comment.
This working directory code is 1:1 the same as in RunCommand: trait?
| return ''; | ||
| } | ||
| return (string)$this->input->getOption(RunCommand::JOB_FILTER); | ||
| } |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
Create your own exception instead of using procedural constants.
ee173e4 to
870074e
Compare
This pull request adds possibility to use
--joband--stageoptions during local rumi execution.