A simple PHP GitHub API client, Object Oriented, tested and documented.

Overview

PHP GitHub API

Build Status StyleCI Latest Stable Version Total Downloads Latest Unstable Version Monthly Downloads Daily Downloads

A simple Object Oriented wrapper for GitHub API, written with PHP.

Uses GitHub API v3 & supports GitHub API v4. The object API (v3) is very similar to the RESTful API.

Features

  • Light and fast thanks to lazy loading of API classes
  • Extensively tested and documented

Requirements

Install

Via Composer.

PHP 7.1+:

composer require knplabs/github-api:^3.0 php-http/guzzle6-adapter:^2.0.1 http-interop/http-factory-guzzle:^1.0

PHP 7.2+:

composer require knplabs/github-api:^3.0 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0

Laravel 6+:

composer require graham-campbell/github:^10.0 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0

We are decoupled from any HTTP messaging client with help by HTTPlug. Read about clients in our docs. graham-campbell/github is by Graham Campbell.

Basic usage of php-github-api client

<?php

// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';

$client = new \Github\Client();
$repositories = $client->api('user')->repositories('ornicar');

From $client object, you can access to all GitHub.

Cache usage

This example uses the PSR6 cache pool redis-adapter. See http://www.php-cache.com/ for alternatives.

<?php

// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';

use Cache\Adapter\Redis\RedisCachePool;

$client = new \Redis();
$client->connect('127.0.0.1', 6379);
// Create a PSR6 cache pool
$pool = new RedisCachePool($client);

$client = new \Github\Client();
$client->addCache($pool);

// Do some request

// Stop using cache
$client->removeCache();

Using cache, the client will get cached responses if resources haven't changed since last time, without reaching the X-Rate-Limit imposed by github.

Documentation

See the doc directory for more detailed documentation.

License

php-github-api is licensed under the MIT License - see the LICENSE file for details

Maintainers

Please read this post first.

This library is maintained by the following people (alphabetically sorted) :

  • @acrobat
  • @Nyholm

Contributors

Thanks to GitHub for the high quality API and documentation.

