Skip to content

Commit

Permalink
Adding PullRequestApi (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyholm authored Nov 8, 2020
1 parent 3e33802 commit 517d05b
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 11 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 6 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions src/Api/PullRequest/GithubPullRequestApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace App\Api\PullRequest;

use App\Model\Repository;
use Github\Api\PullRequest;
use Github\Api\Repo;

/**
* @author Tobias Nyholm <[email protected]>
*/
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,
]);
}
}
22 changes: 22 additions & 0 deletions src/Api/PullRequest/NullPullRequestApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace App\Api\PullRequest;

use App\Model\Repository;

/**
* @author Tobias Nyholm <[email protected]>
*/
class NullPullRequestApi implements PullRequestApi
{
public function show(Repository $repository, $number): array
{
return [];
}

public function findReviewer(Repository $repository, $number, string $type)
{
}
}
20 changes: 20 additions & 0 deletions src/Api/PullRequest/PullRequestApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace App\Api\PullRequest;

use App\Model\Repository;

/**
* Actions that are specific to pull requests.
* Actions like comment/close can be performed using the IssueApi.
*
* @author Tobias Nyholm <[email protected]>
*/
interface PullRequestApi
{
public function show(Repository $repository, $number): array;

public function findReviewer(Repository $repository, $number, string $type);
}

0 comments on commit 517d05b

Please sign in to comment.