Code Monkey home page Code Monkey logo

client's Introduction

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.3. 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.14" \
  "guzzlehttp/guzzle:^7.8" "http-interop/http-factory-guzzle:^1.2"

Framework Integration

Laravel:

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

Symfony:

$ composer require "zeichen32/gitlabapibundle:^6.1"

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).

client's People

Contributors

alfredbez avatar artistan avatar cdaguerre avatar donkidd avatar drumm avatar fbourigault avatar gaooulong avatar gilmiriam avatar glaubinix avatar glensc avatar grahamcampbell avatar jdecool avatar jimmy4o4 avatar jubianchi avatar laurenzgamper avatar m1guelpf avatar m4tthumphrey avatar mirko-jtl avatar moufmouf avatar mujibazizi avatar omarlopesino avatar peterjaap avatar pkolmann avatar radutopala avatar seretos avatar sidneymarieanne avatar sirflip avatar tobiasetter avatar vinkla avatar violuke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

client's Issues

Issue creating snippet

I can't work out what I'm doing wrong. I've got the following code:

<?php

require 'vendor/autoload.php';

$client = new \Gitlab\Client('https://gitlab.example.com/api/v3/'); // change here
$client->authenticate('not_actually_real', \Gitlab\Client::AUTH_URL_TOKEN); // change here

$project = new \Gitlab\Model\Project(17, $client);
$snippet = $project->createSnippet('title', 'someting.txt', 'code_is_cool');

?>

But I'm getting the following error:

Fatal error: Uncaught exception 'Gitlab\Exception\InvalidArgumentException' in /gitlab/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Client.php:115
Stack trace:
#0 /gitlab/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/AbstractModel.php(31): Gitlab\Client->api('snippets')
#1 /gitlab/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Project.php(464): Gitlab\Model\AbstractModel->api('snippets')
#2 /gitlab/test.php(24): Gitlab\Model\Project->createSnippet('title', 'someting.txt', 'code_is_cool')
#3 {main}
  thrown in /gitlab/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Client.php on line 115

What am I doing wrong?

BREAKING CHANGE: Project hooks

The latest commit to master introduces a breaking change when managing project hooks.

Before the method signature for Api\Projects::addHook() was as follows:

public function addHook($project_id, $url, $push_events = true, $issues_events = false, $merge_requests_events = false, $tag_push_events = false)

It is now

public function addHook($project_id, $url, array $params = array('push_events' => true))

This allows the user to specify a URL (required field) and then pass an optional list of event types. As you can see, push_events are enabled by default.

Before the method signature for Api\Projects::updateHook() was as follows:

public function updateHook($project_id, $url, $push_events = true, $issues_events = false, $merge_requests_events = false, $tag_push_events = false)

It is now

public function addHook($project_id, array $params = array())

This allows the user to only update the fields they required.

This also affects the corresponding methods in Model\Project

  • public function addHook($url, array $events = array())
  • public function updateHook($hook_id, array $params)

This will be released (tagged) in the 7.9 release next month.

tag 6.10

could you please tag a new stable release? to be able to use e.g. MergeRequest::opened and rely on stable versions

Gush is integrating this library

I have heard complaints that this library does not use guzzle3 or 4.
It seems like is the only library around for gitlab that is more downloaded so far in packagist.

This ticket is to reference https://github.com/gushphp/gush-gitlab-adapter/blob/master/src/Adapter/GitLabAdapter.php#L86 and also asking for help integrating your library in.

We will first make it work then proceed to rewrite so it will use guzzle4 maybe.

Encouragements and thanks, feel welcome to contribute to Gush and join the core team ๐Ÿ‘ถ

function encodePath problem

I think there is something wrong with function encodePath in AbstractApi.php line 122
As Gitlab documentation says "make sure that the NAMESPACE/PROJECT_NAME is URL-encoded, eg. /api/v3/projects/diaspora%2Fdiaspora (where / is represented by %2F)."

line: rawurlencode($path); encodes path as documentation describes and
line: return str_replace(array('%2F', '.'), array('/', '%2E'), $path)
changes it back

result is 404 error
[07/May/2015:20:29:31 +0200] "GET /api/v3/projects/dd/dd?private_token=

I use earlier version of php-gitlab-api in one of my projects and it works fine

Look into making models persistent

use Gitlab\Client;
use Gitlab\Model\Project;
use Gitlab\Model\Issue;

$client = new Client('http://git.yourdomain.com/api/v3/'); // change here
$client->authenticate('your_gitlab_token_here', Client::AUTH_URL_TOKEN); // change here

