Skip to content

chore: use file.PutContent replace deprecated file.Create#901

Merged
hwbrzzl merged 30 commits intogoravel:masterfrom
kuafuRace:replace-fileCreate
Feb 21, 2025
Merged

chore: use file.PutContent replace deprecated file.Create#901
hwbrzzl merged 30 commits intogoravel:masterfrom
kuafuRace:replace-fileCreate

Conversation

@kuafuRace
Copy link
Contributor

@kuafuRace kuafuRace commented Feb 20, 2025

📑 Description

use file.PutContent replace deprecated file.Create

Summary by CodeRabbit

  • Refactor
    • Standardized the file writing process across various commands and utilities to ensure uniform and reliable behavior.
  • Tests
    • Enhanced environment-related tests, including encryption/decryption workflows, by introducing standardized key constants and streamlining setup.
  • Style
    • Improved code clarity through updated naming conventions and refined formatting within comments and import statements.

✅ Checks

  • Added test cases for my code

- Add `env:encrypt` command to generate `.env.encrypted`
- Add `env:decrypt` command to generate `.env` from `.env.encrypted`
- Add `env:encrypt` command to generate `.env.encrypted`
- Add `env:decrypt` command to generate `.env` from `.env.encrypted`
- Add `env:encrypt` command to generate `.env.encrypted`
- Add `env:decrypt` command to generate `.env` from `.env.encrypted`
@kuafuRace kuafuRace requested a review from a team as a code owner February 20, 2025 09:12
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 20, 2025

Walkthrough

This pull request updates the codebase to replace calls to file.Create with file.PutContent across a range of files. The changes span command handlers, test suites, migration and session drivers, and supporting utilities. A few files also include minor refactors such as renaming receiver variables and reordering import statements, as well as introducing new constants to streamline environment encryption/decryption tests. No functional changes or control flow modifications have been introduced.

Changes

