* epicName added

This commit is contained in:
Dávid Danyi 2018-07-19 16:14:44 +02:00
parent 41b8f0048c
commit 4d5b26642e
2 changed files with 80 additions and 0 deletions

View File

@ -130,6 +130,12 @@ class KanbanEntry implements \JsonSerializable
*/
private $taurusPrio = 9001;
/**
* JIRA: customfield_10004 in task in customfield_10001 of parent
* @var string
*/
private $epicName;
/**
* @var int
*/
@ -598,6 +604,24 @@ class KanbanEntry implements \JsonSerializable
return $this;
}
/**
* @return string
*/
public function getEpicName(): ?string
{
return $this->epicName;
}
/**
* @param string $epicName
* @return KanbanEntry
*/
public function setEpicName(?string $epicName): KanbanEntry
{
$this->epicName = $epicName;
return $this;
}
/**
* @return int
*/
@ -662,6 +686,7 @@ class KanbanEntry implements \JsonSerializable
'key' => $this->getKey(),
'summary' => $this->getSummary(),
'issueType' => $this->getIssueType(),
'epicName' => $this->getEpicName(),
'status' => $this->getStatus(),
'assignee' => $this->getAssignee(),
'additionalAssignees' => $this->getAdditionalAssignees()->getValues(),

View File

@ -31,6 +31,9 @@ class JiraCollectorService
/** @var RouterInterface */
private $router;
/** @var array */
private $cachedEpics = [];
/**
* JiraClientService constructor.
* @param StorageInterface $cache
@ -125,6 +128,51 @@ class JiraCollectorService
return $kanbanBoard;
}
/**
* @param string $parentKey
* @return null|string
*/
private function getEpicNameFromParent(string $parentKey): ?string
{
if(array_key_exists($parentKey, $this->cachedEpics)) {
return $this->cachedEpics[$parentKey];
}
$user = $this->config->get('jira.user');
$password = $this->config->get('jira.password');
/** @var Config $kanbanBoardUriParams */
$jiraIssueBaseUrl = $this->config->get('url.jiraIssue');
$jiraIssueUri = sprintf($jiraIssueBaseUrl, $parentKey);
$response = $this->httpClient
->setUri($jiraIssueUri)
->setAuth($user, $password)
->send();
if (!$response->isSuccess()) {
throw new \UnexpectedValueException("Bad JIRA result", $response->getStatusCode());
}
$parsedJsonParentData = Decoder::decode($response->getBody(), Json::TYPE_ARRAY);
if ($parsedJsonParentData['fields']['customfield_10001']) {
$jiraIssueUri = sprintf($jiraIssueBaseUrl, $parsedJsonParentData['fields']['customfield_10001']);
$response = $this->httpClient
->setUri($jiraIssueUri)
->setAuth($user, $password)
->send();
if (!$response->isSuccess()) {
throw new \UnexpectedValueException("Bad JIRA result", $response->getStatusCode());
}
$parsedJsonEpicData = Decoder::decode($response->getBody(), Json::TYPE_ARRAY);
$this->cachedEpics[$parentKey] = $parsedJsonEpicData['fields']['customfield_10004'];
return $this->cachedEpics[$parentKey];
}
$this->cachedEpics[$parentKey] = null;
return null;
}
/**
* @param $parsedJsonData
* @return KanbanBoard
@ -135,6 +183,7 @@ class JiraCollectorService
$kanbanBoard = new KanbanBoard();
foreach ($parsedJsonData['issues'] as $jsonIssue) {
set_time_limit(30);
$kanbanEntry = new KanbanEntry();
$kanbanEntry->setId(intval($jsonIssue['id']))
->setKey($jsonIssue['key'])
@ -180,6 +229,12 @@ class JiraCollectorService
}
}
// epicName: has parent, and parent has customfield_10001
if (isset($jsonIssue['fields']['parent'])) {
$epicName = $this->getEpicNameFromParent($jsonIssue['fields']['parent']['key']);
$kanbanEntry->setEpicName($epicName);
}
// externalId : customfield_10010
if (isset($jsonIssue['fields']['customfield_10010'])) {
$kanbanEntry->setExternalId($jsonIssue['fields']['customfield_10010']);