Skip to content

Commit 517d05b

Browse files
authored
Adding PullRequestApi (#113)
1 parent 3e33802 commit 517d05b

File tree

5 files changed

+93
-11
lines changed

5 files changed

+93
-11
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"doctrine/doctrine-migrations-bundle": "^3.0",
1010
"doctrine/orm": "^2.7",
1111
"incenteev/composer-parameter-handler": "~2.0",
12-
"knplabs/github-api": "^2.1",
12+
"knplabs/github-api": "^2.16",
1313
"nyholm/psr7": "^1.3",
1414
"sensio/framework-extra-bundle": "^5.1",
1515
"symfony/console": "^5.1",

composer.lock

+6-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace App\Api\PullRequest;
4+
5+
use App\Model\Repository;
6+
use Github\Api\PullRequest;
7+
use Github\Api\Repo;
8+
9+
/**
10+
* @author Tobias Nyholm <[email protected]>
11+
*/
12+
class GithubPullRequestApi implements PullRequestApi
13+
{
14+
/**
15+
* @var Repo
16+
*/
17+
private $github;
18+
private $botUsername;
19+
private $pullRequest;
20+
21+
public function __construct(Repo $github, PullRequest $pullRequest, string $botUsername)
22+
{
23+
$this->github = $github;
24+
$this->botUsername = $botUsername;
25+
$this->pullRequest = $pullRequest;
26+
}
27+
28+
public function show(Repository $repository, $number): array
29+
{
30+
return (array) $this->pullRequest->show($repository->getVendor(), $repository->getName(), $number);
31+
}
32+
33+
/**
34+
* Trigger start of a "find reviewer" job. The job runs on github actions and will comment on the PR.
35+
*/
36+
public function findReviewer(Repository $repository, $number, string $type)
37+
{
38+
$this->github->dispatch($this->botUsername, 'carsonbot', 'find-reviewer', [
39+
'repository' => $repository->getFullName(),
40+
'pull_request_number' => $number,
41+
'type' => $type,
42+
]);
43+
}
44+
}
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Api\PullRequest;
6+
7+
use App\Model\Repository;
8+
9+
/**
10+
* @author Tobias Nyholm <[email protected]>
11+
*/
12+
class NullPullRequestApi implements PullRequestApi
13+
{
14+
public function show(Repository $repository, $number): array
15+
{
16+
return [];
17+
}
18+
19+
public function findReviewer(Repository $repository, $number, string $type)
20+
{
21+
}
22+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Api\PullRequest;
6+
7+
use App\Model\Repository;
8+
9+
/**
10+
* Actions that are specific to pull requests.
11+
* Actions like comment/close can be performed using the IssueApi.
12+
*
13+
* @author Tobias Nyholm <[email protected]>
14+
*/
15+
interface PullRequestApi
16+
{
17+
public function show(Repository $repository, $number): array;
18+
19+
public function findReviewer(Repository $repository, $number, string $type);
20+
}

0 commit comments

Comments
 (0)