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

feat: add command to run apply defer config #1612

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

grindheim
Copy link

@grindheim grindheim commented Mar 18, 2025

Overview

Problem

To simplify the user experience, we have set up a codespace configuration where the dbt.deferConfigPerProject is preconfigured, and we have a task that automatically downloads the manifest from project.

However, the user still needs manually go to Actions and toggle the "Enable defer to production" off and on again in order to activate the deferral with the downloaded manifest.

We'd like to be able set up the environment including deferral end to end without any user actions, and in order to do this, the dbt Power User extension needs to provide a command for applying defer config, much like what happens when toggling the button, so that this task can be triggered by us as soon as the updated manifest has been downloaded.

E.g.

        "dbt.deferConfigPerProject": {
          "": {
              "deferToProduction": true,
              "manifestPathForDeferral": "/workspaces/<rep>/state",
              "manifestPathType": "local",
              "favorState": false
          }

Solution

The suggested solution adds a new command to package.json, and also registers the command in src\commands\index.ts.

Current issues

As there were multiple applyDeferConfig functions configured in the project, I was unsure which one to use. I settled on one defined in DBTProject. However, the issue is here how to trigger this function.
The current implementation seems to not be able to fetch the current project, and can thus not run applyDeferConfig.
This seems to be the error message behind the scenes: NameError: name 'project' is not defined.

I'd appreciate some input on which changes I should implement to make it work as it should

Screenshot/Demo

A picture is worth a thousand words. Please highlight the changes if applicable.

How to test

  • Steps to be followed to verify the solution or code changes
  • Mention if there is any settings configuration added/changed/deleted

Checklist

  • I have run this code and it appears to resolve the stated issue
  • README.md updated and added information about my change

Important

Add dbtPowerUser.applyDeferConfig command to apply defer configuration automatically, but it currently fails due to project fetching issues.

  • Behavior:
    • Adds dbtPowerUser.applyDeferConfig command in package.json to apply defer configuration automatically.
    • Registers command in src/commands/index.ts to apply defer configuration to all projects using project.applyDeferConfig().
  • Issues:
    • Current implementation cannot fetch the current project, causing applyDeferConfig to fail with NameError: name 'project' is not defined.

This description was created by Ellipsis for cdb82e1. It will automatically update as commits are pushed.

Summary by CodeRabbit

  • New Features
    • Introduced a new command, "Apply defer configuration," which enables you to apply deferred configuration settings across multiple projects directly within the extension.
    • Enhanced error handling and success messaging for the new command to improve user experience.

Copy link
Contributor

coderabbitai bot commented Mar 18, 2025

Walkthrough

This pull request introduces a new command dbtPowerUser.applyDeferConfig to the extension. The command is defined in the package.json file and registered within the VSCodeCommands class in src/commands/index.ts. When invoked, the command retrieves the projects from the dbtProjectContainer and applies the deferred configuration concurrently across all projects using Promise.all. Error handling and success messaging are also included in the command implementation.

Changes

File(s) Change Summary
package.json
src/commands/index.ts
Added new command dbtPowerUser.applyDeferConfig. In package.json, the command is defined with its title and category. In index.ts, the command is registered, fetching projects from dbtProjectContainer and executing applyDeferConfig on each project concurrently.

Sequence Diagram(s)

sequenceDiagram
  participant U as User
  participant VS as VSCodeCommands
  participant DC as dbtProjectContainer
  participant P as Project

  U->>VS: Trigger command (dbtPowerUser.applyDeferConfig)
  VS->>DC: getProjects()
  DC-->>VS: [Project1, Project2, ...]
  par Concurrently Apply Defer Config
    VS->>P: applyDeferConfig()
    Note over P: Process deferred configuration
  end
  Note over VS: Await completion using Promise.all
Loading

Suggested reviewers

  • saravmajestic

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e0ba629 and d225bad.

📒 Files selected for processing (1)
  • package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@mdesmet
Copy link
Contributor

mdesmet commented Mar 19, 2025

You could try using a tool like Cursor or aider to try develop this feature.

@mdesmet
Copy link
Contributor

mdesmet commented Mar 20, 2025

Can you elaborate on this:

  • However, the user still needs manually go to Actions and toggle the "Enable defer to production" off and on again in order to activate the deferral with the downloaded manifest.

why is the config not enough?

@grindheim
Copy link
Author

Our issue is that when we set up the github codespace, we predefine the config relating to the defer.
However, the actual production manifest isn't yet available. We have a vs code task that triggers GCP authentication followed by the download of the latest production manifest.

Once this manifest has been downloaded, then I need to somehow tell dbt Power User that the manifest has been added/changed, since it doesn't seem to realize this on its own.

So that's why I need this command to be available, so that my task can simply trigger that command as soon as the manifest is added/updated.

@mdesmet
Copy link
Contributor

mdesmet commented Mar 20, 2025

Can you not add this logic to the run command of your docker container before invocation of vscode?

@grindheim
Copy link
Author

The download of the production manifest needs to be done following user authentication to GCP (using oauth), as it uses those credentials. And secondly, the user might have a long running codespace and would need to update the manifest from time to time.

But in any case, I don't see the downside of having this action available as a command.

@grindheim
Copy link
Author

grindheim commented Mar 20, 2025

Of course, the best thing would be if the extension simply always re-read the manifest at the given path, rather than storing it in cache somewhere, as it seems to be doing now. If we only had to update the file and could then be sure that the updated file would be used, then all would be splendid.

@grindheim grindheim marked this pull request as ready for review March 20, 2025 13:54
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

❌ Changes requested. Reviewed everything up to cdb82e1 in 3 minutes and 2 seconds

More details
  • Looked at 31 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 3 drafted comments based on config settings.
1. src/commands/index.ts:800
  • Draft comment:
    The new command callback uses 'await' but is not declared as async. Add the async keyword to the callback function.
  • Reason this comment was not posted:
    Marked as duplicate.
2. src/commands/index.ts:858
  • Draft comment:
    Typo: In the log message at line 858, change "File doesn't exists at location" to "File doesn't exist at location" for correct grammar.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
3. src/commands/index.ts:644
  • Draft comment:
    Consider capitalizing 'css' to 'CSS' in the string for consistency in the decoration options (line 644).
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.

Workflow ID: wflow_r9KOND5OTHazEdXv


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/commands/index.ts (1)

800-803: Consider adding error handling and user feedback

The implementation applies configurations across all projects but doesn't provide any feedback or handle potential errors.

Consider improving the implementation with error handling and user feedback:

-      commands.registerCommand("dbtPowerUser.applyDeferConfig", () => {
+      commands.registerCommand("dbtPowerUser.applyDeferConfig", async () => {
+        try {
           const projects = this.dbtProjectContainer.getProjects();
-          await Promise.all(projects.map((project) => project.applyDeferConfig()));
+          if (projects.length === 0) {
+            window.showInformationMessage("No dbt projects found to apply defer configuration");
+            return;
+          }
+          
+          await Promise.all(projects.map((project) => project.applyDeferConfig()));
+          window.showInformationMessage("Successfully applied defer configuration to all projects");
+        } catch (error) {
+          this.dbtTerminal.error(
+            "applyDeferConfig",
+            "An error occurred while applying defer configuration",
+            error
+          );
+          window.showErrorMessage(
+            "An error occurred while applying defer configuration: " + error
+          );
+        }
      }),
🧰 Tools
🪛 Biome (1.9.4)

[error] 802-802: await is only allowed within async functions and at the top levels of modules.

(parse)

🪛 ESLint

[error] 802-802: Replace projects.map((project)·=>·project.applyDeferConfig()) with ⏎··········projects.map((project)·=>·project.applyDeferConfig()),⏎········

(prettier/prettier)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ecfed92 and cdb82e1.

📒 Files selected for processing (2)
  • package.json (1 hunks)
  • src/commands/index.ts (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/commands/index.ts

[error] 802-802: await is only allowed within async functions and at the top levels of modules.

(parse)

🪛 ESLint
src/commands/index.ts

[error] 802-802: Replace projects.map((project)·=>·project.applyDeferConfig()) with ⏎··········projects.map((project)·=>·project.applyDeferConfig()),⏎········

(prettier/prettier)

🔇 Additional comments (1)
package.json (1)

757-762: LGTM! The command definition is correctly added.

The new command dbtPowerUser.applyDeferConfig is properly defined with appropriate category and title. This aligns well with the PR objective of automating the "defer to production" feature activation.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/commands/index.ts (1)

800-803: Good implementation of the defer configuration command.

The command correctly retrieves all projects and applies the defer configuration concurrently using Promise.all. The async/await syntax is properly implemented.

However, consider adding error handling to gracefully manage potential failures during the operation.

 commands.registerCommand("dbtPowerUser.applyDeferConfig", async () => {
   const projects = this.dbtProjectContainer.getProjects();
-  await Promise.all(projects.map((project) => project.applyDeferConfig()));
+  try {
+    await Promise.all(projects.map((project) => project.applyDeferConfig()));
+    window.showInformationMessage("Successfully applied defer configuration to all projects");
+  } catch (error) {
+    this.dbtTerminal.error("applyDeferConfig", "Failed to apply defer configuration", error);
+    window.showErrorMessage(`Failed to apply defer configuration: ${error}`);
+  }
 }),
🧰 Tools
🪛 ESLint

[error] 802-802: Replace projects.map((project)·=>·project.applyDeferConfig()) with ⏎··········projects.map((project)·=>·project.applyDeferConfig()),⏎········

(prettier/prettier)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cdb82e1 and f818ef2.

📒 Files selected for processing (1)
  • src/commands/index.ts (1 hunks)
🧰 Additional context used
🪛 ESLint
src/commands/index.ts

[error] 802-802: Replace projects.map((project)·=>·project.applyDeferConfig()) with ⏎··········projects.map((project)·=>·project.applyDeferConfig()),⏎········

(prettier/prettier)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/commands/index.ts (1)

800-809: Well-implemented applyDeferConfig command!

The implementation effectively addresses the goal of automating the "defer to production" feature activation. It efficiently applies configurations to all projects concurrently, includes proper error handling, and provides clear feedback to users.

Consider addressing the ESLint formatting issues by applying this diff:

commands.registerCommand("dbtPowerUser.applyDeferConfig", async () => {
  const projects = this.dbtProjectContainer.getProjects();
  try {
-    await Promise.all(projects.map((project) => project.applyDeferConfig()));
-    window.showInformationMessage("Applied defer configuration");
+    await Promise.all(
+      projects.map((project) => project.applyDeferConfig()),
+    );
+    window.showInformationMessage("Applied defer configuration");
  } catch (error) {
-    this.dbtTerminal.error("applyDeferConfig", "Failed to apply defer configuration", error);
-    window.showErrorMessage(`Failed to apply defer configuration: ${error}`);
+    this.dbtTerminal.error(
+      "applyDeferConfig",
+      "Failed to apply defer configuration",
+      error,
+    );
+    window.showErrorMessage(
+      `Failed to apply defer configuration: ${error}`,
+    );
  }
}),
🧰 Tools
🪛 ESLint

[error] 803-803: Replace projects.map((project)·=>·project.applyDeferConfig()) with ⏎············projects.map((project)·=>·project.applyDeferConfig()),⏎··········

(prettier/prettier)


[error] 806-806: Replace "applyDeferConfig",·"Failed·to·apply·defer·configuration",·error with ⏎············"applyDeferConfig",⏎············"Failed·to·apply·defer·configuration",⏎············error,⏎··········

(prettier/prettier)


[error] 807-807: Replace Failed·to·apply·defer·configuration:·${error} with ⏎············Failed·to·apply·defer·configuration:·${error},⏎··········

(prettier/prettier)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f818ef2 and db793ef.

📒 Files selected for processing (1)
  • src/commands/index.ts (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
src/commands/index.ts (1)
src/dbt_client/dbtTerminal.ts (1) (1)
  • error (105-125)
🪛 ESLint
src/commands/index.ts

[error] 803-803: Replace projects.map((project)·=>·project.applyDeferConfig()) with ⏎············projects.map((project)·=>·project.applyDeferConfig()),⏎··········

(prettier/prettier)


[error] 806-806: Replace "applyDeferConfig",·"Failed·to·apply·defer·configuration",·error with ⏎············"applyDeferConfig",⏎············"Failed·to·apply·defer·configuration",⏎············error,⏎··········

(prettier/prettier)


[error] 807-807: Replace Failed·to·apply·defer·configuration:·${error} with ⏎············Failed·to·apply·defer·configuration:·${error},⏎··········

(prettier/prettier)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/commands/index.ts (1)

800-817: Excellent implementation of the apply defer config command.

The code successfully implements a new command that applies the deferred configuration to all projects. The approach of using Promise.all for concurrent execution is efficient, and the implementation includes proper error handling and user feedback.

There are a couple of missing commas in the error handling section that should be added for consistency with the codebase style:

  this.dbtTerminal.error(
    "applyDeferConfig",
    "Failed to apply defer configuration",
    error
+  );
  window.showErrorMessage(
    `Failed to apply defer configuration: ${error}`
+  );
🧰 Tools
🪛 ESLint

[error] 811-811: Insert ,

(prettier/prettier)


[error] 814-814: Insert ,

(prettier/prettier)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between db793ef and e0ba629.

📒 Files selected for processing (1)
  • src/commands/index.ts (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
src/commands/index.ts (1)
src/dbt_client/dbtTerminal.ts (1) (1)
  • error (105-125)
🪛 ESLint
src/commands/index.ts

[error] 811-811: Insert ,

(prettier/prettier)


[error] 814-814: Insert ,

(prettier/prettier)

@grindheim grindheim changed the title Feature: Add command to run apply defer config feat: add command to run apply defer config Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants