From b404519b9e08f0c5800e68bdc6e0adebbe652fc7 Mon Sep 17 00:00:00 2001 From: Dewstar Date: Fri, 19 Sep 2014 15:16:59 +0200 Subject: [PATCH] Added Delete in CurlClient Added function to resolve an issue in Api Added function to reopen an issue in Api Added function to delete watchers in Api Added function to delete comments in Api Added function to delete attachments in Api --- src/Jira/Api.php | 107 +++++++++++++++++++++++++++++ src/Jira/Api/Client/CurlClient.php | 2 + 2 files changed, 109 insertions(+) mode change 100644 => 100755 src/Jira/Api.php mode change 100644 => 100755 src/Jira/Api/Client/CurlClient.php diff --git a/src/Jira/Api.php b/src/Jira/Api.php old mode 100644 new mode 100755 index 2c642a5..9691555 --- a/src/Jira/Api.php +++ b/src/Jira/Api.php @@ -157,6 +157,13 @@ public function getAttachment($attachmentId) return $result; } + public function deleteAttachment($attachmentId) + { + $result = $this->api(self::REQUEST_DELETE, "/rest/api/2/attachment/$attachmentId"); + + return $result; + } + public function getProjects() { return $this->api(self::REQUEST_GET, "/rest/api/2/project"); @@ -239,6 +246,21 @@ public function addComment($issueKey, $params) return $this->api(self::REQUEST_POST, sprintf("/rest/api/2/issue/%s/comment", $issueKey), $params); } + /** + * delete comment from a ticket + * + * issue key should be YOURPROJ-221 + * + * @param $issueKey + * @param $commentId + * @return mixed + */ + public function deleteComment($issueKey, $commentId) + { + return $this->api(self::REQUEST_DELETE, sprintf("/rest/api/2/issue/%s/comment/%s", $issueKey, $commentId)); + } + + /** * get available transitions for a ticket * @@ -541,6 +563,22 @@ public function setWatchers($issueKey, $watchers) return $result; } + /** + * remove watchers in a ticket + * + * @param $issueKey + * @param $watchers + * @return mixed + */ + public function deleteWatchers($issueKey, $watchers) + { + $result = array(); + foreach($watchers as $w){ + $result[] = $this->api(self::REQUEST_DELETE, sprintf("/rest/api/2/issue/%s/watchers", $issueKey), $w); + } + return $result; + } + /** * close issue * @@ -574,4 +612,73 @@ public function closeIssue($issueKey) } return $result; } + + /** + * reopen issue + * + * @param $issueKey + * @return mixed + * + * @TODO: should have parameters? (e.g comment) + */ + public function reopenIssue($issueKey) + { + $result = array(); + // get available transitions + $tmp_transitions = $this->getTransitions($issueKey, array()); + $tmp_transitions_result = $tmp_transitions->getResult(); + $transitions = $tmp_transitions_result['transitions']; + + // search id for closing ticket + foreach ($transitions as $v) { + // Close ticket if required id was found + if ($v['name'] == "Reopen Issue") { + $result = $this->transition( + $issueKey, + array( + 'transition' => array( + 'id' => $v['id'] + ) + ) + ); + break; + } + } + return $result; + } + + /** + * resolve issue + * + * @param $issueKey + * @return mixed + * + * @TODO: should have parameters? (e.g comment) + */ + public function resolveIssue($issueKey) + { + $result = array(); + // get available transitions + $tmp_transitions = $this->getTransitions($issueKey, array()); + $tmp_transitions_result = $tmp_transitions->getResult(); + $transitions = $tmp_transitions_result['transitions']; + + // search id for closing ticket + foreach ($transitions as $v) { + // Close ticket if required id was found + if ($v['name'] == "Resolve Issue") { + $result = $this->transition( + $issueKey, + array( + 'transition' => array( + 'id' => $v['id'] + ) + ) + ); + break; + } + } + return $result; + } + } diff --git a/src/Jira/Api/Client/CurlClient.php b/src/Jira/Api/Client/CurlClient.php old mode 100644 new mode 100755 index 4a30d41..fb4f780 --- a/src/Jira/Api/Client/CurlClient.php +++ b/src/Jira/Api/Client/CurlClient.php @@ -82,6 +82,8 @@ public function sendRequest($method, $url, $data = array(), $endpoint, Authentic } else { curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); } + } else if($method == "DELETE") { + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); } else { if ($method == "PUT") { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");