Skip to content

Instantly share code, notes, and snippets.

@JulienBreux
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JulienBreux/7cbece369afcb79e7505 to your computer and use it in GitHub Desktop.
Save JulienBreux/7cbece369afcb79e7505 to your computer and use it in GitHub Desktop.
Jira - Epics

How to install?

curl -O https://getcomposer.org/composer.phar
php composer.phar install

How to use?

php -S locahost:8888

How to display?

http://localhost:8888

{
"require": {
"guzzlehttp/guzzle": "~4.0"
}
}
<?php
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////// SETTINGS ////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
define('JIRA_USER', '');
define('JIRA_PASS', '');
define('JIRA_DOMAIN', '');
define('JIRA_PROJECT', '');
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////// DONT'T TOUCH //////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
define('ISSUES_QUERY', 'project = ' . JIRA_PROJECT . ' AND issuetype = Epic AND status != Closed');
define('URL_REST', 'https://' . JIRA_DOMAIN . '.atlassian.net/rest');
define('URL_ISSUES', URL_REST . '/api/2/search?jql=' . urlencode(ISSUES_QUERY));
define('URL_EPICS', URL_REST . '/greenhopper/1.0/xboard/plan/backlog/epics?&rapidViewId=4');
// Use (http://www.php.net/manual/fr/function.date.php)
define('DATE_FORMAT', 'd M Y');
require 'vendor/autoload.php';
try {
$client = new GuzzleHttp\Client();
$responseIssues = $client->get(URL_ISSUES, ['auth' => [JIRA_USER, JIRA_PASS]]);
$responseEpics = $client->get(URL_EPICS, ['auth' => [JIRA_USER, JIRA_PASS]]);
$issues = $responseIssues->json();
$epics = $responseEpics->json();
// Get due dates
$duedates = [];
foreach ($issues['issues'] as $issue) {
$duedates[$issue['key']] = $issue['fields']['duedate']
? new \DateTime($issue['fields']['duedate'])
: null;
}
// List epics
$epicsCollection = new \ArrayObject;
foreach ($epics['epics'] as $epic) {
// Display open issue
if ('Open' === $epic['status']['name']) {
// Useful values
$id = $epic['key'];
// Create epic object
$epicObject = new \stdClass;
// Map common values
$epicObject->id = $id;
$epicObject->name = $epic['epicLabel'];
$epicObject->dueDate = isset($duedates[$id]) ? $duedates[$id] : null;
$epicObject->viewableDueDate = isset($duedates[$id]) ? $duedates[$id]->format(DATE_FORMAT) : '?';
$epicObject->haveUnestimatedIssues = (bool)$epic['epicStats']['percentageUnestimated'];
// Map issues values
$epicObject->issues = new \stdClass;
$epicObject->issues->total = $epic['epicStats']['totalIssueCount'];
$epicObject->issues->percent = $epic['epicStats']['totalIssueCount']
? round(((float)$epic['epicStats']['done'] / (float)$epic['epicStats']['totalIssueCount']) * 100)
: 0;
$epicObject->issues->done = $epic['epicStats']['done'];
$epicObject->issues->notDone = $epic['epicStats']['notDone'];
// Map points values
$epicObject->points = new \stdClass;
$epicObject->points->total = $epic['epicStats']['totalEstimate'];
$epicObject->points->percent = $epic['epicStats']['percentageCompleted'];
$epicObject->points->done = $epic['epicStats']['doneEstimate'];
$epicObject->points->notDone = $epic['epicStats']['notDoneEstimate'];
// Add epic object to collection
$epicsCollection->append($epicObject);
// Clean memory
unset($epicObject);
}
}
} catch (Exception $e) {
exit('Unable to connect! (Auth?)' . PHP_EOL);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////// DISPLAY ////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
?>
<!DOCTYPE>
<html>
<head>
<meta charset="utf-8">
<title>Epics</title>
</head>
<body>
<?php foreach ($epicsCollection as $epic): ?>
<section>
<h2 title="<?= $epic->id; ?>"><?= $epic->name; ?></h2>
<p>
Due date: <?= $epic->viewableDueDate; ?>
<?php if ($epic->haveUnestimatedIssues): ?>
/!\
<?php endif; ?>
</p>
<p>
Points: <?= $epic->points->done; ?>/<?= $epic->points->total; ?> (<?= $epic->points->percent; ?>%)<br>
Issues: <?= $epic->issues->done; ?>/<?= $epic->issues->total; ?> (<?= $epic->issues->percent; ?>%)
</p>
</section>
<?php endforeach; ?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment