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

Enhance Variable Management in Hurl.nvim #228

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

sweep-ai[bot]
Copy link
Contributor

@sweep-ai sweep-ai bot commented Feb 7, 2025

Purpose

Improve variable management in Hurl.nvim by introducing persistent variable storage, supporting environment file parsing, and providing a more robust variable management interface.

This pull request was created to solve the following GitHub issue:

The :HurlManageVariable command doesn't persist values (and doesn't prepopulate from env_file)

Details

No response


Enhance :HurlManageVariable with persistence and env file integration

Description:

The :HurlManageVariable command currently lacks persistence between sessions and doesn't load initial values from the configured env files. This needs to be fixed to improve variable management functionality.

Tasks:

  1. In lua/hurl/main.lua:

    • Modify HurlManageVariable command to load variables from env files on initialization
    • Add persistence functionality to save variables between sessions
    • Update variable management popup to reflect both env file and persisted variables
  2. In lua/hurl/lib/hurl_runner.lua:

    • Add function to parse env files and extract variables
    • Modify variable injection logic to handle both persisted and env file variables
  3. In test/plugin_spec.lua:

    • Add test cases for variable persistence
    • Add test cases for env file variable loading
    • Add test cases for variable management popup

Test:

  • Add the following test cases to test/plugin_spec.lua:
    it('should load variables from env file', function()
      -- Test env file loading
    end)
    
    it('should persist variables between sessions', function()
      -- Test variable persistence
    end)
    
    it('should show both env file and persisted variables in popup', function()
      -- Test popup display
    end)

Add persistence and env file integration to HurlManageVariable

Description:

Enhance the :HurlManageVariable command to persist variables between sessions and load initial values from configured env files.

Tasks:

  1. In lua/hurl/main.lua:

    • Add function to load variables from env files into _HURL_GLOBAL_CONFIG.global_vars
    • Modify HurlManageVariable command to:
      • Read from vim.fn.stdpath('data')/hurl-nvim/variables.json
      • Display both env file and persisted variables
      • Save changes to persistence file
  2. In lua/hurl/utils.lua:

    • Add functions for reading/writing persistent storage
    • Add function to parse env files into variable format
  3. In test/plugin_spec.lua:

    describe('HurlManageVariable', function()
      it('loads variables from env files')
      it('persists variables between sessions')
      it('displays combined env and persisted variables')
    end)

Implementation Notes:

  • Store persistent variables in JSON format
  • Load env file variables on plugin initialization
  • Merge env file variables with persisted variables in display
  • Handle variable conflicts with user notification

Description

This pull request introduces several key enhancements to variable management:

  • Added support for loading variables from environment files
  • Implemented persistent variable storage using JSON
  • Enhanced the HurlManageVariable command with new features:
    • Display variables from both env files and persistent storage
    • Add new variables
    • Edit existing variables
    • Delete user-defined variables
  • Improved error handling and user notifications
  • Added comprehensive test coverage for new variable management functionality

The changes provide users with a more flexible and user-friendly way to manage variables across different Hurl.nvim sessions and environments.

Summary

New Features

  • Persistent variable storage
  • Environment file variable parsing
  • Enhanced variable management UI

Modified files

  • lua/hurl/main.lua: Updated variable management command
  • lua/hurl/utils.lua: Added utility functions for variable handling
  • test/plugin_spec.lua: Added tests for new variable management functionality

New Capabilities

  • Load variables from .env files
  • Persist variables between Neovim sessions
  • Interactive variable management with create, edit, and delete operations

Fixes

Fixes #219. Continue the conversation here: https://app.sweep.dev/c/9916350e-5ad7-45c4-a067-e0933c3c11e0.

To have Sweep make further changes, please add a comment to this PR starting with "Sweep:".

📖 For more information on how to use Sweep, please read our documentation.

Tracking ID: 94fc04369f

Summary by CodeRabbit

  • New Features

    • Enhanced global variable management by merging persisted and environment variables.
    • Improved user interactions with clearer prompts and safeguards for variable creation, editing, and deletion.
  • Tests

    • Introduced comprehensive tests to verify variable loading, saving, and merging, ensuring consistent behavior.

Copy link

codesandbox bot commented Feb 7, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

changeset-bot bot commented Feb 7, 2025

⚠️ No Changeset found

Latest commit: da4a357

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor Author

sweep-ai bot commented Feb 7, 2025

❌ Error while fixing CI

