From 5956d703b8553990110dcee277c05941e1279331 Mon Sep 17 00:00:00 2001 From: Constantin Dumitrescu Date: Sun, 18 Jan 2015 06:51:27 -0500 Subject: [PATCH 1/6] Initial commit. --- src/Jira/Api.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Jira/Api.php b/src/Jira/Api.php index 2c642a5..ff32aae 100644 --- a/src/Jira/Api.php +++ b/src/Jira/Api.php @@ -35,6 +35,8 @@ class Api const REQUEST_POST = "POST"; const REQUEST_PUT = "PUT"; const REQUEST_DELETE = "DELETE"; + + const WORKLOG_COMMENT = 'transition:'; const AUTOMAP_FIELDS = 0x01; @@ -574,4 +576,23 @@ public function closeIssue($issueKey) } return $result; } + + /** + * create JIRA Worklog + * + * @param $issue + * @param $filename + * @param array $options + * @return mixed + */ + public function createWorklogFromTransition($issue, $transitionId, $time, $startDate) + { + $options = array( + "timeSpent" => $time, + "started" => "2013-09-01T10:30:18.932+0530", + "comment" => self::WORKLOG_COMMENT . $transitionId + ); + + return $this->api(self::REQUEST_POST, "/rest/api/2/issue/" . $issue . "/worklog", $options); + } } From 390964e8a2ed080fbe0432b050a5730b8214d7a7 Mon Sep 17 00:00:00 2001 From: Constantin Dumitrescu Date: Sun, 18 Jan 2015 06:59:55 -0500 Subject: [PATCH 2/6] Changed date to the one provided by the arguments function. --- src/Jira/Api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Jira/Api.php b/src/Jira/Api.php index ff32aae..8094979 100644 --- a/src/Jira/Api.php +++ b/src/Jira/Api.php @@ -589,7 +589,7 @@ public function createWorklogFromTransition($issue, $transitionId, $time, $start { $options = array( "timeSpent" => $time, - "started" => "2013-09-01T10:30:18.932+0530", + "started" => $startDate, "comment" => self::WORKLOG_COMMENT . $transitionId ); From 8445c0727e5289cfc372d463120be0536a47d6f7 Mon Sep 17 00:00:00 2001 From: Constantin Dumitrescu Date: Sun, 18 Jan 2015 07:31:07 -0500 Subject: [PATCH 3/6] Changed const name for TRANSITION_DELIMITER text that will appear in the worklog comment. --- src/Jira/Api.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Jira/Api.php b/src/Jira/Api.php index 8094979..1688d67 100644 --- a/src/Jira/Api.php +++ b/src/Jira/Api.php @@ -36,8 +36,7 @@ class Api const REQUEST_PUT = "PUT"; const REQUEST_DELETE = "DELETE"; - const WORKLOG_COMMENT = 'transition:'; - + const TRANSITION_DELIMITER = 'transition:'; const AUTOMAP_FIELDS = 0x01; @@ -590,7 +589,7 @@ public function createWorklogFromTransition($issue, $transitionId, $time, $start $options = array( "timeSpent" => $time, "started" => $startDate, - "comment" => self::WORKLOG_COMMENT . $transitionId + "comment" => self::TRANSITION_DELIMITER . $transitionId ); return $this->api(self::REQUEST_POST, "/rest/api/2/issue/" . $issue . "/worklog", $options); From 37b1c37e7fdafad03ea150495efa235fcbe75a2b Mon Sep 17 00:00:00 2001 From: Constantin Dumitrescu Date: Mon, 19 Jan 2015 10:12:47 -0500 Subject: [PATCH 4/6] Abstracted the createWorkload method. --- src/Jira/Api.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Jira/Api.php b/src/Jira/Api.php index 1688d67..0e8b36d 100644 --- a/src/Jira/Api.php +++ b/src/Jira/Api.php @@ -584,14 +584,16 @@ public function closeIssue($issueKey) * @param array $options * @return mixed */ - public function createWorklogFromTransition($issue, $transitionId, $time, $startDate) + public function createWorklog($issueKey, $time, $options = array()) { - $options = array( - "timeSpent" => $time, - "started" => $startDate, - "comment" => self::TRANSITION_DELIMITER . $transitionId + + $options = array_merge( + array( + "timeSpent" => $time, + ), + $options ); - return $this->api(self::REQUEST_POST, "/rest/api/2/issue/" . $issue . "/worklog", $options); + return $this->api(self::REQUEST_POST, "/rest/api/2/issue/" . $issueKey . "/worklog", $options); } } From ac763e19d6a196ff3040d1688f7ddeb4a95999e1 Mon Sep 17 00:00:00 2001 From: Constantin Dumitrescu Date: Thu, 29 Jan 2015 02:40:18 -0500 Subject: [PATCH 5/6] Add removeWorkflow method. Refactor api call using sprintf. --- src/Jira/Api.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Jira/Api.php b/src/Jira/Api.php index 0e8b36d..e63d61a 100644 --- a/src/Jira/Api.php +++ b/src/Jira/Api.php @@ -594,6 +594,32 @@ public function createWorklog($issueKey, $time, $options = array()) $options ); - return $this->api(self::REQUEST_POST, "/rest/api/2/issue/" . $issueKey . "/worklog", $options); + return $this->api(self::REQUEST_POST, sprintf("/rest/api/2/issue/%s/worklog", $issueKey), $options); + } + + /** + * get JIRA Worklogs for a given issue key + * + * @param $issueKey + * @return mixed + */ + public function getWorklogs($issueKey) + { + return $this->api(self::REQUEST_GET, sprintf("/rest/api/2/issue/%s/worklog", $issueKey)); + } + + /** + * remove a JIRA Worklog + * + * @param $issueKey + * @return mixed + */ + public function removeWorklog($issueKey, $worklogId) + { + $options = array( + "adjustEstimate" => "auto" + ); + + return $this->api(self::REQUEST_DELETE, sprintf("/rest/api/2/issue/%s/worklog/%s", $issueKey, $worklogId), $options); } } From 05b3c073a1d424f219571d2ab1a6c368ad8356bd Mon Sep 17 00:00:00 2001 From: Constantin Dumitrescu Date: Thu, 29 Jan 2015 02:43:52 -0500 Subject: [PATCH 6/6] Add DELETE request method. --- src/Jira/Api/Client/CurlClient.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Jira/Api/Client/CurlClient.php b/src/Jira/Api/Client/CurlClient.php index 4a30d41..c7e8fd0 100644 --- a/src/Jira/Api/Client/CurlClient.php +++ b/src/Jira/Api/Client/CurlClient.php @@ -83,8 +83,8 @@ public function sendRequest($method, $url, $data = array(), $endpoint, Authentic curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); } } else { - if ($method == "PUT") { - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); + if ($method == "PUT" || $method == "DELETE") { + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); } }