Skip to content

Commit 14ff342

Browse files
author
Daniel André Eikeland
committed
Add support for Environments and Deployments api
1 parent 35ecf9b commit 14ff342

File tree

4 files changed

+407
-0
lines changed

4 files changed

+407
-0
lines changed

lib/Gitlab/Api/Deployments.php

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

lib/Gitlab/Api/Environments.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php namespace Gitlab\Api;
2+
3+
class Environments extends AbstractApi
4+
{
5+
/**
6+
* @param int $project_id
7+
* @return mixed
8+
*/
9+
public function all($project_id)
10+
{
11+
return $this->get($this->getProjectPath($project_id, 'environments'));
12+
}
13+
14+
/**
15+
* @param int $project_id
16+
* @param array $params
17+
* @return mixed
18+
*/
19+
public function create($project_id, array $params = array())
20+
{
21+
return $this->post($this->getProjectPath($project_id, "environment"), $params);
22+
}
23+
24+
/**
25+
* @param int $project_id
26+
* @param string $environment_id
27+
* @return mixed
28+
*/
29+
public function remove($project_id, $environment_id)
30+
{
31+
return $this->delete($this->getProjectPath($project_id, 'environments/'.$environment_id));
32+
}
33+
}
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' => '[email protected]',
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' => '[email protected]',
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' => '[email protected]',
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/1')
240+
->will($this->returnValue($expectedArray));
241+
$this->assertEquals($expectedArray, $api->show(1, 'v1.0.0'));
242+
}
243+
244+
protected function getApiClass()
245+
{
246+
return 'Gitlab\Api\Deployments';
247+
}
248+
}

0 commit comments

Comments
 (0)