Skip to content

Commit a6c4be2

Browse files
authored
Merge pull request #274 from zegenie/environments
Add support for Deployments and Environments api
2 parents 384fcba + 99bde8d commit a6c4be2

File tree

5 files changed

+402
-0
lines changed

5 files changed

+402
-0
lines changed

lib/Gitlab/Api/Deployments.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php namespace Gitlab\Api;
2+
3+
class Deployments extends AbstractApi
4+
{
5+
/**
6+
* @param int $project_id
7+
* @param array $parameters
8+
* @return mixed
9+
*/
10+
public function all($project_id, array $parameters = [])
11+
{
12+
$resolver = $this->createOptionsResolver();
13+
return $this->get($this->getProjectPath($project_id, 'deployments'), $resolver->resolve($parameters));
14+
}
15+
16+
/**
17+
* @param int $project_id
18+
* @param string $deployment_id
19+
* @return mixed
20+
*/
21+
public function show($project_id, $deployment_id)
22+
{
23+
return $this->get($this->getProjectPath($project_id, 'deployments/' . $deployment_id));
24+
}
25+
}

lib/Gitlab/Api/Environments.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php namespace Gitlab\Api;
2+
3+
use Symfony\Component\OptionsResolver\OptionsResolver;
4+
5+
class Environments extends AbstractApi
6+
{
7+
/**
8+
* @param int $project_id
9+
* @param array $parameters
10+
* @return mixed
11+
*/
12+
public function all($project_id, array $parameters = [])
13+
{
14+
$resolver = $this->createOptionsResolver();
15+
return $this->get($this->getProjectPath($project_id, 'environments'), $resolver->resolve($parameters));
16+
}
17+
18+
/**
19+
* @param int $project_id
20+
* @param array $parameters (
21+
*
22+
* @var string $name The name of the environment
23+
* @var string $external_url Place to link to for this environment
24+
* )
25+
* @return mixed
26+
*/
27+
public function create($project_id, array $parameters = array())
28+
{
29+
$resolver = new OptionsResolver();
30+
$resolver->setDefined('name')
31+
->setRequired('name')
32+
->setAllowedTypes('name', 'string');
33+
$resolver->setDefined('external_url')
34+
->setAllowedTypes('external_url', 'string');
35+
36+
return $this->post($this->getProjectPath($project_id, 'environment'), $resolver->resolve($parameters));
37+
}
38+
39+
/**
40+
* @param int $project_id
41+
* @param string $environment_id
42+
* @return mixed
43+
*/
44+
public function remove($project_id, $environment_id)
45+
{
46+
return $this->delete($this->getProjectPath($project_id, 'environments/' . $environment_id));
47+
}
48+
}

