norman-huth / github-api
PHP GitHub API 包装器,使用 Laravel HTTP 客户端(基于 Guzzle HTTP 客户端)。
Requires
- php: ^8.2
- guzzlehttp/guzzle: ^7.0
- illuminate/http: ^9.0|^10.0|^11.0
Requires (Dev)
- laravel/pint: ^1.13
- pedrotroller/php-cs-custom-fixer: ^2.33
README
A PHP GitHub API wrapper which used the Laravel HTTP Client (based on Guzzle HTTP client).
此包不需要 Laravel,可以在任何 PHP 应用程序中使用。
API 端点方法是通过来自 octokit/openapi 的引用自动生成的。
安装
composer require norman-huth/github-api
用法
<?php use NormanHuth\GithubApi\Client; require_once __DIR__ . '/vendor/autoload.php'; $client = new Client('{GITHUB_TOKEN_HERE}'); $response = $client->repos()->reposCreateAFork( owner: 'Muetze42', repo: 'github-api', requestBody: ['organization' => 'MyVendor', 'name' => 'MyRepo'] ); // Get data as array return $response->json() // Get data as object return $response->object() // More infos: https://laravel.net.cn/docs/http-client#making-requests
每个方法都返回一个 \Illuminate\Http\Client\Response
。
<?php if ($response->successful()) { return $response->json(); }
端点
参见 ENDPOINTS.md
当前认证用户的别名方法
对于当前认证用户的常用端点,也有可以直接从客户端调用的附加方法。
获取认证用户
对 $client->users()->getTheAuthenticatedUser()
的别名。
使用 REST API 获取关于认证用户的公共和私有信息。
参考: https://githubdocs.cn/en/rest/users/users#get-the-authenticated-user
<?php $client->whoami();
列出认证用户的仓库
参考: https://githubdocs.cn/en/rest/repos/repos#list-repositories-for-the-authenticated-user
对 $client->repos()->listRepositoriesForTheAuthenticatedUser()
的别名。
<?php $client->userRepositories();
列出认证用户的 gists
参考: https://githubdocs.cn/rest/gists/gists#list-gists-for-the-authenticated-user
对 $client->gists()->listGistsForTheAuthenticatedUser()
的别名。
<?php $client->userGists();
列出分配给认证用户的问题
参考: https://githubdocs.cn/en/rest/issues/issues#list-issues-assigned-to-the-authenticated-user
对 $client->issues()->listIssuesAssignedToTheAuthenticatedUser()
的别名。
<?php $client->userIssues();
列出分配给认证用户的提醒
参考: https://githubdocs.cn/en/rest/activity/notifications#list-notifications-for-the-authenticated-user
对 $client->activity()->listNotificationsForTheAuthenticatedUser()
的别名。
<?php $client->userNotifications();
列出分配给认证用户的组织问题
对 $client->issues()->listOrganizationIssuesAssignedToTheAuthenticatedUser()
的别名。
<?php $client->userOrganizationIssues();
列出分配给认证用户的仓库提醒
对 $client->activity()->listRepositoryNotificationsForTheAuthenticatedUser()
的别名。
<?php $client->userRepositoryNotifications();