Skip to content

Commit 400db4d

Browse files
[11.1] Added CI schedule variables endpoints (#569)
Co-authored-by: Graham Campbell <[email protected]>
1 parent ca43707 commit 400db4d

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

src/Api/Schedules.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,47 @@ public function remove($project_id, int $schedule_id)
7070
{
7171
return $this->delete($this->getProjectPath($project_id, 'pipeline_schedules/'.self::encodePath($schedule_id)));
7272
}
73+
74+
/**
75+
* @param int|string $project_id
76+
* @param int $schedule_id
77+
* @param array $params
78+
*
79+
* @return mixed
80+
*/
81+
public function addVariable($project_id, int $schedule_id, array $params)
82+
{
83+
$path = 'pipeline_schedules/'.self::encodePath($schedule_id).'/variables';
84+
85+
return $this->post($this->getProjectPath($project_id, $path), $params);
86+
}
87+
88+
/**
89+
* @param int|string $project_id
90+
* @param int $schedule_id
91+
* @param string $variable_key
92+
* @param array $params
93+
*
94+
* @return mixed
95+
*/
96+
public function updateVariable($project_id, int $schedule_id, string $variable_key, array $params)
97+
{
98+
$path = 'pipeline_schedules/'.self::encodePath($schedule_id).'/variables/'.self::encodePath($variable_key);
99+
100+
return $this->put($this->getProjectPath($project_id, $path), $params);
101+
}
102+
103+
/**
104+
* @param int|string $project_id
105+
* @param int $schedule_id
106+
* @param string $variable_key
107+
*
108+
* @return mixed
109+
*/
110+
public function removeVariable($project_id, int $schedule_id, string $variable_key)
111+
{
112+
$path = 'pipeline_schedules/'.self::encodePath($schedule_id).'/variables/'.self::encodePath($variable_key);
113+
114+
return $this->delete($this->getProjectPath($project_id, $path));
115+
}
73116
}

tests/Api/ScheduleTest.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,73 @@ public function shouldRemoveSchedule(): void
135135
$this->assertEquals($expectedBool, $api->remove(1, 2));
136136
}
137137

138+
/**
139+
* @test
140+
*/
141+
public function shouldCreateScheduleVariable(): void
142+
{
143+
$expectedArray = [
144+
'key' => 'FOO_BAR',
145+
'variable_type' => 'env_var',
146+
'value' => 'BAZ',
147+
];
148+
149+
$api = $this->getApiMock();
150+
$api->expects($this->once())
151+
->method('post')
152+
->with('projects/1/pipeline_schedules/2/variables', $expectedArray)
153+
->will($this->returnValue($expectedArray));
154+
155+
$this->assertEquals($expectedArray, $api->addVariable(
156+
1,
157+
2,
158+
$expectedArray
159+
));
160+
}
161+
162+
/**
163+
* @test
164+
*/
165+
public function shouldUpdateScheduleVariable(): void
166+
{
167+
$variabelName = 'FOO_BAR';
168+
$expectedArray = [
169+
'key' => $variabelName,
170+
'variable_type' => 'env_var',
171+
'value' => 'BAZ',
172+
];
173+
174+
$api = $this->getApiMock();
175+
$api->expects($this->once())
176+
->method('put')
177+
->with('projects/1/pipeline_schedules/2/variables/' . $variabelName, $expectedArray)
178+
->will($this->returnValue($expectedArray));
179+
180+
$this->assertEquals($expectedArray, $api->updateVariable(
181+
1,
182+
2,
183+
$variabelName,
184+
$expectedArray
185+
));
186+
}
187+
188+
/**
189+
* @test
190+
*/
191+
public function shouldRemoveScheduleVariable(): void
192+
{
193+
$expectedBool = true;
194+
195+
$api = $this->getApiMock();
196+
$api->expects($this->once())
197+
->method('delete')
198+
->with('projects/1/pipeline_schedules/2/variables/FOO_BAR')
199+
->will($this->returnValue($expectedBool))
200+
;
201+
202+
$this->assertEquals($expectedBool, $api->removeVariable(1, 2, 'FOO_BAR'));
203+
}
204+
138205
protected function getApiClass()
139206
{
140207
return Schedules::class;

0 commit comments

Comments
 (0)