jellydn / hurl.nvim

Hurl.nvim is a Neovim plugin designed to run HTTP requests directly from `.hurl` files. Elevate your API development workflow by executing and viewing responses without leaving your editor.
https://gyazo.com/19492e8b5366cec3f22d5fd97a63f37a
MIT License
129 stars 14 forks source link

fix: git_utils.is_git_repo() - respect git command output #161

Closed edlandm closed 2 months ago

edlandm commented 2 months ago

WHAT

git rev-parse --is-inside-work-tree can be used to test if the command is being run from inside of git repository because it will fail if run from outside of a repository. However, it can also run successfully but output 'false' if run from within a directory inside of the repository that is not part of a worktree.

This is most likely to happen if using a bare repository and the hurl file is kept in a location outside of a worktree. Previously, attempting to run such a hurl request threw an error in find_env_files for attempting to concatenate local 'git_root' (nil, in this case) and no further hurl requests could be run from neovim.

This commit allows find_env_files to continue as if not in a git repo.

WHY

I'm making this pull request because it fixes things for my workflow. Without it I get the error in the below screenshot.

Feel free to fix it a different way if you prefer, my fix was pretty quick just to get it working for me.

HOW

Screenshots (if appropriate):

image

Before Fix

hurl nvim-bug-steps-to-reproduce with_fix

After Fix

hurl nvim-bug-steps-to-reproduce without_fix

Types of changes

Checklist:

Summary by CodeRabbit

codesandbox[bot] commented 2 months ago

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders
Open Preview

changeset-bot[bot] commented 2 months ago

⚠️ No Changeset found

Latest commit: 67260565c69c053e7ad8ced615e2e4f1cd435783

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](https://github.com/edlandm/hurl.nvim/new/fix-find_env_files-git_worktree?filename=.changeset/good-balloons-sip.md&value=---%0A%22%40fake-scope%2Ffake-pkg%22%3A%20patch%0A---%0A%0Afix%3A%20git_utils.is_git_repo()%20-%20respect%20git%20command%20output%0A)

ellipsis-dev[bot] commented 2 months ago

Your free trial has expired. To keep using Ellipsis, sign up at https://app.ellipsis.dev for $20/seat/month or reach us at help@ellipsis.dev

coderabbitai[bot] commented 2 months ago

Walkthrough

The recent update enhances the is_git_repo function in git_utils.lua to accurately determine if the current directory is a Git repository. This is achieved by capturing the result of a shell command and verifying it against the expected output, improving the reliability of the check.

Changes

File Path Change Summary
lua/hurl/git_utils.lua Modified is_git_repo function to store the result of git rev-parse --is-inside-work-tree and return true only if the command succeeds and the result is 'true'.

🐰✨ In a warren of code, where functions play, is_git_repo found a clearer way. With checks and balances, it now can say, "This is a Git repo, hip-hip-hooray!" 🌟🌿


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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `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 generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@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.` 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 as PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger a review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configration 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
jellydn commented 2 months ago

Hi @edlandm, Thank you for your work. I would prefer to expose find_env_files as the config and let users override as they want. What do you think?

jellydn commented 2 months ago

Hi @edlandm Now, you can set the find_env_files_in_folders option. The good thing it was hardcode to follow folders.

  local scan_dir = {
    {
      dir = '/src',
    },
    {
      dir = '/test',
    },
    {
      dir = '/tests',
    },
    {
      dir = '/server',
    },
    {
      dir = '/src/tests',
    },
    {
      dir = '/server/tests',
    },
  }

Now, it's under your control :)