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

chore: making autocommit GA #36347

Open
wants to merge 12 commits into
base: release
Choose a base branch
from
Open

chore: making autocommit GA #36347

wants to merge 12 commits into from

Conversation

sondermanish
Copy link
Contributor

@sondermanish sondermanish commented Sep 16, 2024

Description

  • Removal of release_git_autocommit_feature_enabled flag
  • Removal of fallback implementation to classes which was autocommit flag annotated
  • Removal of irrelevant test cases post removal of fallback implementation.

Fixes #Issue Number
or
Fixes Issue URL

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags="@tag.Git"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/10959883470
Commit: d370a43
Cypress dashboard.
Tags: @tag.Git
Spec:


Fri, 20 Sep 2024 13:40:21 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced file operations for resource management in Git, including methods for saving, deleting, and reading resources.
    • Streamlined handling of auto-commit functionalities, making certain features universally accessible.
  • Bug Fixes

    • Removed outdated fallback implementations for auto-commit eligibility and Git auto-commit helpers.
  • Refactor

    • Simplified constructors and dependencies in file operation classes, improving maintainability.
    • Eliminated feature flag dependencies from various components, including tests, focusing on core functionality.
  • Tests

    • Removed tests related to feature flags, streamlining the testing process for auto-commit and migration functionalities.

@sondermanish sondermanish self-assigned this Sep 16, 2024
@sondermanish sondermanish requested a review from a team as a code owner September 16, 2024 11:39
Copy link
Contributor

coderabbitai bot commented Sep 16, 2024

Walkthrough

This pull request encompasses significant refactoring and removal of various classes and methods related to file operations and auto-commit functionality within a Git context. Key changes include the deletion of the FileOperationsCEImpl class, modifications to the FileOperationsCEv2Impl class, and the removal of feature flag dependencies in several test classes. The overall structure aims to streamline file management and enhance the clarity of resource handling while simplifying the testing framework.

Changes

File Path Change Summary
app/server/appsmith-git/src/main/java/com/appsmith/git/files/operations/FileOperationsCEImpl.java Deleted the FileOperationsCEImpl class, which handled various file operations related to Git.
app/server/appsmith-git/src/main/java/com/appsmith/git/files/operations/FileOperationsCEv2Impl.java Modified the FileOperationsCEv2Impl class to enhance file operations and removed dependencies on previous implementations. Added new methods for resource management and removed feature flag annotations from several methods.
app/server/appsmith-git/src/main/java/com/appsmith/git/files/operations/FileOperationsImpl.java Simplified the constructor of the FileOperationsImpl class by reducing the number of parameters, enhancing maintainability.
app/server/appsmith-server/src/test/java/com/appsmith/server/git/ServerSchemaMigrationEnforcerTest.java Removed tests and the FeatureFlagService dependency, simplifying the test setup.
app/server/appsmith-server/src/test/java/com/appsmith/server/migrations/JsonSchemaVersionsTest.java Removed feature flag-related logic from tests, focusing on direct assertions.
app/server/appsmith-interfaces/src/main/java/com/appsmith/external/enums/FeatureFlagEnum.java Removed two feature flags related to Git autocommit, indicating a shift in feature management strategy.

Possibly related PRs

Suggested labels

Bug, Task, Integrations Product

Poem

In the land of code where changes flow,
Files and flags, they come and go.
With cleaner paths and tests so bright,
Git operations now feel just right!
A refactor here, a tweak with care,
Simplifying tasks, a breath of fresh air! 🌟


Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d2fa027 and d370a43.

Files selected for processing (1)
  • app/client/cypress/e2e/Regression/ClientSide/Git/GitAutocommit_spec.ts (0 hunks)
Files not reviewed due to no reviewable changes (1)
  • app/client/cypress/e2e/Regression/ClientSide/Git/GitAutocommit_spec.ts

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.

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.

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Sep 16, 2024
@@ -290,51 +279,6 @@ private void removeCustomJsLibsEntries(JsonObject applicationObjectNode) {
}
}

@Test
public void savedFile_reSavedWithDifferentSerialisationLogic_diffOccurs()
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we instead change these tests for positives on auto-commits?

