Skip to content

Commit 14eae2b

Browse files
authored
Merge branch 'master' into issue-participants
2 parents 47bab96 + 289e42c commit 14eae2b

File tree

10 files changed

+463
-45
lines changed

10 files changed

+463
-45
lines changed

lib/Gitlab/Api/Issues.php

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,17 @@ class Issues extends AbstractApi
2121
*/
2222
public function all($project_id = null, array $parameters = [])
2323
{
24-
$resolver = $this->createOptionsResolver();
25-
26-
$resolver->setDefined('state')
27-
->setAllowedValues('state', ['opened', 'closed'])
28-
;
29-
$resolver->setDefined('labels');
30-
$resolver->setDefined('milestone');
31-
$resolver->setDefined('iids')
32-
->setAllowedTypes('iids', 'array')
33-
->setAllowedValues('iids', function (array $value) {
34-
return count($value) == count(array_filter($value, 'is_int'));
35-
})
36-
;
37-
$resolver->setDefined('scope')
38-
->setAllowedValues('scope', ['created-by-me', 'assigned-to-me', 'all'])
39-
;
40-
$resolver->setDefined('order_by')
41-
->setAllowedValues('order_by', ['created_at', 'updated_at'])
42-
;
43-
$resolver->setDefined('sort')
44-
->setAllowedValues('sort', ['asc', 'desc'])
45-
;
46-
$resolver->setDefined('search');
47-
$resolver->setDefined('assignee_id')
48-
->setAllowedTypes('assignee_id', 'integer')
49-
;
50-
5124
$path = $project_id === null ? 'issues' : $this->getProjectPath($project_id, 'issues');
5225

53-
return $this->get($path, $resolver->resolve($parameters));
26+
return $this->get($path, $this->createOptionsResolver()->resolve($parameters));
27+
}
28+
29+
public function group($group_id, array $parameters = [])
30+
{
31+
return $this->get(
32+
$this->getGroupPath($group_id, 'issues'),
33+
$this->createOptionsResolver()->resolve($parameters)
34+
);
5435
}
5536

5637
/**
@@ -338,4 +319,39 @@ public function showParticipants($project_id, $issue_iid)
338319
{
339320
return $this->get($this->getProjectPath($project_id, 'issues/' .$this->encodePath($issue_iid)).'/participants');
340321
}
322+
323+
/**
324+
* {@inheritDoc}
325+
*/
326+
protected function createOptionsResolver()
327+
{
328+
$resolver = parent::createOptionsResolver();
329+
330+
$resolver->setDefined('state')
331+
->setAllowedValues('state', ['opened', 'closed'])
332+
;
333+
$resolver->setDefined('labels');
334+
$resolver->setDefined('milestone');
335+
$resolver->setDefined('iids')
336+
->setAllowedTypes('iids', 'array')
337+
->setAllowedValues('iids', function (array $value) {
338+
return count($value) == count(array_filter($value, 'is_int'));
339+
})
340+
;
341+
$resolver->setDefined('scope')
342+
->setAllowedValues('scope', ['created-by-me', 'assigned-to-me', 'all'])
343+
;
344+
$resolver->setDefined('order_by')
345+
->setAllowedValues('order_by', ['created_at', 'updated_at'])
346+
;
347+
$resolver->setDefined('sort')
348+
->setAllowedValues('sort', ['asc', 'desc'])
349+
;
350+
$resolver->setDefined('search');
351+
$resolver->setDefined('assignee_id')
352+
->setAllowedTypes('assignee_id', 'integer')
353+
;
354+
355+
return $resolver;
356+
}
341357
}

lib/Gitlab/Api/Users.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ public function show($id)
6868
* @param int $id
6969
* @return mixed
7070
*/
71-
public function usersProjects($id)
71+
public function usersProjects($id, array $params = array())
7272
{
73-
return $this->get('users/'.$this->encodePath($id).'/projects');
73+
return $this->get('users/'.$this->encodePath($id).'/projects', $params);
7474
}
7575

