ssionn / github-forge-laravel

为 Laravel 提供的 GitHub REST API 客户端

v0.0.59 2024-08-23 00:11 UTC

This package is auto-updated.

Last update: 2024-09-24 08:58:30 UTC


README

一个用于集成 GitHub API 功能的 Laravel 扩展包。

安装

  1. 通过 Composer 安装包

    composer require ssionn/github-forge-laravel
  2. (如果您使用的是 Laravel 5.5 或更早版本) 注册服务提供者:将以下行添加到 config/app.php 文件中的 providers 数组

    'providers' => [
        // Other Service Providers
    
        Ssionn\GithubForgeLaravel\GitHubForgeServiceProvider::class,
    ],
  3. 发布配置文件

    php artisan vendor:publish --provider="Ssionn\GithubForgeLaravel\GithubForgeServiceProvider" --tag=config
  4. 在配置文件 config/github-forge.php 中设置您的 GitHub API 令牌

    return [
        'token' => env('GITHUB_API_TOKEN', 'your-github-token-here'),
    ];

使用

您可以直接在应用程序中使用 GithubClient,例如:

use Ssionn\GithubForgeLaravel\GitHubClient;

$client = app('github-forge');
$response = $client->getUser($username);

或者,您可以使用提供的门面(facade)以更方便和简洁的语法使用:

use Ssionn\GithubForgeLaravel\Facades\GithubForge;

$response = GithubForge::getUser($username);

门面方法如下:

  • GithubForge::getUser(string $username)
  • GithubForge::getRepositories(string $username, string $type = 'all', string $sort = 'full_name', string $direction = 'asc', int $perPage = 30, int $page = 1)
  • GithubForge::getRepository(string $owner, string $repo)
  • GithubForge::getContributors(string $owner, string $repo)
  • GithubForge::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)
  • GithubForge::getIssues(string $owner, string $repo, string $state = 'open', int $perPage = 30, int $page = 1)

选择最适合您需求的方法,并享受与 GitHub API 的流畅集成。

许可协议

本软件包采用 MIT 许可协议许可。