Skip to content

Commit 03393ea

Browse files
committed
fixed #73 - implemented issue linke.
1 parent 125ec1b commit 03393ea

File tree

4 files changed

+76
-13
lines changed

4 files changed

+76
-13
lines changed

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ $iss = new IssueService(new ArrayConfiguration(
115115
- [Get Issue worklog](#get-issue-worklog)
116116
- [Add watcher in Issue](#add-issue-watcher)
117117

118+
### IssueLink
119+
120+
* [Create Issue Link](#create-issue-link)
121+
* [Get Issue LinkType](#get-issue-linktype)
122+
118123
### User
119124
- [Get User Info](#get-user-info)
120125

@@ -845,7 +850,58 @@ try {
845850
} catch (JiraException $e) {
846851
$this->assertTrue(false, 'testSearch Failed : '.$e->getMessage());
847852
}
853+
```
854+
855+
#### Create Issue Link
856+
857+
The Link Issue Resource provides functionality to manage issue links.
858+
859+
```php
860+
<?php
861+
require 'vendor/autoload.php';
862+
863+
use JiraRestApi\IssueLink\IssueLink;
864+
use JiraRestApi\IssueLink\IssueLinkService;
865+
use JiraRestApi\JiraException;
866+
867+
try {
868+
$il = new IssueLink();
869+
870+
$il->setInwardIssue('TEST-258')
871+
->setOutwardIssue('TEST-249')
872+
->setLinkTypeName('Relates' )
873+
->setComment('Linked related issue via REST API.');
874+
875+
$ils = new IssueLinkService();
876+
877+
$ret = $ils->addIssueLink($il);
878+
879+
} catch (JiraException $e) {
880+
print("Error Occured! " . $e->getMessage());
881+
}
882+
```
883+
884+
#### Get Issue LinkType
885+
886+
Rest resource to retrieve a list of issue link types.
887+
888+
```php
889+
<?php
890+
require 'vendor/autoload.php';
848891

892+
use JiraRestApi\IssueLink\IssueLink;
893+
use JiraRestApi\IssueLink\IssueLinkService;
894+
use JiraRestApi\JiraException;
895+
896+
try {
897+
$ils = new IssueLinkService();
898+
899+
$ret = $ils->getIssueLinkTypes();
900+
901+
var_dump($ret);
902+
} catch (JiraException $e) {
903+
print("Error Occured! " . $e->getMessage());
904+
}
849905
```
850906

851907
#### Get User Info

src/IssueLink/IssueLink.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace JiraRestApi\IssueLink;
44

55
use JiraRestApi\ClassSerialize;
6+
use JiraRestApi\Issue\Comment;
67

78
class IssueLink implements \JsonSerializable
89
{
@@ -48,9 +49,18 @@ public function setOutwardIssue($issueKey)
4849
return $this;
4950
}
5051

51-
public function setComments($comment)
52+
/**
53+
* @param $comment string or \JiraRestApi\Issue\Comment instance
54+
* @return $this
55+
*/
56+
public function setComment($comment)
5257
{
53-
$this->comment = $comment;
58+
if (is_string($comment)) {
59+
$this->comment = new Comment();
60+
$this->comment->setBody($comment);
61+
} else if($comment instanceof Comment ) {
62+
$this->comment = $comment;
63+
}
5464

5565
return $this;
5666
}

src/IssueLink/IssueLinkService.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@ public function addIssueLink($issueLink)
2020
$type = 'POST';
2121

2222
$ret = $this->exec($url, $data, $type);
23-
24-
$this->log->addDebug('add issue link result='.var_export($ret, true));
25-
//$comment = $this->json_mapper->map(
26-
// json_decode($ret), new Comment()
27-
//);
28-
29-
return $this->http_response === 201 ? true : 'qqq';
30-
//https://docs.atlassian.com/jira/REST/server/#api/2/issueLink-linkIssues
3123
}
3224

3325
public function getIssueLinkTypes()
@@ -38,8 +30,10 @@ public function getIssueLinkTypes()
3830

3931
$ret = $this->exec($url);
4032

33+
$data = json_encode(json_decode($ret)->issueLinkTypes);
34+
4135
$linkTypes = $this->json_mapper->mapArray(
42-
json_decode($ret), new \ArrayObject(), '\JiraRestApi\IssueLink\IssueLinkType'
36+
json_decode($data, false), new \ArrayObject(), '\JiraRestApi\IssueLink\IssueLinkType'
4337
);
4438

4539
return $linkTypes;

src/JiraClient.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,11 @@ public function exec($context, $post_data = null, $custom_request = null)
191191
$body = curl_error($ch);
192192
curl_close($ch);
193193

194-
//The server successfully processed the request, but is not returning any content.
195-
if ($this->http_response == 204) {
194+
/*
195+
* 201: The request has been fulfilled, resulting in the creation of a new resource.
196+
* 204: The server successfully processed the request, but is not returning any content.
197+
*/
198+
if ($this->http_response === 204 || $this->http_response === 201) {
196199
return true;
197200
}
198201

0 commit comments

Comments
 (0)