From 517d05be333fe57120d75fba1d17b3a7a89656fa Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 8 Nov 2020 17:34:16 +0100 Subject: [PATCH] Adding PullRequestApi (#113) --- composer.json | 2 +- composer.lock | 16 +++---- src/Api/PullRequest/GithubPullRequestApi.php | 44 ++++++++++++++++++++ src/Api/PullRequest/NullPullRequestApi.php | 22 ++++++++++ src/Api/PullRequest/PullRequestApi.php | 20 +++++++++ 5 files changed, 93 insertions(+), 11 deletions(-) create mode 100644 src/Api/PullRequest/GithubPullRequestApi.php create mode 100644 src/Api/PullRequest/NullPullRequestApi.php create mode 100644 src/Api/PullRequest/PullRequestApi.php diff --git a/composer.json b/composer.json index 896c2dce..83a02e10 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "doctrine/doctrine-migrations-bundle": "^3.0", "doctrine/orm": "^2.7", "incenteev/composer-parameter-handler": "~2.0", - "knplabs/github-api": "^2.1", + "knplabs/github-api": "^2.16", "nyholm/psr7": "^1.3", "sensio/framework-extra-bundle": "^5.1", "symfony/console": "^5.1", diff --git a/composer.lock b/composer.lock index f6444dfd..a8a9707c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "27b90ddccf7df7888b4326f52a0ecb16", + "content-hash": "a8b56476d73ecdedb62be955b238e0ef", "packages": [ { "name": "clue/stream-filter", @@ -1467,16 +1467,16 @@ }, { "name": "knplabs/github-api", - "version": "v2.15.0", + "version": "v2.16.0", "source": { "type": "git", "url": "https://github.com/KnpLabs/php-github-api.git", - "reference": "03445f26843ec44319fe1f3c2a8ef6fcd545a154" + "reference": "e1c5dca1b7d2abeb218a041c29e522d62f7c6a7f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/KnpLabs/php-github-api/zipball/03445f26843ec44319fe1f3c2a8ef6fcd545a154", - "reference": "03445f26843ec44319fe1f3c2a8ef6fcd545a154", + "url": "https://api.github.com/repos/KnpLabs/php-github-api/zipball/e1c5dca1b7d2abeb218a041c29e522d62f7c6a7f", + "reference": "e1c5dca1b7d2abeb218a041c29e522d62f7c6a7f", "shasum": "" }, "require": { @@ -1532,17 +1532,13 @@ "gist", "github" ], - "support": { - "issues": "https://github.com/KnpLabs/php-github-api/issues", - "source": "https://github.com/KnpLabs/php-github-api/tree/2.x" - }, "funding": [ { "url": "https://github.com/acrobat", "type": "github" } ], - "time": "2020-07-11T16:45:45+00:00" + "time": "2020-11-08T13:42:56+00:00" }, { "name": "monolog/monolog", diff --git a/src/Api/PullRequest/GithubPullRequestApi.php b/src/Api/PullRequest/GithubPullRequestApi.php new file mode 100644 index 00000000..31720561 --- /dev/null +++ b/src/Api/PullRequest/GithubPullRequestApi.php @@ -0,0 +1,44 @@ + + */ +class GithubPullRequestApi implements PullRequestApi +{ + /** + * @var Repo + */ + private $github; + private $botUsername; + private $pullRequest; + + public function __construct(Repo $github, PullRequest $pullRequest, string $botUsername) + { + $this->github = $github; + $this->botUsername = $botUsername; + $this->pullRequest = $pullRequest; + } + + public function show(Repository $repository, $number): array + { + return (array) $this->pullRequest->show($repository->getVendor(), $repository->getName(), $number); + } + + /** + * Trigger start of a "find reviewer" job. The job runs on github actions and will comment on the PR. + */ + public function findReviewer(Repository $repository, $number, string $type) + { + $this->github->dispatch($this->botUsername, 'carsonbot', 'find-reviewer', [ + 'repository' => $repository->getFullName(), + 'pull_request_number' => $number, + 'type' => $type, + ]); + } +} diff --git a/src/Api/PullRequest/NullPullRequestApi.php b/src/Api/PullRequest/NullPullRequestApi.php new file mode 100644 index 00000000..cfb20585 --- /dev/null +++ b/src/Api/PullRequest/NullPullRequestApi.php @@ -0,0 +1,22 @@ + + */ +class NullPullRequestApi implements PullRequestApi +{ + public function show(Repository $repository, $number): array + { + return []; + } + + public function findReviewer(Repository $repository, $number, string $type) + { + } +} diff --git a/src/Api/PullRequest/PullRequestApi.php b/src/Api/PullRequest/PullRequestApi.php new file mode 100644 index 00000000..cff69382 --- /dev/null +++ b/src/Api/PullRequest/PullRequestApi.php @@ -0,0 +1,20 @@ + + */ +interface PullRequestApi +{ + public function show(Repository $repository, $number): array; + + public function findReviewer(Repository $repository, $number, string $type); +}