Clear cache of report, fix di.
parent
78c57e65c8
commit
7dfe2df78b
|
@ -6,6 +6,9 @@ tracking_service:
|
||||||
auth_token: '<value from youtrack hub>'
|
auth_token: '<value from youtrack hub>'
|
||||||
base_url: 'https://test.youtrack.com'
|
base_url: 'https://test.youtrack.com'
|
||||||
report_id: '<89-123>'
|
report_id: '<89-123>'
|
||||||
|
report:
|
||||||
|
# default report id for report command
|
||||||
|
default: '<83-541>'
|
||||||
export:
|
export:
|
||||||
template_path: '~/.config/rprt-cli/invoice-template.html'
|
template_path: '~/.config/rprt-cli/invoice-template.html'
|
||||||
output: '/tmp/[[YEAR]]-[[month]]-invoice.pdf'
|
output: '/tmp/[[YEAR]]-[[month]]-invoice.pdf'
|
||||||
|
|
|
@ -22,6 +22,11 @@ use RprtCli\Utils\TimeTrackingServices\YoutrackService;
|
||||||
# use Symfony\Component\Translation\Translator;
|
# use Symfony\Component\Translation\Translator;
|
||||||
#use Symfony\Component\Translation\Loader\PoFileLoader;
|
#use Symfony\Component\Translation\Loader\PoFileLoader;
|
||||||
|
|
||||||
|
// @TODO I could still use this d-i to have a plugin system.
|
||||||
|
// New plugins should have a dependencies.php in their folders
|
||||||
|
// and have dependencies defined there. Construct method
|
||||||
|
// should inject the right service.
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'config.file' => 'rprt.config.yml',
|
'config.file' => 'rprt.config.yml',
|
||||||
'config.path' => '~/.config/rprt-cli/',
|
'config.path' => '~/.config/rprt-cli/',
|
||||||
|
|
|
@ -9,7 +9,7 @@ use DI\ContainerBuilder;
|
||||||
require __DIR__ . '/vendor/autoload.php';
|
require __DIR__ . '/vendor/autoload.php';
|
||||||
|
|
||||||
$builder = new ContainerBuilder();
|
$builder = new ContainerBuilder();
|
||||||
$builder->addDefinitions('dependencies.php');
|
$builder->addDefinitions(__DIR__ . '/dependencies.php');
|
||||||
$container = $builder->build();
|
$container = $builder->build();
|
||||||
|
|
||||||
$application = new Application();
|
$application = new Application();
|
||||||
|
|
|
@ -70,10 +70,13 @@ class ReportCommand extends Command {
|
||||||
$this->trackingService->setReportId($report);
|
$this->trackingService->setReportId($report);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
elseif ($report = $this->config->get('tracking_service.youtrack.report.default')) {
|
||||||
|
$this->trackingService->setReportId($report);
|
||||||
|
}
|
||||||
// Currently we only support csv download.
|
// Currently we only support csv download.
|
||||||
$report_id = $this->trackingService->getReportId();
|
$report_id = $this->trackingService->getReportId();
|
||||||
$report_name = $reports[$report_id];
|
$report_name = $reports[$report_id];
|
||||||
|
$this->trackingService->clearReportCache($report_id);
|
||||||
$file = $this->trackingService->downloadReport($report_id);
|
$file = $this->trackingService->downloadReport($report_id);
|
||||||
// var_dump($file);
|
// var_dump($file);
|
||||||
$output->writeln("report: <info>{$report_name}</info>");
|
$output->writeln("report: <info>{$report_name}</info>");
|
||||||
|
|
|
@ -175,6 +175,9 @@ class ReportCsv implements ReportCsvInterface
|
||||||
public function generateReportTable(string $filePath) {
|
public function generateReportTable(string $filePath) {
|
||||||
// ticket-id, ticket-name, time-spent
|
// ticket-id, ticket-name, time-spent
|
||||||
$data = $this->parseReportData($filePath);
|
$data = $this->parseReportData($filePath);
|
||||||
|
if (empty($data)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
[$previous, $time_sum, $project_time, $table, $all_projects] = [$data[0]['id'], 0, 0, [], []];
|
[$previous, $time_sum, $project_time, $table, $all_projects] = [$data[0]['id'], 0, 0, [], []];
|
||||||
foreach ($data as $line) {
|
foreach ($data as $line) {
|
||||||
$project = explode('-', $line['id'])[0];
|
$project = explode('-', $line['id'])[0];
|
||||||
|
|
|
@ -54,17 +54,21 @@ class YoutrackService implements YoutrackInterface
|
||||||
|
|
||||||
protected function requestYoutrackPath(string $path, array $query) {
|
protected function requestYoutrackPath(string $path, array $query) {
|
||||||
$yt_url = $this->getYtUrl($path);
|
$yt_url = $this->getYtUrl($path);
|
||||||
$yt_token = $this->getYtToken();
|
$headers = $this->getHeaders();
|
||||||
$headers = [
|
|
||||||
"Authorization" => "Bearer $yt_token",
|
|
||||||
'Cache-Control' => 'no-cache',
|
|
||||||
];
|
|
||||||
return $this->httpClient->request('GET', $yt_url, [
|
return $this->httpClient->request('GET', $yt_url, [
|
||||||
'query' => $query,
|
'query' => $query,
|
||||||
'headers' => $headers
|
'headers' => $headers
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getHeaders() {
|
||||||
|
$yt_token = $this->getYtToken();
|
||||||
|
return [
|
||||||
|
"Authorization" => "Bearer $yt_token",
|
||||||
|
'Cache-Control' => 'no-cache',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function getReportId(): ?string
|
public function getReportId(): ?string
|
||||||
{
|
{
|
||||||
// --report option value should take precedence.
|
// --report option value should take precedence.
|
||||||
|
@ -157,4 +161,31 @@ class YoutrackService implements YoutrackInterface
|
||||||
);
|
);
|
||||||
return $reports;
|
return $reports;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function clearReportCache(string $report_id) :void {
|
||||||
|
$path = "/youtrack/api/reports/${report_id}/status";
|
||||||
|
$query = [
|
||||||
|
'$top' => -1,
|
||||||
|
'fields' => 'calculationInProgress,error(id),errorMessage,isOutdated,lastCalculated,progress,wikifiedErrorMessage'
|
||||||
|
];
|
||||||
|
$post = [
|
||||||
|
'lastCalculated' => floor(microtime(true) * 1000),
|
||||||
|
'calculationInProgress' => true,
|
||||||
|
'wikifiedErrorMessage' => '',
|
||||||
|
'isOutdated' => false,
|
||||||
|
'progress' => -1,
|
||||||
|
'error' => null,
|
||||||
|
'errorMessage' => null,
|
||||||
|
'$type' => 'ReportStatus'
|
||||||
|
];
|
||||||
|
$yt_url = $this->getYtUrl($path);
|
||||||
|
$response = $this->httpClient->request('POST', $yt_url, [
|
||||||
|
'query' => $query,
|
||||||
|
'headers' => $this->getHeaders(),
|
||||||
|
'json' => $post,
|
||||||
|
]);
|
||||||
|
$body = (string) $response->getBody()->getContents();
|
||||||
|
// var_dump($body);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue