Skip to content

Commit c78a5cd

Browse files
authored
Merge pull request #3 from m4tthumphrey/master
Update master from base fork
2 parents a260b19 + 69bdabe commit c78a5cd

31 files changed

Lines changed: 1166 additions & 87 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ You get the idea! Take a look around ([API methods](https://github.com/m4tthumph
9999
Framework Integrations
100100
----------------------
101101
- **Symfony** - https://github.com/Zeichen32/GitLabApiBundle
102-
- **Laravel** - https://github.com/vinkla/laravel-gitlab
102+
- **Laravel** - https://github.com/GrahamCampbell/Laravel-GitLab
103103

104104
If you have integrated GitLab into a popular PHP framework, let us know!
105105

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"require": {
2424
"php": "^5.6 || ^7.0",
2525
"ext-xml": "*",
26-
"php-http/client-common": "^1.5",
26+
"php-http/client-common": "^1.6",
2727
"php-http/client-implementation": "^1.0",
2828
"php-http/discovery": "^1.2",
2929
"php-http/httplug": "^1.1",
@@ -34,7 +34,7 @@
3434
"guzzlehttp/psr7": "^1.2",
3535
"php-http/guzzle6-adapter": "^1.0",
3636
"php-http/mock-client": "^1.0",
37-
"phpunit/phpunit": "~4.5"
37+
"phpunit/phpunit": "^5.0"
3838
},
3939
"autoload": {
4040
"psr-4": { "Gitlab\\": "lib/Gitlab/" }
@@ -44,7 +44,7 @@
4444
},
4545
"extra": {
4646
"branch-alias": {
47-
"dev-master": "9.0.x-dev"
47+
"dev-master": "9.8.x-dev"
4848
}
4949
}
5050
}

lib/Gitlab/Api/AbstractApi.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Http\Message\MultipartStream\MultipartStreamBuilder;
99
use Http\Message\StreamFactory;
1010
use Psr\Http\Message\ResponseInterface;
11+
use Psr\Http\Message\StreamInterface;
1112
use Symfony\Component\OptionsResolver\OptionsResolver;
1213

1314
/**
@@ -89,7 +90,7 @@ protected function post($path, array $parameters = array(), $requestHeaders = ar
8990

9091
$body = null;
9192
if (empty($files) && !empty($parameters)) {
92-
$body = $this->streamFactory->createStream(QueryStringBuilder::build($parameters));
93+
$body = $this->prepareBody($parameters);
9394
$requestHeaders['Content-Type'] = 'application/x-www-form-urlencoded';
9495
} elseif (!empty($files)) {
9596
$builder = new MultipartStreamBuilder($this->streamFactory);
@@ -128,7 +129,7 @@ protected function put($path, array $parameters = array(), $requestHeaders = arr
128129

129130
$body = null;
130131
if (!empty($parameters)) {
131-
$body = $this->streamFactory->createStream(http_build_query($parameters));
132+
$body = $this->prepareBody($parameters);
132133
$requestHeaders['Content-Type'] = 'application/x-www-form-urlencoded';
133134
}
134135

@@ -197,6 +198,18 @@ protected function createOptionsResolver()
197198
return $resolver;
198199
}
199200

201+
/**
202+
* @param array $parameters
203+
* @return StreamInterface
204+
*/
205+
private function prepareBody(array $parameters = [])
206+
{
207+
$raw = QueryStringBuilder::build($parameters);
208+
$stream = $this->streamFactory->createStream($raw);
209+
210+
return $stream;
211+
}
212+
200213
private function preparePath($path, array $parameters = [])
201214
{
202215
if (count($parameters) > 0) {

lib/Gitlab/Api/Environments.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,14 @@ public function remove($project_id, $environment_id)
4545
{
4646
return $this->delete($this->getProjectPath($project_id, 'environments/' . $environment_id));
4747
}
48+
49+
/**
50+
* @param int $project_id
51+
* @param string $environment_id
52+
* @return mixed
53+
*/
54+
public function stop($project_id, $environment_id)
55+
{
56+
return $this->post($this->getProjectPath($project_id, 'environments/'.$this->encodePath($environment_id).'/stop'));
57+
}
4858
}

lib/Gitlab/Api/Groups.php

Lines changed: 74 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php namespace Gitlab\Api;
22

3+
use Symfony\Component\OptionsResolver\Options;
4+
35
class Groups extends AbstractApi
46
{
57
/**
@@ -17,36 +19,7 @@ class Groups extends AbstractApi
1719
*/
1820
public function all(array $parameters = [])
1921
{
20-
$resolver = $this->createOptionsResolver();
21-
$booleanNormalizer = function ($value) {
22-
return $value ? 'true' : 'false';
23-
};
24-
25-
$resolver->setDefined('skip_groups')
26-
->setAllowedTypes('skip_groups', 'array')
27-
->setAllowedValues('skip_groups', function (array $value) {
28-
return count($value) == count(array_filter($value, 'is_int'));
29-
})
30-
;
31-
$resolver->setDefined('all_available')
32-
->setAllowedTypes('all_available', 'bool')
33-
->setNormalizer('all_available', $booleanNormalizer)
34-
;
35-
$resolver->setDefined('search');
36-
$resolver->setDefined('order_by')
37-
->setAllowedValues('order_by', ['name', 'path'])
38-
;
39-
$resolver->setDefined('sort')
40-
->setAllowedValues('sort', ['asc', 'desc'])
41-
;
42-
$resolver->setDefined('statistics')
43-
->setAllowedTypes('statistics', 'bool')
44-
->setNormalizer('statistics', $booleanNormalizer)
45-
;
46-
$resolver->setDefined('owned')
47-
->setAllowedTypes('owned', 'bool')
48-
->setNormalizer('owned', $booleanNormalizer)
49-
;
22+
$resolver = $this->getGroupSearchResolver();
5023

5124
return $this->get('groups', $resolver->resolve($parameters));
5225
}
@@ -65,16 +38,26 @@ public function show($id)
6538
* @param string $path
6639
* @param string $description
6740
* @param string $visibility
41+
* @param bool $lfs_enabled
42+
* @param bool $request_access_enabled
43+
* @param int $parent_id
44+
* @param int $shared_runners_minutes_limit
6845
* @return mixed
6946
*/
70-
public function create($name, $path, $description = null, $visibility = 'private')
47+
public function create($name, $path, $description = null, $visibility = 'private', $lfs_enabled = null, $request_access_enabled = null, $parent_id = null, $shared_runners_minutes_limit = null)
7148
{
72-
return $this->post('groups', array(
49+
$params = array(
7350
'name' => $name,
7451
'path' => $path,
7552
'description' => $description,
7653
'visibility' => $visibility,
77-
));
54+
'lfs_enabled' => $lfs_enabled,
55+
'request_access_enabled' => $request_access_enabled,
56+
'parent_id' => $parent_id,
57+
'shared_runners_minutes_limit' => $shared_runners_minutes_limit,
58+
);
59+
60+
return $this->post('groups', array_filter($params, 'strlen'));
7861
}
7962

8063
/**
@@ -180,7 +163,7 @@ public function removeMember($group_id, $user_id)
180163
public function projects($id, array $parameters = [])
181164
{
182165
$resolver = $this->createOptionsResolver();
183-
$booleanNormalizer = function ($value) {
166+
$booleanNormalizer = function (Options $resolver, $value) {
184167
return $value ? 'true' : 'false';
185168
};
186169

@@ -213,4 +196,61 @@ public function projects($id, array $parameters = [])
213196

214197
return $this->get('groups/'.$this->encodePath($id).'/projects', $resolver->resolve($parameters));
215198
}
199+
200+
/**
201+
* @param int $groupId
202+
* @param array $parameters (
203+
*
204+
* @var int[] $skip_groups Skip the group IDs passes.
205+
* @var bool $all_available Show all the groups you have access to.
206+
* @var string $search Return list of authorized groups matching the search criteria.
207+
* @var string $order_by Order groups by name or path. Default is name.
208+
* @var string $sort Order groups in asc or desc order. Default is asc.
209+
* @var bool $statistics Include group statistics (admins only).
210+
* @var bool $owned Limit by groups owned by the current user.
211+
* )
212+
* @return mixed
213+
*/
214+
public function subgroups($groupId, array $parameters = [])
215+
{
216+
$resolver = $this->getGroupSearchResolver();
217+
218+
return $this->get('groups/'.$this->encodePath($groupId).'/subgroups', $resolver->resolve($parameters));
219+
}
220+
221+
private function getGroupSearchResolver()
222+
{
223+
$resolver = $this->createOptionsResolver();
224+
$booleanNormalizer = function (Options $resolver, $value) {
225+
return $value ? 'true' : 'false';
226+
};
227+
228+
$resolver->setDefined('skip_groups')
229+
->setAllowedTypes('skip_groups', 'array')
230+
->setAllowedValues('skip_groups', function (array $value) {
231+
return count($value) == count(array_filter($value, 'is_int'));
232+
})
233+
;
234+
$resolver->setDefined('all_available')
235+
->setAllowedTypes('all_available', 'bool')
236+
->setNormalizer('all_available', $booleanNormalizer)
237+
;
238+
$resolver->setDefined('search');
239+
$resolver->setDefined('order_by')
240+
->setAllowedValues('order_by', ['name', 'path'])
241+
;
242+
$resolver->setDefined('sort')
243+
->setAllowedValues('sort', ['asc', 'desc'])
244+
;
245+
$resolver->setDefined('statistics')
246+
->setAllowedTypes('statistics', 'bool')
247+
->setNormalizer('statistics', $booleanNormalizer)
248+
;
249+
$resolver->setDefined('owned')
250+
->setAllowedTypes('owned', 'bool')
251+
->setNormalizer('owned', $booleanNormalizer)
252+
;
253+
254+
return $resolver;
255+
}
216256
}

lib/Gitlab/Api/Jobs.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function artifacts($project_id, $job_id)
8181
public function artifactsByRefName($project_id, $ref_name, $job_name)
8282
{
8383
return $this->getAsResponse("projects/".$this->encodePath($project_id)."/jobs/artifacts/".$this->encodePath($ref_name)."/download", array(
84-
'job' => $job_name
84+
'job' => $this->encodePath($job_name)
8585
))->getBody();
8686
}
8787

lib/Gitlab/Api/MergeRequests.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php namespace Gitlab\Api;
22

3+
use Symfony\Component\OptionsResolver\Options;
34
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
45
use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException;
56

@@ -36,7 +37,7 @@ class MergeRequests extends AbstractApi
3637
public function all($project_id, array $parameters = [])
3738
{
3839
$resolver = $this->createOptionsResolver();
39-
$datetimeNormalizer = function (\DateTimeInterface $value) {
40+
$datetimeNormalizer = function (Options $resolver, \DateTimeInterface $value) {
4041
return $value->format('c');
4142
};
4243
$resolver->setDefined('iids')
@@ -156,6 +157,18 @@ public function addNote($project_id, $mr_id, $note)
156157
));
157158
}
158159

160+
/**
161+
* @param int $projectId
162+
* @param int $mrId
163+
* @param int $noteId
164+
*
165+
* @return mixed
166+
*/
167+
public function removeNote($projectId, $mrId, $noteId)
168+
{
169+
return $this->delete($this->getProjectPath($projectId, 'merge_requests/'.$this->encodePath($mrId).'/notes/'.$this->encodePath($noteId)));
170+
}
171+
159172
/**
160173
* @param int $project_id
161174
* @param int $mr_id

0 commit comments

Comments
 (0)