Skip to content

Commit 60ab818

Browse files
committed
Merge branch 'feature/issue-link' into develop
2 parents 49e2477 + 03393ea commit 60ab818

File tree

5 files changed

+218
-2
lines changed

5 files changed

+218
-2
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: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
namespace JiraRestApi\IssueLink;
4+
5+
use JiraRestApi\ClassSerialize;
6+
use JiraRestApi\Issue\Comment;
7+
8+
class IssueLink implements \JsonSerializable
9+
{
10+
use ClassSerialize;
11+
12+
public function jsonSerialize()
13+
{
14+
$vars = array_filter(get_object_vars($this));
15+
16+
return $vars;
17+
}
18+
19+
/**
20+
* @param $typeName issue type string(ex: 'Duplicate')
21+
* @return $this
22+
*/
23+
public function setLinkTypeName($typeName)
24+
{
25+
$this->type['name'] = $typeName;
26+
27+
return $this;
28+
}
29+
30+
/**
31+
* @param $issueKey inward issue key or id
32+
* @return $this
33+
*/
34+
public function setInwardIssue($issueKey)
35+
{
36+
$this->inwardIssue['key'] = $issueKey;
37+
38+
return $this;
39+
}
40+
41+
/**
42+
* @param $issueKey out ward issue key or id
43+
* @return $this
44+
*/
45+
public function setOutwardIssue($issueKey)
46+
{
47+
$this->outwardIssue['key'] = $issueKey;
48+
49+
return $this;
50+
}
51+
52+
/**
53+
* @param $comment string or \JiraRestApi\Issue\Comment instance
54+
* @return $this
55+
*/
56+
public function setComment($comment)
57+
{
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+
}
64+
65+
return $this;
66+
}
67+
68+
/** @var array */
69+
public $type;
70+
71+
/** @var \JiraRestApi\Issue\Issue */
72+
public $inwardIssue;
73+
74+
/** @var \JiraRestApi\Issue\Issue */
75+
public $outwardIssue;
76+
77+
/** @var \JiraRestApi\Issue\Comment */
78+
public $comment;
79+
}

src/IssueLink/IssueLinkService.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace JiraRestApi\IssueLink;
4+
5+
use JiraRestApi\JiraException;
6+
7+
class IssueLinkService extends \JiraRestApi\JiraClient
8+
{
9+
private $uri = '';
10+
11+
public function addIssueLink($issueLink)
12+
{
13+
$this->log->addInfo("addIssueLink=\n");
14+
15+
$data = json_encode($issueLink);
16+
17+
$this->log->addDebug("Create IssueLink=\n".$data);
18+
19+
$url = $this->uri . "/issueLink";
20+
$type = 'POST';
21+
22+
$ret = $this->exec($url, $data, $type);
23+
}
24+
25+
public function getIssueLinkTypes()
26+
{
27+
$this->log->addInfo("getIssueLinkTYpes=\n");
28+
29+
$url = $this->uri . "/issueLinkType";
30+
31+
$ret = $this->exec($url);
32+
33+
$data = json_encode(json_decode($ret)->issueLinkTypes);
34+
35+
$linkTypes = $this->json_mapper->mapArray(
36+
json_decode($data, false), new \ArrayObject(), '\JiraRestApi\IssueLink\IssueLinkType'
37+
);
38+
39+
return $linkTypes;
40+
}
41+
}

src/IssueLink/IssueLinkType.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace JiraRestApi\IssueLink;
4+
5+
use JiraRestApi\ClassSerialize;
6+
7+
/**
8+
* Class IssueLinkType
9+
* @package JiraRestApi\Issue
10+
* @see https://docs.atlassian.com/jira/REST/server/#api/2/issueLinkType-createIssueLinkType
11+
*/
12+
class IssueLinkType implements \JsonSerializable
13+
{
14+
use ClassSerialize;
15+
16+
public function jsonSerialize()
17+
{
18+
$vars = array_filter(get_object_vars($this));
19+
20+
return $vars;
21+
}
22+
23+
/** @var integer */
24+
public $id;
25+
26+
/** @var string */
27+
public $name;
28+
29+
/** @var string */
30+
public $inward;
31+
32+
/** @var string */
33+
public $outward;
34+
35+
/** @var string */
36+
public $self;
37+
}

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)