Skip to content

Conversation

@creativeprojects
Copy link
Owner

Fixes #369

@coderabbitai
Copy link

coderabbitai bot commented Jun 17, 2024

Walkthrough

The recent modifications to filesearch/filesearch.go and filesearch/filesearch_test.go include a variable renaming, platform-specific configuration handling, and testing enhancements. Specifically, the XDGAppName variable was renamed to AppName, and new logic was added to improve configuration discovery on Darwin platforms. Parallel test execution capabilities were introduced, and a new test function was implemented for a path manipulation utility.

Changes

Files Change Summary
filesearch/filesearch.go Renamed XDGAppName to AppName, adjusted configuration logic for Darwin, and added a utility function for paths.
filesearch/filesearch_test.go Introduced t.Parallel() in various test functions and added a new test for the path utility function.

Assessment against linked issues

Objective Addressed Explanation
Load config from ~/.config/resticprofile on MacOS too (#369)

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>.
    • 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.
    • @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 as 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.

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

@codecov
Copy link

codecov bot commented Jun 17, 2024

Codecov Report

Attention: Patch coverage is 92.30769% with 2 lines in your changes missing coverage. Please review.

Project coverage is 71.52%. Comparing base (0598026) to head (52c86e4).

Files Patch % Lines
filesearch/filesearch.go 92.31% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #370      +/-   ##
==========================================
+ Coverage   71.48%   71.52%   +0.04%     
==========================================
  Files         121      121              
  Lines       12723    12746      +23     
==========================================
+ Hits         9095     9116      +21     
- Misses       3218     3220       +2     
  Partials      410      410              
Flag Coverage Δ
unittests 71.52% <92.31%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@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: 2

Outside diff range and nitpick comments (2)
filesearch/filesearch.go (2)

Line range hint 210-210: Potential security issue: Subprocess exec.Command used in ShellExpand might be susceptible to command injection if not properly sanitized.

Consider sanitizing the filename parameter to prevent any potential command injection vulnerabilities.


Line range hint 83-83: The variable displayFile is reassigned in the FindConfigurationFile function without using its initial value.

Consider initializing displayFile directly in the conditional branches to avoid unnecessary assignment.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0598026 and 49142b6.

Files selected for processing (5)
  • .goreleaser.yml (1 hunks)
  • codecov.yml (1 hunks)
  • filesearch/filesearch.go (7 hunks)
  • filesearch/filesearch_test.go (8 hunks)
  • schedule/scheduler_config.go (3 hunks)
Files skipped from review due to trivial changes (3)
  • .goreleaser.yml
  • codecov.yml
  • schedule/scheduler_config.go
Additional context used
golangci-lint
filesearch/filesearch.go

[medium] 210-210: G204: Subprocess launched with a potential tainted input or cmd arguments (gosec)


83-83: assigned to displayFile, but reassigned without using the value (wastedassign)

filesearch/filesearch_test.go

58-58: Function 'testLocations' is too long (135 > 60) (funlen)


1-1: package should be filesearch_test instead of filesearch (testpackage)


279-279: TestShellExpand's subtests should call t.Parallel (tparallel)


312-312: TestFindConfigurationIncludes's subtests should call t.Parallel (tparallel)

GitHub Check: codecov/patch
filesearch/filesearch.go

[warning] 235-235: filesearch/filesearch.go#L235
Added line #L235 was not covered by tests


[warning] 279-279: filesearch/filesearch.go#L279
Added line #L279 was not covered by tests

Additional comments not posted (6)
filesearch/filesearch.go (4)

20-20: The variable XDGAppName has been renamed to AppName to reflect a more generic usage, aligning with the PR's objective to support macOS. This change also impacts the rest of the code where XDGAppName was used.


43-45: Added macOS-specific configuration paths using the AppName variable. This aligns with the PR's objective to support configuration loading from ~/.config/resticprofile on macOS. Ensure that this path is widely recognized on macOS systems as a standard configuration directory.


259-259: The getSearchBinaryLocations function has been updated to include user-specific binary locations on non-Windows platforms. This is a logical extension to handle binaries in user-specific directories.


220-220: The function getSearchConfigurationLocations has been updated to include configuration paths for macOS using a newly introduced utility function addRootToRelativePaths. This change is crucial for supporting macOS as per the PR's objective.

However, the added lines are not covered by tests.

Also applies to: 222-222, 224-224, 233-235, 237-237

filesearch/filesearch_test.go (2)

43-44: The use of t.Parallel() in TestDefaultConfigDirs is appropriate for allowing parallel execution of tests, improving test execution speed.


368-399: The new test function TestAddRootToRelativePaths effectively checks the functionality of the addRootToRelativePaths utility function. It covers various scenarios including empty root and absolute paths.

Copy link

@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: 2

Outside diff range and nitpick comments (4)
filesearch/filesearch.go (2)

Line range hint 220-236: The logic to dynamically construct configuration paths based on the platform is robust and maintainable. However, consider handling potential errors from os.UserHomeDir() to ensure reliability even in edge cases where the home directory might not be accessible or determinable.

- home, _ := os.UserHomeDir()
+ home, err := os.UserHomeDir()
+ if err != nil {
+   return []string{} // or handle error appropriately
+ }

Line range hint 210-210: Subprocess launched with potentially tainted input in ShellExpand. Ensure that inputs are sanitised or validated to prevent injection vulnerabilities.

- cmd := exec.Command("sh", "-c", fmt.Sprintf("echo %s", strings.ReplaceAll(filename, " ", `\ `)))
+ safeFilename := strings.ReplaceAll(filename, " ", `\ `)
+ safeFilename = strings.ReplaceAll(safeFilename, ";", `\:`)
+ cmd := exec.Command("sh", "-c", fmt.Sprintf("echo %s", safeFilename))
filesearch/filesearch_test.go (2)

Line range hint 58-58: The testLocations function is quite long, which might hinder maintainability and readability. Consider breaking it down into smaller, more focused helper functions.


Line range hint 1-1: The package declaration should be filesearch_test instead of filesearch to ensure that the tests are properly isolated and are black-box tests. This helps in validating the public interface of the package without relying on its internal state.

- package filesearch
+ package filesearch_test
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 49142b6 and 76dfc49.

Files selected for processing (2)
  • filesearch/filesearch.go (7 hunks)
  • filesearch/filesearch_test.go (11 hunks)
Additional context used
golangci-lint
filesearch/filesearch.go

[medium] 210-210: G204: Subprocess launched with a potential tainted input or cmd arguments (gosec)


83-83: assigned to displayFile, but reassigned without using the value (wastedassign)

filesearch/filesearch_test.go

58-58: Function 'testLocations' is too long (135 > 60) (funlen)


1-1: package should be filesearch_test instead of filesearch (testpackage)

Additional comments not posted (4)
filesearch/filesearch.go (2)

20-20: Renaming XDGAppName to AppName simplifies and generalises the variable name, aligning with the broader use case beyond XDG contexts. Good improvement for clarity and maintainability.


43-45: Adding macOS specific configuration paths under .config/resticprofile/ aligns with the XDG standards and improves user experience on macOS by standardising configuration locations across different systems.

filesearch/filesearch_test.go (2)

43-44: Using t.Parallel() to run tests in parallel is a great practice to improve test execution efficiency. Consistent application across all tests ensures better performance.


197-198: Good use of t.Parallel() in test functions to enhance test execution efficiency. Ensure consistency by applying it to all subtests as well.

Also applies to: 237-238, 245-246, 257-258, 280-281, 305-306, 315-316, 356-357, 375-376

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 76dfc49 and 52c86e4.

Files selected for processing (1)
  • filesearch/filesearch.go (8 hunks)
Files not reviewed due to errors (1)
  • filesearch/filesearch.go (no review received)
Additional context used
golangci-lint
filesearch/filesearch.go

74-74: don't use init function (gochecknoinits)


[medium] 210-210: G204: Subprocess launched with a potential tainted input or cmd arguments (gosec)


83-83: assigned to displayFile, but reassigned without using the value (wastedassign)

@creativeprojects creativeprojects merged commit 6da0317 into master Jun 18, 2024
@creativeprojects creativeprojects deleted the add-dot-config-to-path branch June 18, 2024 21:59
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.

Load config from ~/.config/resticprofile on MacOS too

2 participants