Comments
  • Add support for Guzzle from 4.x to 6.x

    Add support for Guzzle from 4.x to 6.x

    Closes #157.

    I propose to keep guzzle 3 support for BC and trigger a deprecated error to prevent user that support will be dropped in next major release.

    This PR is under progress.

    opened by soullivaneuh 22
  • Upgrade to PHP 7

    Upgrade to PHP 7

    Replaces #647 with passing tests and CS

    Why?

    This package would be still available for PHP 5.6-.

    Questions

    1. How to approach string/int issue in parameters?

    Often there was random typehint and for string and int there was autore-type to string rawurlencode method.

    Should be allow both string and int and manuall rawurlencode((string) $id) or be strict in parameters?

    2. How to approach null/array return values?

    At least accroding to tests, some api calls return null on fail or empty results. Array was expected in typehtings.

    At the moment they return array|null. Is that ok?

    opened by TomasVotruba 19
  • [3.x] Re-worked pagination to not mutate the api classes

    [3.x] Re-worked pagination to not mutate the api classes

    This re-works pagination to avoid mutating the API classes. It took a few attempts to get the implementation details right. Let me explain why I chose to use clone:

    1. If we were to use new static(...), then I would have had to have made the abstract api constructor final. This could cause problems for people mocking the api classes, and also limits the possibility to thunk up arguments to the api classes, say if we want to introduce an api class which takes an extra parameter which is always used (this is common place in the gitlab fork of this library).
    2. Is there another way to do things without making the constructor final or using clone? Well, we could have every api object implement perPage for themselves. This is kinda cumbersome though, and I don't think we want to do this.

    This PR partially addresses #904.

    So, I think cloning then setting the private property, within the abstract api class is the way to go, and nicely separates responsibilities. Classes that extend the abstract api class cannot mutate the property, and outsiders also cannot either. They have to call perPage which gives a fresh instance (one we've cloned).

    opened by GrahamCampbell 17
  • Make chaining available in Stargazers

    Make chaining available in Stargazers

    Allows for:

    $stargazers = $client->repo()->stargazers()->configure('star')->all('vuejs', 'vue');
    

    instead of

    $stargazers = $client->repo()->stargazers();
    $stargazers->configure('star');
    $stargazers = $stargazers->all('vuejs', 'vue');
    
    opened by Swader 16
  • Switch to PSR18 client implementation and bump httplug minimum version to ^2.0

    Switch to PSR18 client implementation and bump httplug minimum version to ^2.0

    php-http/client-implementation is deprecated and Guzzle 7 doesn't implement it, so this will be a blocker for anyone wanting to upgrade from Guzzle 6 to 7 and use this package at the same time.


    Related: https://github.com/m4tthumphrey/php-gitlab-api/pull/511, https://github.com/BitbucketAPI/Client/pull/39, https://github.com/php-http/discovery/pull/175.

    feature 
    opened by GrahamCampbell 15
  • Revert

    Revert "Fixed the exceptions"

    Reverts KnpLabs/php-github-api#410. // cc @sagikazarmark

    The other fix in the underlying http library is better. There are still issues here anyway.

    Closes #420.

    opened by GrahamCampbell 15
  • Decouple from Guzzle

    Decouple from Guzzle

    This PR replaces #352. We do not want to be coupled to Guzzle, instead we want to use an abstraction layer so the end user can choose what HTTP message implementation to use.

    This PR removes all our HTTP layer and replaces it with Httplug and custom plugins. I struggled for a while to make this PR backwards compatible but the code got too complicated and would have left us with an abstraction for an abstraction.

    Question to the maintainers: Do you like this change? Should I continue with this PR and complete the TODOs?

    TODO

    • [x] Add some more docs about HTTP plug in the readme.
    • [x] Make sure existing docs are up to date
    • [x] Make sure the tests passes
    opened by Nyholm 14
  • Add basic search api implementation.

    Add basic search api implementation.

    Example usage:

    $client->api('search')->find('issues', "repo:$repo $filter");
    

    The new search api seems to need its own class since it returns objects in a different format. This basic function seems to mimic your API syntax pretty closely.

    opened by stackpr 14
  • Could not add assignee to issue! Got:

    Could not add assignee to issue! Got: "Not Found"

    Hi, I am using the following code:

    $issue = $this->github->issues()->create($org = 'gansel-rechtsanwaelte', $repo = 'lf', [
        'title' => 'test',
        'body' => 'test body',
    ]);
    dump($issue); // the issue gets created!
    
    $assignees = $this->github->api('issue')->assignees()->listAvailable($org, $repo);
    dump($assignees); // all of them are listed
    
    // try to assign myself to an issue (I am org and repo owner)
    $this->github->api('issue')->assignees()->add($org, $repo, $issue['id'], [
        'assignees' => ['OskarStark']
    ]);
    
    The error In GithubExceptionThrower.php line 100:

    [Github\Exception\RuntimeException (404)] Not Found

    Exception trace: at /app/vendor/knplabs/github-api/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php:100 Github\HttpClient\Plugin\GithubExceptionThrower->Github\HttpClient\Plugin{closure}() at /app/vendor/php-http/httplug/src/Promise/HttpFulfilledPromise.php:34 Http\Client\Promise\HttpFulfilledPromise->then() at /app/vendor/knplabs/github-api/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php:101 Github\HttpClient\Plugin\GithubExceptionThrower->doHandleRequest() at /app/vendor/php-http/client-common/src/Plugin/VersionBridgePlugin.php:22 Github\HttpClient\Plugin\GithubExceptionThrower->handleRequest() at /app/vendor/php-http/client-common/src/PluginClient.php:132 Http\Client\Common\PluginClient->Http\Client\Common{closure}() at /app/vendor/php-http/client-common/src/PluginClient.php:146 Http\Client\Common\PluginClient->Http\Client\Common{closure}() at /app/vendor/php-http/client-common/src/PluginClient.php:90 Http\Client\Common\PluginClient->sendRequest() at /app/vendor/php-http/client-common/src/HttpMethodsClient.php:82 Http\Client\Common\HttpMethodsClient->sendRequest() at /app/vendor/php-http/client-common/src/HttpMethodsClient.php:73 Http\Client\Common\HttpMethodsClient->send() at /app/vendor/php-http/client-common/src/HttpMethodsClient.php:47 Http\Client\Common\HttpMethodsClient->post() at /app/vendor/knplabs/github-api/lib/Github/Api/AbstractApi.php:164 Github\Api\AbstractApi->postRaw() at /app/vendor/knplabs/github-api/lib/Github/Api/AbstractApi.php:146 Github\Api\AbstractApi->post() at /app/vendor/knplabs/github-api/lib/Github/Api/Issue/Assignees.php:66 Github\Api\Issue\Assignees->add() at /app/src/Command/Test/TestRamicroCreateAkteCommand.php:79 App\Command\Test\TestRamicroCreateAkteCommand->execute() at /app/vendor/symfony/console/Command/Command.php:255 Symfony\Component\Console\Command\Command->run() at /app/vendor/symfony/console/Application.php:952 Symfony\Component\Console\Application->doRunCommand() at /app/vendor/symfony/framework-bundle/Console/Application.php:87 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /app/vendor/symfony/console/Application.php:273 Symfony\Component\Console\Application->doRun() at /app/vendor/symfony/framework-bundle/Console/Application.php:73 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /app/vendor/symfony/console/Application.php:149 Symfony\Component\Console\Application->run() at /app/bin/console:42

    Checked the Github-API docs, but everything looks correct: https://developer.github.com/v3/issues/assignees/#parameters

    opened by OskarStark 13
  • IDE friendly API

    IDE friendly API

    It would be great if the different sub-APIs could be exposed through dedicated methods in the main client rather than having to use ->api('issues') which breaks any kind of autocompletion or type checks on the library usage.

    opened by stof 13
  • Actions (#872)

    Actions (#872)

    • [x] Artifacts
    • [x] Secrets
    • [x] Self-hosted runners
    • [x] Workflows
    • [x] Workflow jobs
    • [x] Workflow runs

    Documentation: https://developer.github.com/v3/actions/

    opened by lexor 12
  • Add .phpstorm.meta.php to improve code completion

    Add .phpstorm.meta.php to improve code completion

    Folks, adding a .phpstorm.meta.php file with something like this below, would make users' experience with the package in PhpStorm a bit better when using calls like ->api('issue'):

    <?php
    namespace PHPSTORM_META {
        override( \Github\Client::api(0),
          map( [
            "issue" => \Github\Api\Issue::class,
            //...
        ]));
    }
    

    Would you be interested in adding it?

    opened by pronskiy 1
  • ResultPager::get() can return string

    ResultPager::get() can return string

    Because ResultPager::get() here returns the return value of ResponseMediator::getContent(), it can occasionally return a string, which causes an unhelpful TypeError since it should only ever return an array. Other usages of ResponseMediator::getContent() allow for this, but the ResultPager one does not.

    This has been occurring in practice to us so figured I'd raise it here - let me know any other information you need on this issue, it is my first one!

    opened by dangrous 3
  • Secrets Scanning Alerts

    Secrets Scanning Alerts

    Add Secrets Scanning Alerts for Entreprise, Organizations and Repository

    https://docs.github.com/en/[email protected]/rest/secret-scanning#list-secret-scanning-alerts-for-an-enterprise call : Sprintf("enterprises/%v/secret-scanning/alerts", %enterprise)

    https://docs.github.com/en/[email protected]/rest/secret-scanning#list-secret-scanning-alerts-for-an-organization call : Sprintf("orgs/%v/secret-scanning/alerts", %org)

    https://docs.github.com/en/[email protected]/rest/secret-scanning#list-secret-scanning-alerts-for-a-repository call : Sprintf("repos/%v/%v/secret-scanning/alerts", owner, repo)

    feature-request good first issue 
    opened by ls-philippe-gamache 1
  • Update list repositories methods in Teams and Apps API.

    Update list repositories methods in Teams and Apps API.

    Updated repositories method in Teams api to support the new end point. Added params argument for Apps listRepositories method and Teams repositories method.

    opened by raghavendra89 0
Releases(v3.9.0)
Owner
KNP Labs
Happy Awesome Developers
KNP Labs
OpenAI API Client is a component-oriented, extensible client library for the OpenAI API. It's designed to be faster and more memory efficient than traditional PHP libraries.

OpenAI API Client in PHP (community-maintained) This library is a component-oriented, extensible client library for the OpenAI API. It's designed to b

Mounir R'Quiba 6 Jun 14, 2023
PHP GitHub Sponsors is a package that integrates directly with the GitHub Sponsors GraphQL API.

PHP GitHub Sponsors PHP GitHub Sponsors is a package that integrates directly with the GitHub Sponsors GraphQL API. Using it, you can easily check if

GitHub PHP 101 Nov 2, 2022
NovaGram - An elegant, Object-Oriented, reliable PHP Telegram Bot Library

An elegant, Object-Oriented, reliable PHP Telegram Bot Library Full Documentation • Public support group Examples • Features • Installation ?

Gaetano 165 Jan 6, 2023
Google-api-php-client - A PHP client library for accessing Google APIs

Google APIs Client Library for PHP Reference Docs https://googleapis.github.io/google-api-php-client/main/ License Apache 2.0 The Google API Client Li

Google APIs 8.4k Dec 30, 2022
Generate pretty release changelogs using the commit log and Github API.

zenstruck/changelog Generate pretty release changelogs using the commit log and Github API. Changelog entries are in the following format: {short hash

Kevin Bond 3 Jun 20, 2022
PHP JSON-RPC 2.0 Server/Client Implementation with Automatic Client Class Generation via SMD

PHP JSON-RPC 2.0 Server/Client Implementation with Automatic Client Class Generation via SMD

Sergey Bykov 63 Feb 14, 2022
PHP library for the GitHub API v3

GitHub API v3 - PHP Library Currently under construction. Overview Provides access to GitHub API v3 via an Object Oriented PHP library. The goal of th

Darren Rees 62 Jul 28, 2022
Nexmo REST API client for PHP. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.

Client Library for PHP Support Notice This library and it's associated packages, nexmo/client and nexmo/client-core have transitioned into a "Maintena

Nexmo 75 Sep 23, 2022
A GitHub API bridge for Laravel

Laravel GitHub Laravel GitHub was created by, and is maintained by Graham Campbell, and is a PHP GitHub API bridge for Laravel. It utilises my Laravel

Graham Campbell 547 Dec 30, 2022
DigitalOcean API v2 client for Symfony and API Platform

DigitalOcean Bundle for Symfony and API Platform DunglasDigitalOceanBundle allows using the DigitalOcean API from your Symfony and API Platform projec

Kévin Dunglas 25 Jul 27, 2022
API client for ThePay - payment gate API

This is the official highly compatible public package of The Pay SDK which interacts with The Pay's REST API. To get started see examples below.

ThePay.cz s.r.o. 3 Oct 27, 2022
Code Quiz MonoRepo (API, API Client, App)

Code Quiz Welcome to the Code Quiz Open Source project from How To Code Well. This is an Open Source project that includes an API and an App for the d

How To Code Well 2 Nov 20, 2022
Attempting to create an intelligent mock of the Google API PHP Client for unit and functional testing

google-api-php-client-mock A small scale intelligent mock of the Google API PHP Client for unit and functional testing. Overview This is intended to m

SIL International 0 Jan 4, 2022
A laravel 5 package for reading and writing to facebook graph object with ease in laravelish syntax

Fluent-Facebook Docs A laravel 5 package for reading and writing to facebook graph object with ease in laravelish syntax. Check out how easy it is to

iluminar 47 Dec 8, 2022
⚡️ Web3 PHP is a supercharged PHP API client that allows you to interact with a generic Ethereum RPC.

Web3 PHP is a supercharged PHP API client that allows you to interact with a generic Ethereum RPC. This project is a work-in-progress. Code and docume

Web3 PHP 665 Dec 23, 2022
Retrieve the GitHub Sponsors of a given user/organization.

Laravel GitHub Sponsors Retrieve the GitHub Sponsors of any user/organization and check if someone is sponsoring you. Installation composer require as

Astrotomic 7 Apr 27, 2022
GitHub Action to dynamically update CONTRIBUTORS file

Generate / Update CONTRIBUTORS File - GitHub Action This GitHub Action updates a CONTRIBUTORS file with the top contributors from the specified projec

minicli 86 Dec 21, 2022
A discord bot for creating github repo issues.

Discord Issue Bot A discord bot for creating github repo issues. Requires: php-zlib, php-json, mysql, composer Tested on: Ubuntu 20.04.3, PHP Version

null 1 Jan 20, 2022
Xendit REST API Client for PHP - Card, Virtual Account, Invoice, Disbursement, Recurring Payments, Payout, EWallet, Balance, Retail Outlets Services

Xendit REST API Client for PHP - Card, Virtual Account, Invoice, Disbursement, Recurring Payments, Payout, EWallet, Balance, Retail Outlets Services

Xendit 96 Jan 6, 2023