Skip to content

Commit d375c35

Browse files
committed
fixed #526 I've implemented getting customField action.
1 parent 69dfc13 commit d375c35

File tree

5 files changed

+116
-7
lines changed

5 files changed

+116
-7
lines changed

src/Issue/CustomField.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\Issue;
4+
5+
class CustomField implements \JsonSerializable
6+
{
7+
public int $id;
8+
9+
public string $name;
10+
11+
public string $description;
12+
13+
public array $type;
14+
15+
public string $searcherKey;
16+
17+
public array $projectIds;
18+
19+
public array $issueTypeIds;
20+
21+
public string $self;
22+
23+
public int $numericId;
24+
25+
public bool $isLocked;
26+
27+
public bool $isManaged;
28+
29+
public bool $isAllProjects;
30+
31+
public bool $isTrusted;
32+
33+
public int $projectsCount;
34+
35+
public int $screensCount;
36+
37+
public function jsonSerialize(): mixed
38+
{
39+
return array_filter(get_object_vars($this));
40+
}
41+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace JiraRestApi\Issue;
4+
5+
class CustomFieldSearchResult implements \JsonSerializable
6+
{
7+
public int $maxResults;
8+
9+
public int $startAt;
10+
11+
public int $total;
12+
13+
public bool $isLast;
14+
15+
/**
16+
* @var array of CustomField
17+
*/
18+
public array $values;
19+
20+
public function jsonSerialize(): mixed
21+
{
22+
return array_filter(get_object_vars($this));
23+
}
24+
}

src/Issue/IssueService.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -822,22 +822,26 @@ public function getPriority(int $priorityId): Priority
822822
* Get priority by id.
823823
* throws HTTPException if the priority is not found, or the calling user does not have permission or view it.
824824
*
825-
* @param int $priorityId Id of priority.
825+
* @param $paramArray array parameters
826826
*
827827
* @throws \JsonMapper_Exception
828828
* @throws JiraException
829829
*
830-
* @return Priority priority
830+
* @return CustomFieldSearchResult array of CustomeFiled
831+
*
832+
* @see https://docs.atlassian.com/software/jira/docs/api/REST/9.14.0/#api/2/customFields-getCustomFields
831833
*/
832-
public function getCustomFields(int $priorityId): Priority
834+
public function getCustomFields(array $paramArray = []): CustomFieldSearchResult
833835
{
834-
$ret = $this->exec("priority/$priorityId", null);
836+
$ret = $this->exec("customFields".$this->toHttpQueryParameter($paramArray), null);
835837

836838
$this->log->info('Result='.$ret);
837839

840+
//\JiraRestApi\Dumper::dd(json_decode($ret, false));
841+
838842
return $this->json_mapper->map(
839-
json_decode($ret),
840-
new Priority()
843+
json_decode($ret, false),
844+
new CustomFieldSearchResult()
841845
);
842846
}
843847

src/JiraClient.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,11 +484,14 @@ public function setAPIUri(string $api_uri): string
484484
/**
485485
* convert to query array to http query parameter.
486486
*/
487-
public function toHttpQueryParameter(array $paramArray): string
487+
public function toHttpQueryParameter(array $paramArray, bool $dropNullKey = true): string
488488
{
489489
$queryParam = '?';
490490

491491
foreach ($paramArray as $key => $value) {
492+
if ($dropNullKey === true && empty($value)) {
493+
continue;
494+
}
492495
$v = null;
493496

494497
// some param field(Ex: expand) type is array.

tests/CustomFieldsTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace JiraRestApi\Test;
44

5+
use JiraRestApi\Issue\IssueService;
56
use PHPUnit\Framework\TestCase;
67
use JiraRestApi\Dumper;
78
use JiraRestApi\Field\Field;
@@ -10,6 +11,37 @@
1011

1112
class CustomFieldsTest extends TestCase
1213
{
14+
/**
15+
* @Test
16+
*
17+
* @return array|string[]|void
18+
*/
19+
public function get_customer_field()
20+
{
21+
try {
22+
$iss = new IssueService();
23+
24+
$paramArray = [
25+
'startAt' => 1,
26+
'maxResults' => 50,
27+
'search' => null,
28+
'projectIds' => [1, 2, 3],
29+
'screenIds' => null,
30+
'types' => null,
31+
32+
'sortOrder' => null,
33+
'sortColumn' => null,
34+
'lastValueUpdate' => null,
35+
];
36+
$customerFieldSearchResult = $iss->getCustomFields($paramArray);
37+
38+
$this->assertLessThan(1, $customerFieldSearchResult->total);
39+
40+
} catch (JiraException $e) {
41+
$this->assertTrue(false, 'testSearch Failed : '.$e->getMessage());
42+
}
43+
}
44+
1345
public function testGetFields()
1446
{
1547
try {
@@ -26,6 +58,7 @@ public function testGetFields()
2658
return $matches[0];
2759
}, $ret);
2860

61+
$this->assertTrue(true);
2962
return $ids;
3063

3164
} catch (JiraException $e) {
@@ -49,6 +82,7 @@ public function testGetFieldOptions($ids)
4982
Dumper::dump($ret);
5083
}catch (JiraException $e) {}
5184
}
85+
$this->assertTrue(true);
5286
} catch (JiraException $e) {
5387
$this->assertTrue(false, 'testGetFieldOptions Failed : '.$e->getMessage());
5488
}
@@ -69,6 +103,9 @@ public function testCreateFields()
69103
$fieldService = new FieldService();
70104

71105
$ret = $fieldService->create($field);
106+
107+
$this->assertTrue(true);
108+
72109
Dumper::dump($ret);
73110
} catch (JiraException $e) {
74111
$this->assertTrue(false, 'Field Create Failed : '.$e->getMessage());

0 commit comments

Comments
 (0)