Skip to content

Commit

Permalink
Merge pull request #231 from aik099/create-remote-link-fix
Browse files Browse the repository at this point in the history
Adjust "Api::createRemoteLink" params with Jira API params
  • Loading branch information
aik099 authored Jan 7, 2025
2 parents 236316d + 6c93c57 commit c4c1d90
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/Jira/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -723,27 +723,25 @@ public function createAttachment($issue_key, $filename, $name = null)
* @param string $global_id Global ID.
* @param array $application Application.
*
* @return array|false
* @return array
* @since 2.0.0
* @link https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issue-remote-links/#api-rest-api-2-issue-issueidorkey-remotelink-post
*/
public function createRemoteLink(
$issue_key,
array $object = array(),
array $object,
$relationship = null,
$global_id = null,
array $application = null
) {
$options = array(
$params = array_filter(array(
'globalId' => $global_id,
'relationship' => $relationship,
'object' => $object,
);

if ( $application !== null ) {
$options['application'] = $application;
}
'application' => $application,
));

return $this->api(self::REQUEST_POST, sprintf('/rest/api/2/issue/%s/remotelink', $issue_key), $options, true);
return $this->api(self::REQUEST_POST, sprintf('/rest/api/2/issue/%s/remotelink', $issue_key), $params, true);
}

/**
Expand Down
103 changes: 103 additions & 0 deletions tests/Jira/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,109 @@ public function testReleaseVersionParameterMerging()
$this->assertFalse($this->api->releaseVersion(111000, $release_date, array('test' => 'extra')));
}

/**
* @dataProvider createRemoteLinkDataProvider
*/
public function testCreateRemoteLink(array $method_params, array $expected_api_params)
{
$response = file_get_contents(__DIR__ . '/resources/api_create_remote_link.json');

$this->expectClientCall(
Api::REQUEST_POST,
'/rest/api/2/issue/JRE-123/remotelink',
$expected_api_params,
$response
);

$expected = json_decode($response, true);
$actual = call_user_func_array(array($this->api, 'createRemoteLink'), $method_params);

if ( $actual !== false ) {
$this->assertEquals($expected, $actual);
}
}

public static function createRemoteLinkDataProvider()
{
return array(
'object only' => array(
array(
'JRE-123',
array(
'title' => 'TSTSUP-111',
'url' => 'http://www.mycompany.com/support?id=1',
),
),
array(
'object' => array(
'title' => 'TSTSUP-111',
'url' => 'http://www.mycompany.com/support?id=1',
),
),
),
'object+relationship' => array(
array(
'JRE-123',
array(
'title' => 'TSTSUP-111',
'url' => 'http://www.mycompany.com/support?id=1',
),
'blocked by',
),
array(
'relationship' => 'blocked by',
'object' => array(
'title' => 'TSTSUP-111',
'url' => 'http://www.mycompany.com/support?id=1',
),
),
),
'object+global_id' => array(
array(
'JRE-123',
array(
'title' => 'TSTSUP-111',
'url' => 'http://www.mycompany.com/support?id=1',
),
null,
'global-id',
),
array(
'globalId' => 'global-id',
'object' => array(
'title' => 'TSTSUP-111',
'url' => 'http://www.mycompany.com/support?id=1',
),
),
),
'object+application' => array(
array(
'JRE-123',
array(
'title' => 'TSTSUP-111',
'url' => 'http://www.mycompany.com/support?id=1',
),
null,
null,
array(
'name' => 'My Acme Tracker',
'type' => 'com.acme.tracker',
),
),
array(
'object' => array(
'title' => 'TSTSUP-111',
'url' => 'http://www.mycompany.com/support?id=1',
),
'application' => array(
'name' => 'My Acme Tracker',
'type' => 'com.acme.tracker',
),
),
),
);
}

public function testFindVersionByName()
{
$project_key = 'POR';
Expand Down
4 changes: 4 additions & 0 deletions tests/Jira/resources/api_create_remote_link.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"id": 17095,
"self": "https://test.atlassian.net/rest/api/2/issue/JRE-123/remotelink/17095"
}

0 comments on commit c4c1d90

Please sign in to comment.