Traceback
Traceback (most recent call last):
  File "/app/sweepai/handlers/fix_ci.py", line 285, in fix_ci_failures_once
    logs_list = get_ci_failure_logs(installation_id=installation_id, runs=error_runs, pull_request=pull_request)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/sweepai/ci/fetch_ci.py", line 268, in get_ci_failure_logs
    logs = get_ci_failure_log(installation_id, run, pull_request, fetched_urls)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/sweepai/ci/fetch_ci.py", line 254, in get_ci_failure_log
    raw_binary_logs = download_raw_logs(
                      ^^^^^^^^^^^^^^^^^^
  File "/app/sweepai/ci/fetch_ci.py", line 224, in download_raw_logs
    raise Exception(f"Sweep was unable to fetch CI/CD logs for {repo_full_name} due to GitHub errors.")
Exception: Sweep was unable to fetch CI/CD logs for jellydn/hurl.nvim due to GitHub errors.

Sweep was unable to fetch CI/CD logs for jellydn/hurl.nvim due to GitHub errors.

Sweep has encountered a runtime error unrelated to your request. Please let us know via this link or at support@sweep.dev directly.

📖 For more information on how to use Sweep, please read our documentation.

Tracking ID: 94fc04369f-ci-0

Copy link
Contributor

coderabbitai bot commented Feb 7, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes enhance the HurlManageVariable command in the Hurl.nvim plugin. The command now retrieves persisted variables from storage and loads environment file variables, merging them with precedence for persisted values. The user interface prompts have been updated to clarify actions such as creating, editing, and deleting variables—with deletion of environment variables prevented. Additionally, new utility functions for parsing environment files and managing persistent JSON storage are introduced. The test suite now includes cases to verify env file loading, variable persistence, and the merged display.

Changes

File(s) Summary
lua/hurl/main.lua Updated HurlManageVariable command to load persisted and env file variables, merge them (persisted taking precedence), update UI prompts, and add deletion/edit safeguards.
lua/hurl/utils.lua Added new functions: parse_env_file (reads env files into key-value pairs), get_storage_path (ensures JSON storage directory existence), load_persisted_vars, and save_persisted_vars.
test/plugin_spec.lua Introduced a new "Variable Management" test suite that sets up a clean state and validates env file loading, variable persistence, and proper merging of variables.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant H as HurlManageVariable Command
    participant UT as Utils Module
    participant S as Storage/Env File
    U->>H: Trigger :HurlManageVariable
    H->>UT: load_persisted_vars()
    H->>UT: parse_env_file()
    UT-->>H: Return persisted and env variables
    H->>H: Merge variables (persisted wins)
    H->>U: Display UI with merged variables
    U->>H: Edit/Delete/Add variable
    H->>UT: save_persisted_vars(updated variables)
    U->>H: Confirm changes
Loading

Assessment against linked issues

Objective Addressed Explanation
Load environment file variables for HurlManageVariable (#219)
Persist variables between sessions (#219)
Display merged env file and persisted variables in the popup (#219)

Possibly related PRs

Poem

I'm a rabbit with a twinkle in my eye,
Hopping through code under a bright blue sky.
With env and persistence merged into one,
Variables dance as changes are done.
I code with hops and joyful cheer—
Celebrating a burrow of improvements here!
🐰💻


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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. (Beta)
  • @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.

@jellydn
Copy link
Owner

jellydn commented Feb 7, 2025

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Feb 7, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@jellydn jellydn requested a review from Copilot February 7, 2025 13:43

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request.

Files not reviewed (3)
  • lua/hurl/main.lua: Language not supported
  • lua/hurl/utils.lua: Language not supported
  • test/plugin_spec.lua: Language not supported
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 (4)
lua/hurl/main.lua (1)

308-329: Consider sorting newly created variables.

Appending a new variable at the bottom may lead to confusion for larger sets of variables. For better readability and consistency, you might want to insert the variable in alphabetical order or re-sort the entire list whenever a variable is created.

test/plugin_spec.lua (1)

31-41: Add broader test coverage for environment file parsing.

Tests currently check a simple key-value pair. To fortify reliability, consider verifying corner cases (e.g., quoted values, no value after “=”, “export” prefix, or comments with leading spaces) to ensure robust parsing in different real-world scenarios.

lua/hurl/utils.lua (2)

278-301: Consider supporting more advanced .env formats.

Currently, you only parse “KEY=VALUE” lines. Real-world .env files sometimes contain quotes, multiline values, or “export KEY=VALUE” forms. If you want broader flexibility, consider extending this parser or clarifying limitations in docs.


314-350: Storing variables in plain JSON may pose security risks.

Loading and saving JSON is fine for typical use cases, but be aware that secrets in plain text can be compromised. If needed, consider encrypting sensitive data under a key or restricting file permissions to mitigate potential leaks.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2181e24 and 23bd5ee.

📒 Files selected for processing (3)
  • lua/hurl/main.lua (1 hunks)
  • lua/hurl/utils.lua (1 hunks)
  • test/plugin_spec.lua (1 hunks)
🔇 Additional comments (6)
lua/hurl/main.lua (3)

248-265: Confirm variable precedence and consider secure storage.

You’re merging environment variables into persisted variables with “force,” giving persisted vars the highest precedence. Please verify that this is the desired order if environment variables are supposed to override local changes. Also, be mindful that storing secrets in plain text could be risky if these variables contain sensitive data. You might consider a more secure storage strategy (e.g., file-level permissions, encryption) to mitigate potential leaks.


292-306: Editing flow looks good—ensure test coverage.

The edit logic is straightforward; it directly updates persisted variables and the buffer line. This flow is essential to test under various scenarios (e.g., incomplete or canceled input). If not covered yet, consider adding integration tests for the popup-based edit flow to ensure it’s robust.


331-346: Environment variable deletion prevention is commendable.

This logic correctly prevents removing environment-populated variables. Users receive a warning and are blocked from such deletions. This approach helps avoid accidental misconstruction of environment states.

test/plugin_spec.lua (2)

43-49: Persist and reload logic looks correct.

The test effectively ensures variables remain consistent across sessions, covering writing and reading from storage. Great job adding this coverage.


51-71: Verify handling of conflicts between env and persisted variables.

Your test checks a simple merge scenario. Consider adding a test case where the same variable is defined in both env and persisted sets, then confirm your precedence logic is enforced properly.

lua/hurl/utils.lua (1)

303-312: Creating and verifying storage directory works well.

The code reliably checks for the directory, creates it if absent, then returns a usable path. This is straightforward and effective.

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.

The :HurlManageVariable command doesn't persist values (and doesn't prepopulate from env_file)
1 participant