Clear cache of report, fix di.

master
Lio Novelli 2022-05-14 22:08:54 +02:00
parent 78c57e65c8
commit 7dfe2df78b
6 changed files with 52 additions and 7 deletions

View File

@ -6,6 +6,9 @@ tracking_service:
auth_token: '<value from youtrack hub>'
base_url: 'https://test.youtrack.com'
report_id: '<89-123>'
report:
# default report id for report command
default: '<83-541>'
export:
template_path: '~/.config/rprt-cli/invoice-template.html'
output: '/tmp/[[YEAR]]-[[month]]-invoice.pdf'

View File

@ -22,6 +22,11 @@ use RprtCli\Utils\TimeTrackingServices\YoutrackService;
# use Symfony\Component\Translation\Translator;
#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 [
'config.file' => 'rprt.config.yml',
'config.path' => '~/.config/rprt-cli/',

View File

@ -9,7 +9,7 @@ use DI\ContainerBuilder;
require __DIR__ . '/vendor/autoload.php';
$builder = new ContainerBuilder();
$builder->addDefinitions('dependencies.php');
$builder->addDefinitions(__DIR__ . '/dependencies.php');
$container = $builder->build();
$application = new Application();

View File

@ -70,10 +70,13 @@ class ReportCommand extends Command {
$this->trackingService->setReportId($report);
}
}
elseif ($report = $this->config->get('tracking_service.youtrack.report.default')) {
$this->trackingService->setReportId($report);
}
// Currently we only support csv download.
$report_id = $this->trackingService->getReportId();
$report_name = $reports[$report_id];
$this->trackingService->clearReportCache($report_id);
$file = $this->trackingService->downloadReport($report_id);
// var_dump($file);
$output->writeln("report: <info>{$report_name}</info>");

View File

@ -175,6 +175,9 @@ class ReportCsv implements ReportCsvInterface
public function generateReportTable(string $filePath) {
// ticket-id, ticket-name, time-spent
$data = $this->parseReportData($filePath);
if (empty($data)) {
return [];
}
[$previous, $time_sum, $project_time, $table, $all_projects] = [$data[0]['id'], 0, 0, [], []];
foreach ($data as $line) {
$project = explode('-', $line['id'])[0];

View File

@ -54,17 +54,21 @@ class YoutrackService implements YoutrackInterface
protected function requestYoutrackPath(string $path, array $query) {
$yt_url = $this->getYtUrl($path);
$yt_token = $this->getYtToken();
$headers = [
"Authorization" => "Bearer $yt_token",
'Cache-Control' => 'no-cache',
];
$headers = $this->getHeaders();
return $this->httpClient->request('GET', $yt_url, [
'query' => $query,
'headers' => $headers
]);
}
protected function getHeaders() {
$yt_token = $this->getYtToken();
return [
"Authorization" => "Bearer $yt_token",
'Cache-Control' => 'no-cache',
];
}
public function getReportId(): ?string
{
// --report option value should take precedence.
@ -157,4 +161,31 @@ class YoutrackService implements YoutrackInterface
);
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);
}
}