7676
/**

lib/Gitlab/Api/Wiki.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php namespace Gitlab\Api;
2+
3+
class Wiki extends AbstractApi
4+
{
5+
6+
/**
7+
* @param int $project_id
8+
* @param array $params
9+
* @return mixed
10+
*/
11+
public function create($project_id, array $params)
12+
{
13+
return $this->post($this->getProjectPath($project_id, 'wikis'), $params);
14+
}
15+
16+
/**
17+
* @param int $project_id
18+
* @param int $wiki_slug
19+
* @return mixed
20+
*/
21+
public function show($project_id, $wiki_slug)
22+
{
23+
return $this->get($this->getProjectPath($project_id, 'wikis/'.$this->encodePath($wiki_slug)));
24+
}
25+
26+
/**
27+
* @param int $project_id
28+
* @return mixed
29+
*/
30+
public function showAll($project_id)
31+
{
32+
return $this->get($this->getProjectPath($project_id, 'wikis'));
33+
}
34+
35+
/**
36+
* @param int $project_id
37+
* @param array $params
38+
* @return mixed
39+
*/
40+
public function update($project_id, $wiki_slug, array $params)
41+
{
42+
return $this->put($this->getProjectPath($project_id, 'wikis/'.$this->encodePath($wiki_slug)), $params);
43+
}
44+
45+
/**
46+
* @param int $project_id
47+
* @param int $wiki_slug
48+
* @return mixed
49+
*/
50+
public function remove($project_id, $wiki_slug)
51+
{
52+
return $this->delete($this->getProjectPath($project_id, 'wikis/'.$this->encodePath($wiki_slug)));
53+
}
54+
}

lib/Gitlab/Client.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,14 @@ public function schedules()
305305
return new Api\Schedules($this);
306306
}
307307

308+
/**
309+
* @return Api\Wiki
310+
*/
311+
public function wiki()
312+
{
313+
return new Api\Wiki($this);
314+
}
315+
308316
/**
309317
* @return Api\IssuesStatistics
310318
*/
@@ -398,10 +406,12 @@ public function api($name)
398406
case 'schedules':
399407
return $this->schedules();
400408

409+
case 'wiki':
410+
return $this->wiki();
411+
401412
case 'issues_statistics':
402413
return $this->issuesStatistics();
403414

404-
405415
default:
406416
throw new InvalidArgumentException('Invalid endpoint: "'.$name.'"');
407417
}

lib/Gitlab/Model/Project.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ public static function fromArray(Client $client, array $data)
117117
if (isset($data['shared_with_groups'])) {
118118
$groups = [];
119119
foreach ($data['shared_with_groups'] as $group) {
120+
foreach ($group as $keys => $value) {
121+
$group[str_replace('group_', '', $keys)] = $value;
122+
unset($group[$keys]);
123+
}
120124
$groups[] = Group::fromArray($client, $group);
121125
}
122126
$data['shared_with_groups'] = $groups;

lib/Gitlab/Model/Wiki.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace Gitlab\Model;
4+
5+
use Gitlab\Client;
6+
7+
/**
8+
* Class Wiki
9+
*
10+
* @property-read string $slug
11+
* @property-read string $title
12+
* @property-read string $format
13+
* @property-read string $content
14+
* @property-read Project $project
15+
*/
16+
class Wiki extends AbstractModel
17+
{
18+
/**
19+
* @var array
20+
*/
21+
protected static $properties = array(
22+
"project",
23+
"slug",
24+
"title",
25+
"format",
26+
"content",
27+
);
28+
29+
/**
30+
* @param Client $client
31+
* @param Project $project
32+
* @param array $data
33+
* @return Wiki
34+
*/
35+
public static function fromArray(Client $client, Project $project, array $data)
36+
{
37+
$wiki = new static($project, $data['slug'], $client);
38+
39+
return $wiki->hydrate($data);
40+
}
41+
42+
/**
43+
* @param Project $project
44+
* @param string $slug
45+
* @param Client $client
46+
*/
47+
public function __construct(Project $project, $slug = null, Client $client = null)
48+
{
49+
$this->setClient($client);
50+
$this->setData('project', $project);
51+
$this->setData('slug', $slug);
52+
}
53+
54+
/**
55+
* @return Wiki
56+
*/
57+
public function show()
58+
{
59+
$data = $this->client->wiki()->show($this->project->id, $this->slug);
60+
61+
return static::fromArray($this->getClient(), $this->project, $data);
62+
}
63+
64+
/**
65+
* @param array $params
66+
* @return Wiki
67+
*/
68+
public function update(array $params)
69+
{
70+
$data = $this->client->wiki()->update($this->project->id, $this->slug, $params);
71+
72+
return static::fromArray($this->getClient(), $this->project, $data);
73+
}
74+
}

test/Gitlab/Tests/Api/IssuesTest.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,66 @@ public function shouldGetAllIssues()
2222
$this->assertEquals($expectedArray, $api->all());
2323
}
2424

