diff --git a/config/packages/github_api.yaml b/config/packages/github_api.yaml index 3b4ad6ed..ac6a6aef 100644 --- a/config/packages/github_api.yaml +++ b/config/packages/github_api.yaml @@ -33,3 +33,45 @@ services: class: Symfony\Component\HttpClient\Retry\GenericRetryStrategy arguments: - [0, 404, 423, 425, 429, 500, 502, 503, 504, 507, 510] + + + # Register different APIs as services + + Github\Api\Issue: + factory: ['@Github\Client', api] + arguments: [issue] + + Github\Api\Issue\Comments: + factory: ['@Github\Api\Issue', comments] + calls: + - ['setPerPage', [100]] + + Github\Api\Issue\Labels: + factory: ['@Github\Api\Issue', labels] + calls: + - ['setPerPage', [100]] + + Github\Api\Issue\Milestones: + factory: ['@Github\Api\Issue', milestones] + + Github\Api\Issue\Timeline: + factory: ['@Github\Api\Issue', timeline] + calls: + - [configure] + + Github\Api\PullRequest: + factory: ['@Github\Client', api] + arguments: [pullRequest] + + Github\Api\PullRequest\Review: + factory: ['@Github\Api\PullRequest', reviews] + + Github\Api\Repo: + factory: ['@Github\Client', api] + arguments: [repo] + + Github\Api\Search: + factory: ['@Github\Client', api] + arguments: [search] + calls: + - ['setPerPage', [100]] diff --git a/config/services.yaml b/config/services.yaml index a417dc16..36387fb8 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -61,32 +61,6 @@ services: resource: '../src/Subscriber/*' autoconfigure: false - Github\Api\Issue: - factory: ['@Github\Client', api] - arguments: [issue] - - Github\Api\PullRequest: - factory: ['@Github\Client', api] - arguments: [pullRequest] - - Github\Api\Repo: - factory: ['@Github\Client', api] - arguments: [repo] - - Github\Api\Search: - factory: ['@Github\Client', api] - arguments: [search] - - Github\Api\Issue\Labels: - factory: ['@Github\Api\Issue', labels] - calls: - - ['setPerPage', [100]] - - Github\Api\Issue\Milestones: - factory: ['@Github\Api\Issue', milestones] - - Github\Api\Issue\Comments: - factory: ['@Github\Api\Issue', comments] App\Api\Issue\IssueApi: '@App\Api\Issue\GithubIssueApi' App\Api\Label\LabelApi: '@App\Api\Label\GithubLabelApi' diff --git a/config/services_test.yaml b/config/services_test.yaml index 5c745283..2467a470 100644 --- a/config/services_test.yaml +++ b/config/services_test.yaml @@ -6,5 +6,5 @@ services: App\Api\Issue\IssueApi: '@App\Api\Issue\NullIssueApi' App\Api\Label\LabelApi: '@App\Api\Label\StaticLabelApi' App\Api\Milestone\MilestoneApi: '@App\Api\Milestone\StaticMilestoneApi' - App\Api\PullRequest\PullRequestApi: '@App\Api\PullRequest\GithubPullRequestApi' + App\Api\PullRequest\PullRequestApi: '@App\Api\PullRequest\NullPullRequestApi' App\Api\Status\StatusApi: '@App\Api\Status\NullStatusApi' diff --git a/src/Api/PullRequest/GithubPullRequestApi.php b/src/Api/PullRequest/GithubPullRequestApi.php index 61e3ae6d..738bad18 100644 --- a/src/Api/PullRequest/GithubPullRequestApi.php +++ b/src/Api/PullRequest/GithubPullRequestApi.php @@ -12,9 +12,6 @@ */ class GithubPullRequestApi implements PullRequestApi { - /** - * @var Repo - */ private $github; private $pullRequest; private $search; diff --git a/src/Command/RunTaskCommand.php b/src/Command/RunTaskCommand.php index 9b8000f0..f8b026c6 100644 --- a/src/Command/RunTaskCommand.php +++ b/src/Command/RunTaskCommand.php @@ -40,7 +40,7 @@ protected function execute(InputInterface $input, OutputInterface $output) try { $this->taskRunner->run($task); } catch (\Exception $e) { - $this->logger->error('Failed running task', ['excpetion' => $e]); + $this->logger->error('Failed running task', ['exception' => $e]); $output->writeln($e->getMessage()); } } diff --git a/src/Service/TaskScheduler.php b/src/Service/TaskScheduler.php new file mode 100644 index 00000000..57d80a6a --- /dev/null +++ b/src/Service/TaskScheduler.php @@ -0,0 +1,31 @@ + + */ +class TaskScheduler +{ + private $taskRepo; + + public function __construct(TaskRepository $taskRepo) + { + $this->taskRepo = $taskRepo; + } + + public function runLater(Repository $repository, $number, int $action, \DateTimeImmutable $checkAt) + { + $task = new Task($repository->getFullName(), $number, $action, $checkAt); + $this->taskRepo->persist($task); + $this->taskRepo->flush(); + } +}