Skip to content

Issue #91: update search() to work with search/jql #97

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
82 changes: 82 additions & 0 deletions src/Issue/IssueBulkResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace JiraCloud\Issue;

/**
* Issue search result.
*/
class IssueBulkResult
{
/**
* @var string
*/
public $expand;

/**
* @var \JiraCloud\Issue\Issue[]
*/
public $issues;

/**
* @var array
*/
public $issueErrors;

/**
* @return array
*/
public function getIssueErrors()
{
return $this->issueErrors;
}

/**
* @param array $issueErrors
*/
public function setIssueErrors($issueErrors)
{
$this->issueErrors = $issueErrors;
}

/**
* @return Issue[]
*/
public function getIssues()
{
return $this->issues;
}

/**
* @param Issue[] $issues
*/
public function setIssues($issues)
{
$this->issues = $issues;
}

/**
* @param int $ndx
*
* @return Issue
*/
public function getIssue($ndx)
{
return $this->issues[$ndx];
}

/**
* @return string
*/
public function getExpand()
{
return $this->expand;
}

/**
* @param string $expand
*/
public function setExpand($expand)
{
$this->expand = $expand;
}
}
77 changes: 7 additions & 70 deletions src/Issue/IssueSearchResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,74 +10,27 @@ class IssueSearchResult
/**
* @var string
*/
public $expand;

/**
* @var int
*/
public $startAt;

/**
* @var int
*/
public $maxResults;

/**
* @var int
*/
public $total;
public $nextPageToken;

/**
* @var \JiraCloud\Issue\Issue[]
*/
public $issues;

/**
* @return int
*/
public function getStartAt()
{
return $this->startAt;
}

/**
* @param int $startAt
*/
public function setStartAt($startAt)
{
$this->startAt = $startAt;
}

/**
* @return int
*/
public function getMaxResults()
{
return $this->maxResults;
}

/**
* @param int $maxResults
*/
public function setMaxResults($maxResults)
{
$this->maxResults = $maxResults;
}

/**
* @return int
* @return string
*/
public function getTotal()
public function getNextPageToken()
{
return $this->total;
return $this->nextPageToken;
}

/**
* @param int $total
* @param string $nextPageToken
*/
public function setTotal($total)
public function setNextPageToken($nextPageToken)
{
$this->total = $total;
$this->nextPageToken = $nextPageToken;
}

/**
Expand Down Expand Up @@ -105,20 +58,4 @@ public function getIssue($ndx)
{
return $this->issues[$ndx];
}

/**
* @return string
*/
public function getExpand()
{
return $this->expand;
}

/**
* @param string $expand
*/
public function setExpand($expand)
{
$this->expand = $expand;
}
}
84 changes: 72 additions & 12 deletions src/Issue/IssueService.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,34 +481,94 @@ public function transition(string|int $issueIdOrKey, Transition $transition): ?s
* Search issues.
*
* @param string $jql
* @param int $startAt
* @param string $nextPageToken
* @param int $maxResults
* @param array $fields
* @param array $expand
* @param bool $validateQuery
* @param string $expand
* @param array $reconcileIssues
*
* @throws \JsonMapper_Exception
* @throws JiraException
*
* @return IssueSearchResult
*/
public function search(string $jql, int $startAt = 0, int $maxResults = 15, array $fields = [], array $expand = [], bool $validateQuery = true): IssueSearchResult
public function search(string $jql, string $nextPageToken = '', int $maxResults = 50, array $fields = [], string $expand = '', array $reconcileIssues = []): IssueSearchResult
{
$data = [
'jql' => $jql,
'maxResults' => $maxResults,
'fields' => $fields,
'expand' => $expand,
'reconcileIssues' => $reconcileIssues,
];

if ($nextPageToken) {
$data['nextPageToken'] = $nextPageToken;
}

$ret = $this->exec('search//jql', json_encode($data), 'POST');
$json = json_decode($ret);

$result = $this->json_mapper->map(
$json,
new IssueSearchResult()
);

return $result;
}

/**
* Search issues.
*
* @param string $jql
*
* @throws \JsonMapper_Exception
* @throws JiraException
*
* @return string[] array of count
*
* @phpstan-return array<string>
*/
public function searchApproximateCount(string $jql): array
{
$data = json_encode([
'jql' => $jql,
]);

$ret = $this->exec('search//approximate-count', $data, 'POST');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

propal : search/approximate-count

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RomainMILLAN it's got a double slash because single slash gets stripped out. I'm not sure why but decided to just work around it.


return json_decode($ret, true);
}

/**
* Bulk fetch issues.
*
* @param array $issueIdsOrKeys
* @param array $fields
* @param array $expand
* @param bool $fieldsByKeys
*
* @throws \JsonMapper_Exception
* @throws JiraException
*
* @return IssueBulkResult
*/
public function bulkFetch(array $issueIdsOrKeys, array $fields = [], array $expand = [], bool $fieldsByKeys = false): IssueBulkResult
{
$data = json_encode([
'jql' => $jql,
'startAt' => $startAt,
'maxResults' => $maxResults,
'fields' => $fields,
'expand' => $expand,
'validateQuery' => $validateQuery,
'issueIdsOrKeys' => $issueIdsOrKeys,
'fields' => $fields,
'expand' => $expand,
'fieldsByKeys' => $fieldsByKeys,
]);

$ret = $this->exec('search', $data, 'POST');
$ret = $this->exec('issue//bulkfetch', $data, 'POST');

$json = json_decode($ret);

$result = $this->json_mapper->map(
$json,
new IssueSearchResult()
new IssueBulkResult()
);

return $result;
Expand Down