diff --git a/README.md b/README.md index 01bd1257..58d14923 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 +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) diff --git a/src/Issue/IssueService.php b/src/Issue/IssueService.php index 743b58a9..a300b3b0 100644 --- a/src/Issue/IssueService.php +++ b/src/Issue/IssueService.php @@ -2,6 +2,7 @@ namespace JiraRestApi\Issue; +use JiraRestApi\Dumper; use JiraRestApi\JiraException; class IssueService extends \JiraRestApi\JiraClient @@ -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; + } }