@Autowired
JsonSchemaVersions jsonSchemaVersions;

@Autowired
JsonSchemaVersionsFallback jsonSchemaVersionsFallback;

@Disabled
Copy link
Contributor

Choose a reason for hiding this comment

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

Deletion instead here?

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

Outside diff range and nitpick comments (1)
app/server/appsmith-server/src/test/java/com/appsmith/server/migrations/JsonSchemaVersionsTest.java (1)

Line range hint 29-33: Let's give this test method a more accurate name!

I noticed that you've updated the getServerVersion_whenFeatureFlagIsOn_returnsIncremented test method to directly compare the versions from jsonSchemaVersions and jsonSchemaVersionsFallback, without any feature flag checks. That's like saying, "Let's skip the flag and get straight to the point!"

However, the current test method name doesn't quite match the updated behavior. Consider renaming it to something like getServerVersion_returnsExpectedValue or getServerVersion_matchesFallbackValue to better reflect what the test is actually asserting.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4dcec5f and eb7f1b1.

Files selected for processing (16)
  • app/server/appsmith-git/src/main/java/com/appsmith/git/files/operations/FileOperationsCEImpl.java (0 hunks)
  • app/server/appsmith-git/src/main/java/com/appsmith/git/files/operations/FileOperationsCEv2Impl.java (3 hunks)
  • app/server/appsmith-git/src/main/java/com/appsmith/git/files/operations/FileOperationsImpl.java (1 hunks)
  • app/server/appsmith-git/src/test/java/com/appsmith/git/helpers/FileUtilsImplTest.java (1 hunks)
  • app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/operations/FileOperationsCE.java (0 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/AutoCommitEligibilityHelperFallbackImpl.java (0 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/AutoCommitEligibilityHelperImpl.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/GitAutoCommitHelperFallbackImpl.java (0 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/GitAutoCommitHelperImpl.java (1 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/git/ServerSchemaMigrationEnforcerTest.java (0 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitEventHandlerImplTest.java (0 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitServiceTest.java (0 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/helpers/AutoCommitEligibilityHelperTest.java (0 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/helpers/GitAutoCommitHelperImplTest.java (0 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/migrations/JsonSchemaMigrationTest.java (0 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/migrations/JsonSchemaVersionsTest.java (1 hunks)
Files not reviewed due to no reviewable changes (10)
  • app/server/appsmith-git/src/main/java/com/appsmith/git/files/operations/FileOperationsCEImpl.java
  • app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/operations/FileOperationsCE.java
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/AutoCommitEligibilityHelperFallbackImpl.java
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/GitAutoCommitHelperFallbackImpl.java
  • app/server/appsmith-server/src/test/java/com/appsmith/server/git/ServerSchemaMigrationEnforcerTest.java
  • app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitEventHandlerImplTest.java
  • app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitServiceTest.java
  • app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/helpers/AutoCommitEligibilityHelperTest.java
  • app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/helpers/GitAutoCommitHelperImplTest.java
  • app/server/appsmith-server/src/test/java/com/appsmith/server/migrations/JsonSchemaMigrationTest.java
Additional comments not posted (15)
app/server/appsmith-server/src/test/java/com/appsmith/server/migrations/JsonSchemaVersionsTest.java (2)

4-4: Good job importing the @Disabled annotation!

The @Disabled annotation is a handy tool for temporarily disabling test methods or classes. It's like telling the test runner, "Hey, skip this one for now!" Keep up the great work!


21-21: Let's double-check why we're disabling this test method.

I see that you've used the @Disabled annotation to skip the getServerVersion_whenFeatureFlagIsOff_returnsFallbackValue test method. It's like telling the test, "Take a break, buddy!"

However, it's important to understand the reason behind disabling tests. Can you please verify if this test method is no longer needed due to the removal of feature flag-related logic? If so, consider removing the test method altogether instead of leaving it disabled.

app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/AutoCommitEligibilityHelperImpl.java (1)

28-28: Excellent work on refactoring the class to remove the fallback implementation! 🎉

By directly implementing the AutoCommitEligibilityHelper interface without extending AutoCommitEligibilityHelperFallbackImpl, you've taken a step towards a more focused and maintainable implementation. This change suggests a shift in how the class handles its responsibilities, potentially leading to a more streamlined approach.

However, it's important to consider the following:

  • Ensure that the class no longer relies on any inherited methods or properties from the removed superclass.
  • Reevaluate the class's functionality and interactions with other components to maintain proper behavior.
  • Conduct thorough testing to verify that the class still functions as expected without the fallback implementation.

Keep up the great work in simplifying the codebase and improving maintainability! 👨‍🏫👩‍🏫

app/server/appsmith-git/src/test/java/com/appsmith/git/helpers/FileUtilsImplTest.java (1)

44-44: Verify the impact of the constructor changes on the test behavior.

Class, the constructor of FileOperationsImpl has been modified to remove parameters related to gitServiceConfig, gitExecutor, and GsonBuilder. Instead, it now accepts null and ObservationHelper.NOOP as arguments.

While this simplification might improve the readability and maintainability of the test code, it's crucial to ensure that the removed parameters were not critical for the test setup. Passing null and ObservationHelper.NOOP could potentially affect the behavior of the tests if those parameters were previously utilized.

Please run the following script to verify the impact of the changes on the test behavior:

If the tests pass without any issues, the changes can be considered safe. However, if the tests fail or exhibit unexpected behavior, it might be necessary to revisit the constructor changes and ensure that the required dependencies are properly handled.

To improve the code further, consider adding comments explaining the rationale behind passing null and ObservationHelper.NOOP to the constructor. This will help future maintainers understand the purpose of these arguments and the impact of the changes.

Verification successful

Class, it appears we've encountered a small hiccup in our verification process. The sandbox environment doesn't have Maven installed, so we'll need to take a different approach. Let's examine the codebase more closely using some static analysis techniques. Pay attention now, as we're going to run a few commands to gather more information:

These commands will help us understand how the FileOperationsImpl is being used in our tests and if there are any other similar changes. Let's see what we can learn from this, shall we?


Alright, class, let's review what we've learned from our code investigation! It appears that our changes to the FileOperationsImpl constructor are consistent throughout the codebase. This is excellent news!

The constructor changes are verified and align with the codebase.

Let's break it down:

  1. The FileOperationsImpl class in the main code now has a simplified constructor that takes two parameters: PrettyPrinter and ObservationHelper. This is a good simplification, removing unnecessary dependencies.

  2. Our test file, FileUtilsImplTest.java, correctly uses this new constructor by passing null for PrettyPrinter and ObservationHelper.NOOP for ObservationHelper.

  3. The removal of gitServiceConfig, gitExecutor, and GsonBuilder from the constructor is consistent and doesn't appear to cause any issues in the codebase.

However, class, I have a small suggestion to improve our code:

  • In the test file, we're passing null for the PrettyPrinter. While this works, it might be beneficial to add a comment explaining why we're using null here. This will help future students... I mean, developers, understand the reasoning behind this choice.

Overall, great job on simplifying the code! The changes appear to be safe and improve the maintainability of our project. Keep up the good work!

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of the constructor changes on the test behavior.

# Test: Run the tests and check for any failures or errors.
mvn test -Dtest=FileUtilsImplTest

Length of output: 106


Script:

#!/bin/bash
# Search for usage of FileOperationsImpl in test files
echo "Searching for FileOperationsImpl usage in test files:"
rg "new FileOperationsImpl\(" --type java --glob "*Test.java" -C 2

echo "\nChecking for similar constructor changes in FileOperationsImpl:"
rg "FileOperationsImpl\([^)]*\)" --type java -C 2

echo "\nExamining the FileOperationsImpl class:"
fd FileOperationsImpl.java --exec cat {}

Length of output: 3570

app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/GitAutoCommitHelperImpl.java (1)

29-29: Excellent work removing the @Primary annotation!

Removing this annotation aligns perfectly with the goal of making the autocommit feature generally available. It's clear you've put thought into streamlining the codebase. Keep up the great work!

app/server/appsmith-git/src/main/java/com/appsmith/git/files/operations/FileOperationsCEv2Impl.java (10)

Line range hint 64-72: Excellent work simplifying the constructor!

The refactored constructor streamlines the initialization process by removing unnecessary dependencies. The usage of SerializationUtils.getBasicObjectMapper(prettyPrinter) to initialize the objectMapper is a cleaner approach. Well done!


196-206: Great job implementing the saveResource method!

The method nicely encapsulates the logic for saving a resource to a file. It takes care of creating the necessary directories and handles any exceptions that may occur during the write operation. The boolean return value provides a clear indication of the operation's success. Keep up the good work!


215-229: Excellent implementation of the scanAndDeleteFileForDeletedResources method!

The method efficiently scans the resource directory and deletes files that no longer have a corresponding valid resource. The use of Files.walk to stream the paths and the filtering logic to identify files to be deleted is well-structured. The error handling and logging ensure that any issues during the directory scan are properly captured. Great work!


238-252: Great job implementing the scanAndDeleteDirectoryForDeletedResources method!

The method effectively scans the resource directory and deletes directories that no longer have a corresponding valid resource. The use of Files.walk with a depth of 1 ensures that only the immediate subdirectories are considered. The filtering logic correctly identifies the directories to be deleted, excluding the resource directory itself. The error handling and logging provide visibility into any issues that may occur during the directory scan. Well done!


259-268: Excellent implementation of the deleteDirectory method!

The method provides a convenient way to delete a directory and its contents. The check for the directory's existence before attempting to delete it is a good practice. The use of FileUtils.deleteDirectory from the Apache Commons IO library simplifies the deletion process and handles the recursive deletion of subdirectories and files. The error handling and logging ensure that any issues during the deletion are properly captured. Great work!


275-284: Great job implementing the deleteFile method!

The method provides a straightforward way to delete a file. The use of Files.deleteIfExists is a good choice as it avoids throwing an exception if the file doesn't exist. The error handling for DirectoryNotEmptyException and IOException ensures that any issues during the file deletion are properly logged. The specific error messages provide clarity on the nature of the problem. Well done!


292-305: Excellent implementation of the readFileAsString method!

The method provides a convenient way to read the content of a file as a plain text string. The use of FileUtils.readFileToString from the Apache Commons IO library simplifies the file reading process. The inclusion of observability using observationHelper.createSpan is a good practice for monitoring and tracing. The error handling and logging ensure that any issues during the file read are properly captured. Returning an empty string in case of an error is a safe fallback. Great work!


307-328: Great job implementing the deleteIndexLockFile method!

The method provides a useful functionality to delete the index lock file if it's stale. The logic to check the creation time of the lock file against the specified valid time is well-implemented. Appending ".lock" to the file path before deletion ensures that the correct file is targeted. Returning a Mono with the time difference or 0 provides flexibility for reactive programming. The error handling and logging for IOException ensure that any issues during the attribute reading are properly captured. Well done!


Line range hint 75-80: Excellent refactoring of the saveMetadataResource method!

The removal of the @FeatureFlagged annotation indicates that the feature is now always enabled, simplifying the code. Converting the metadata to an ObjectNode and adding the FILE_FORMAT_VERSION ensures consistency. Calling the saveResource method to save the metadata resource promotes code reuse and maintainability. Great work!


Line range hint 83-98: Good job updating the saveWidgets method!

The removal of the @FeatureFlagged annotation indicates that the feature is now always enabled, simplifying the code. The rest of the method implementation remains unchanged, which is fine since it already handles the saving of widgets correctly. Keep up the good work!

Comment on lines +15 to +16
public FileOperationsImpl(PrettyPrinter prettyPrinter, ObservationHelper observationHelper) {
super(prettyPrinter, observationHelper);
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Alright, class! 📚 Let's review what we've learned from our code investigation. 🧑‍🏫

Pop quiz: Unnecessary import alert! 🚨

Our detective work has revealed that while we've successfully simplified our constructor, we've left behind a small clue that needs our attention. Can anyone spot it? That's right! The GitServiceConfig import and @Import annotation are still lingering in our FileOperationsImpl class, even though they're no longer needed.

Let's clean up our code to make it sparkle! ✨ Here's your homework assignment:

  1. Remove the unnecessary import statement for GitServiceConfig.
  2. Erase the @Import({GitServiceConfig.class}) annotation from the class.

Remember, class, keeping our code clean and tidy is just as important as making it work! 🧹🧼

Now, for some good news! 🎉 The removal of GitExecutor and GsonBuilder from the constructor appears to have been a success. We couldn't find any traces of them in the parent class or other parts of the codebase. Great job on simplifying our dependencies!

However, we must always be thorough in our work. So, here's an extra credit assignment:

  1. Conduct comprehensive tests on the FileOperationsImpl class to ensure we haven't accidentally removed any important functionality.

Keep up the excellent work, students! You're all on your way to becoming top-notch code detectives! 🕵️‍♀️🕵️‍♂️

Analysis chain

Excellent work on refactoring the constructor to reduce dependencies! 👏

The changes to the constructor signature indicate a conscious effort to minimize the coupling between the FileOperationsImpl class and other components. This is a step in the right direction towards improving the maintainability and testability of the codebase. 🎉

However, it's crucial to ensure that the removal of the GitServiceConfig, GitExecutor, and GsonBuilder dependencies does not adversely impact the functionality of the class or introduce runtime exceptions. 🔍

To verify the impact of the dependency removal, please run the following script:

Please share the results of the verification script so that we can assess the impact of the changes and ensure that the class continues to function as expected. 📊

Keep up the great work! 🌟


Class, let's continue our investigation! 🧑‍🏫📚 We've made some interesting discoveries, but we need to dig a little deeper to fully understand the impact of our changes. Let's run another set of tests to gather more information.

Now, students, let's see what these new tests reveal about our code changes! 🔍🧐

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of the dependency removal on the class functionality and the codebase.

# Test 1: Search for the usage of the removed dependencies in the class. Expect: No occurrences.
rg --type java -A 5 $'GitServiceConfig|GitExecutor|GsonBuilder' app/server/appsmith-git/src/main/java/com/appsmith/git/files/operations/FileOperationsImpl.java

# Test 2: Search for the usage of the `FileOperationsImpl` constructor in the codebase. Expect: All occurrences to match the new signature.
rg --type java -A 5 $'new FileOperationsImpl' app/server/appsmith-git/

Length of output: 1551


Script:

#!/bin/bash
# Description: Further investigate the usage of GitServiceConfig and the impact of removed dependencies

# Test 1: Check for methods using GitServiceConfig in FileOperationsImpl
ast-grep --lang java --pattern 'class FileOperationsImpl {
  $$$
  $_(GitServiceConfig $_) {
    $$$
  }
  $$$
}' app/server/appsmith-git/src/main/java/com/appsmith/git/files/operations/FileOperationsImpl.java

# Test 2: Search for GitExecutor and GsonBuilder usage in the parent class
rg --type java -A 5 'GitExecutor|GsonBuilder' app/server/appsmith-git/src/main/java/com/appsmith/git/files/operations/FileOperationsCEv2Impl.java

# Test 3: Check for other classes that might be affected by the changes
rg --type java -A 5 'extends FileOperationsCEv2Impl|implements FileOperations' app/server/appsmith-git/

Length of output: 2003

Copy link
Contributor

@nidhi-nair nidhi-nair left a comment

Choose a reason for hiding this comment

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

Thanks for the extra clean up you've done wherever required. Could you please associate those tests to auto-commit where applicable instead of straight up removing them? We can templatize them at a later point and refactor, but we shouldn't get rid of the behaviour check entirely, especially in the abence of server enforcer.

Copy link
Contributor

@nidhi-nair nidhi-nair left a comment

Choose a reason for hiding this comment

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

@sondermanish there's changes required on this PR, removing the review request for now.

@brayn003
Copy link
Contributor

brayn003 commented Sep 17, 2024

Let's remove feature flag mention in these files too?

@brayn003 brayn003 added the ok-to-test Required label for CI label Sep 17, 2024
@brayn003
Copy link
Contributor

There is an issue here. Autocommit is not coming up to be enabled by default

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

Outside diff range and nitpick comments (7)
app/server/appsmith-git/src/main/java/com/appsmith/git/files/operations/FileOperationsCEv2Impl.java (7)

193-203: Great job implementing the saveResource method!

The method has a clear purpose and is well-structured. It creates parent directories if they don't exist and calls writeToFile to write the object. The IOException is handled appropriately.

Consider extracting the error logging logic to a separate method for better reusability. For example:

private void logError(String message, Path path, Exception e) {
    log.error(message, path, e.getMessage());
    log.debug(e.getMessage());
}

Then, you can call this method in the catch block:

} catch (IOException e) {
    logError("Error while writing resource to file {} with {}", path, e);
}

This way, you can reuse the error logging logic in other methods as well.


212-226: Nicely done implementing the scanAndDeleteFileForDeletedResources method!

The method effectively scans the directory and deletes unwanted files using the deleteFile method. The IOException is handled appropriately.

To avoid potential NullPointerException, consider adding a null check for the validResources set at the beginning of the method:

public void scanAndDeleteFileForDeletedResources(Set<String> validResources, Path resourceDirectory) {
    if (validResources == null) {
        throw new IllegalArgumentException("validResources cannot be null");
    }
    // rest of the method
}

This way, you can ensure that the validResources set is not null before using it in the filter condition.


235-249: Well done implementing the scanAndDeleteDirectoryForDeletedResources method!

The method effectively scans the directory and deletes unwanted subdirectories using the deleteDirectory method. The IOException is handled appropriately.

Similar to the previous suggestion, consider adding a null check for the validResources set at the beginning of the method:

public void scanAndDeleteDirectoryForDeletedResources(Set<String> validResources, Path resourceDirectory) {
    if (validResources == null) {
        throw new IllegalArgumentException("validResources cannot be null");
    }
    // rest of the method
}

This way, you can ensure that the validResources set is not null before using it in the filter condition.


256-265: Good job implementing the deleteDirectory method!

The method effectively deletes the directory and its contents using the FileUtils.deleteDirectory method from Apache Commons IO library. The IOException is handled appropriately.

To avoid potential NullPointerException, consider adding a null check for the directory parameter at the beginning of the method:

public void deleteDirectory(Path directory) {
    if (directory == null) {
        throw new IllegalArgumentException("directory cannot be null");
    }
    // rest of the method
}

This way, you can ensure that the directory parameter is not null before using it.


272-281: Nice implementation of the deleteFile method!

The method effectively deletes the file using the Files.deleteIfExists method. It handles the DirectoryNotEmptyException and IOException appropriately and logs error messages.

To avoid potential NullPointerException, consider adding a null check for the filePath parameter at the beginning of the method:

public void deleteFile(Path filePath) {
    if (filePath == null) {
        throw new IllegalArgumentException("filePath cannot be null");
    }
    // rest of the method
}

This way, you can ensure that the filePath parameter is not null before using it.


289-302: Great work implementing the readFileAsString method!

The method effectively reads the file content as a string using the FileUtils.readFileToString method from Apache Commons IO library. It handles the IOException appropriately and logs an error message.

To avoid potential NullPointerException, consider adding a null check for the filePath parameter at the beginning of the method:

public String readFileAsString(Path filePath) {
    if (filePath == null) {
        throw new IllegalArgumentException("filePath cannot be null");
    }
    // rest of the method
}

This way, you can ensure that the filePath parameter is not null before using it.


304-325: Excellent implementation of the deleteIndexLockFile method!

The method effectively checks the file creation time and deletes the file if it's older than the specified time using the deleteFile method. It returns a Mono of the time difference in seconds if the file is deleted, or a Mono of 0 otherwise. The IOException is handled appropriately and an error message is logged.

To improve readability, consider extracting the file path concatenation logic to a separate method. For example:

private Path getIndexLockFilePath(Path path) {
    return Paths.get(path + ".lock");
}

Then, you can use this method in the deleteIndexLockFile method:

Path lockFilePath = getIndexLockFilePath(path);
deleteFile(lockFilePath);

This way, the file path concatenation logic is encapsulated in a separate method, making the code more readable.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 77a8962 and 2ce9b84.

Files selected for processing (4)
  • app/server/appsmith-git/src/main/java/com/appsmith/git/files/operations/FileOperationsCEv2Impl.java (3 hunks)
  • app/server/appsmith-git/src/main/java/com/appsmith/git/files/operations/FileOperationsImpl.java (1 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/git/ServerSchemaMigrationEnforcerTest.java (5 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/migrations/JsonSchemaVersionsTest.java (0 hunks)
Files not reviewed due to no reviewable changes (1)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/migrations/JsonSchemaVersionsTest.java
Files skipped from review as they are similar to previous changes (1)
  • app/server/appsmith-git/src/main/java/com/appsmith/git/files/operations/FileOperationsImpl.java
Additional comments not posted (10)
app/server/appsmith-git/src/main/java/com/appsmith/git/files/operations/FileOperationsCEv2Impl.java (5)

Line range hint 61-69: Excellent work simplifying the constructor!

The removal of unused dependencies like GitServiceConfig, GitExecutor, and GsonBuilder streamlines the initialization process. The remaining dependencies PrettyPrinter and ObservationHelper are being utilized effectively.


Line range hint 72-77: Nice refactoring of the saveMetadataResource method!

The removal of the @FeatureFlagged annotation suggests that the feature is now always enabled, which simplifies the code.

Calling the saveResource method is a good refactoring as it reuses the common functionality of saving a resource to a file.


Line range hint 80-97: Good removal of the @FeatureFlagged annotation from the saveWidgets method!

The removal of the @FeatureFlagged annotation suggests that the feature is now always enabled, which simplifies the code.

The rest of the method implementation remains the same, so no further changes are needed.


Line range hint 100-115: Nice removal of the @FeatureFlagged annotation from the writeToFile method!

The removal of the @FeatureFlagged annotation suggests that the feature is now always enabled, which simplifies the code.

The rest of the method implementation remains the same, so no further changes are needed.


Line range hint 124-141: Good job removing the @FeatureFlagged annotation from the readFile method!

The removal of the @FeatureFlagged annotation suggests that the feature is now always enabled, which simplifies the code.

The rest of the method implementation remains the same, so no further changes are needed.

app/server/appsmith-server/src/test/java/com/appsmith/server/git/ServerSchemaMigrationEnforcerTest.java (5)

43-43: Good work! The import statement looks correct.

The ApplicationEventPublisher import is necessary for the new test case.


123-125: Excellent! The dependency injections are set up correctly.

The new mocked and spied dependencies are properly annotated and will be useful for the new test case. Keep up the good work!

Also applies to: 128-133, 137-138, 141-144


Line range hint 294-294: Past review comment resolved: The test case has been removed as suggested.

The removal of the savedFile_reSavedWithDifferentSerialisationLogic_diffOccurs test case is appropriate since it is no longer relevant. The past review comment has been addressed satisfactorily.


399-452: Fantastic work on adding the new test case!

The autocommitMigration_WhenServerVersionIsBehindDiffOccursAnd_CommitSuccess test case is a valuable addition to the test suite. It thoroughly verifies the auto-commit functionality during server migration and ensures that commits are successful when the server version is behind.

The test case is well-structured, properly sets up the test environment, mocks necessary dependencies, and makes clear assertions on the expected behavior. This enhances the overall test coverage and helps maintain the reliability of the auto-commit feature.

Great job on this test case! Keep up the excellent work in ensuring the robustness of our codebase.


454-467: Nice work on adding the createEvent helper method!

The createEvent method is a great addition to the test class. It encapsulates the creation logic for the AutoCommitEvent object and provides default values for the test case.

By extracting this logic into a separate method, you have improved the code readability and maintainability. The method is properly scoped as private and returns the expected AutoCommitEvent object, making it easy to use in the test case.

This is a good practice to follow when creating test data. Keep up the great work in writing clean and maintainable test code!

@brayn003 brayn003 removed ok-to-test Required label for CI labels Sep 18, 2024
@brayn003 brayn003 added ok-to-test Required label for CI labels Sep 18, 2024
@sondermanish
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/10939532673.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 36347.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-36347.dp.appsmith.com

@sondermanish sondermanish added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Sep 20, 2024
Copy link

Failed server tests

  • com.appsmith.server.imports.internal.ImportServiceTests#importArtifactFromInvalidJsonFileWithoutArtifactTest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants