Skip to content

Commit acc4011

Browse files
authored
Merge pull request #3 from m4tthumphrey/master
Merging from upstream
2 parents 1972512 + 65ffd89 commit acc4011

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+3982
-2536
lines changed

.gitattributes

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
* text=auto
2+
3+
/doc export-ignore
4+
/test export-ignore
5+
/.gitattributes export-ignore
6+
/.gitignore export-ignore
7+
/.styleci.yml export-ignore
8+
/.travis.yml export-ignore
9+
/phpunit.xml.dist export-ignore
10+
/README.md export-ignore
11+
/UPGRADE.md export-ignore

.styleci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
preset: psr2

.travis.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
language: php
22

3+
sudo: false
4+
35
php:
4-
- 5.3
5-
- 5.4
6-
- 5.5
76
- 5.6
87
- 7.0
8+
- 7.1
9+
10+
matrix:
11+
include:
12+
- php: 7.2
13+
env: STATIC_ANALYSIS=yes
914

1015
before_script:
1116
- travis_retry composer self-update
1217
- travis_retry composer install --no-interaction --prefer-source
18+
- if [ "$STATIC_ANALYSIS" != "" ]; then curl -L https://github.com/phpstan/phpstan/releases/download/0.8/phpstan.phar -o phpstan.phar; fi;
1319

