【问题标题】:How can I get a released version for every project on Jira?如何获得 Jira 上每个项目的发布版本?
【发布时间】:2016-09-06 22:49:50
【问题描述】:

我正在使用 Symfony 2.8 (PHP),我想通过 API Rest Jira 获取 Jira 上每个项目的所有版本,然后过滤主题以便仅选择已发布的版本。

我找到了这种方法,但我不知道如何使用 'expand' 参数来达到版本

Image 1

Image 2

【问题讨论】:

    标签: php rest symfony jira-rest-api


    【解决方案1】:

    第一步:在 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;
    }
    

    第三步:创建一个获取所有版本的服务

    <?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;
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-04
      • 1970-01-01
      • 1970-01-01
      • 2015-11-30
      • 1970-01-01
      • 2017-10-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多