Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Ssionn committed Jul 23, 2024
1 parent a6e6fc4 commit ff01749
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Facades/GithubForge.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @method static array|null getUser(string $username)
* @method static array|null getRepositories(string $username, string $type = 'all', string $sort = 'full_name', string $direction = 'asc', int $perPage = 30, int $page = 1)
* @method static array|null getRepository(string $owner, string $repo)
* @method static array|null getContributors(string $owner, string $repo)
* @method static array|null getCommitsFromRepository(string $owner, string $repo, ?string $sha = null, ?string $path = null, ?string $author = null, ?string $since = null, ?string $until = null, int $perPage = 30, int $page = 1)
* @method static array|null getIssues(string $owner, string $repo, string $state = 'open', int $perPage = 30, int $page = 1)
*
Expand Down
23 changes: 23 additions & 0 deletions src/GithubClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,29 @@ public function getCommitsFromRepository(
return $response->json();
});
}
/**
* Get all contributors from repository
*
* @param string $owner The owner of the repository
* @param string $repo The name of the repository
*
*/
public function getContributors(string $owner, string $repo): ?array
{
$response = Http::withHeaders([
'Accept' => 'application/vnd.github.v3+json',
'Authorization' => 'Bearer ' . $this->token,
'X-GitHub-Api-Version' => '2022-11-28',
])->get("{$this->baseUrl}/repos/{$owner}/{$repo}/contributors");

if ($response->failed()) {
return null;
}

return Cache::remember('github_repo_' . $repo . '_contributors', 3600, function () use ($response) {
return $response->json();
});
}

/**
* Get issues from a repository.
Expand Down

0 comments on commit ff01749

Please sign in to comment.