GitLab PHP API Client

Overview

GitLab PHP API Client

We present a modern GitLab API v4 client for PHP.

Banner

Build Status StyleCI Status Software License Packagist Downloads Latest Version

This is strongly based on php-github-api by KnpLabs. With this in mind, we now have very similar clients for:

Check out the change log, releases, security policy, license, code of conduct, and contribution guidelines.

Installation

This version supports PHP 7.4-8.1. To get started, simply require the project using Composer. You will also need to install packages that "provide" psr/http-client-implementation and psr/http-factory-implementation.

Standard Installation

$ composer require "m4tthumphrey/php-gitlab-api:^11.7" "guzzlehttp/guzzle:^7.4" "http-interop/http-factory-guzzle:^1.2"

Framework Integration

Laravel:

$ composer require "graham-campbell/gitlab:^6.0"

Symfony:

$ composer require "zeichen32/gitlabapibundle:^6.0" "symfony/http-client:^5.4" "nyholm/psr7:^1.4"

We are decoupled from any HTTP messaging client by using PSR-7, PSR-17, PSR-18, and HTTPlug. You can visit HTTPlug for library users to get more information about installing HTTPlug related packages. The framework integration graham-campbell/gitlab is by Graham Campbell and zeichen32/gitlabapibundle is by Jens Averkamp.

General API Usage

// Token authentication
$client = new Gitlab\Client();
$client->authenticate('your_http_token', Gitlab\Client::AUTH_HTTP_TOKEN);

// OAuth2 authentication
$client = new Gitlab\Client();
$client->authenticate('your_oauth_token', Gitlab\Client::AUTH_OAUTH_TOKEN);

// An example API call
$project = $client->projects()->create('My Project', [
    'description' => 'This is a project',
    'issues_enabled' => false,
]);

Self-Hosted GitLab

$client = new Gitlab\Client();
$client->setUrl('https://git.yourdomain.com');
$client->authenticate('your_http_token', Gitlab\Client::AUTH_HTTP_TOKEN);

Example with Pager

$pager = new Gitlab\ResultPager($client);
$issues = $pager->fetchAll($client->issues(), 'all', [null, ['state' => 'closed']]);

HTTP Client Builder

By providing a Gitlab\HttpClient\Builder to the Gitlab\Client constructor, you can customize the HTTP client. For example, to customize the user agent:

$plugin = new Http\Client\Common\Plugin\HeaderSetPlugin([
    'User-Agent' => 'Foobar',
]);

$builder = new Gitlab\HttpClient\Builder();
$builder->addPlugin($plugin);

$client = new Gitlab\Client($builder);

One can read more about HTTPlug plugins here. Take a look around the API methods, and please feel free to report any bugs, noting our code of conduct.

Contributing

We will gladly receive issue reports and review and accept pull requests, in accordance with our code of conduct and contribution guidelines!

$ make install
$ make test

Security

If you discover a security vulnerability within this package, please send an email to Graham Campbell at [email protected]. All security vulnerabilities will be promptly addressed. You may view our full security policy here.

License

GitLab PHP API Client is licensed under The MIT License (MIT).

