Skip to content

Commit

Permalink
Feature/new view (#1)
Browse files Browse the repository at this point in the history
* Collect ticket informations

* Show user issues

* Show user issues
  • Loading branch information
patriziotomato authored Jul 23, 2019
1 parent 199d66a commit 032a589
Showing 1 changed file with 79 additions and 9 deletions.
88 changes: 79 additions & 9 deletions src/Responses/Versions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@

use Carbon\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use JiraRestApi\Issue\IssueService;
use JiraRestApi\Issue\Version;
use Khill\Duration\Duration;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Use this class to filter through Versions fluently
Expand Down Expand Up @@ -97,26 +100,93 @@ public function notOverdue()
return $this;
}

public function withTicketInformation()
public function withTicketInformation(int $verbosityLevel = OutputInterface::VERBOSITY_NORMAL)
{
$issueService = new IssueService();

$this->filteredVersions->transform(function ($version) use ($issueService) {
$searchResult = $issueService->search(
'resolution = Unresolved AND fixVersion = ' . $version->id
);
$this->filteredVersions->transform(function ($version) use ($issueService, $verbosityLevel) {
$searchResult = $issueService->search('fixVersion = '.$version->id, 0, 500);

$version->remainingOpenIssues = $searchResult->total ?? 0;
if ($verbosityLevel >= OutputInterface::VERBOSITY_VERY_VERBOSE) {
if ($version->archived) {
Log::debug("- Skipping ticket informations for milestone {$version->name} #$version->id");

return $version;
}

Log::debug("- Updating milestone {$version->name} #$version->id");
}

//dd($searchResult);

$version->totalIssues = 0;
$version->remainingOpenIssues = 0;
$version->estimatedEffortInHours = 0;
$version->remainingEffortInHours = 0;
$version->issuesNotAssigned = 0;
$version->issuesNotEstimated = 0;

foreach ($searchResult->getIssues() as $issue) {
$hours = 0;
$version->totalIssues++;

$version->issuesNotAssigned += $issue->fields->assignee ? 0 : 1;
$version->issuesNotEstimated += $issue->fields->aggregatetimeoriginalestimate ? 0 : 1;

$hoursEstimated = 0;
if ($issue->fields->aggregatetimeoriginalestimate) {
$hours = $issue->fields->aggregatetimeoriginalestimate / 60 / 60;
$hoursEstimated = $issue->fields->aggregatetimeoriginalestimate / 60 / 60;
}
$version->remainingEffortInHours = round($version->remainingEffortInHours + $hours, 1);
$version->estimatedEffortInHours = round($version->estimatedEffortInHours + $hoursEstimated, 4);

if (!$issue->fields->resolutiondate) {

$version->remainingOpenIssues++;

$hoursLeft = 0;

if ($issue->fields->timeestimate) {
$hoursLeft = $issue->fields->timeestimate / 60 / 60;
}

$version->remainingEffortInHours = round($version->remainingEffortInHours + $hoursLeft, 4);
}

$version->issues[$issue->key] = [
'key' => $issue->key,
'reporter' => $issue->fields->reporter ? [
'name' => $issue->fields->reporter->name,
'display_name' => $issue->fields->reporter->displayName,
'avatar_url' => $issue->fields->reporter->avatarUrls['48x48'],
] : null,
'created' => $issue->fields->created ? Carbon::instance($issue->fields->created) : null,
'updated' => $issue->fields->updated ? Carbon::instance($issue->fields->updated) : null,
'description' => $issue->fields->description,
'priority' => $issue->fields->priority ? $issue->fields->priority->name : null,
'assignee' => $issue->fields->assignee ? [
'name' => $issue->fields->assignee->name,
'display_name' => $issue->fields->assignee->displayName,
'avatar_url' => $issue->fields->assignee->avatarUrls['48x48'],
] : null,
'duedate' => $issue->fields->duedate ? new Carbon($issue->fields->duedate) : null,
'resolutiondate' => $issue->fields->resolutiondate ? new Carbon($issue->fields->resolutiondate) : null,
'effort_estimated' => (int)$issue->fields->aggregatetimeoriginalestimate,
'effort_estimated_remaining' => (int)$issue->fields->timeestimate,
'effort_spent' => (int)$issue->fields->aggregatetimespent,
'effort_estimated_readable' => (new Duration((int)$issue->fields->aggregatetimeoriginalestimate,
8))->humanize(),
'effort_estimated_remaining_readable' => (new Duration((int)$issue->fields->timeestimate,
8))->humanize(),
'effort_spent_readable' => (new Duration((int)$issue->fields->aggregatetimespent,
8))->humanize(),
'lastViewed' => $issue->fields->lastViewed ? new Carbon($issue->fields->lastViewed->scalar) : null,
];
}

$version->estimatedEffortInHoursReadable = (new Duration((int)$version->estimatedEffortInHours * 60 * 60,
8))->humanize();
$version->remainingEffortInHoursReadable = (new Duration((int)$version->remainingEffortInHours * 60 * 60,
8))->humanize();

return $version;
});

Expand Down

0 comments on commit 032a589

Please sign in to comment.