Skip to content

Commit

Permalink
fixed #116
Browse files Browse the repository at this point in the history
  • Loading branch information
lesstif committed Jun 2, 2018
1 parent 74bac97 commit 1893488
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ $iss = new IssueService(new ArrayConfiguration(
- [Create Sub Task](#create-sub-task)
- [Add Attachment](#add-attachment)
- [Update issue](#update-issue)
- [Update Labels](#update-labels)
- [Change assignee](#change-assignee)
- [Remove issue](#remove-issue)
- [Add comment](#add-comment)
Expand Down Expand Up @@ -633,6 +634,48 @@ try {

If you want to change the custom field type when updating an issue, you can call the *addCustomField* function just as you did for creating issue.


##### Update labels

This function is a convenient wrapper for add or remove label in the issue.

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

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

try {
$issueKey = 'TEST-123';

$issueService = new IssueService();

$addLabels = [
'triaged', 'customer-request', 'sales-request'
];

$removeLabel = [
'will-be-remove', 'this-label-is-typo'
];

$ret = $issueService->updateLabels($issueKey,
$addLabels,
$removeLabel,
$notifyUsers = false
);

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


### #Change Assignee



#### Change Assignee

[See Jira API reference](https://docs.atlassian.com/software/jira/docs/api/REST/7.6.1/#api/2/issue-assign)
Expand Down
39 changes: 39 additions & 0 deletions src/Issue/IssueService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace JiraRestApi\Issue;

use JiraRestApi\Dumper;
use JiraRestApi\JiraException;

class IssueService extends \JiraRestApi\JiraClient
Expand Down Expand Up @@ -927,4 +928,42 @@ public function getIssueSecuritySchemes($securityId)

return $res;
}

/**
* convenient wrapper function for add or remove labels.
*
* @param string|int $issueIdOrKey
* @param array|null $addLablesParam
* @param array|null $removeLabelsParam
* @param bool $notifyUsers
*
* @return Issue|object class
*
* @throws JiraException
*/
public function updateLabels($issueIdOrKey, $addLablesParam, $removeLabelsParam, $notifyUsers = true)
{
$labels = [];
foreach($addLablesParam as $a) {
array_push($labels, ["add" => $a]);
}

foreach($removeLabelsParam as $r) {
array_push($labels, ["remove" => $r]);
}

$postData = json_encode([
"update" => [
"labels" => $labels
]
], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT );

$this->log->addInfo("Update labels=\n".$postData);

$queryParam = '?'.http_build_query(["notifyUsers" => $notifyUsers]);

$ret = $this->exec($this->uri."/$issueIdOrKey".$queryParam, $postData, 'PUT');

return $ret;
}
}

0 comments on commit 1893488

Please sign in to comment.