1420
script:
1521
- vendor/bin/phpunit --verbose --coverage-text
22+
- if [ "$STATIC_ANALYSIS" != "" ]; then php phpstan.phar analyse --level=4 lib; fi;

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Matt Humphrey
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,44 @@ A PHP wrapper to be used with [Gitlab's API](https://github.com/gitlabhq/gitlabh
22
==============
33

44
[![Build Status](https://travis-ci.org/m4tthumphrey/php-gitlab-api.svg?branch=master)](https://travis-ci.org/m4tthumphrey/php-gitlab-api)
5+
[![StyleCI](https://styleci.io/repos/6816335/shield?branch=master)](https://styleci.io/repos/6816335)
6+
[![Total Downloads](https://poser.pugx.org/m4tthumphrey/php-gitlab-api/downloads?format=flat-square)](https://packagist.org/packages/m4tthumphrey/php-gitlab-api)
7+
[![Latest Stable Version](https://poser.pugx.org/m4tthumphrey/php-gitlab-api/version?format=flat-square)](https://packagist.org/packages/m4tthumphrey/php-gitlab-api)
8+
[![Latest Unstable Version](https://poser.pugx.org/m4tthumphrey/php-gitlab-api/v/unstable?format=flat-square)](//packagist.org/packages/m4tthumphrey/php-gitlab-api)
59

610
Based on [php-github-api](https://github.com/m4tthumphrey/php-github-api) and code from [KnpLabs](https://github.com/KnpLabs/php-github-api).
711

812
Installation
913
------------
10-
1. Install Composer
1114

12-
```bash
13-
$ curl -sS https://getcomposer.org/installer | php
14-
$ sudo mv composer.phar /usr/local/bin/composer
15-
```
15+
Via [composer](https://getcomposer.org)
1616

17-
2. Add the following to your require block in composer.json config.
18-
19-
> Note: be careful when using the `dev-master` tag as this may have unexpected results depending on your version of
20-
Gitlab. See the Versioning section below for more information.
21-
22-
`php composer.phar require m4tthumphrey/php-gitlab-api:dev-master`
17+
```bash
18+
composer require m4tthumphrey/php-gitlab-api php-http/guzzle6-adapter
19+
```
2320

24-
3. Include Composer's autoloader:
21+
Why `php-http/guzzle6-adapter`? We are decoupled from any HTTP messaging client with help by [HTTPlug](http://httplug.io).
2522

26-
```php
27-
require_once dirname(__DIR__).'/vendor/autoload.php';
28-
```
23+
You can visit [HTTPlug for library users](http://docs.php-http.org/en/latest/httplug/users.html) to get more information about installing HTTPlug related packages.
2924

3025
Versioning
3126
----------
3227

33-
From the 6.0 stable release of Gitlab, I shall now be matching the client version with the Gitlab version. For example
34-
when Gitlab 6.1 is released I will release version 6.1.0 of the API client. If I need to make future updates to the client
35-
before the next API version is released, I'll simply use a 3rd build version - `6.1.1`, `6.1.2` etc for example.
28+
Depending on your Gitlab server version, you must choose the right version of this library.
29+
Please refer to the following table to pick the right one.
3630

37-
It is recommended that you keep your composer file in sync with whatever version of Gitlab you are currently running:
38-
if you are using 6.0, you should require `6.0.*`; 6.1 should be `6.1.*`...
31+
|Version|Gitlab API Version|Gitlab Version|
32+
|-------|------------------|--------------|
33+
|9.x | V4 | >= 9.0 |
34+
|8.x | V3 | < 9.5 |
3935

4036
General API Usage
4137
-----------------
4238

4339
```php
44-
$client = new \Gitlab\Client('http://git.yourdomain.com/api/v3/'); // change here
45-
$client->authenticate('your_gitlab_token_here', \Gitlab\Client::AUTH_URL_TOKEN); // change here
40+
$client = \Gitlab\Client::create('http://git.yourdomain.com')
41+
->authenticate('your_gitlab_token_here', \Gitlab\Client::AUTH_URL_TOKEN)
42+
;
4643

4744
$project = $client->api('projects')->create('My Project', array(
4845
'description' => 'This is a project',
@@ -57,8 +54,9 @@ Model Usage
5754
You can also use the library in an object oriented manner:
5855

5956
```php
60-
$client = new \Gitlab\Client('http://git.yourdomain.com/api/v3/'); // change here
61-
$client->authenticate('your_gitlab_token_here', \Gitlab\Client::AUTH_URL_TOKEN); // change here
57+
$client = \Gitlab\Client::create('http://git.yourdomain.com')
58+
->authenticate('your_gitlab_token_here', \Gitlab\Client::AUTH_URL_TOKEN)
59+
;
6260

6361
# Creating a new project
6462
$project = \Gitlab\Model\Project::create($client, 'My Project', array(
@@ -85,7 +83,7 @@ You get the idea! Take a look around ([API methods](https://github.com/m4tthumph
8583
Framework Integrations
8684
----------------------
8785
- **Symfony** - https://github.com/Zeichen32/GitLabApiBundle
88-
- **Laravel** - https://github.com/vinkla/gitlab
86+
- **Laravel** - https://github.com/vinkla/laravel-gitlab
8987

9088
If you have integrated GitLab into a popular PHP framework, let us know!
9189

UPGRADE.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# UPGRADE FROM 8.0 to 9.0
2+
3+
Since 9.0, lib no longer use buzz 0.7+, instead it has an HTTPlug abstraction layer.
4+
5+
## `Gitlab\Client` changes
6+
7+
* The constructor no longer allow to specify base url. Use `setUrl` or `Client::create` instead.
8+
* The default url is set to `https://gitlab.com`.
9+
* The `$options` constructor argument have been removed, the `getOption` and `setOption` methods have been removed.
10+
See [documentation](doc/customize.md) to know how to customize the client timeout and how to use a custom user agent.
11+
* The `setBaseUrl` and `getBaseUrl` methods have been removed. Use `setUrl` instead.
12+
* The `clearHeaders` and `setHeaders` methods have been removed. See [documentation](doc/customize.md) to know how use custom headers.
13+
* The `setHttpClient` method have been removed. Use a `Gitlab\HttpClient\Builder` instead.
14+
* The `getHttpClient` method return type is changed to `Http\Client\Common\HttpMethodsClient`.
15+
16+
## `Gitlab\Api\AbstractApi` changes
17+
18+
* The `PER_PAGE` class constant have been removed.
19+
20+
## `Gitlab\Api\DeployKeys` changes
21+
22+
* The `all` method now take a single argument which is an associative array of query string parameters.
23+
* The `ORDER_BY` and `SORT` class constants have been removed.
24+
25+
## `Gitlab\Api\Groups` changes
26+
27+
* The `visibility_level` parameter have been removed from `create` method. Use `visibility` instead.
28+
* The `all` method now take a single argument which is an associative array of query string parameters.
29+
* The `search` method have been removed. Use `all` method instead.
30+
* The `members` method second and subsequent arguments have been replaced by a single associative array of query string parameters.
31+
* The `projects` method second and subsequent arguments have been replaced by a single associative array of query string parameters.
32+
33+
## `Gitlab\Api\Issues` changes
34+
35+
* The second argument of `update`, `remove`, `showComments`, `showComment`, `addComment`, `updateComment`, `removeComment`,
36+
`setTimeEstimate`, `resetTimeEstimate`, `addSpentTime` and `resetSpentTime` methods is now a scoped issue id (iid).
37+
* The `all` method second and subsequent arguments have been replaced by a single associative array of query string parameters.
38+
39+
## `Gitlab\Api\IssueBoards` changes
40+
41+
* The `all` method second and subsequent arguments have been replaced by a single associative array of query string parameters.
42+
43+
## `Gitlab\Api\MergeRequests` changes
44+
45+
* The `getList`, `getByIid`, `merged`, `opened` and `closed` methods have been removed. Use `all` method instead.
46+
* The `ORDER_BY` and `SORT` class constants have been removed.
47+
* The `all` method now take a single argument which is an associative array of query string parameters.
48+
* The `getNotes` method now take only two arguments, the project id and the merge request iid.
49+
50+
## `Gitlab\Api\Milestones` changes
51+
52+
* The `all` method second and subsequent arguments have been replaced by a single associative array of query string parameters.
53+
54+
## `Gitlab\Api\Projects` changes
55+
56+
* The `keys`, `key`, `addKey`, `removeKey`, `disableKey` and `enableKey` methods have been removed.
57+
Use the `deployKeys`, `deployKey`, `addDeployKey`, `deleteDeployKey`, `removeDeployKey` and `enableDeployKey` instead.
58+
* The `ORDER_BY` and `SORT` class constants have been removed.
59+
* The `accessible`, `owned` and `search` methods have been removed. Use `all` method instead.
60+
* The `all` method now take a single argument which is an associative array of query string parameters.
61+
* The `trace` method have been removed. Use `Gitlab\Api\Jobs::trace` instead.
62+
* The `builds` method have been removed. Use `Gitlab\Api\Jobs::all` instead.
63+
* The `build` method have been removed. Use `Gitlab\Api\Jobs::show` instead.
64+
* The `events` method second and subsequent arguments have been replaced by a single associative array of query string parameters.
65+
* The `deployments` method second and subsequent arguments have been replaced by a single associative array of query string parameters.
66+
67+
## `Gitlab\Api\ProjectNamespaces` changes
68+
69+
* The `search` method have been removed. Use `all` method instead.
70+
* The `all` method now take a single argument which is an associative array of query string parameters.
71+
72+
## `Gitlab\Api\Repositories` changes
73+
74+
* The `commitBuilds` method have been removed. Use `Gitlab\Api\Projects::pipelines` instead.
75+
* The `commits` method second and subsequent arguments have been replaced by a single associative array of query string parameters.
76+
* The `commitComments` method third and subsequent arguments have been replaced by a single associative array of query string parameters.
77+
78+
## `Gitlab\Model\Project` changes
79+
80+
* The `keys`, `key`, `addKey`, `removeKey`, `disableKey` and `enableKey` methods have been removed.
81+
Use the `deployKeys`, `deployKey`, `addDeployKey`, `deleteDeployKey`, `removeDeployKey` and `enableDeployKey` instead.
82+
83+
## `Gitlab\Model\Snippet` changes
84+
85+
* The `expires_at` property have been removed.`
86+
87+
## `Gitlab\Model\Users` changes
88+
89+
* The `all` method now take a single argument which is an associative array of query string parameters.
90+
* The `lookup` and `search` methods have been removed. Use `all` method instead.

composer.json

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,49 @@
1-
{
2-
"name": "m4tthumphrey/php-gitlab-api",
3-
"type": "library",
4-
"description": "GitLab API client",
5-
"homepage": "https://github.com/m4tthumphrey/php-gitlab-api",
6-
"keywords": ["gitlab", "api"],
7-
"license": "MIT",
8-
"authors": [
9-
{
10-
"name": "Matt Humphrey",
11-
"homepage": "http://m4tt.io"
12-
},
13-
{
14-
"name": "KnpLabs Team",
15-
"homepage": "http://knplabs.com"
16-
},
17-
{
18-
"name": "Thibault Duplessis",
19-
"email": "thibault.duplessis@gmail.com",
20-
"homepage": "http://ornicar.github.com"
21-
}
22-
],
23-
"require": {
24-
"php": ">=5.3.2",
25-
"ext-curl": "*",
26-
"ext-xml": "*",
27-
"kriswallsmith/buzz": ">=0.7"
28-
},
29-
"require-dev": {
30-
"phpunit/phpunit": "~4.5"
31-
},
32-
"autoload": {
33-
"psr-0": { "Gitlab\\": "lib/" }
34-
}
35-
}
1+
{
2+
"name": "m4tthumphrey/php-gitlab-api",
3+
"type": "library",
4+
"description": "GitLab API client",
5+
"homepage": "https://github.com/m4tthumphrey/php-gitlab-api",
6+
"keywords": ["gitlab", "api"],
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Matt Humphrey",
11+
"homepage": "http://m4tt.io"
12+
},
13+
{
14+
"name": "KnpLabs Team",
15+
"homepage": "http://knplabs.com"
16+
},
17+
{
18+
"name": "Thibault Duplessis",
19+
"email": "thibault.duplessis@gmail.com",
20+
"homepage": "http://ornicar.github.com"
21+
}
22+
],
23+
"require": {
24+
"php": "^5.6 || ^7.0",
25+
"php-http/client-common": "^1.5",
26+
"php-http/client-implementation": "^1.0",
27+
"php-http/discovery": "^1.2",
28+
"php-http/httplug": "^1.1",
29+
"php-http/multipart-stream-builder": "^1.0",
30+
"symfony/options-resolver": "^2.6 || ^3.0"
31+
},
32+
"require-dev": {
33+
"guzzlehttp/psr7": "^1.2",
34+
"php-http/guzzle6-adapter": "^1.0",
35+
"php-http/mock-client": "^1.0",
36+
"phpunit/phpunit": "~4.5"
37+
},
38+
"autoload": {
39+
"psr-4": { "Gitlab\\": "lib/Gitlab/" }
40+
},
41+
"autoload-dev": {
42+
"psr-4": { "Gitlab\\Tests\\": "test/Gitlab/Tests/" }
43+
},
44+
"extra": {
45+
"branch-alias": {
46+
"dev-master": "9.0.x-dev"
47+
}
48+
}
49+
}

doc/customize.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## Customize `php-gitlab-api`
2+
3+
### How to set custom headers (including `User-Agent`)?
4+
5+
By providing a `Gitlab\HttpClient\Builder` to the `Gitlab\Client` constructor, you can customize the HTTP client.
6+
7+
```php
8+
$plugin = new Http\Client\Common\Plugin\HeaderSetPlugin([
9+
'User-Agent' => 'Foobar',
10+
]);
11+
12+
$builder = new Gitlab\HttpClient\Builder();
13+
$builder->addPlugin($plugin);
14+
15+
$client = new Gitlab\Client($builder);
16+
```
17+
Read more about [HTTPlug plugins here](http://docs.php-http.org/en/latest/plugins/introduction.html#how-it-works).
18+
19+
### How to customize the HTTP client timeout?
20+
As timeout configuration is not compatible with HTTP client abstraction, you have to create the `Gitlab\Client` with
21+
an explicit HTTP client implementation.
22+
23+
```php
24+
$httpClient = Http\Adapter\Guzzle6::createWithConfig([
25+
'timeout' => 1.0
26+
]);
27+
$client = Gitlab\Client::createWithHttpClient($httpClient);
28+
```

0 commit comments

Comments
 (0)