File(s) Change Summary
auth/console/*.go, console/console/*.go, event/console/*.go, http/console/*.go, mail/console/*.go, queue/console/*.go, validation/console/*.go Replaced file.Create with file.PutContent in command handlers and test functions to update file writing methods without altering logic.
database/console/*.go, database/migration/migrator.go Updated file creation calls to use file.PutContent in database commands and migration routines.
foundation/console/*.go, foundation/application_test.go, foundation/console/env_decrypt_command_test.go, foundation/console/env_encrypt_command_test.go, foundation/console/vendor_publish_command*.go Standardized file operations by switching to file.PutContent; added new constants and renamed setup methods in environment encryption/decryption tests; adjusted import order in one test file.
http/context.go Renamed receiver variable from r to c in context methods to improve consistency.
log/logrus_writer_test.go Modified logging hook to use file.PutContent instead of file.Create for file-based log entry writing.
queue/task_test.go, session/driver/file.go, support/console/console_test.go, support/docker/container.go, support/file/file_test.go, translation/file_loader_test.go Replaced file creation calls with file.PutContent in tests, session drivers, container locking, and translation file loading.
testing/http/assertable_json_test.go Reformatted comment spacing for improved readability.

Possibly related PRs

Suggested reviewers

  • kkumar-gcc

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 golangci-lint (1.62.2)

Error: can't load config: the Go language version (go1.23) used to build golangci-lint is lower than the targeted Go version (1.24.0)
Failed executing command with error: can't load config: the Go language version (go1.23) used to build golangci-lint is lower than the targeted Go version (1.24.0)

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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.

@codecov
Copy link

codecov bot commented Feb 20, 2025

Codecov Report

Attention: Patch coverage is 31.81818% with 15 lines in your changes missing coverage. Please review.

Project coverage is 67.78%. Comparing base (34c641e) to head (8545a1e).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
auth/console/policy_make_command.go 0.00% 0 Missing and 1 partial ⚠️
console/console/make_command.go 0.00% 0 Missing and 1 partial ⚠️
event/console/event_make_command.go 0.00% 0 Missing and 1 partial ⚠️
event/console/listener_make_command.go 0.00% 0 Missing and 1 partial ⚠️
foundation/console/package_make_command.go 0.00% 0 Missing and 1 partial ⚠️
foundation/console/test_make_command.go 0.00% 0 Missing and 1 partial ⚠️
foundation/console/vendor_publish_command.go 0.00% 0 Missing and 1 partial ⚠️
http/console/controller_make_command.go 0.00% 0 Missing and 1 partial ⚠️
http/console/middleware_make_command.go 0.00% 0 Missing and 1 partial ⚠️
http/console/request_make_command.go 0.00% 0 Missing and 1 partial ⚠️
... and 5 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #901      +/-   ##
==========================================
- Coverage   67.83%   67.78%   -0.05%     
==========================================
  Files         154      154              
  Lines       10194    10194              
==========================================
- Hits         6915     6910       -5     
- Misses       2943     2951       +8     
+ Partials      336      333       -3     

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

@kuafuRace
Copy link
Contributor Author

Ready Review

@kuafuRace kuafuRace changed the title refactor: use file.PutContent replace deprecated file.Create chore: use file.PutContent replace deprecated file.Create Feb 20, 2025
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 (3)
database/console/seeder_make_command.go (1)

52-54: Consider consistent error handling across commands.

While the change to file.PutContent is correct, the error handling differs from other similar commands. Other commands log the error using ctx.Error() before returning, but this one directly returns the error.

Consider applying this change for consistency:

 if err := file.PutContent(m.GetFilePath(), r.populateStub(r.getStub(), m.GetPackageName(), m.GetStructName())); err != nil {
+    ctx.Error(err.Error())
-    return err
+    return nil
 }
auth/console/policy_make_command.go (1)

52-54: Consider consistent error handling across commands.

While the change to file.PutContent is correct, the error handling differs from other similar commands. Other commands log the error using ctx.Error() before returning, but this one directly returns the error.

Consider applying this change for consistency:

 if err := file.PutContent(m.GetFilePath(), r.populateStub(r.getStub(), m.GetPackageName(), m.GetStructName())); err != nil {
+    ctx.Error(err.Error())
-    return err
+    return nil
 }
database/console/observer_make_command.go (1)

52-54: Consider consistent error handling.

The error handling here differs from other similar commands. Other commands log the error and return nil, while this one returns the error directly.

Consider applying this change for consistency:

 if err := file.PutContent(m.GetFilePath(), r.populateStub(r.getStub(), m.GetPackageName(), m.GetStructName())); err != nil {
-    return err
+    ctx.Error(err.Error())
+    return nil
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between efd2987 and 8545a1e.

📒 Files selected for processing (35)
  • auth/console/jwt_secret_command_test.go (2 hunks)
  • auth/console/policy_make_command.go (1 hunks)
  • console/console/key_generate_command_test.go (2 hunks)
  • console/console/make_command.go (1 hunks)
  • database/console/factory_make_command.go (1 hunks)
  • database/console/model_make_command.go (1 hunks)
  • database/console/observer_make_command.go (1 hunks)
  • database/console/seeder_make_command.go (1 hunks)
  • database/migration/migrator.go (1 hunks)
  • event/console/event_make_command.go (1 hunks)
  • event/console/listener_make_command.go (1 hunks)
  • foundation/application_test.go (1 hunks)
  • foundation/console/about_command_test.go (1 hunks)
  • foundation/console/env_decrypt_command_test.go (4 hunks)
  • foundation/console/env_encrypt_command_test.go (5 hunks)
  • foundation/console/package_make_command.go (1 hunks)
  • foundation/console/test_make_command.go (1 hunks)
  • foundation/console/vendor_publish_command.go (1 hunks)
  • foundation/console/vendor_publish_command_test.go (3 hunks)
  • http/console/controller_make_command.go (1 hunks)
  • http/console/middleware_make_command.go (1 hunks)
  • http/console/request_make_command.go (1 hunks)
  • http/context.go (1 hunks)
  • log/logrus_writer_test.go (1 hunks)
  • mail/console/mail_make_command.go (1 hunks)
  • queue/console/job_make_command.go (1 hunks)
  • queue/task_test.go (1 hunks)
  • session/driver/file.go (1 hunks)
  • support/console/console_test.go (2 hunks)
  • support/docker/container.go (1 hunks)
  • support/file/file_test.go (2 hunks)
  • testing/http/assertable_json_test.go (11 hunks)
  • translation/file_loader_test.go (1 hunks)
  • validation/console/filter_make_command.go (1 hunks)
  • validation/console/rule_make_command.go (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • foundation/console/about_command_test.go
  • testing/http/assertable_json_test.go
🧰 Additional context used
🪛 Gitleaks (8.21.2)
foundation/console/env_decrypt_command_test.go

18-18: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

🔇 Additional comments (35)
http/context.go (1)

25-26: LGTM! Improved readability with better receiver naming.

The change from r to c as the receiver variable name is a good improvement, as it better represents the context receiver and follows common Go conventions.

Also applies to: 34-36, 39-40, 43-44

queue/task_test.go (1)

23-23: LGTM! Successfully replaced deprecated method.

The change from file.Create to file.PutContent aligns with the PR objective and maintains the same functionality.

auth/console/jwt_secret_command_test.go (1)

24-24: LGTM! Successfully replaced deprecated method in test functions.

The change from file.Create to file.PutContent in both test functions aligns with the PR objective while maintaining the same test behavior.

Also applies to: 47-47

event/console/event_make_command.go (1)

48-48: LGTM! Successfully replaced deprecated method in command handler.

The change from file.Create to file.PutContent in the Handle method aligns with the PR objective while maintaining the same functionality and error handling.

session/driver/file.go (1)

89-89:

Details

❓ Verification inconclusive

LGTM! Correctly replaced deprecated method.

The change from file.Create to file.PutContent maintains the same functionality while using the updated method.

Let's verify the deprecation notice for file.Create:


🏁 Script executed:

#!/bin/bash
# Search for deprecation notice in file package
rg -A 2 "Create.*\[Deprecated\]" || rg -A 2 "@deprecated.*Create"

Length of output: 66


LGTM with a manual deprecation check required.

The change from file.Create to file.PutContent preserves the intended functionality and thread safety. However, our automated search did not find any deprecation notice for file.Create. Please manually verify whether file.Create is marked as deprecated in the file package documentation to ensure the correctness of this update.

console/console/make_command.go (1)

46-46: LGTM! Consistent with the deprecation update.

The replacement maintains the same error handling and functionality while using the updated method.

foundation/console/test_make_command.go (1)

53-53: LGTM! Properly updated to use non-deprecated method.

The change maintains consistency with other files while preserving error handling and functionality.

database/console/model_make_command.go (1)

52-52: LGTM! Successfully updated to non-deprecated method.

The change aligns with the updates in other files while maintaining proper error handling.

mail/console/mail_make_command.go (1)

52-52: LGTM! Appropriate use of file.PutContent.

The change from file.Create to file.PutContent is correctly implemented, maintaining the same error handling pattern.

http/console/middleware_make_command.go (1)

48-48: LGTM! Appropriate use of file.PutContent.

The change from file.Create to file.PutContent is correctly implemented, maintaining the same error handling pattern.

queue/console/job_make_command.go (1)

49-49: LGTM! Correctly replaced deprecated method.

The change from file.Create to file.PutContent is appropriate and maintains the same functionality.

validation/console/rule_make_command.go (1)

49-49: LGTM! Correctly replaced deprecated method.

The change from file.Create to file.PutContent is appropriate and maintains the same functionality.

database/console/factory_make_command.go (1)

52-52: LGTM! Correctly replaced deprecated method.

The change from file.Create to file.PutContent is appropriate and maintains the same functionality.

http/console/request_make_command.go (1)

48-48: LGTM: Appropriate replacement of deprecated method.

The change from file.Create to file.PutContent is correctly implemented with proper error handling.

validation/console/filter_make_command.go (1)

49-49: LGTM: Consistent implementation of file handling update.

The replacement of file.Create with file.PutContent is properly implemented.

http/console/controller_make_command.go (2)

58-58: LGTM: Well-implemented file handling update.

The change from file.Create to file.PutContent is correctly implemented with proper error handling.


1-1:

Details

✅ Verification successful

Verify complete replacement of deprecated method.

Let's ensure all instances of file.Create have been replaced throughout the codebase.


🏁 Script executed:

#!/bin/bash
# Search for any remaining instances of file.Create
ast-grep --pattern 'file.Create($$$)'

Length of output: 39


Below is an additional verification step using rg (ripgrep) to ensure no instances of file.Create remain in the codebase. Please run this command and verify the output manually:

Once confirmed that no instances of file.Create appear, you can consider the deprecated method fully replaced.


🏁 Script executed:

#!/bin/bash
# Re-verify using ripgrep for any occurrences of file.Create (case-insensitive)
rg --ignore-case 'file\.Create' .

Length of output: 35


Replacement verified for deprecated method usage.

All instances of file.Create have been successfully replaced throughout the codebase. Both the AST-based search and the ripgrep verification confirmed that no references to file.Create remain.

foundation/console/package_make_command.go (1)

84-84: LGTM! Successfully replaced deprecated method.

The change from file.Create to file.PutContent is correctly implemented while maintaining the same error handling and functionality.

support/file/file_test.go (1)

24-24: LGTM! Test cases updated correctly.

The test cases have been properly updated to use PutContent instead of Create. The comprehensive test coverage in TestPutContent ensures the reliability of this change.

Also applies to: 54-54

console/console/key_generate_command_test.go (1)

33-33: LGTM! Test cases updated correctly.

The key generation test cases have been properly updated to use PutContent instead of Create. The test coverage remains comprehensive, including environment-specific behavior and error cases.

Also applies to: 76-76

translation/file_loader_test.go (1)

27-34: LGTM! Test setup updated correctly.

The translation file loader test setup has been properly updated to use PutContent instead of Create. The test coverage remains comprehensive, including various file types, permissions, and error cases.

support/docker/container.go (1)

160-160: LGTM: Successfully replaced deprecated method.

The change from file.Create to file.PutContent maintains the same functionality while using the updated API.

foundation/console/env_decrypt_command_test.go (2)

16-18: LGTM: Improved test data organization.

Moving test data to constants improves maintainability and reusability.

🧰 Tools
🪛 Gitleaks (8.21.2)

18-18: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)


29-31: LGTM: Successfully replaced deprecated method.

The change from file.Create to file.PutContent maintains the same functionality while using the updated API.

foundation/console/env_encrypt_command_test.go (2)

17-18: LGTM: Improved test data organization.

Moving test data to constants improves maintainability and reusability.


30-31: LGTM: Successfully replaced deprecated method.

The change from file.Create to file.PutContent maintains the same functionality while using the updated API.

support/console/console_test.go (2)

93-93: LGTM: Successfully replaced deprecated method.

The change from file.Create to file.PutContent maintains the same functionality while using the updated API.


103-103: LGTM: Successfully replaced deprecated method.

The change from file.Create to file.PutContent maintains the same functionality while using the updated API.

foundation/console/vendor_publish_command.go (1)

243-243: LGTM: Successfully replaced deprecated method.

The change from file.Create to file.PutContent aligns with the PR objective and maintains the existing error handling.

database/migration/migrator.go (1)

41-41: LGTM: Successfully replaced deprecated method.

The change from supportfile.Create to supportfile.PutContent is correctly implemented and maintains the existing error handling for migration file creation.

foundation/console/vendor_publish_command_test.go (3)

37-37: LGTM: Successfully updated test file creation.

Test setup correctly uses file.PutContent for creating test files in TestGetSourceFiles.

Also applies to: 39-39


67-67: LGTM: Successfully updated test file creation.

Test setup correctly uses file.PutContent for creating test files in TestGetSourceFilesForDir.

Also applies to: 69-69, 71-71, 73-73, 75-75


277-277: LGTM: Successfully updated test file creation.

Test setup correctly uses file.PutContent for creating test files in TestPublish.

Also applies to: 279-279, 281-281, 283-283

foundation/application_test.go (1)

47-47: LGTM: Successfully updated test environment file creation.

The change from file.Create to file.PutContent is correctly implemented for creating the test .env file.

log/logrus_writer_test.go (1)

609-609: LGTM! The change from file.Create to file.PutContent is appropriate.

The replacement aligns with the PR objective to update deprecated method calls, and the implementation maintains proper error handling.

Comment on lines +49 to 51
if err := file.PutContent(m.GetFilePath(), r.populateStub(r.getStub(), m.GetPackageName(), m.GetStructName())); err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Maintain consistent error handling across commands.

Other command handlers log errors using ctx.Error() before returning. Consider updating the error handling to match:

 if err := file.PutContent(m.GetFilePath(), r.populateStub(r.getStub(), m.GetPackageName(), m.GetStructName())); err != nil {
-    return err
+    ctx.Error(err.Error())
+    return nil
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if err := file.PutContent(m.GetFilePath(), r.populateStub(r.getStub(), m.GetPackageName(), m.GetStructName())); err != nil {
return err
}
if err := file.PutContent(m.GetFilePath(), r.populateStub(r.getStub(), m.GetPackageName(), m.GetStructName())); err != nil {
ctx.Error(err.Error())
return nil
}

Copy link
Contributor

@hwbrzzl hwbrzzl left a comment

Choose a reason for hiding this comment

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

Thanks!

@hwbrzzl hwbrzzl merged commit f9d26fb into goravel:master Feb 21, 2025
13 of 15 checks passed
@kuafuRace kuafuRace deleted the replace-fileCreate branch February 23, 2025 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants