Skip to content

Commit

Permalink
Merge pull request #75 from keboola/adamvyborny-CM-399-error-500-in-d…
Browse files Browse the repository at this point in the history
…bt-docs-action

Error 500 in dbt docs action
  • Loading branch information
AdamVyborny authored Jan 10, 2023
2 parents 0385e18 + 80caac9 commit 8710a3d
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ protected function getSyncActions(): array

/**
* @return array<string, string>
* @throws \Keboola\Component\UserException
*/
protected function actionDbtDocs(): array
{
Expand All @@ -194,6 +195,7 @@ protected function actionDbtDocs(): array
$branchId = $this->getConfig()->getBranchId();

$this->artifacts->downloadLastRun($componentId, $configId, $branchId);
$this->artifacts->checkIfCorrectStepIsDownloaded(DbtService::COMMAND_DOCS_GENERATE);

$html = $this->artifacts->readFromFile(DbtService::COMMAND_DOCS_GENERATE, 'index.html');
$manifest = $this->artifacts->readFromFile(DbtService::COMMAND_DOCS_GENERATE, 'manifest.json');
Expand Down
21 changes: 21 additions & 0 deletions src/Service/ArtifactsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public function writeResults(string $projectPath, string $step): void
$this->filesystem->mirror(sprintf('%s/target/', $projectPath), $artifactsPath);
}

/**
* @throws \Keboola\Component\UserException
*/
public function downloadLastRun(string $componentId, string $configId, string $branchId): ?int
{
$query = sprintf(
Expand Down Expand Up @@ -86,9 +89,15 @@ public function downloadLastRun(string $componentId, string $configId, string $b
return $file['id'];
}

/**
* @throws \Keboola\Component\UserException
*/
public function readFromFile(string $step, string $filePath): string
{
$file = new SplFileInfo(sprintf('%s/%s/%s', $this->getDownloadDir(), $step, $filePath));
if (!$file->isFile()) {
throw new UserException(sprintf('Missing "%s" file in downloaded artifact', $filePath));
}
return (string) file_get_contents($file->getPathname());
}

Expand All @@ -111,4 +120,16 @@ private function mkdir(string $path): void
$this->filesystem->mkdir($path);
}
}

/**
* @throws \Keboola\Component\UserException
*/
public function checkIfCorrectStepIsDownloaded(string $step): void
{
$docsPath = sprintf('%s/%s', $this->getDownloadDir(), $step);
if (!$this->filesystem->exists($docsPath)) {
throw new UserException('No artifact from previous dbt docs generate found. ' .
'Run the component first with dbt docs generate command enabled.');
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Missing "index.html" file in downloaded artifact
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"componentId": "keboola.dbt-transformation",
"action": "dbtDocs",
"parameters": {
"configId": "12345"
}
}

0 comments on commit 8710a3d

Please sign in to comment.