Skip to content

Add New Method for Returning Board List With Offset/Paginated Results #535

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
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
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2470,6 +2470,43 @@ try {
}

```

#### Get boards
[See Jira API reference](https://developer.atlassian.com/cloud/jira/software/rest/#api-rest-agile-1-0-board-get)

```php
<?php
require 'vendor/autoload.php';

use JiraRestApi\Board\BoardService;

try {
$results = [];
$startAt = 0;
$maxResults = 50; // maximum allowed for board queries

do {
$response = $this->boardService->getBoards([
'startAt' => $startAt,
'maxResults' => $maxResults
]);

$results = [...$results, ...$response->getBoards()];

$startAt += $maxResults;

} while($startAt < $response->total);

var_dump($results);

} catch (JiraRestApi\JiraException $e) {
print('Error Occured! ' . $e->getMessage());
}

```



#### Get board info
[See Jira API reference](https://developer.atlassian.com/cloud/jira/software/rest/#api-rest-agile-1-0-board-boardId-get)

Expand Down
47 changes: 47 additions & 0 deletions src/Board/BoardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,29 @@ public function getBoardList($paramArray = []): ?\ArrayObject
}
}

/**
* Get list of boards with paginated results.
*
* @param array $paramArray
*
* @return PaginatedResult|null array of Board class
*@throws \JiraRestApi\JiraException
*
*/
public function getBoards($paramArray = []): ?PaginatedResult
{
$json = $this->exec($this->uri.$this->toHttpQueryParameter($paramArray), null);
try {
return $this->json_mapper->map(
json_decode($json, false, 512, $this->getJsonOptions()),
new PaginatedResult()
);
} catch (\JsonException $exception) {
$this->log->error("Response cannot be decoded from json\nException: {$exception->getMessage()}");
return null;
}
}

public function getBoard($id, $paramArray = []): ?Board
{
$json = $this->exec($this->uri.'/'.$id.$this->toHttpQueryParameter($paramArray), null);
Expand Down Expand Up @@ -122,6 +145,30 @@ public function getBoardSprints($boardId, $paramArray = []): ?\ArrayObject
}
}

/**
* Get list of boards with paginated results.
*
* @param array $paramArray
*
* @throws \JiraRestApi\JiraException
*
* @return PaginatedResult|null array of Board class
*/
public function getSprintsForBoard($boardId, $paramArray = []): ?PaginatedResult
{
$json = $this->exec($this->uri.'/'.$boardId.'/sprint'.$this->toHttpQueryParameter($paramArray), null);

try {
return $this->json_mapper->map(
json_decode($json, false, 512, $this->getJsonOptions()),
new PaginatedResult()
);
} catch (\JsonException $exception) {
$this->log->error("Response cannot be decoded from json\nException: {$exception->getMessage()}");
return null;
}
}

/**
* @return \ArrayObject|Epic[]|null
*/
Expand Down
129 changes: 129 additions & 0 deletions src/Board/PaginatedResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?php

namespace JiraRestApi\Board;

/**
* Paginated Result object for BoardService
*/
class PaginatedResult
{
/**
* @var string
*/
public $expand;

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

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

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

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

/**
* @var bool
*/
public $isLast;

/**
* @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
*/
public function getTotal()
{
return $this->total;
}

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

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

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

/**
* @param int $index
*
* @return mixed
*/
public function getValue($index)
{
return $this->values[$index];
}

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

/**
* @param string $expand
*/
public function setExpand($expand)
{
$this->expand = $expand;
}
}
25 changes: 25 additions & 0 deletions tests/BoardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,31 @@ public function get_all_boards() : string
return $last_board_id;
}

/**
* @test
*
* Test we can obtain the paginated board list.
*/
public function get_boards() : string

Choose a reason for hiding this comment

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

Method name BoardTest::get_boards is not in camel caps format

Copy link
Contributor Author

@nickpoulos nickpoulos Jun 10, 2024

Choose a reason for hiding this comment

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

...but neither is any other method in the this test class?

Is it more important to keep consistency within the file or attempt to bring one new method in line with our new standards? Let me know and I can adjust accordingly. 👍

{
$board_service = new BoardService();

$board_list = $board_service->getBoards();
$this->assertInstanceOf(BoardResult::class, $board_list, 'We receive a board list.');

$last_board_id = null;
foreach ($board_list->getBoards() as $board) {
$this->assertInstanceOf(Board::class, $board, 'Each element of the list is a Board instance.');
$this->assertNotNull($board->self, 'self must not null');
$this->assertNotNull($board->name, 'name must not null');
$this->assertNotNull($board->type, 'type must not null');

$last_board_id = $board->id;
}

return $last_board_id;
}

/**
* @test
*
Expand Down