Skip to content

Adjust "Api::createRemoteLink" params with Jira API params #231

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

Merged
merged 1 commit into from
Jan 7, 2025
Merged
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
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"
}
Loading