Skip to content

Commit 54ba79f

Browse files
authored
Issue #91: update search() to work with search/jql (#97)
* Add new search method and deprecate old one * Update IssueService.php * Update IssueService.php * style fix * Update IssueSearchResult.php * Create IssueBulkResult.php * Update IssueService.php * Update IssueService.php
1 parent aeb388b commit 54ba79f

3 files changed

Lines changed: 161 additions & 82 deletions

File tree

src/Issue/IssueBulkResult.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
namespace JiraCloud\Issue;
4+
5+
/**
6+
* Issue search result.
7+
*/
8+
class IssueBulkResult
9+
{
10+
/**
11+
* @var string
12+
*/
13+
public $expand;
14+
15+
/**
16+
* @var \JiraCloud\Issue\Issue[]
17+
*/
18+
public $issues;
19+
20+
/**
21+
* @var array
22+
*/
23+
public $issueErrors;
24+
25+
/**
26+
* @return array
27+
*/
28+
public function getIssueErrors()
29+
{
30+
return $this->issueErrors;
31+
}
32+
33+
/**
34+
* @param array $issueErrors
35+
*/
36+
public function setIssueErrors($issueErrors)
37+
{
38+
$this->issueErrors = $issueErrors;
39+
}
40+
41+
/**
42+
* @return Issue[]
43+
*/
44+
public function getIssues()
45+
{
46+
return $this->issues;
47+
}
48+
49+
/**
50+
* @param Issue[] $issues
51+
*/
52+
public function setIssues($issues)
53+
{
54+
$this->issues = $issues;
55+
}
56+
57+
/**
58+
* @param int $ndx
59+
*
60+
* @return Issue
61+
*/
62+
public function getIssue($ndx)
63+
{
64+
return $this->issues[$ndx];
65+
}
66+
67+
/**
68+
* @return string
69+
*/
70+
public function getExpand()
71+
{
72+
return $this->expand;
73+
}
74+
75+
/**
76+
* @param string $expand
77+
*/
78+
public function setExpand($expand)
79+
{
80+
$this->expand = $expand;
81+
}
82+
}

src/Issue/IssueSearchResult.php

Lines changed: 7 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -10,74 +10,27 @@ class IssueSearchResult
1010
/**
1111
* @var string
1212
*/
13-
public $expand;
14-
15-
/**
16-
* @var int
17-
*/
18-
public $startAt;
19-
20-
/**
21-
* @var int
22-
*/
23-
public $maxResults;
24-
25-
/**
26-
* @var int
27-
*/
28-
public $total;
13+
public $nextPageToken;
2914

3015
/**
3116
* @var \JiraCloud\Issue\Issue[]
3217
*/
3318
public $issues;
3419

3520
/**
36-
* @return int
37-
*/
38-
public function getStartAt()
39-
{
40-
return $this->startAt;
41-
}
42-
43-
/**
44-
* @param int $startAt
45-
*/
46-
public function setStartAt($startAt)
47-
{
48-
$this->startAt = $startAt;
49-
}
50-
51-
/**
52-
* @return int
53-
*/
54-
public function getMaxResults()
55-
{
56-
return $this->maxResults;
57-
}
58-
59-
/**
60-
* @param int $maxResults
61-
*/
62-
public function setMaxResults($maxResults)
63-
{
64-
$this->maxResults = $maxResults;
65-
}
66-
67-
/**
68-
* @return int
21+
* @return string
6922
*/
70-
public function getTotal()
23+
public function getNextPageToken()
7124
{
72-
return $this->total;
25+
return $this->nextPageToken;
7326
}
7427

7528
/**
76-
* @param int $total
29+
* @param string $nextPageToken
7730
*/
78-
public function setTotal($total)
31+
public function setNextPageToken($nextPageToken)
7932
{
80-
$this->total = $total;
33+
$this->nextPageToken = $nextPageToken;
8134
}
8235

