norman-huth/github-api

该包已废弃,不再维护。未建议替代包。

PHP GitHub API 包装器,使用 Laravel HTTP 客户端(基于 Guzzle HTTP 客户端)。

1.0.1 2024-03-11 16:54 UTC

This package is auto-updated.

Last update: 2024-04-11 17:14:40 UTC


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();

列出分配给认证用户的组织问题

参考: https://githubdocs.cn/en/rest/issues/issues#list-organization-issues-assigned-to-the-authenticated-user

$client->issues()->listOrganizationIssuesAssignedToTheAuthenticatedUser() 的别名。

<?php

$client->userOrganizationIssues();

列出分配给认证用户的仓库提醒

参考: https://githubdocs.cn/en/rest/activity/notifications#list-repository-notifications-for-the-authenticated-user

$client->activity()->listRepositoryNotificationsForTheAuthenticatedUser() 的别名。

<?php

$client->userRepositoryNotifications();