Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get project name from dbt #1469

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/dbt_client/dbtCloudIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export class DBTCloudProjectIntegration
private static QUEUE_ALL = "all";
private targetPath?: string;
private version: number[] | undefined;
private projectName: string = "unknown_" + crypto.randomUUID();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Import the 'crypto' module

The crypto module is used but not imported. You need to import it to use crypto.randomUUID().

Apply this diff to fix the missing import:

+import * as crypto from 'crypto';

Committable suggestion was skipped due to low confidence.

private adapterType: string = "unknown";
private packagesInstallPath?: string;
private modelPaths?: string[];
Expand Down Expand Up @@ -376,6 +377,10 @@ export class DBTCloudProjectIntegration
return this.version || [0, 0, 0];
}

getProjectName(): string {
return this.projectName;
}

getPythonBridgeStatus(): boolean {
return this.python.connected;
}
Expand Down Expand Up @@ -988,6 +993,15 @@ export class DBTCloudProjectIntegration
stderr,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please specify a return type for the lookupValue function to improve code readability and maintainability. This also applies to the lookupEntries function in the same file.

);
}
const lookupValue = (lookupString: string) => {
const regexString = `${lookupString}\\s*(.*)`;
const regexp = new RegExp(regexString, "gm");
const matches = regexp.exec(stdout);
if (matches?.length === 2) {
return matches[1];
}
throw new Error(`Could not find any entries for ${lookupString}`);
};
const lookupEntries = (lookupString: string) => {
const regexString = `${lookupString}\\s*\\[(.*)\\]`;
const regexp = new RegExp(regexString, "gm");
Expand All @@ -1007,6 +1021,7 @@ export class DBTCloudProjectIntegration
this.macroPaths = lookupEntries("Macro paths").map((p) =>
join(this.projectRoot.fsPath, p),
);
this.projectName = lookupValue("Project name");
this.packagesInstallPath = join(this.projectRoot.fsPath, "dbt_packages");
} catch (error) {
this.terminal.warn(
Expand Down
12 changes: 12 additions & 0 deletions src/dbt_client/dbtCoreIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ export class DBTCoreProjectIntegration
private adapterType?: string;
private targetName?: string;
private version?: number[];
private projectName: string = "unknown_" + crypto.randomUUID();
private packagesInstallPath?: string;
private modelPaths?: string[];
private seedPaths?: string[];
Expand Down Expand Up @@ -378,6 +379,7 @@ export class DBTCoreProjectIntegration
this.macroPaths = await this.findMacroPaths();
this.packagesInstallPath = await this.findPackagesInstallPath();
this.version = await this.findVersion();
this.projectName = await this.findProjectName();
this.adapterType = await this.findAdapterType();
}

Expand Down Expand Up @@ -560,6 +562,10 @@ export class DBTCoreProjectIntegration
return this.version;
}

getProjectName(): string {
return this.projectName;
}

async findAdapterType(): Promise<string | undefined> {
return this.python.lock<string>(
(python) => python`project.config.credentials.type`,
Expand Down Expand Up @@ -1060,6 +1066,12 @@ export class DBTCoreProjectIntegration
);
}

private async findProjectName(): Promise<string> {
return this.python?.lock<string>(
(python) => python!`to_dict(project.config.project_name)`,
);
}

private throwBridgeErrorIfAvailable() {
const allDiagnostics: DiagnosticCollection[] = [
this.pythonBridgeDiagnostics,
Expand Down
1 change: 1 addition & 0 deletions src/dbt_client/dbtIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ export interface DBTProjectIntegration extends Disposable {
getPackageInstallPath(): string | undefined;
getAdapterType(): string | undefined;
getVersion(): number[] | undefined;
getProjectName(): string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Missing getProjectName() Implementation in Implementing Classes

Several classes implementing DBTProjectIntegration do not include the newly added getProjectName() method. Please ensure that all implementing classes define this method to maintain the interface contract.

  • src/dbt_client/dbtCloudIntegration.ts
  • src/dbt_client/dbtCoreIntegration.ts
🔗 Analysis chain

LGTM! Verify implementations of DBTProjectIntegration.

The addition of the getProjectName(): string method to the DBTProjectIntegration interface is a good enhancement for standardizing project name retrieval across DBT integrations.

Ensure that all classes implementing DBTProjectIntegration are updated to include this new method. Run the following script to check for implementations:


getSelectedTarget(): string | undefined;
// parse manifest
rebuildManifest(): Promise<void>;
Expand Down
2 changes: 1 addition & 1 deletion src/manifest/dbtProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export class DBTProject implements Disposable {
}

public getProjectName() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please specify a return type for the getProjectName function to improve code readability and maintainability.

return this.projectConfig.name;
return this.dbtProjectIntegration.getProjectName();
}

getSelectedTarget() {
Expand Down