如何获得 Jira 上每个项目的发布版本?
How can I get a released version for every project on Jira?
我正在使用 Symfony 2.8 (PHP),我想通过 API Rest Jira 获取 Jira 上每个项目的所有版本,然后过滤主题以便select 仅发布版本。
我找到了这个方法,但我不知道如何使用 'expand' 参数来达到版本
第一步:在 config.yml
有关 Guzzle 配置的更多信息:http://docs.guzzlephp.org/en/latest/quickstart.html
csa_guzzle:
clients:
jira:
config:
base_uri: "https://jira.*****.*****.***/rest/api/2/"
timeout: 20.0
headers:
Accept: "application/json"
Content-Type: "application/json"
verify: false
auth: ['api','password','Basic']
第二步:创建一个 GuzzleHttp 客户端服务,用于向 api
发送请求
<?php
namespace AppBundle\Service\Atlassian\Jira\Client;
use GuzzleHttp\Client as GuzzleClientHttp;
use GuzzleHttp\Exception\ServerException;
use Psr\Http\Message\ResponseInterface;
class GuzzleClient
{
/**
* Guzzle Client.
*
* @var GuzzleClientHttp
*/
protected $guzzle;
/**
* Response object of request.
*
* @var ResponseInterface
*/
protected $response;
/**
* GuzzleClient constructor.
*
* @param GuzzleClientHttp $guzzle
*/
public function __construct(GuzzleClientHttp $guzzle)
{
$this->guzzle = $guzzle ?: new GuzzleClientHttp();
}
public function send($method = 'GET', $url, $parameters = [])
{
try {
$this->response = $this->guzzle->request($method, $url, ['query' => $parameters]);
} catch (ServerException $exception) {
$this->response = $exception->getResponse();
}
return $this->getContents();
}
/**
* Return the contents as a string of last request.
*
* @return string
*/
public function getContents()
{
return $this->response->getBody()->getContents();
}
/**
* Getter for GuzzleClient.
*
* @return GuzzleClientHttp
*/
public function getClient()
{
return $this->guzzle;
}
/**
* Getter for last Response.
*
* @return ResponseInterface
*/
public function getResponse()
{
return $this->response;
}
第 3 步:创建用于获取所有版本的服务
<?php
namespace AppBundle\Service\Atlassian\Jira;
use AppBundle\Service\Atlassian\Jira\Client\GuzzleClient;
class ApiService
{
/**
* Client HTTP.
*
* @var GuzzleClient
*/
protected $client;
/**
* ApiService constructor.
*
* @param GuzzleClient $client
*/
public function __construct(GuzzleClient $client)
{
$this->client = $client;
}
/**
* Get all released versions for a given projectKey.
*
* @param string $projectKey
* @return null|array
*/
public function getVersions($projectKey)
{
$versions = json_decode($this->client->send('GET', 'project/'.$projectKey."/versions/"));
for($i=0;$i< count($versions); $i++)
{
if($versions[$i]->released== false)
{
$result = $versions[$i]->name;
}
}
return $versions;
}
}
我正在使用 Symfony 2.8 (PHP),我想通过 API Rest Jira 获取 Jira 上每个项目的所有版本,然后过滤主题以便select 仅发布版本。
我找到了这个方法,但我不知道如何使用 'expand' 参数来达到版本
第一步:在 config.yml
有关 Guzzle 配置的更多信息:http://docs.guzzlephp.org/en/latest/quickstart.html
csa_guzzle:
clients:
jira:
config:
base_uri: "https://jira.*****.*****.***/rest/api/2/"
timeout: 20.0
headers:
Accept: "application/json"
Content-Type: "application/json"
verify: false
auth: ['api','password','Basic']
第二步:创建一个 GuzzleHttp 客户端服务,用于向 api
发送请求<?php
namespace AppBundle\Service\Atlassian\Jira\Client;
use GuzzleHttp\Client as GuzzleClientHttp;
use GuzzleHttp\Exception\ServerException;
use Psr\Http\Message\ResponseInterface;
class GuzzleClient
{
/**
* Guzzle Client.
*
* @var GuzzleClientHttp
*/
protected $guzzle;
/**
* Response object of request.
*
* @var ResponseInterface
*/
protected $response;
/**
* GuzzleClient constructor.
*
* @param GuzzleClientHttp $guzzle
*/
public function __construct(GuzzleClientHttp $guzzle)
{
$this->guzzle = $guzzle ?: new GuzzleClientHttp();
}
public function send($method = 'GET', $url, $parameters = [])
{
try {
$this->response = $this->guzzle->request($method, $url, ['query' => $parameters]);
} catch (ServerException $exception) {
$this->response = $exception->getResponse();
}
return $this->getContents();
}
/**
* Return the contents as a string of last request.
*
* @return string
*/
public function getContents()
{
return $this->response->getBody()->getContents();
}
/**
* Getter for GuzzleClient.
*
* @return GuzzleClientHttp
*/
public function getClient()
{
return $this->guzzle;
}
/**
* Getter for last Response.
*
* @return ResponseInterface
*/
public function getResponse()
{
return $this->response;
}
第 3 步:创建用于获取所有版本的服务
<?php
namespace AppBundle\Service\Atlassian\Jira;
use AppBundle\Service\Atlassian\Jira\Client\GuzzleClient;
class ApiService
{
/**
* Client HTTP.
*
* @var GuzzleClient
*/
protected $client;
/**
* ApiService constructor.
*
* @param GuzzleClient $client
*/
public function __construct(GuzzleClient $client)
{
$this->client = $client;
}
/**
* Get all released versions for a given projectKey.
*
* @param string $projectKey
* @return null|array
*/
public function getVersions($projectKey)
{
$versions = json_decode($this->client->send('GET', 'project/'.$projectKey."/versions/"));
for($i=0;$i< count($versions); $i++)
{
if($versions[$i]->released== false)
{
$result = $versions[$i]->name;
}
}
return $versions;
}
}