Skip to content

Commit

Permalink
get project version field.
Browse files Browse the repository at this point in the history
  • Loading branch information
lesstif authored and KwangSeob Jeong committed Nov 8, 2017
1 parent 135d6cf commit 7a406c7
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 14 deletions.
64 changes: 63 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ $iss = new IssueService(new ArrayConfiguration(
- [Get Project Info](#get-project-info)
- [Get All Project list](#get-all-project-list)
- [Get Project Type](#get-project-type)
- [Get Project Version](#get-project-version)

### Custom Field
- [Get All Field list](#get-all-field-list)
Expand Down Expand Up @@ -208,6 +209,66 @@ try {

```

#### Get Project Version

get all project's versions.

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

use JiraRestApi\Project\ProjectService;
use JiraRestApi\Issue\Version;
use JiraRestApi\JiraException;

try {
$proj = new ProjectService();

$vers = $proj->getVersions('TEST');

foreach ($vers as $v) {
// $v is JiraRestApi\Issue\Version
var_dump($v);
}
} catch (JiraException $e) {
print("Error Occured! " . $e->getMessage());
}

```

or get pagenated project's versions.

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

use JiraRestApi\Project\ProjectService;
use JiraRestApi\Issue\Version;
use JiraRestApi\JiraException;

try {
$param = [
'startAt' => 0,
'maxResults' => 10,
'orderBy' => 'name',
//'expand' => null,
];

$proj = new ProjectService();

$vers = $proj->getVersionsPagenated('TEST', $param);

foreach ($vers as $v) {
// $v is JiraRestApi\Issue\Version
var_dump($v);
}
} catch (JiraException $e) {
print("Error Occured! " . $e->getMessage());
}

```


#### Get All Field List

```php
Expand Down Expand Up @@ -1087,4 +1148,5 @@ Apache V2 License

# JIRA Rest API Documents
* 6.4 - https://docs.atlassian.com/jira/REST/6.4/
* latest - https://docs.atlassian.com/jira/REST/latest/
* Jira Server latest - https://docs.atlassian.com/jira/REST/server/
* Jira Cloud latest - https://docs.atlassian.com/jira/REST/latest/
8 changes: 1 addition & 7 deletions src/Issue/IssueService.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@ public function get($issueIdOrKey, $paramArray = [], $issueObject = null)
{
$issueObject = ($issueObject) ? $issueObject : new Issue();

$queryParam = '?';

foreach ($paramArray as $key => $value) {
$queryParam .= $key.'='.implode(',', $value).'&';
}

$ret = $this->exec($this->uri.'/'.$issueIdOrKey.$queryParam, null);
$ret = $this->exec($this->uri.'/'.$issueIdOrKey.$this->toHttpQueryParameter($paramArray), null);

$this->log->addInfo("Result=\n".$ret);

Expand Down
21 changes: 15 additions & 6 deletions src/Issue/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,30 @@ class Version implements \JsonSerializable
/* @var string */
public $id;

/* @var string|null */
public $description;

/* @var string */
/* @var string Version name: ex: 4.2.3 */
public $name;

/* @var bool */
/* @var string|null version description: ex; improvement performance */
public $description;

/* @var bool */
public $archived;

/* @var bool */
public $released;

/* @var DateTime */
/* @var DateTime|null */
public $releaseDate;

/* @var bool */
public $overdue;

/* @var string|null */
public $userReleaseDate;

/* @var int */
public $projectId;

public function __construct($name = null)
{
$this->name = $name;
Expand Down
26 changes: 26 additions & 0 deletions src/JiraClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,4 +433,30 @@ public function setAPIUri($api_uri)
{
$this->api_uri = $api_uri;
}

/**
* convert to query array to http query parameter
* @param $paramArray
*
* @return string
*/
public function toHttpQueryParameter($paramArray)
{
$queryParam = '?';

foreach ($paramArray as $key => $value) {
$v = null;

// some param field(Ex: expand) type is array.
if (is_array($value)) {
$v = implode(',', $value);
} else {
$v = $value;
}

$queryParam .= $key.'='.$v.'&';
}

return $queryParam;
}
}
55 changes: 55 additions & 0 deletions src/Project/ProjectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,59 @@ public function getAccessibleProjectType($key)

return $type;
}

/**
* get pagenated Project versions
*
* @param $projectIdOrKey
* @param array $queryParam
*
* @return mixed array of version
*/
public function getVersionsPagenated($projectIdOrKey, $queryParam = [])
{
$default = [
'startAt' => 0,
'maxResults' => 50,
// order by following field: sequence, name, startDate, releaseDate
//'orderBy' => null,
//'expand' => null,
];

$param = $this->toHttpQueryParameter(
array_merge($default, $queryParam)
);

$ret = $this->exec($this->uri."/$projectIdOrKey/version".$param);

$this->log->addInfo('Result='.$ret);

//@see https://docs.atlassian.com/jira/REST/server/#api/2/project-getProjectVersions
$json = json_decode($ret);

$prjs = $this->json_mapper->mapArray(
$json->values, new \ArrayObject(), '\JiraRestApi\Issue\Version'
);

return $prjs;
}

/**
* get specified's project versions
*
* @param $projectIdOrKey
* @return mixed array of version
*/
public function getVersions($projectIdOrKey)
{
$ret = $this->exec($this->uri."/$projectIdOrKey/versions");

$this->log->addInfo('Result='.$ret);

$prjs = $this->json_mapper->mapArray(
json_decode($ret, false), new \ArrayObject(), '\JiraRestApi\Issue\Version'
);

return $prjs;
}
}
9 changes: 9 additions & 0 deletions tests/ProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,13 @@ public function testGetProjectAccessibleException()

$prjtyp = $proj->getAccessibleProjectType('foobar');
}

public function testGetProjectVersion()
{
$proj = new ProjectService();

$prjs = $proj->getVersions('TEST');

var_dump($prjs);
}
}

0 comments on commit 7a406c7

Please sign in to comment.