Skip to content

Commit 152ae78

Browse files
authored
Merge pull request #179 from TheKvist/time-tracking-features
Time tracking features
2 parents d65f153 + 6cc26a0 commit 152ae78

File tree

2 files changed

+108
-2
lines changed

2 files changed

+108
-2
lines changed

lib/Gitlab/Api/Issues.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,44 @@ public function removeComment($project_id, $issue_id, $note_id)
127127
return $this->delete($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id).'/notes/'.$this->encodePath($note_id)));
128128
}
129129

130+
/**
131+
* @param int $project_id
132+
* @param int $issue_id
133+
* @param string $duration
134+
*/
135+
public function setTimeEstimate($project_id, $issue_id, $duration)
136+
{
137+
return $this->post($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id).'/time_estimate'), array('duration' => $duration));
138+
}
139+
140+
/**
141+
* @param int $project_id
142+
* @param int $issue_id
143+
*/
144+
public function resetTimeEstimate($project_id, $issue_id)
145+
{
146+
return $this->post($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id).'/reset_time_estimate'));
147+
}
148+
149+
/**
150+
* @param int $project_id
151+
* @param int $issue_id
152+
* @param string $duration
153+
*/
154+
public function addSpentTime($project_id, $issue_id, $duration)
155+
{
156+
return $this->post($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id).'/add_spent_time'), array('duration' => $duration));
157+
}
158+
159+
/**
160+
* @param int $project_id
161+
* @param int $issue_id
162+
*/
163+
public function resetSpentTime($project_id, $issue_id)
164+
{
165+
return $this->post($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id).'/reset_spent_time'));
166+
}
167+
130168
/**
131169
* @param int $project_id
132170
* @param int $issue_iid

test/Gitlab/Tests/Api/IssuesTest.php

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,72 @@ public function shouldUpdateComment()
187187
$this->assertEquals($expectedArray, $api->updateComment(1, 2, 3, 'An edited comment'));
188188
}
189189

190-
protected function getApiClass()
190+
/**
191+
* @test
192+
*/
193+
public function shouldSetTimeEstimate()
191194
{
192-
return 'Gitlab\Api\Issues';
195+
$expectedArray = array('time_estimate' => 14400, 'total_time_spent' => 0, 'human_time_estimate' => '4h', 'human_total_time_spent' => null);
196+
197+
$api = $this->getApiMock();
198+
$api->expects($this->once())
199+
->method('post')
200+
->with('projects/1/issues/2/time_estimate', array('duration' => '4h'))
201+
->will($this->returnValue($expectedArray))
202+
;
203+
204+
$this->assertEquals($expectedArray, $api->setTimeEstimate(1, 2, '4h'));
205+
}
206+
207+
/**
208+
* @test
209+
*/
210+
public function shouldResetTimeEstimate()
211+
{
212+
$expectedArray = array('time_estimate' => 0, 'total_time_spent' => 0, 'human_time_estimate' => null, 'human_total_time_spent' => null);
213+
214+
$api = $this->getApiMock();
215+
$api->expects($this->once())
216+
->method('post')
217+
->with('projects/1/issues/2/reset_time_estimate')
218+
->will($this->returnValue($expectedArray))
219+
;
220+
221+
$this->assertEquals($expectedArray, $api->resetTimeEstimate(1, 2));
222+
}
223+
224+
/**
225+
* @test
226+
*/
227+
public function shouldAddSpentTime()
228+
{
229+
$expectedArray = array('time_estimate' => 0, 'total_time_spent' => 14400, 'human_time_estimate' => null, 'human_total_time_spent' => '4h');
230+
231+
$api = $this->getApiMock();
232+
$api->expects($this->once())
233+
->method('post')
234+
->with('projects/1/issues/2/add_spent_time', array('duration' => '4h'))
235+
->will($this->returnValue($expectedArray))
236+
;
237+
238+
$this->assertEquals($expectedArray, $api->addSpentTime(1, 2, '4h'));
239+
}
240+
241+
/**
242+
* @test
243+
*/
244+
public function shouldResetSpentTime()
245+
{
246+
$expectedArray = array('time_estimate' => 0, 'total_time_spent' => 0, 'human_time_estimate' => null, 'human_total_time_spent' => null);
247+
248+
$api = $this->getApiMock();
249+
$api->expects($this->once())
250+
->method('post')
251+
->with('projects/1/issues/2/reset_spent_time')
252+
->will($this->returnValue($expectedArray))
253+
;
254+
255+
$this->assertEquals($expectedArray, $api->resetSpentTime(1, 2));
193256
}
194257

195258
/**
@@ -208,4 +271,9 @@ public function shouldGetIssueTimeStats()
208271

209272
$this->assertEquals($expectedArray, $api->getTimeStats(1, 2));
210273
}
274+
275+
protected function getApiClass()
276+
{
277+
return 'Gitlab\Api\Issues';
278+
}
211279
}

0 commit comments

Comments
 (0)