-
Notifications
You must be signed in to change notification settings - Fork 429
/
GitHubApi.php
43 lines (35 loc) · 1.15 KB
/
GitHubApi.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace App\Services\GitHub;
use Github\Client;
use Github\ResultPager;
use Illuminate\Support\Collection;
class GitHubApi
{
public function __construct(Client $client)
{
$this->client = $client;
}
public function fetchPublicRepositories(string $userName): Collection
{
$repos = $this->fetchAllResults('organization', 'repositories', [$userName]);
return collect($repos)->filter(function ($repo) {
return $repo['private'] === false;
});
}
public function fetchContributors(string $userName, string $repoName): Collection
{
return collect($this->fetchAllResults('repo', 'statistics', [$userName, $repoName]));
}
public function fetchPullRequests(string $userName, string $repoName): Collection
{
return collect($this->fetchAllResults('pull_request', 'all', [$userName, $repoName]));
}
protected function fetchAllResults(string $interfaceName, string $method, array $parameters)
{
return (new ResultPager($this->client))->fetchAll(
$this->client->api($interfaceName),
$method,
$parameters
);
}
}