25+
/**
26+
* @test
27+
*/
28+
public function shouldGetAllGroupIssues()
29+
{
30+
$expectedArray = array(
31+
array('id' => 1, 'title' => 'An issue'),
32+
array('id' => 2, 'title' => 'Another issue'),
33+
);
34+
35+
$api = $this->getApiMock();
36+
$api->expects($this->once())
37+
->method('get')
38+
->with('groups/1/issues', array())
39+
->will($this->returnValue($expectedArray))
40+
;
41+
42+
$this->assertEquals($expectedArray, $api->group(1));
43+
}
44+
45+
/**
46+
* @test
47+
*/
48+
public function shouldGetGroupIssuesWithPagination()
49+
{
50+
$expectedArray = array(
51+
array('id' => 1, 'title' => 'An issue'),
52+
array('id' => 2, 'title' => 'Another issue'),
53+
);
54+
55+
$api = $this->getApiMock();
56+
$api->expects($this->once())
57+
->method('get')
58+
->with('groups/1/issues', array('page' => 2, 'per_page' => 5))
59+
->will($this->returnValue($expectedArray))
60+
;
61+
62+
$this->assertEquals($expectedArray, $api->group(1, ['page' => 2, 'per_page' => 5]));
63+
}
64+
65+
/**
66+
* @test
67+
*/
68+
public function shouldGetGroupIssuesWithParams()
69+
{
70+
$expectedArray = array(
71+
array('id' => 1, 'title' => 'An issue'),
72+
array('id' => 2, 'title' => 'Another issue'),
73+
);
74+
75+
$api = $this->getApiMock();
76+
$api->expects($this->once())
77+
->method('get')
78+
->with('groups/1/issues', array('order_by' => 'created_at', 'sort' => 'desc', 'labels' => 'foo,bar', 'state' => 'opened'))
79+
->will($this->returnValue($expectedArray))
80+
;
81+
82+
$this->assertEquals($expectedArray, $api->group(1, array('order_by' => 'created_at', 'sort' => 'desc', 'labels' => 'foo,bar', 'state' => 'opened')));
83+
}
84+
2585
/**
2686
* @test
2787
*/

test/Gitlab/Tests/Api/UsersTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,25 @@ public function shouldShowUsersProjects()
112112
$this->assertEquals($expectedArray, $api->usersProjects(1));
113113
}
114114

115+
/**
116+
* @test
117+
*/
118+
public function shouldShowUsersProjectsWithLimit()
119+
{
120+
$expectedArray = array(
121+
array('id' => 1, 'name' => 'matt-project-1')
122+
);
123+
124+
$api = $this->getApiMock();
125+
$api->expects($this->once())
126+
->method('get')
127+
->with('users/1/projects')
128+
->will($this->returnValue($expectedArray))
129+
;
130+
131+
$this->assertEquals($expectedArray, $api->usersProjects(1, ['per_page'=>1]));
132+
}
133+
115134
/**
116135
* @test
117136
*/

0 commit comments

Comments
 (0)