$project = new Project($client);
$project->name = 'A project';
$project->description = 'This is a project';
$project->save();

The following block

$issue = new Issue($client);
$issue->title = 'This is an issue';
$issue->addLabel('bug');
$issue->save();

$project->addIssue($issue);
// or
$issue->project = $project;

would be the same as

$project->createIssue('This is an issue', array(
    'labels' => array('bug')
));

projects/search

Hi,

I think it could be nice to search projects using per_page & page parameters

Parameters:

  • query (required) - A string contained in the project name
  • per_page (optional) - number of projects to return per page
  • page (optional) - the page to retrieve

Best,
G.

improve library move to guzzle 4 out of buzz

previous: #32

The library uses buzz introducing yet another dep in gush. We can move it to guzzle 4 which is suit. In addition we should start semver also bugfixes so we can change https://github.com/gushphp/gush-gitlab-adapter/blob/master/composer.json#L5 which is a mistake on the version this should require.

Gitlab support works more or less, I have tried it before. Not sure if there were things that worked differently or need more support. So if we have request please let us open tickets on gush-gitlab-adapter /cc @matthiasnoback

Cant create a user

Hi,

I run this command

$client->api('users')->create('[email protected]','test',array('name'=>'name','username'=>'username'));

I get an error like follows:
PHP Fatal error: Uncaught exception 'Gitlab\Exception\ErrorException' with message '400 (Bad request) "email" not given' in /home/damian/public_html/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/HttpClient/Listener/ErrorListener.php:47

Not sure if this is a bug or something wrong with my setup?

Cheers

Implement hook tag_push_events

The tag push events have been added to Gitlab API v7.4.0.rc1 (gitlabhq/gitlabhq@b4963e9)

What would be required to implement such feature? I was about to propose a merge request but I guess it's a bit more complicated and would require to implement all changes from Gitlab 6.9.1, according to the versionning policy.

Thanks you

Where do i get gitlab access_token

I have install gitlab CE in my local server and i also wanted to develop an php based application for using gitlab as Oauth2service provider . so im wondering how it will be achieved. I got up with this package and read all the documentation in read me file but one question remains me to start nothing that is where do i get a token. i have created a application in my gitlab and i have now app-id , secrete and callback url.. please help me.

The `getFile()` method does not appear to return the full file content.

First thanks for this API, it works well and looks to save myself and others a ton of time.

I'm currently looking to retrieve a file contents from a given repo. I'm using the following:
$project = $client->api('repositories')->getFile( $project_id, $file_path, $ref ); which does work, but the content appears to be truncated. I know that GitHub API limits file sizes, and I haven't been able to determine if GitLabs is doing the same, my file is 4KB.

I've also tried using the blob() method.

Updating users

Is there a reason that there is no functions in Gitlab\Api\Users for updating/deleting a user in gitlab?

I'd be happy to add the functionality and make a pull request just wanted to ask why first or Is it just that you didn't the functionality personally (like you said in the readme)?

Or could we just make the functions delete and put in Gitlab\Api\AbstractApi public rather than protected so they can be called on an instance of Gitlab\Api\Users (again happy to do it just wanted to ask)?

PSR-4

http://www.php-fig.org/psr/psr-4/

This enables us to have a VendorName\PackageName namespace. I would suggest "php-gitlab-api\php-gitlab-api" as the vendor\package names. this may be better suited then in a GitHub organisation.
It would also allow the code structure to be a little bit neater.

It would also make the suggested adapter packages a little neater and easier to find.

Thoughts?

GitLab.com API issue

I tried to create a new project using the example but it seems I get this error every time:
PHP Fatal error: Uncaught exception 'Gitlab\Exception\ErrorException' with message '400 (Bad request) "name" not given'

I use the hosted GitLab at gitlab.com.

PHP Version support

What should be the minimum supported version of PHP? Considering 5.3 was released over 5 years ago and that 5.6 was recently released, I would suggest the library targets no less that 5.5.

Tree function path argument for subfolders

There's an issue with the tree function to access subfolders. It doesn't append the 'path' argument value to the url.

Example:

/repository/branches/[branchname]/[project id]/repository/tree/[path]

How to use with gitlab.com

I was wondering if i can use it with gitlab.com repos . I was unable to decide what the host param will be if using with gitlab.com

$client = new \Gitlab\Client('https://git.yourdomain.com/api/v3/'); // change here

Tagged version

Could you please release tags to make it more stable/predictable for users to deploy.

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

Swap model constructor parameters around

IE

$project = new Project($client, 1);

instead of

$project = new Project(1, $client);

This would make $client mandatory but it is always passed anyway so do not see any disadvantages to this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.