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

Persistent profiles #6

Merged
merged 4 commits into from
Dec 7, 2024
Merged

Persistent profiles #6

merged 4 commits into from
Dec 7, 2024

Conversation

pablopunk
Copy link
Owner

@pablopunk pablopunk commented Dec 7, 2024

Summary by CodeRabbit

  • New Features

    • Introduced profile persistence, allowing users to remember and reuse the last used profile with the dot command.
    • Added functionality to remove the last used profile using the --remove-profile option.
  • Documentation

    • Updated the README.md to include details about the new profile persistence feature and usage instructions.
  • Tests

    • Added a new test case to verify the functionality of saving the last used profile.

Copy link
Contributor

coderabbitai bot commented Dec 7, 2024

Warning

Rate limit exceeded

@pablopunk has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 23 minutes and 3 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 50c8995 and aba015b.

Walkthrough

The changes introduced in this pull request enhance the dot application by adding profile persistence functionality. A new section in the README.md explains how profiles are remembered for subsequent commands, allowing users to run dot without specifying a profile each time. The dot.lua script has been updated to include a --remove-profile option, with new functions for managing profile storage. Additionally, a new test case has been added to verify the profile saving functionality in spec/dot_spec.lua.

Changes

File Change Summary
README.md Added section on profile persistence; included instructions for using and removing profiles; minor formatting adjustments.
dot.lua Introduced remove_profile variable; added functions save_last_profile, get_last_profile, remove_last_profile; updated parse_args and main functions; replaced print statements with print_section.
spec/dot_spec.lua Added test case "should save the last used profile" to verify profile saving functionality.

Possibly related PRs

  • defaults #5: The changes in dot.lua related to command-line argument parsing and profile management are directly connected to the main PR's enhancements for profile persistence, as both involve managing user profiles and command-line options.

Poem

In the burrow where commands do play,
Profiles linger, come what may.
With a hop and a skip, they stay in line,
Just run dot, and all will be fine!
Remove the last with a simple call,
Our little app remembers it all! 🐇✨


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 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.

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: 4

🧹 Outside diff range and nitpick comments (3)
README.md (1)

244-261: Consider adding information about profile storage location.

The documentation clearly explains the feature and provides good examples. Consider adding a note about where the profile information is stored (.git/dot or .dot file) to help users understand the persistence mechanism.

🧰 Tools
🪛 Markdownlint (0.35.0)

259-259: null
Dollar signs used before commands without showing output

(MD014, commands-show-output)

spec/dot_spec.lua (1)

548-588: Enhance test coverage for profile persistence.

While the test case effectively verifies the basic profile saving functionality, consider adding tests for:

  1. Profile removal using --remove-profile
  2. Edge cases like empty profile names or invalid profiles
  3. Different storage locations (.git/dot vs .dot)

Example test cases to add:

it("should remove the last used profile", function()
  -- Set up and save a profile first
  setup_profile(
    "test_profile",
    [[return { modules = { "neovim" } }]]
  )
  assert.is_true(run_dot "test_profile")
  
  -- Verify profile is saved
  local dot_file_path = pl_path.join(dotfiles_dir, ".dot")
  assert.is_true(pl_path.isfile(dot_file_path))
  
  -- Remove profile
  assert.is_true(run_dot "--remove-profile")
  
  -- Verify profile is removed
  assert.is_false(pl_path.isfile(dot_file_path))
end)

it("should handle git directory for profile storage", function()
  -- Set up git directory
  local git_dir = pl_path.join(dotfiles_dir, ".git")
  pl_dir.makepath(git_dir)
  
  -- Save profile
  assert.is_true(run_dot "test_profile")
  
  -- Verify profile is saved in .git/dot
  local dot_file_path = pl_path.join(git_dir, "dot")
  assert.is_true(pl_path.isfile(dot_file_path))
end)
dot.lua (1)

99-101: Consider using a consistent message format.

The print_section function introduces a new message format. Consider using the existing print_message function for consistency.

-local function print_section(message)
-  print(colors.bold .. colors.blue .. "[" .. message .. "]" .. colors.reset)
-end
+local function print_section(message)
+  print("")
+  print_message("section", message)
+end

-- Update print_message to handle sections
local function print_message(message_type, message)
   local color, symbol
   if message_type == "success" then
     color, symbol = colors.green, "✓"
   elseif message_type == "error" then
     color, symbol = colors.red, "✗"
   elseif message_type == "warning" then
     color, symbol = colors.yellow, "!"
   elseif message_type == "info" then
     color, symbol = colors.blue, "•"