Comments
  • Http client adapters

    Http client adapters

    This is a draft implementation of HTTP adapters solving #49.

    The library now supports:

    • Guzzle 3
    • Guzzle 4
    • Buzz

    The user has to choose an adapter when creating the API client :

    <?php
    
    $buzz = new \Gitlab\HttpClient\Adapter\BuzzAdapter();
    $guzzle3 = new \Gitlab\HttpClient\Adapter\Guzzle3Adapter();
    $guzzle4 = new \Gitlab\HttpClient\Adapter\Guzzle4Adapter();
    
    $bgitlab = new \Gitlab\Client('http://git.foobar.com/api/v3/', $buzz);
    $bgitlab->authenticate('foobar', \Gitlab\HttpClient\HttpClientInterface::AUTH_HTTP_TOKEN);
    
    $g3gitlab = new \Gitlab\Client('http://git.foobar.com/api/v3/', $guzzle3);
    $g3gitlab->authenticate('foobar', \Gitlab\HttpClient\HttpClientInterface::AUTH_HTTP_TOKEN);
    
    $g4gitlab = new \Gitlab\Client('http://git.foobar.com/api/v3/', $guzzle4);
    $g4gitlab->authenticate('foobar', \Gitlab\HttpClient\HttpClientInterface::AUTH_HTTP_TOKEN);
    

    :warning: This will break user's code when updating the library :warning: but I think it's a minor change.

    discussion breaking internals 
    opened by jubianchi 27
  • ErrorListener does not support message array

    ErrorListener does not support message array

    The Gitlab\HttpClient\Listener\ErrorListener will produce a Fatal error (Wrong parameters for ErrorException) when the Gitlab API returns a error message that contains an array instead of a string message. Offending line: 46

    {"message":{"path":["has already been taken"]}}
    

    This will mostly happen when an data validation error occurs. See Data validation and error reporting for possible response formats.

    A simple solution could be to json encode the message when it's not a string.

    Used versions: GitLab 7.4.0; GitLab API v3

    opened by Maff- 22
  • Decouple from Buzz

    Decouple from Buzz

    As discussed in #171 this replace the buzz client by httplug.

    I tried to implement this as it was done by @Nyholm for https://github.com/KnpLabs/php-github-api. This remove all the HttpClient stuff which was built on the top of Buzz. Instead it use Httplug standard plugins with a few custom ones for error handling and authentication.

    I set PHP required version to 5.6+ as discussed in #171.

    This IS a breaking change.

    To do

    • [x] Update documentation.
    • [x] Describe breaking changes.
    • [x] Add tests.
    • [x] Do intensive tests against real gitlab repositories.
    • [x] Update ResultPager.
    • [x] https://github.com/m4tthumphrey/php-gitlab-api/pull/191#issuecomment-308155979
    breaking 
    opened by fbourigault 20
  • [11.1] Added CI schedule variables endpoints

    [11.1] Added CI schedule variables endpoints

    I added the create/edit/delete Endpoints described in https://docs.gitlab.com/ee/api/pipeline_schedules.html#create-a-new-pipeline-schedule-variable.


    Closes #508.

    opened by mgrundkoetter 19
  • Gitlab API v4

    Gitlab API v4

    https://about.gitlab.com/2017/02/22/gitlab-8-17-released/ With v4 in beta and set to be released on 3/22 is their any current plans on how to update this project to use the new api?

    opened by bdandoy 18
  • createFile method not working

    createFile method not working

    Getting error: {"error":"file_path is missing, branch_name is missing, commit_message is missing, content is missing"}

    I am using syntax $project->createFile('file1', 'contents', 'master', 'file');

    So far I have $project->getFile() working so I am not sure if this is a bug or like a permissions problem?

    opened by drupalninja 18
  • Not possible to create issues

    Not possible to create issues

    I am trying to create issues, but its not possible.

    Using this code: $client->api('issues')->create(220, ['title' => 'Test', 'description' => 'test']);

    If I var_dump the $params in AbstractApi post method i do get a return like this:

    array:2 [
      "title" => "Test"
      "description" => "test"
    ]
    
    

    But still i get the response: Gitlab\Exception\ErrorException with message '400 (Bad request) "title" not given'

    opened by larsemil 18
  • Document that Issues::all() does not in fact return all issues due to pagination

    Document that Issues::all() does not in fact return all issues due to pagination

    The GitLab API normally limits the list of issues to 100 entries per request, with a default of 20. This means that Issues::all() and Project::issues() by extension only return the first 20 issues of a project by default, which is surprising given their respective names. It'd be nice if the docs stated this fact, and provided a workaround.

    I'd be willing to write a PR for this.

    opened by isomorpheme 17
  • using block-method returns an Exception

    using block-method returns an Exception

    the server's answer for blocking a user is a bool value but the API expects an array which lead to an exception

    
    $gitlab = new Gitlab\Client();
    $gitlab->setUrl('customgitlaburl');
    $gitlab->authenticate($gitlab_api_access_token, Gitlab\Client::AUTH_HTTP_TOKEN);
    $user = $gitlab->users()->all(array("username" => $username));
    $gitlab->users()->block($user[0]["id"]);
    

    Result: PHP Fatal error: Uncaught Gitlab\Exception\RuntimeException: json_decode error: Expected JSON of type array, bool given. in /home/gitlab_ad_usersync/include/gitlab_api/vendor/m4tthumphrey/php-gitlab-api/src/HttpClient/Util/JsonArray.php:33 Stack trace: #0 /home/gitlab_ad_usersync/include/gitlab_api/vendor/m4tthumphrey/php-gitlab-api/src/HttpClient/Message/ResponseMediator.php(49): Gitlab\HttpClient\Util\JsonArray::decode('true') #1 /home/gitlab_ad_usersync/include/gitlab_api/vendor/m4tthumphrey/php-gitlab-api/src/Api/AbstractApi.php(143): Gitlab\HttpClient\Message\ResponseMediator::getContent(Object(GuzzleHttp\Psr7\Response)) #2 /home/gitlab_ad_usersync/include/gitlab_api/vendor/m4tthumphrey/php-gitlab-api/src/Api/Users.php(200): Gitlab\Api\AbstractApi->post('users/78/block') #3 /home. in /home/gitlab_ad_usersync/include/gitlab_api/vendor/m4tthumphrey/php-gitlab-api/src/HttpClient/Util/JsonArray.php on line 33

    same for the unblock method. blocking and unblocking is executed nonetheless

    opened by FSD-Christian-ADM 15
  • Pagination of Project Members

    Pagination of Project Members

    GitLab API per default defines 20 items per_page for the returned result. Now if a project has more than 20 members we have an issue with increasing the number of items to max i.e. 100.

    Therefore I complemented your code.

    Many thanks!

    opened by tobiasetter 15
  • [RFC] Drop models API

    [RFC] Drop models API

    It's hard to keep up-dated. Unless someone wants to volunteer to spend a lot of time going through all of the models code updating it, maybe we should remove the models entirely?

    opened by GrahamCampbell 12
  • add 'updated_at' to 'order_by' for pipelines()

    add 'updated_at' to 'order_by' for pipelines()

    The Gitlab-Api (https://docs.gitlab.com/15.4/ee/api/pipelines.html#list-project-pipelines) states that pipelines can be ordered by 'updated_at' as well. It already works by allowing it here.

    opened by marcsimeon 0
Releases(11.8.0)
  • 11.8.0(Apr 24, 2022)

    • Add support for reviewer_id and wip params in MergeRequests::all()
    • Add support for GroupEpics::issues()
    • Add support for Projects::pipelineJobs() and protected tags
    • Add support for the confidential filter in Issues:all()
    • Allow specifying params in Wiki::showAll()
    • Allow specifying params in SystemHooks::create()
    • Allow chmod action and execute_filemode attribute
    • Implement group merge requests endpoints
    • Implement event endpoints
    Source code(tar.gz)
    Source code(zip)
  • 11.7.1(Apr 24, 2022)

  • 11.7.0(Jan 24, 2022)

  • 11.6.0(Jan 24, 2022)

  • 11.5.1(Jan 23, 2022)

  • 11.5.0(Dec 26, 2021)

    • Added support for filtering environments by state
    • Added support for approval rules endpoints
    • Added support for toggling the activate state of users
    • Added support for managing packages
    • Added support for filtering projects by topics
    • Added support for locked merge requests
    • Added support for filtering groups and projects by user
    • Added support for removing protected branches
    • Added support for psr/cache:^2.0
    • Added support for symfony/options-resolver:^6.0
    • Added support for PHP 8.1
    Source code(tar.gz)
    Source code(zip)
  • 11.4.1(Dec 26, 2021)

  • 11.4.0(Mar 27, 2021)

    • Added parameters to the list of project repository tags
    • Added support for the epics endpoints
    • Added support for project access tokens
    • Added support for reverting commits
    Source code(tar.gz)
    Source code(zip)
  • 11.3.0(Mar 14, 2021)

  • 11.2.1(Mar 14, 2021)

  • 11.2.0(Feb 20, 2021)

    • Added support for user memberships
    • Add support for the following projects parameters: id_after, id_before, last_activity_after, last_activity_before, repository_checksum_failed, repository_storage, wiki_checksum_failed, with_custom_attributes, with_programming_language
    Source code(tar.gz)
    Source code(zip)
  • 11.1.0(Jan 25, 2021)

    • Added CI schedule variables endpoints
    • Added support for triggering a pipeline
    • Added support for the search_namespaces projects parameter
    • Added support for order_by and sort deployments parameters
    Source code(tar.gz)
    Source code(zip)
  • 11.0.0(Dec 22, 2020)

    • Removed models API
    • Dropped support for PHP 7.1
    • Updated to latest labels API
    • Made builder class final
    • Re-worked pagination
    • Client authenticate and setUrl now return void
    • Added additional return type enforcement
    Source code(tar.gz)
    Source code(zip)
  • 10.4.0(Dec 22, 2020)

    • Add min_access_level option to group search
    • Added support for additional issue order clauses
    • Added params array to remove user method to support hard_delete
    Source code(tar.gz)
    Source code(zip)
  • 10.3.1(Dec 4, 2020)

  • 10.3.0(Nov 27, 2020)

  • 10.2.0(Nov 9, 2020)

  • 10.1.2(Nov 9, 2020)

  • 10.1.1(Oct 26, 2020)

  • 10.0.2(Oct 26, 2020)

  • 9.19.2(Oct 26, 2020)

  • 10.1.0(Oct 24, 2020)

    • Added method to get protected branches for a project
    • Added with_merge_status_recheck option for fetching MRs
    • Added commit cherry-pick API
    • Added support for optional Note parameters
    • Deprecated models API
    Source code(tar.gz)
    Source code(zip)
  • 10.0.1(Oct 24, 2020)

  • 9.19.1(Oct 24, 2020)

  • 10.0.0(Aug 15, 2020)

  • 9.19.0(Aug 15, 2020)

  • 9.18.2(Aug 15, 2020)

  • 10.0.0-RC2(Jul 23, 2020)

  • 10.0.0-RC1(Jul 22, 2020)

    • Removed all deprecated functionality
    • Switched to PSR-17 and PSR-18
    • Encode URIs according to RFC 3986
    • Send request bodies as JSON to GitLab
    • Redesigned pagination
    • Added array types where missing
    • Added scalar param types
    • Added user events API
    Source code(tar.gz)
    Source code(zip)
  • 9.18.1(Jul 22, 2020)

Owner
PHP GitLab API
 PHP GitLab API
A PHP implementation of the Unleash protocol aka Feature Flags in GitLab

A PHP implementation of the Unleash protocol aka Feature Flags in GitLab. You may also be interested in the Symfony Bundle for this package. This impl

Unleash 38 Dec 25, 2022
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
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
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
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
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
⚡️ 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
A simple PHP GitHub API client, Object Oriented, tested and documented.

PHP GitHub API A simple Object Oriented wrapper for GitHub API, written with PHP. Uses GitHub API v3 & supports GitHub API v4. The object API (v3) is

KNP Labs 2k Jan 7, 2023
A simple Object Oriented PHP Client for Termii SMS API

Termii Client A simple Object Oriented PHP Client for Termii SMS API. Uses Termii API. Requirements PHP >= 7.2 Guzzlehttp ~6|~7 Installation Via Compo

Ilesanmi Olawale Adedotun 5 Feb 24, 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
php 8 client for the lemon.markets api

lemon.markets php client This repository contains a php 8+ compatible client for the https://lemon.markets API. The documentation of the API can be fo

Daniel Freudenberger 4 Nov 17, 2022
PHP client for Microsoft Azure Face API.

Microsoft Azure Face API PHP client A PHP library that utilizes Azure Face REST API. Requirements PHP >= 7.4 Installation composer require darmen/php-

Darmen Amanbayev 6 Sep 14, 2022
Google PHP API Client Services

Google PHP API Client Services

Google APIs 1.1k Dec 22, 2022
PHP Client for the GoFlink API

GoFlink PHP API Client This project is an unofficial library to communicate with the GoFlink API from your PHP project. Documentation about the API is

Rico Hageman 4 Oct 3, 2022
A PHP client for the official Kizeo Forms API V3+. 📌

Kizeo Forms API V3+ - PHP This is a Swagger generated doc for Kizeo REST API 3. You can find additionnal documentation here : Online documentation. Th

siapepfrance 1 Oct 26, 2021
Shopee Open API v2 Client build with php

Shopee PHP Client This is a Shopee PHP Client, currently supported for API V2 in ShopeeOpenPlatform Composer Install composer require haistar/shopee-p

ravimukti 17 Dec 27, 2022
PHP client library for the DynamicPDF Cloud API.

PHP Client (php-client) The PHP Client (php-client) project uses the DynamicPDF Cloud API's PHP client library to create, merge, split, form fill, sta

DynamicPDF Cloud API 0 Nov 29, 2021