lib/Gitlab/Api/Repositories.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class Repositories extends AbstractApi
66
{
77
/**
88
* @param int $project_id
9+
* @param array $parameters
910
* @return mixed
1011
*/
1112
public function branches($project_id, array $parameters = [])
Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
<?php namespace Gitlab\Tests\Api;
2+
3+
class DeploymentsTest extends TestCase
4+
{
5+
/**
6+
* @test
7+
*/
8+
public function shouldGetAllDeployments()
9+
{
10+
$expectedArray = array(
11+
array(
12+
'created_at' => '2016-08-11T07:36:40.222Z',
13+
'deployable' =>
14+
array(
15+
'commit' =>
16+
array(
17+
'author_email' => 'admin@example.com',
18+
'author_name' => 'Administrator',
19+
'created_at' => '2016-08-11T09:36:01.000+02:00',
20+
'id' => '99d03678b90d914dbb1b109132516d71a4a03ea8',
21+
'message' => 'Merge branch \'new-title\' into \'master\'
22+
23+
Update README
24+
25+
26+
27+
See merge request !1',
28+
'short_id' => '99d03678',
29+
'title' => 'Merge branch \'new-title\' into \'master\'
30+
',
31+
),
32+
'coverage' => null,
33+
'created_at' => '2016-08-11T07:36:27.357Z',
34+
'finished_at' => '2016-08-11T07:36:39.851Z',
35+
'id' => 657,
36+
'name' => 'deploy',
37+
'ref' => 'master',
38+
'runner' => null,
39+
'stage' => 'deploy',
40+
'started_at' => null,
41+
'status' => 'success',
42+
'tag' => false,
43+
'user' =>
44+
array(
45+
'avatar_url' => 'http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
46+
'bio' => null,
47+
'created_at' => '2016-08-11T07:09:20.351Z',
48+
'id' => 1,
49+
'linkedin' => '',
50+
'location' => null,
51+
'name' => 'Administrator',
52+
'skype' => '',
53+
'state' => 'active',
54+
'twitter' => '',
55+
'username' => 'root',
56+
'web_url' => 'http://localhost:3000/root',
57+
'website_url' => '',
58+
),
59+
),
60+
'environment' =>
61+
array(
62+
'external_url' => 'https://about.gitlab.com',
63+
'id' => 9,
64+
'name' => 'production',
65+
),
66+
'id' => 41,
67+
'iid' => 1,
68+
'ref' => 'master',
69+
'sha' => '99d03678b90d914dbb1b109132516d71a4a03ea8',
70+
'user' =>
71+
array(
72+
'avatar_url' => 'http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
73+
'id' => 1,
74+
'name' => 'Administrator',
75+
'state' => 'active',
76+
'username' => 'root',
77+
'web_url' => 'http://localhost:3000/root',
78+
),
79+
),
80+
array(
81+
'created_at' => '2016-08-11T11:32:35.444Z',
82+
'deployable' =>
83+
array(
84+
'commit' =>
85+
array(
86+
'author_email' => 'admin@example.com',
87+
'author_name' => 'Administrator',
88+
'created_at' => '2016-08-11T13:28:26.000+02:00',
89+
'id' => 'a91957a858320c0e17f3a0eca7cfacbff50ea29a',
90+
'message' => 'Merge branch \'rename-readme\' into \'master\'
91+
92+
Rename README
93+
94+
95+
96+
See merge request !2',
97+
'short_id' => 'a91957a8',
98+
'title' => 'Merge branch \'rename-readme\' into \'master\'
99+
',
100+
),
101+
'coverage' => null,
102+
'created_at' => '2016-08-11T11:32:24.456Z',
103+
'finished_at' => '2016-08-11T11:32:35.145Z',
104+
'id' => 664,
105+
'name' => 'deploy',
106+
'ref' => 'master',
107+
'runner' => null,
108+
'stage' => 'deploy',
109+
'started_at' => null,
110+
'status' => 'success',
111+
'tag' => false,
112+
'user' =>
113+
array(
114+
'avatar_url' => 'http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
115+
'bio' => null,
116+
'created_at' => '2016-08-11T07:09:20.351Z',
117+
'id' => 1,
118+
'linkedin' => '',
119+
'location' => null,
120+
'name' => 'Administrator',
121+
'skype' => '',
122+
'state' => 'active',
123+
'twitter' => '',
124+
'username' => 'root',
125+
'web_url' => 'http://localhost:3000/root',
126+
'website_url' => '',
127+
),
128+
),
129+
'environment' =>
130+
array(
131+
'external_url' => 'https://about.gitlab.com',
132+
'id' => 9,
133+
'name' => 'production',
134+
),
135+
'id' => 42,
136+
'iid' => 2,
137+
'ref' => 'master',
138+
'sha' => 'a91957a858320c0e17f3a0eca7cfacbff50ea29a',
139+
'user' =>
140+
array(
141+
'avatar_url' => 'http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
142+
'id' => 1,
143+
'name' => 'Administrator',
144+
'state' => 'active',
145+
'username' => 'root',
146+
'web_url' => 'http://localhost:3000/root',
147+
),
148+
),
149+
);
150+
151+
$api = $this->getApiMock();
152+
$api->expects($this->once())
153+
->method('get')
154+
->with('projects/1/deployments')
155+
->will($this->returnValue($expectedArray));
156+
$this->assertEquals($expectedArray, $api->all(1));
157+
}
158+
159+
/**
160+
* @test
161+
*/
162+
public function shouldShowDeployment()
163+
{
164+
$expectedArray = array(
165+
array(
166+
'created_at' => '2016-08-11T11:32:35.444Z',
167+
'deployable' =>
168+
array(
169+
'commit' =>
170+
array(
171+
'author_email' => 'admin@example.com',
172+
'author_name' => 'Administrator',
173+
'created_at' => '2016-08-11T13:28:26.000+02:00',
174+
'id' => 'a91957a858320c0e17f3a0eca7cfacbff50ea29a',
175+
'message' => 'Merge branch \'rename-readme\' into \'master\'
176+
177+
Rename README
178+
179+
180+
181+
See merge request !2',
182+
'short_id' => 'a91957a8',
183+
'title' => 'Merge branch \'rename-readme\' into \'master\'
184+
',
185+
),
186+
'coverage' => null,
187+
'created_at' => '2016-08-11T11:32:24.456Z',
188+
'finished_at' => '2016-08-11T11:32:35.145Z',
189+
'id' => 664,
190+
'name' => 'deploy',
191+
'ref' => 'master',
192+
'runner' => null,
193+
'stage' => 'deploy',
194+
'started_at' => null,
195+
'status' => 'success',
196+
'tag' => false,
197+
'user' =>
198+
array(
199+
'avatar_url' => 'http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
200+
'bio' => null,
201+
'created_at' => '2016-08-11T07:09:20.351Z',
202+
'id' => 1,
203+
'linkedin' => '',
204+
'location' => null,
205+
'name' => 'Administrator',
206+
'skype' => '',
207+
'state' => 'active',
208+
'twitter' => '',
209+
'username' => 'root',
210+
'web_url' => 'http://localhost:3000/root',
211+
'website_url' => '',
212+
),
213+
),
214+
'environment' =>
215+
array(
216+
'external_url' => 'https://about.gitlab.com',
217+
'id' => 9,
218+
'name' => 'production',
219+
),
220+
'id' => 42,
221+
'iid' => 2,
222+
'ref' => 'master',
223+
'sha' => 'a91957a858320c0e17f3a0eca7cfacbff50ea29a',
224+
'user' =>
225+
array(
226+
'avatar_url' => 'http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
227+
'id' => 1,
228+
'name' => 'Administrator',
229+
'state' => 'active',
230+
'username' => 'root',
231+
'web_url' => 'http://localhost:3000/root',
232+
),
233+
),
234+
);
235+
236+
$api = $this->getApiMock();
237+
$api->expects($this->once())
238+
->method('get')
239+
->with('projects/1/deployments/42')
240+
->will($this->returnValue($expectedArray));
241+
$this->assertEquals($expectedArray, $api->show(1, 42));
242+
}
243+
244+
protected function getApiClass()
245+
{
246+
return 'Gitlab\Api\Deployments';
247+
}
248+
}

0 commit comments

Comments
 (0)