PHPackages                             horde/githubapiclient - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. horde/githubapiclient

ActiveLibrary[API Development](/categories/api)

horde/githubapiclient
=====================

Interact with the Github API from PHP code

v0.0.1RC1(1mo ago)01491LGPL-2.1-onlyPHPPHP ^8.2

Since Apr 28Pushed 1mo ago6 watchersCompare

[ Source](https://github.com/horde/GithubApiClient)[ Packagist](https://packagist.org/packages/horde/githubapiclient)[ Docs](https://www.horde.org)[ RSS](/packages/horde-githubapiclient/feed)WikiDiscussions FRAMEWORK\_6\_0 Synced 3w ago

READMEChangelog (5)Dependencies (14)Versions (14)Used By (1)

horde/githubapiclient
=====================

[](#hordegithubapiclient)

A horde/http based client for the GitHub REST API v3.

Installation
------------

[](#installation)

```
composer require horde/githubapiclient
```

**Upgrading?** See the [Migration Guide](doc/MIGRATION.md) for upgrading from earlier versions.

Quick Start
-----------

[](#quick-start)

```
use Horde\GithubApiClient\GithubApiClient;
use Horde\GithubApiClient\GithubApiConfig;
use Horde\GithubApiClient\GithubRepository;
use Horde\Http\Client;

// Create configuration
$config = new GithubApiConfig(accessToken: 'your-github-token');

// Create HTTP client (PSR-18 compatible)
$httpClient = new Client();
$requestFactory = new \Horde\Http\RequestFactory();
$streamFactory = new \Horde\Http\StreamFactory();

// Create API client
$client = new GithubApiClient($httpClient, $requestFactory, $config, $streamFactory);

// Use the client
$repo = new GithubRepository(owner: 'horde', name: 'components');
$pullRequests = $client->listPullRequests($repo);
```

Features
--------

[](#features)

### Repository Management

[](#repository-management)

- List repositories in an organization
- Get repository details

### Pull Requests

[](#pull-requests)

- Create new pull requests
- List pull requests with filters (base branch, head ref, state)
- Get a single pull request with complete details
- Update pull request (title, body, base branch, state)
- Merge pull requests (merge, squash, or rebase)
- Close pull requests
- Reopen closed pull requests

### Comments

[](#comments)

- List all comments on a pull request
- Create a comment on a pull request
- Update existing comments
- Delete comments

### Reviews

[](#reviews)

- List all reviews on a pull request
- Request reviewers (users and teams)
- Check review states (APPROVED, CHANGES\_REQUESTED, COMMENTED, DISMISSED)

### Status Checks

[](#status-checks)

- Get combined commit status
- List GitHub Actions check runs
- Monitor CI/CD pipeline status

### Labels

[](#labels)

- List labels on issues/pull requests
- Add labels to issues/pull requests
- Set (replace) all labels on issues/pull requests
- Remove labels from issues/pull requests

### Rate Limiting

[](#rate-limiting)

- Check current rate limit status
- Inspect OAuth token scopes

Detailed Usage
--------------

[](#detailed-usage)

### Working with Pull Requests

[](#working-with-pull-requests)

#### List Pull Requests

[](#list-pull-requests)

```
$repo = new GithubRepository(owner: 'horde', name: 'components');

// List all open pull requests
$pullRequests = $client->listPullRequests($repo);

// Filter by base branch
$pullRequests = $client->listPullRequests($repo, baseBranch: 'main');

// Filter by head ref
$pullRequests = $client->listPullRequests($repo, headRef: 'feature-branch');

foreach ($pullRequests as $pr) {
    echo "PR #{$pr->number}: {$pr->title}\n";
}
```

#### Get Pull Request Details

[](#get-pull-request-details)

```
$pr = $client->getPullRequest($repo, number: 123);

echo "Title: {$pr->title}\n";
echo "State: {$pr->state}\n";
echo "Mergeable: " . ($pr->mergeable ? 'Yes' : 'No') . "\n";
echo "Draft: " . ($pr->draft ? 'Yes' : 'No') . "\n";
```

#### Create Pull Request

[](#create-pull-request)

```
use Horde\GithubApiClient\CreatePullRequestParams;

// Create a regular pull request
$params = new CreatePullRequestParams(
    title: 'Add new feature',
    head: 'feature-branch',
    base: 'main',
    body: 'This PR adds a new feature\n\nCloses #123'
);
$newPr = $client->createPullRequest($repo, $params);

// Create a draft pull request
$draftParams = new CreatePullRequestParams(
    title: 'Work in progress',
    head: 'wip-branch',
    base: 'develop',
    body: 'This is still being worked on',
    draft: true
);
$draftPr = $client->createPullRequest($repo, $draftParams);

// Create PR from a fork
$forkParams = new CreatePullRequestParams(
    title: 'Fix from fork',
    head: 'username:feature-branch',  // Format: username:branch
    base: 'main'
);
$forkPr = $client->createPullRequest($repo, $forkParams);
```

#### Update Pull Request

[](#update-pull-request)

```
use Horde\GithubApiClient\PullRequestUpdate;

// Update title and body
$update = new PullRequestUpdate(
    title: 'New PR Title',
    body: 'Updated description'
);
$updatedPr = $client->updatePullRequest($repo, 123, $update);

// Change base branch
$update = new PullRequestUpdate(base: 'develop');
$updatedPr = $client->updatePullRequest($repo, 123, $update);

// Close a pull request
$closedPr = $client->closePullRequest($repo, 123);

// Reopen a closed pull request
$reopenedPr = $client->reopenPullRequest($repo, 123);
```

#### Merge Pull Request

[](#merge-pull-request)

```
use Horde\GithubApiClient\MergePullRequestParams;

// Simple merge with defaults
$params = new MergePullRequestParams();
$result = $client->mergePullRequest($repo, 123, $params);

if ($result->merged) {
    echo "Merged successfully: {$result->sha}\n";
}

// Squash merge with custom commit message
$params = new MergePullRequestParams(
    commitTitle: 'feat: add new feature',
    commitMessage: 'This PR implements feature X\n\nCloses #123',
    mergeMethod: 'squash'
);
$result = $client->mergePullRequest($repo, 123, $params);

// Rebase merge
$params = new MergePullRequestParams(mergeMethod: 'rebase');
$result = $client->mergePullRequest($repo, 123, $params);

// Safe merge with SHA check
$params = new MergePullRequestParams(
    sha: 'abc123def456',  // Only merge if head SHA matches
    mergeMethod: 'merge'
);
$result = $client->mergePullRequest($repo, 123, $params);
```

### Working with Comments

[](#working-with-comments)

```
// List comments
$comments = $client->listPullRequestComments($repo, 123);
foreach ($comments as $comment) {
    echo "{$comment->author->login}: {$comment->body}\n";
}

// Create a comment
$comment = $client->createPullRequestComment($repo, 123, 'Looks good to me!');
echo "Created comment: {$comment->htmlUrl}\n";

// Update a comment
$updatedComment = $client->updateComment($repo, $comment->id, 'Updated comment text');

// Delete a comment
$client->deleteComment($repo, $comment->id);
```

### Working with Reviews

[](#working-with-reviews)

```
// List reviews
$reviews = $client->listPullRequestReviews($repo, 123);
foreach ($reviews as $review) {
    echo "{$review->user->login}: {$review->state}\n";
}

// Request reviewers
$updatedPr = $client->requestReviewers(
    $repo,
    123,
    reviewers: ['username1', 'username2'],
    teamReviewers: ['team-slug']
);
```

### Working with Status Checks

[](#working-with-status-checks)

```
// Get combined status for a commit or branch
$status = $client->getCombinedStatus($repo, 'main');
echo "Overall status: {$status->state}\n";
echo "Total checks: {$status->totalCount}\n";

foreach ($status->statuses as $check) {
    echo "{$check->context}: {$check->state}\n";
}

// List check runs (GitHub Actions)
$checkRuns = $client->listCheckRuns($repo, 'feature-branch');
foreach ($checkRuns as $run) {
    echo "{$run->name}: {$run->status}/{$run->conclusion}\n";
}
```

### Working with Labels

[](#working-with-labels)

```
// List labels
$labels = $client->listIssueLabels($repo, 123);
foreach ($labels as $label) {
    echo "{$label->name} (#{$label->color})\n";
}

// Add labels
$labels = $client->addLabels($repo, 123, ['bug', 'priority-high']);

// Set labels (replaces all existing labels)
$labels = $client->setLabels($repo, 123, ['bug', 'in-progress']);

// Remove a label
$client->removeLabel($repo, 123, 'wontfix');
```

### Rate Limiting and Token Information

[](#rate-limiting-and-token-information)

```
// Check rate limit
$rateLimit = $client->getRateLimit();
echo "Remaining: {$rateLimit->remaining}/{$rateLimit->limit}\n";
echo "Resets at: {$rateLimit->reset}\n";

// Check token scopes
$scopes = $client->getTokenScopes();
if ($scopes->hasScope('repo')) {
    echo "Token has repo access\n";
}
```

Architecture
------------

[](#architecture)

This library follows a Request Factory pattern:

- **Value Objects**: Immutable data classes (`GithubPullRequest`, `GithubComment`, etc.)
- **Factories**: Create value objects from API responses
- **Request Factories**: Build PSR-7 HTTP requests for each API endpoint
- **Collections**: Typed collections implementing `Iterator` and `Countable`
- **DTOs**: Data Transfer Objects for complex request parameters

All classes use PHP 8.2+ features including:

- Named parameters
- Readonly properties
- Strict types
- Constructor property promotion

Testing
-------

[](#testing)

```
# Run unit tests
vendor/bin/phpunit

# Run with coverage
vendor/bin/phpunit --coverage-html coverage/
```

Requirements
------------

[](#requirements)

- PHP 8.2 or higher
- PSR-18 HTTP Client implementation
- PSR-7 HTTP Message implementation
- PSR-17 HTTP Factories implementation

License
-------

[](#license)

See the enclosed file LICENSE for license information (LGPL 2.1).

Contributing
------------

[](#contributing)

This package follows PER-1 coding standards with strict type declarations.

All commits should follow the Conventional Commits specification:

- `feat:` - New features
- `fix:` - Bug fixes
- `docs:` - Documentation changes
- `test:` - Test additions or modifications
- `refactor:` - Code refactoring
- `chore:` - Maintenance tasks

Additional Documentation
------------------------

[](#additional-documentation)

- [API Reference](doc/API.md) - Complete API documentation for all classes and methods
- [Migration Guide](doc/MIGRATION.md) - Guide for upgrading from earlier versions
- `bin/demo-client.php` - Working examples of all features

###  Health Score

42

—

FairBetter than 89% of packages

Maintenance93

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~77 days

Recently: every ~21 days

Total

6

Last Release

36d ago

PHP version history (2 changes)v0.0.1alpha2PHP ^8.3

v0.0.1alpha5PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/c931cd02664859360478593450d6c473a05bb12b209dfacfc534cd13257cc7ef?d=identicon)[ralflang](/maintainers/ralflang)

![](https://www.gravatar.com/avatar/e4f6c6771993db2ed500959b42353f6cf6a2ca0406d9617f7ae680f4504faa4a?d=identicon)[horde](/maintainers/horde)

---

Top Contributors

[![ralflang](https://avatars.githubusercontent.com/u/646976?v=4)](https://github.com/ralflang "ralflang (54 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/horde-githubapiclient/health.svg)

```
[![Health](https://phpackages.com/badges/horde-githubapiclient/health.svg)](https://phpackages.com/packages/horde-githubapiclient)
```

###  Alternatives

[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k12](/packages/tempest-framework)[cakephp/cakephp

The CakePHP framework

8.8k19.1M1.7k](/packages/cakephp-cakephp)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

35729.6k2](/packages/telnyx-telnyx-php)[mollie/mollie-api-php

Mollie API client library for PHP. Mollie is a European Payment Service provider and offers international payment methods such as Mastercard, VISA, American Express and PayPal, and local payment methods such as iDEAL, Bancontact, SOFORT Banking, SEPA direct debit, Belfius Direct Net, KBC Payment Button and various gift cards such as Podiumcadeaukaart and fashioncheque.

60315.4M74](/packages/mollie-mollie-api-php)[getbrevo/brevo-php

Official Brevo provided RESTFul API V3 php library

1003.6M46](/packages/getbrevo-brevo-php)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

84735.1k](/packages/flow-php-flow)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
