Skip to content

Commit

Permalink
Move some stuff in commands
Browse files Browse the repository at this point in the history
  • Loading branch information
j0k3r committed Mar 4, 2017
1 parent 9fa231a commit c25da8e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 26 deletions.
40 changes: 27 additions & 13 deletions src/AppBundle/Command/SyncStarredReposCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)

protected function execute(InputInterface $input, OutputInterface $output)
{
$users = [];

if ($input->getOption('id')) {
$users = [$input->getOption('id')];
} elseif ($input->getOption('username')) {
$user = $this->userRepository->findOneByUsername($input->getOption('username'));

if ($user) {
$users = [$user->getId()];
}
} else {
$users = $this->userRepository->findAllToSync();
}
$users = $this->retrieveUsers($input);

if (count(array_filter($users)) <= 0) {
$output->writeln('<error>No users found</error>');
Expand Down Expand Up @@ -106,4 +94,30 @@ protected function execute(InputInterface $input, OutputInterface $output)

return 0;
}

/**
* Retrieve users to work on.
*
* @param InputInterface $input
*
* @return array
*/
private function retrieveUsers(InputInterface $input)
{
if ($input->getOption('id')) {
return [$input->getOption('id')];
}

if ($input->getOption('username')) {
$user = $this->userRepository->findOneByUsername($input->getOption('username'));

if ($user) {
return [$user->getId()];
}

return [];
}

return $this->userRepository->findAllToSync();
}
}
40 changes: 27 additions & 13 deletions src/AppBundle/Command/SyncVersionsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)

protected function execute(InputInterface $input, OutputInterface $output)
{
$repos = [];

if ($input->getOption('repo_id')) {
$repos = [$input->getOption('repo_id')];
} elseif ($input->getOption('repo_name')) {
$repo = $this->repoRepository->findOneByFullName($input->getOption('repo_name'));

if ($repo) {
$repos = [$repo->getId()];
}
} else {
$repos = $this->repoRepository->findAllForRelease();
}
$repos = $this->retrieveRepos($input);

if (count(array_filter($repos)) <= 0) {
$output->writeln('<error>No repos found</error>');
Expand Down Expand Up @@ -108,4 +96,30 @@ protected function execute(InputInterface $input, OutputInterface $output)

return 0;
}

/**
* Retrieve repos to work on.
*
* @param InputInterface $input
*
* @return array
*/
private function retrieveRepos(InputInterface $input)
{
if ($input->getOption('repo_id')) {
return [$input->getOption('repo_id')];
}

if ($input->getOption('repo_name')) {
$repo = $this->repoRepository->findOneByFullName($input->getOption('repo_name'));

if ($repo) {
return [$repo->getId()];
}

return [];
}

return $this->repoRepository->findAllForRelease();
}
}

0 comments on commit c25da8e

Please sign in to comment.