Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added "deleteIssue" function and changed "CurlClient" to support DELETE request #53

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/Jira/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public function __construct(
AuthenticationInterface $authentication,
ClientInterface $client = null
) {
//Regular expression to remove trailing slash
$endpoint = preg_replace('{/$}', '', $endpoint);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By replace code with solution below no explanatory comment is needed:

$endpoint = rtrim($endpoint, '/');

Sounds like useful change, but not sure how it's related to this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually just remove it from this PR, because there is another PR doing the same thing: #25 .


$this->setEndPoint($endpoint);
$this->authentication = $authentication;

Expand Down Expand Up @@ -150,6 +153,24 @@ public function editIssue($issueKey, $params)
}


/**
* Delete issue
*
* @param $issueKey should be YOURPROJ-221
* @param $deleteSubtasks if all subtask should be deleted
* @return mixed
*/
public function deleteIssue($issueKey, $deleteSubtasks = 'true')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trick that JIRA needs boolean specified as strings is it's internal thing and doesn't need to be exposed via API client interface. This way please replace 'true' with true.

{
return $this->api(
self::REQUEST_DELETE, sprintf("/rest/api/2/issue/%s", $issueKey),
array (
'deleteSubtasks' => $deleteSubtasks
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change $deleteSubtasks into $deleteSubtasks ? 'true' : 'false'.

)
);
}


public function getAttachment($attachmentId)
{
$result = $this->api(self::REQUEST_GET, "/rest/api/2/attachment/$attachmentId", array(), true);
Expand Down
12 changes: 7 additions & 5 deletions src/Jira/Api/Client/CurlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ public function sendRequest($method, $url, $data = array(), $endpoint, Authentic
} else {
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
}
} else {
if ($method == "PUT") {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
}
} elseif ($method == "DELETE") {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DELETE calls can have parameters. The correct implementation is done in #76.


} elseif ($method == "PUT") {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
}


$data = curl_exec($curl);

Expand Down