Skip to content

Commit

Permalink
implemeneted remote issue link action(create/get) - fixed #67
Browse files Browse the repository at this point in the history
  • Loading branch information
lesstif committed Feb 10, 2018
1 parent 72f9bbb commit 79701d0
Show file tree
Hide file tree
Showing 5 changed files with 261 additions and 0 deletions.
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ $iss = new IssueService(new ArrayConfiguration(
- [Simple JQL](#simple-query)
- [JQL With pagination](#jql-with-pagination)
- [Using JQL Query class](#jql-query-class)
- [Remote Issue Link](#remote-issue-link)
- [Get Remote Issue Link](#get-remote-issue-link)
- [Create Remote Issue Link](#create-remote-issue-link)
- [Issue time tracking](#issue-time-tracking)
- [Add worklog in Issue](#add-worklog-in-issue)
- [Edit worklog in Issue](#edit-worklog-in-issue)
Expand Down Expand Up @@ -845,6 +848,63 @@ try {
}
```

#### Remote Issue Link


##### get remote issue link

* [See Jira API reference](https://docs.atlassian.com/software/jira/docs/api/REST/7.6.1/#api/2/issue-getRemoteIssueLinks)

```php

use JiraRestApi\Issue\IssueService;
use JiraRestApi\Issue\RemoteIssueLink;
use JiraRestApi\JiraException;

try {
$issueService = new IssueService();

$rils = $issueService->getRemoteIssueLink($issueKey);

// rils is array of RemoteIssueLink classes
var_dump($rils);
} catch (HTTPException $e) {
$this->assertTrue(false, $e->getMessage());
}

```

##### create remote issue link

* [See Jira API reference](https://docs.atlassian.com/software/jira/docs/api/REST/7.6.1/#api/2/issue-getRemoteIssueLinks)

```php
use JiraRestApi\Issue\IssueService;
use JiraRestApi\Issue\RemoteIssueLink;
use JiraRestApi\JiraException;

$issueKey = 'TEST-316';

try {
$issueService = new IssueService();

$ril = new RemoteIssueLink();

$ril->setUrl('http://www.mycompany.com/support?id=1')
->setTitle('Remote Link Title')
->setRelationship('causes')
->setSummary('Crazy customer support issue')
;

$rils = $issueService->createOrUpdateRemoteIssueLink($issueKey, $ril);

// rils is array of RemoteIssueLink classes
var_dump($rils);
} catch (JiraException $e) {
$this->assertTrue(false, 'Create Failed : '.$e->getMessage());
}
```

#### Issue time tracking

This methods use `get issue` and `edit issue` methods internally.
Expand Down
43 changes: 43 additions & 0 deletions src/Issue/IssueService.php
Original file line number Diff line number Diff line change
Expand Up @@ -754,4 +754,47 @@ public function notify($issueIdOrKey, $notify)
throw new JiraException('notify failed: response code='.$ret);
}
}

/**
* Get a remote issue links on the issue.
*
* @param $issueIdOrKey Issue id Or Key
*
* @throws JiraException
*
* @return array array os RemoteIssueLink class
*
* @see https://developer.atlassian.com/server/jira/platform/jira-rest-api-for-remote-issue-links/
* @see https://docs.atlassian.com/software/jira/docs/api/REST/7.6.1/#api/2/issue-getRemoteIssueLinks
*/
public function getRemoteIssueLink($issueIdOrKey)
{
$full_uri = $this->uri."/$issueIdOrKey/remotelink";

$ret = $this->exec($full_uri, null);

$rils = $this->json_mapper->mapArray(
json_decode($ret, false), new \ArrayObject(), RemoteIssueLink::class
);

return $rils;
}

public function createOrUpdateRemoteIssueLink($issueIdOrKey, RemoteIssueLink $ril)
{
$full_uri = $this->uri."/$issueIdOrKey/remotelink";

$data = json_encode($ril, JSON_UNESCAPED_SLASHES);

$this->log->addDebug("create remoteIssueLink=$data\n");

$ret = $this->exec($full_uri, $data, 'POST');

$res = $this->json_mapper->map(
json_decode($ret), new RemoteIssueLink()
);

return $res;
}

}
55 changes: 55 additions & 0 deletions src/Issue/RemoteIssueLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
namespace JiraRestApi\Issue;

class RemoteIssueLink implements \JsonSerializable
{
/** @var integer */
public $id;

/** @var string */
public $self;

/** @var string */
public $globalId;

/** @var array|null */
public $application;

/** @var string|null */
public $relationship;

/** @var RemoteIssueLinkObject|null */
public $object;

public function jsonSerialize()
{
return array_filter(get_object_vars($this));
}

public function setUrl($url)
{
if(is_null($this->object))
$this->object = new RemoteIssueLink();

$this->object->url = $url;
return $this;
}

public function setTitle($title)
{
$this->object->title = $title;
return $this;
}

public function setSummary($summary)
{
$this->object->summary = $summary;
return $this;
}

public function setRelationship($relationship)
{
$this->relationship = $relationship;
return $this;
}
}
34 changes: 34 additions & 0 deletions src/Issue/RemoteIssueLinkObject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
namespace JiraRestApi\Issue;


class RemoteIssueLinkObject
{
/** @var string */
public $url;

/** @var string */
public $title;

/** @var string|null */
public $summary;

/** @var array|null */
public $icon;

/**
* @var array|null
*
* ```json
* "status": {
* "resolved": true,
* "icon": {
* "url16x16": "http://www.mycompany.com/support/resolved.png",
* "title": "Case Closed",
* "link": "http://www.mycompany.com/support?id=1&details=closed"
* }
* }
* ```
*/
public $status;
}
69 changes: 69 additions & 0 deletions tests/RemoteIssueLinkTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

use JiraRestApi\Issue\IssueService;
use JiraRestApi\Issue\RemoteIssueLink;
use JiraRestApi\JiraException;

class RemoteIssueLinkTest extends PHPUnit_Framework_TestCase
{

public function testCreateRemoteIssueLink()
{
$issueKey = 'TEST-316';

try {
$issueService = new IssueService();

$ril = new RemoteIssueLink();

$ril->setUrl('http://www.mycompany.com/support?id=1')
->setTitle('Remote Link Title')
->setRelationship('causes')
->setSummary('Crazy customer support issue')
;

$issueService->createOrUpdateRemoteIssueLink($issueKey, $ril);

return $issueKey;
} catch (JiraException $e) {
$this->assertTrue(false, 'Create Failed : '.$e->getMessage());
}
}

/**
* @depends testCreateRemoteIssueLink
*/
public function testGetRemoteIssue($issueKey)
{

try {
$issueService = new IssueService();

$rils = $issueService->getRemoteIssueLink($issueKey);

$this->assertGreaterThan(0, count($rils));

$this->assertInstanceOf(RemoteIssueLink::class, $rils[0]);

return $issueKey;
} catch (HTTPException $e) {
$this->assertTrue(false, $e->getMessage());
}
}


/**
* @depends testGetRemoteIssue
*/
public function testDeleteRemoteIssueLink($issueKey)
{
// not yet impl
$this->markTestIncomplete();
try {

return $issueKey;
} catch (JiraException $e) {
$this->assertTrue(false, 'Create Failed : '.$e->getMessage());
}
}
}

0 comments on commit 79701d0

Please sign in to comment.