8336
/**
@@ -105,20 +58,4 @@ public function getIssue($ndx)
10558
{
10659
return $this->issues[$ndx];
10760
}
108-
109-
/**
110-
* @return string
111-
*/
112-
public function getExpand()
113-
{
114-
return $this->expand;
115-
}
116-
117-
/**
118-
* @param string $expand
119-
*/
120-
public function setExpand($expand)
121-
{
122-
$this->expand = $expand;
123-
}
12461
}

src/Issue/IssueService.php

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -481,34 +481,94 @@ public function transition(string|int $issueIdOrKey, Transition $transition): ?s
481481
* Search issues.
482482
*
483483
* @param string $jql
484-
* @param int $startAt
484+
* @param string $nextPageToken
485485
* @param int $maxResults
486486
* @param array $fields
487-
* @param array $expand
488-
* @param bool $validateQuery
487+
* @param string $expand
488+
* @param array $reconcileIssues
489489
*
490490
* @throws \JsonMapper_Exception
491491
* @throws JiraException
492492
*
493493
* @return IssueSearchResult
494494
*/
495-
public function search(string $jql, int $startAt = 0, int $maxResults = 15, array $fields = [], array $expand = [], bool $validateQuery = true): IssueSearchResult
495+
public function search(string $jql, string $nextPageToken = '', int $maxResults = 50, array $fields = [], string $expand = '', array $reconcileIssues = []): IssueSearchResult
496+
{
497+
$data = [
498+
'jql' => $jql,
499+
'maxResults' => $maxResults,
500+
'fields' => $fields,
501+
'expand' => $expand,
502+
'reconcileIssues' => $reconcileIssues,
503+
];
504+
505+
if ($nextPageToken) {
506+
$data['nextPageToken'] = $nextPageToken;
507+
}
508+
509+
$ret = $this->exec('search//jql', json_encode($data), 'POST');
510+
$json = json_decode($ret);
511+
512+
$result = $this->json_mapper->map(
513+
$json,
514+
new IssueSearchResult()
515+
);
516+
517+
return $result;
518+
}
519+
520+
/**
521+
* Search issues.
522+
*
523+
* @param string $jql
524+
*
525+
* @throws \JsonMapper_Exception
526+
* @throws JiraException
527+
*
528+
* @return string[] array of count
529+
*
530+
* @phpstan-return array<string>
531+
*/
532+
public function searchApproximateCount(string $jql): array
533+
{
534+
$data = json_encode([
535+
'jql' => $jql,
536+
]);
537+
538+
$ret = $this->exec('search//approximate-count', $data, 'POST');
539+
540+
return json_decode($ret, true);
541+
}
542+
543+
/**
544+
* Bulk fetch issues.
545+
*
546+
* @param array $issueIdsOrKeys
547+
* @param array $fields
548+
* @param array $expand
549+
* @param bool $fieldsByKeys
550+
*
551+
* @throws \JsonMapper_Exception
552+
* @throws JiraException
553+
*
554+
* @return IssueBulkResult
555+
*/
556+
public function bulkFetch(array $issueIdsOrKeys, array $fields = [], array $expand = [], bool $fieldsByKeys = false): IssueBulkResult
496557
{
497558
$data = json_encode([
498-
'jql' => $jql,
499-
'startAt' => $startAt,
500-
'maxResults' => $maxResults,
501-
'fields' => $fields,
502-
'expand' => $expand,
503-
'validateQuery' => $validateQuery,
559+
'issueIdsOrKeys' => $issueIdsOrKeys,
560+
'fields' => $fields,
561+
'expand' => $expand,
562+
'fieldsByKeys' => $fieldsByKeys,
504563
]);
505564

506-
$ret = $this->exec('search', $data, 'POST');
565+
$ret = $this->exec('issue//bulkfetch', $data, 'POST');
566+
507567
$json = json_decode($ret);
508568

509569
$result = $this->json_mapper->map(
510570
$json,
511-
new IssueSearchResult()
571+
new IssueBulkResult()
512572
);
513573

514574
return $result;

0 commit comments

Comments
 (0)