+  elseif message_type == "section" then
+    print(colors.bold .. colors.blue .. "[" .. message .. "]" .. colors.reset)
+    return
   else
     color, symbol = colors.reset, ">"
   end
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 59d786a and c50bba6.

📒 Files selected for processing (3)
  • README.md (2 hunks)
  • dot.lua (11 hunks)
  • spec/dot_spec.lua (1 hunks)
🧰 Additional context used
🪛 Markdownlint (0.35.0)
README.md

259-259: null
Dollar signs used before commands without showing output

(MD014, commands-show-output)

dot.lua Outdated Show resolved Hide resolved
dot.lua Outdated Show resolved Hide resolved
dot.lua Show resolved Hide resolved
dot.lua Show resolved Hide resolved
pablopunk and others added 2 commits December 7, 2024 17:19
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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: 3

🧹 Outside diff range and nitpick comments (4)
dot.lua (4)

20-20: Consistency: Initialize remove_profile with other flags

For better readability and consistency, consider grouping the initialization of remove_profile with other flag variables (e.g., force_mode, purge_mode, etc.) at lines 13-19.

This helps maintain a logical structure and makes it easier to locate related variables.


46-47: Validate command-line options in parse_args

The parse_args function is becoming lengthy with multiple elseif conditions. Consider refactoring it to improve maintainability and readability.

You could use a table to map command-line arguments to actions or flags, which would simplify adding new options in the future.


63-63: Update help message formatting

The help message for --remove-profile is not aligned with the rest of the options. Consider adjusting the indentation for consistency.

Apply this diff to fix the alignment:

       --hooks           Run hooks even if dependencies haven't changed
-      --remove-profile  Remove the last used profile
+      --remove-profile   Remove the last used profile
       -h                Display this help message

99-101: Use existing print_message function for consistency

Instead of creating a new print_section function, consider using the existing print_message function to maintain consistency in output formatting.

If a distinct section header is necessary, perhaps extend print_message to handle this case.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c50bba6 and 50c8995.

📒 Files selected for processing (1)
  • dot.lua (11 hunks)
🔇 Additional comments (8)
dot.lua (8)

83-83: Ensure options table includes all parsed flags

Good job adding remove_profile to the returned options table. This ensures that the main function can access the new flag.


747-747: Enhance module processing messages

Using print_section(module_name) improves the readability of the script's output by clearly delineating module processing sections.


810-816: Handle loading errors in process_tool function

Good job adding error messages when loading or executing profiles fails. This will aid in debugging.


847-847: Handle missing modules gracefully

The error message "Module not found" helps users understand when a specified module does not exist.


852-862: Add error handling for file operations in save_last_profile

The save_last_profile function should handle potential errors when opening and writing to the file to prevent silent failures.

This issue was previously raised. Consider implementing error handling as suggested.


864-876: Add error handling and profile validation in get_last_profile

The get_last_profile function should validate that the profile exists and handle errors reading the file.

This mirrors a previous suggestion. Implementing validation ensures robustness.


878-884: Add error handling for file removal in remove_last_profile

The remove_last_profile function should check if the file exists before attempting to remove it and handle any errors during removal.

Refer to the prior feedback for detailed recommendations.


904-909: ⚠️ Potential issue

Check the success of profile removal

After calling remove_last_profile, verify that the profile was successfully removed before confirming to the user.

Modify the function to return a status and update the main function accordingly.

Apply this diff:

      if options.remove_profile then
-        remove_last_profile()
-        print_message("info", "Profile removed.")
+        local success = remove_last_profile()
+        if success then
+          print_message("info", "Profile removed.")
+        else
+          print_message("error", "Failed to remove profile.")
+        end
        return
      end

And update remove_last_profile:

  local function remove_last_profile()
    local file_path = ".git/dot"
    if not is_dir(".git") then
      file_path = ".dot"
    end
-   os.remove(file_path)
+   local success, err = os.remove(file_path)
+   if not success then
+     return false
+   end
+   return true
  end

Likely invalid or redundant comment.

dot.lua Show resolved Hide resolved
dot.lua Show resolved Hide resolved
dot.lua Show resolved Hide resolved
@pablopunk pablopunk merged commit 279b14e into main Dec 7, 2024
2 checks passed
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.

1 participant