Skip to content

Commit

Permalink
fixed #40
Browse files Browse the repository at this point in the history
  • Loading branch information
lesstif committed Jul 10, 2016
1 parent 42c1c7a commit 9dc81a7
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 9 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ If you are developing with laravel framework(5.x), you must append above configu
- [Perform an advanced search, using the JQL](#perform-an-advanced-search)
- [Issue time tracking](#issue-time-tracking)
- [Add worklog in Issue](#add-worklog-in-issue)
- [Edit worklog in Issue](#edit-worklog-in-issue)
- [Get Issue worklog](#get-issue-worklog)

### User
Expand Down Expand Up @@ -548,6 +549,37 @@ try {

```

#### edit worklog in issue

```php
<?php
require 'vendor/autoload.php';

use JiraRestApi\Issue\IssueService;
use JiraRestApi\Issue\Worklog;
use JiraRestApi\JiraException;

$issueKey = 'TEST-961';
$workLogid = '12345';

try {
$workLog = new Worklog();

$workLog->setComment('I did edit previous worklog here.')
->setStarted("2016-05-29 13:15:34")
->setTimeSpent('3d 4h 5m');

$issueService = new IssueService();

$ret = $issueService->updateWorklog($issueKey, $workLog, $workLogid);

var_dump($ret);
} catch (JiraException $e) {
$this->assertTrue(false, 'Edit worklog Failed : '.$e->getMessage());
}

```

#### Get issue worklog

```php
Expand Down
40 changes: 31 additions & 9 deletions src/Issue/IssueService.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,25 +377,21 @@ public function getWorklogById($issueIdOrKey, $workLogId)
}

/**
* add work log to issue. if worklog id in 3rd param is passed, it will edit the worklog
* add work log to issue.
*
* @param mixed $issueIdOrKey
* @param object $worklog
* @param int $worklogId
*
* @return Worklog Object
*/
public function addWorklog($issueIdOrKey, $worklog, $worklogId = NULL){
public function addWorklog($issueIdOrKey, $worklog){
$this->log->addInfo("addWorklog=\n");

$data = json_encode($worklog);
if($worklogId === NULL){
$url = $this->uri . "/$issueIdOrKey/worklog";
$type = 'POST';
}else{
$url = $this->uri . "/$issueIdOrKey/worklog/$worklogId";
$type = 'PUT';
}
$url = $this->uri . "/$issueIdOrKey/worklog";
$type = 'POST';

$ret = $this->exec($url, $data, $type);

$ret_worklog = $this->json_mapper->map(
Expand All @@ -405,6 +401,32 @@ public function addWorklog($issueIdOrKey, $worklog, $worklogId = NULL){
return $ret_worklog;
}

/**
* edit the worklog
*
* @param $issueIdOrKey
* @param $worklog
* @param string $worklogId
* @return object
* @throws JiraException
* @throws \JsonMapper_Exception
*/
public function editWorklog($issueIdOrKey, $worklog, $worklogId){
$this->log->addInfo("editWorklog=\n");

$data = json_encode($worklog);
$url = $this->uri . "/$issueIdOrKey/worklog/$worklogId";
$type = 'PUT';

$ret = $this->exec($url, $data, $type);

$ret_worklog = $this->json_mapper->map(
json_decode($ret), new Worklog()
);

return $ret_worklog;
}

/**
* Get all priorities.
*
Expand Down
26 changes: 26 additions & 0 deletions tests/WorkLogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,32 @@ public function testAddWorkLogInIssue()
/**
* @depends testAddWorkLogInIssue
*/
public function testEditWorkLogInIssue($workLogid)
{
try {
$workLog = new Worklog();

$workLog->setComment('I did edit previous worklog here.')
->setStarted('2016-05-29 13:41:12')
->setTimeSpent('2d 7h 5m');

$issueService = new IssueService();

$ret = $issueService->editWorklog($this->issueKey, $workLog, $workLogid);

Dumper::dump($ret);

$workLogid = $ret->{'id'};

return $workLogid;
} catch (JiraException $e) {
$this->assertTrue(false, 'Create Failed : '.$e->getMessage());
}
}

/**
* @depends testUpdateWorkLogInIssue
*/
public function testGetWorkLogById($workLogid)
{
try {
Expand Down

0 comments on commit 9dc81a7

Please sign in to comment.