krzysztofzylka/github 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

krzysztofzylka/github

Composer 安装命令:

composer require krzysztofzylka/github

包简介

PHP GitHub API client library

README 文档

README

A PHP library for interacting with the GitHub API v3. This library provides a simple and intuitive interface for working with GitHub repositories, users, issues, pull requests, and more.

Features

  • Authentication: Support for Personal Access Tokens, OAuth tokens, and Basic authentication
  • Repository Management: Create, update, delete repositories and manage branches
  • Issue Management: Create, update, close, and manage issues
  • Pull Request Management: Create, update, merge pull requests
  • User Management: Get user information and manage user data
  • Organization Management: Work with GitHub organizations
  • Authorization: Check permissions and token validity
  • Rate Limiting: Built-in rate limit handling
  • Pagination: Automatic pagination for large result sets

Installation

composer require krzysztozylka/github

Quick Start

Basic Usage

use krzysztofzylka\github\Github;
use krzysztofzylka\github\Auth\TokenAuth;

// Create authentication
$auth = new TokenAuth('your-personal-access-token');

// Initialize GitHub client
$github = new Github($auth);

// Get authenticated user
$user = $github->users()->me();

// Get repository information
$repo = $github->repositories()->get('owner', 'repository-name');

// List issues
$issues = $github->issues()->all('owner', 'repository-name');

Authentication Methods

Personal Access Token

use krzysztofzylka\github\Auth\TokenAuth;

$auth = new TokenAuth('your-personal-access-token');

OAuth Token

use krzysztofzylka\github\Auth\OAuthAuth;

$auth = new OAuthAuth('your-oauth-token');

Basic Authentication (Deprecated)

use krzysztofzylka\github\Auth\BasicAuth;

$auth = new BasicAuth('username', 'password');

API Examples

Repository Operations

// Get repository
$repo = $github->repositories()->get('owner', 'repo-name');

// Create repository
$newRepo = $github->repositories()->create([
    'name' => 'new-repository',
    'description' => 'Repository description',
    'private' => false
]);

// List user repositories
$repos = $github->repositories()->listUserRepos('username');

// List branches
$branches = $github->repositories()->listBranches('owner', 'repo-name');

// Create branch
$branch = $github->repositories()->createBranch('owner', 'repo-name', 'new-branch', 'commit-sha');

Issue Operations

// List issues
$issues = $github->issues()->all('owner', 'repo-name', [
    'state' => 'open',
    'labels' => 'bug'
]);

// Create issue
$issue = $github->issues()->create('owner', 'repo-name', [
    'title' => 'Bug report',
    'body' => 'Issue description',
    'labels' => ['bug', 'help wanted']
]);

// Update issue
$updatedIssue = $github->issues()->update('owner', 'repo-name', 123, [
    'title' => 'Updated title'
]);

// Close issue
$github->issues()->close('owner', 'repo-name', 123);

Pull Request Operations

// List pull requests
$prs = $github->pullRequests()->all('owner', 'repo-name', [
    'state' => 'open'
]);

// Create pull request
$pr = $github->pullRequests()->create('owner', 'repo-name', [
    'title' => 'Feature implementation',
    'head' => 'feature-branch',
    'base' => 'main',
    'body' => 'Pull request description'
]);

// Merge pull request
$github->pullRequests()->merge('owner', 'repo-name', 123, [
    'merge_method' => 'squash'
]);

User Operations

// Get authenticated user
$user = $github->users()->me();

// Get user by username
$user = $github->users()->get('username');

// Update user profile
$updatedUser = $github->users()->update([
    'name' => 'New Name',
    'bio' => 'Updated bio'
]);

// List user organizations
$orgs = $github->users()->organizations('username');

Authorization and Permissions

// Check token scopes
$scopes = $github->authorization()->getScopes();

// Check if token has specific scope
if ($github->authorization()->hasScope('repo')) {
    // Can access private repositories
}

// Check if token can perform action
if ($github->authorization()->canPerformAction('create_repo')) {
    // Can create repositories
}

// Get rate limit information
$rateLimit = $github->authorization()->getRateLimit();

// Check if token is valid
if ($github->authorization()->isTokenValid()) {
    // Token is working
}

Error Handling

The library throws standard PHP exceptions for API errors:

try {
    $repo = $github->repositories()->get('owner', 'non-existent-repo');
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
    echo "Code: " . $e->getCode();
}

Rate Limiting

The library automatically handles GitHub's rate limiting:

// Get current rate limit information
$rateLimit = $github->getClient()->getRateLimit();

echo "Limit: " . $rateLimit['limit'];
echo "Remaining: " . $rateLimit['remaining'];
echo "Reset time: " . date('Y-m-d H:i:s', $rateLimit['reset']);

Pagination

For endpoints that return large result sets, the library automatically handles pagination:

// Get all repositories (automatically paginated)
$allRepos = $github->repositories()->listUserRepos('username');

// Limit pagination to specific number of pages
$limitedRepos = $github->getClient()->paginate('/user/repos', [], 5);

Requirements

  • PHP 8.0 or higher
  • cURL extension
  • JSON extension

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

krzysztofzylka/github 适用场景与选型建议

krzysztofzylka/github 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.55k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 krzysztofzylka/github 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 krzysztofzylka/github 我们能提供哪些服务?
定制开发 / 二次开发

基于 krzysztofzylka/github 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.55k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-19