Skip to content

feat: Git modularisation backend structure#37843

Merged
sondermanish merged 1 commit intoreleasefrom
feat/super-git
Nov 29, 2024
Merged

feat: Git modularisation backend structure#37843
sondermanish merged 1 commit intoreleasefrom
feat/super-git

Conversation

@sondermanish
Copy link
Contributor

@sondermanish sondermanish commented Nov 29, 2024

Description

  • Added structure for git modularisation

Fixes #37434 #37435

No CI is required as the code is not exposed/ connected to existing code

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/12080532772
Commit: 0c251dd
Cypress dashboard.
Tags: @tag.Git
Spec:


Fri, 29 Nov 2024 08:03:23 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Introduced Git handling capabilities, including committing changes, managing repositories, and handling branches.
    • Added support for managing Git user profiles and permissions related to artifact creation.
    • Enhanced artifact management with new methods for creating and retrieving artifacts based on workspace and repository details.
  • Bug Fixes

    • Improved error handling and validation for Git operations, ensuring robust interaction with remote repositories.
  • Documentation

    • Updated documentation to reflect new methods and functionalities related to Git operations and artifact management.

@sondermanish sondermanish requested a review from a team as a code owner November 29, 2024 07:11
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 29, 2024

Walkthrough

The pull request introduces several new classes, interfaces, and methods to enhance Git functionality within the application. Key additions include CommitDTO and GitUser for encapsulating commit details and user information, respectively. The FSGitHandler interface and its implementations provide a comprehensive set of Git operations, while new utility classes facilitate Git profile management and analytics tracking. Additionally, several methods for artifact handling and permission management are introduced, supporting the overarching goal of creating a unified Git service across different implementations.

Changes

File Change Summary
app/server/appsmith-git/src/main/java/com/appsmith/git/dto/CommitDTO.java Added CommitDTO class with fields for commit details.
app/server/appsmith-git/src/main/java/com/appsmith/git/dto/GitUser.java Added GitUser class to represent a Git user with attributes like name and email.
app/server/appsmith-git/src/main/java/com/appsmith/git/handler/FSGitHandlerImpl.java Introduced FSGitHandlerImpl class implementing Git operations.
app/server/appsmith-git/src/main/java/com/appsmith/git/handler/ce/FSGitHandlerCEImpl.java Added FSGitHandlerCEImpl class with methods for Git operations in a repository.
app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/handler/FSGitHandler.java Introduced FSGitHandler interface defining Git operation methods.
app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/GitApplicationHelperCEImpl.java Added methods for workspace artifact permissions and new artifact creation.
app/server/appsmith-server/src/main/java/com/appsmith/server/constants/ce/RefType.java Introduced RefType enum for reference types.
app/server/appsmith-server/src/main/java/com/appsmith/server/domains/ce/GitArtifactMetadataCE.java Changed visibility of setDefaultArtifactId method from private to public.
app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ApplicationImportDTO.java Overridden methods for artifact handling in ApplicationImportDTO.
app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ArtifactImportDTO.java Added abstract methods for artifact handling in ArtifactImportDTO.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitService.java Introduced CentralGitService interface for Git operations.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCE.java Added methods for artifact import and connection in CentralGitServiceCE.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCECompatible.java Introduced CentralGitServiceCECompatible interface extending existing functionality.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCECompatibleImpl.java Added implementation for CentralGitServiceCECompatible.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java Implemented CentralGitServiceCE for managing Git operations.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/GitHandlingService.java Introduced GitHandlingService interface for Git operations.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/GitHandlingServiceCE.java Added methods for Git connection and repository management.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/GitHandlingServiceCECompatible.java Introduced GitHandlingServiceCECompatible interface extending existing functionality.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/GitType.java Added GitType enum for categorizing Git configurations.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/dtos/ArtifactJsonTransformationDTO.java Introduced ArtifactJsonTransformationDTO for managing JSON transformations in Git.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCECompatibleImpl.java Added implementation for handling Git file system operations.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCEImpl.java Implemented GitHandlingServiceCE for Git operations.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceImpl.java Introduced GitFSServiceImpl for handling Git file system operations.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/resolver/GitArtifactHelperResolver.java Added GitArtifactHelperResolver for resolving Git artifact helpers.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/resolver/GitArtifactHelperResolverCE.java Introduced GitArtifactHelperResolverCE for managing Git artifacts.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/resolver/GitHandlingServiceResolver.java Added GitHandlingServiceResolver for resolving Git handling services.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/resolver/GitHandlingServiceResolverCE.java Introduced GitHandlingServiceResolverCE for managing Git handling services.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/utils/GitAnalyticsUtils.java Added GitAnalyticsUtils for handling Git operation analytics.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/utils/GitProfileUtils.java Introduced GitProfileUtils for managing user Git profiles.
app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitArtifactHelperCE.java Added methods for artifact permissions and creation in GitArtifactHelperCE.

Assessment against linked issues

Objective Addressed Explanation
Create a super service for common Git service across FS and native implementations (#37421)

Suggested labels

Backend, Git Product, Git Platform Pod, Inviting Contribution

Suggested reviewers

  • nidhi-nair
  • ApekshaBhosale
  • sagar-qa007

"In the land of code where Git flows free,
New classes and methods, oh what a spree!
CommitDTO and GitUser join the fray,
With FSGitHandler leading the way.
Permissions and profiles, all neatly aligned,
A Git service super, so well-defined!" 🎉


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 Epic A zenhub epic that describes a project Git Product Issues related to version control product Packages & Git Pod All issues belonging to Packages and Git labels Nov 29, 2024
@sondermanish sondermanish self-assigned this Nov 29, 2024
@sondermanish sondermanish added the ok-to-test Required label for CI label Nov 29, 2024
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: 22

🧹 Outside diff range and nitpick comments (47)
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/GitHandlingServiceCE.java (5)

16-16: Consider making validateGitConnectDTO reactive

The method validateGitConnectDTO currently returns Set<String> synchronously. For consistency with the reactive programming paradigm used elsewhere in the interface, consider returning Mono<Set<String>>.

Apply this diff to update the return type:

- Set<String> validateGitConnectDTO(GitConnectDTO gitConnectDTO);
+ Mono<Set<String>> validateGitConnectDTO(GitConnectDTO gitConnectDTO);

18-18: Consider making getRepoName reactive

getRepoName returns a String synchronously. To maintain consistency and accommodate potential asynchronous operations, consider returning Mono<String>.

Apply this diff to update the return type:

- String getRepoName(GitConnectDTO gitConnectDTO);
+ Mono<String> getRepoName(GitConnectDTO gitConnectDTO);

22-23: Address the TODO: Modify GitAuth class for native implementation

There's a TODO comment indicating pending changes to the GitAuth class. Please ensure this is addressed before merging.

Would you like assistance in implementing the modifications to the GitAuth class?


40-44: Standardize method name spelling

The method initialiseReadMe uses British English spelling. To maintain consistency across the codebase, consider renaming it to initializeReadMe.

Apply this diff to rename the method:

- Mono<Boolean> initialiseReadMe(
+ Mono<Boolean> initializeReadMe(

40-44: Consider reducing parameter list by using a DTO

initializeReadMe has multiple parameters. Encapsulating these into a single DTO can enhance readability and maintainability.

app/server/appsmith-server/src/main/java/com/appsmith/server/git/utils/GitAnalyticsUtils.java (2)

30-74: Consider simplifying overloaded methods

The multiple overloaded addAnalyticsForGitOperation methods could be streamlined by using a builder pattern or a parameter object to encapsulate parameters. This will enhance maintainability and readability.


88-89: Avoid duplicating keys in analyticsProps

Both FieldName.APPLICATION_ID and "appId" (also FieldName.ORGANIZATION_ID and "orgId") are used with the same values. Consider using a single key to prevent redundancy.

Also applies to: 108-111

app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/handler/FSGitHandler.java (5)

15-17: Update Javadoc to correctly reference the interface

The comment refers to "This class" but should be "This interface" since FSGitHandler is an interface.

Apply this diff to correct the comment:

 /**
- * This class is a replica of gitExecutor, the methods would be re-evaluated as we will enter the git epic domain
+ * This interface is a replica of GitExecutor; the methods will be re-evaluated as we enter the Git epic domain
  */

20-29: Complete Javadoc by documenting all parameters

The method commitArtifact has parameters like isSuffixedPath and doAmend that are not described in the Javadoc. Please add descriptions for all parameters to enhance clarity.

Apply this diff to update the Javadoc:

     /**
      * This method will handle the git-commit functionality. Under the hood it checks if the repo has already been
      * initialised
      * @param repoPath      parent path to repo
      * @param commitMessage message which will be registered for this commit
      * @param authorName    author details
      * @param authorEmail   author details
+     * @param isSuffixedPath indicates if the provided path is suffixed
+     * @param doAmend       flag to specify if the commit should amend the previous one
      * @return if the commit was successful
      */

45-50: Include @throws in Javadoc for exceptions

The method createNewRepository throws GitAPIException, but the Javadoc lacks an @throws tag. Please include it to specify the exceptions that may be thrown.

Apply this diff to update the Javadoc:

     /**
      * Method to create a new repository to provided path
      * @param repoPath path where new repo needs to be created
+     * @throws GitAPIException if an error occurs during repository creation
      * @return if the operation was successful
      */

101-109: Document exceptions thrown by methods

The method pullApplication may throw IOException, but this is not documented in the Javadoc. Please add an @throws tag to indicate the possible exceptions.

Apply this diff to update the Javadoc:

     /**
      * Pull changes from remote branch and merge the changes
      * @param repoSuffix suffixedPath used to generate the base repo path this includes orgId, defaultAppId, repoName
      * @param remoteUrl ssh url of the git repo(we support cloning via ssh url only with deploy key)
      * @param branchName remoteBranchName from which commits will be fetched and merged to the current branch
      * @param privateKey generated by us and specific to the defaultApplication
      * @param publicKey generated by us and specific to the defaultApplication
+     * @throws IOException if an I/O error occurs during the pull operation
      * @return success message
      */

118-121: Remove commented-out code or explain its purpose

The method listBranches is commented out. If it's no longer needed, consider removing it. If it's kept for future use, please add a TODO comment explaining why it's commented out.

app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCEImpl.java (1)

251-255: Remove unused parameter readmeFileName

The parameter String readmeFileName in the initialiseReadMe method is not used within the method body. Consider removing it to improve code readability.

Apply this diff to remove the unused parameter:

-public Mono<Boolean> initialiseReadMe(
-        ArtifactJsonTransformationDTO jsonTransformationDTO,
-        Artifact artifact,
-        String readmeFileName,
-        String originHeader) {
+public Mono<Boolean> initialiseReadMe(
+        ArtifactJsonTransformationDTO jsonTransformationDTO,
+        Artifact artifact,
+        String originHeader) {
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java (4)

118-118: Address the pending permission handling

The // TODO: permission bit deferred to gitArtifactHelper comment indicates that permission handling is pending. It's important to implement this to ensure proper access control.

Would you like assistance in implementing this functionality or should I open a new GitHub issue to track this task?


535-535: Correct the spelling of readMeIntialisationMono

The variable readMeIntialisationMono has a typo. Please rename it to readMeInitializationMono for consistency and readability.


596-596: Implement the commitArtifact method

The TODO comment indicates that the commitArtifact method needs implementation. It's essential for committing changes to the artifact.

Shall I assist in implementing this method or open a new GitHub issue for tracking?


605-609: Implement the detachRemote method

The TODO suggests that detachRemote should be implemented similarly to disconnectGitRepo. This method is important for detaching the remote repository when needed.

Would you like help in implementing this method or prefer to create a new GitHub issue?

app/server/appsmith-git/src/main/java/com/appsmith/git/handler/ce/FSGitHandlerCEImpl.java (1)

252-254: Simplify null or empty string check

Use StringUtils.isNullOrEmpty for clarity when checking if a string is null or empty.

Apply this diff:

-if (!StringUtils.isEmptyOrNull(remoteRefUpdate.getMessage())) {
+if (!StringUtils.isNullOrEmpty(remoteRefUpdate.getMessage())) {
app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ArtifactImportDTO.java (2)

5-10: LGTM! Consider adding class-level documentation.

The abstract class structure is well-designed for the modularization goal. Consider adding Javadoc to explain the purpose and contract.

+/**
+ * Base DTO for artifact import operations.
+ * Provides a common contract for different types of artifacts in the system.
+ */
 public abstract class ArtifactImportDTO {

9-9: Consider validation requirements for implementations.

Implementations of setArtifact should include appropriate null checks and type validation.

Example implementation pattern:

@Override
public void setArtifact(Artifact artifact) {
    if (artifact == null) {
        throw new IllegalArgumentException("Artifact cannot be null");
    }
    if (!(artifact instanceof SpecificArtifact)) {
        throw new IllegalArgumentException("Invalid artifact type");
    }
    this.artifact = (SpecificArtifact) artifact;
}
app/server/appsmith-git/src/main/java/com/appsmith/git/dto/CommitDTO.java (2)

5-7: TODO comment needs elaboration

The TODO comment is vague and doesn't provide enough context about what additions might be needed for native implementation.

Consider adding more details about the planned native implementation scope:

-* TODO: scope for addition in case of native implementation
+* TODO: Potential extensions needed for native Git implementation:
+* - Additional fields for native Git specific metadata
+* - Integration points with JGit/native Git commands

8-9: Consider using more specific Lombok annotations

While @Data provides comprehensive functionality, for DTOs it's often better to be explicit about what you need.

Consider replacing @Data with more specific annotations:

-@Data
+@Getter
+@Setter
+@ToString
+@EqualsAndHashCode
app/server/appsmith-server/src/main/java/com/appsmith/server/git/resolver/GitHandlingServiceResolver.java (1)

7-9: Add class-level documentation.

Consider adding Javadoc to describe the purpose and responsibilities of this resolver class, especially its role in the Git modularization structure.

 @Slf4j
 @Component
+/**
+ * Resolves and provides appropriate Git handling service implementations.
+ * Part of the Git backend modularization structure, extending the CE implementation
+ * to support both FS and native Git operations.
+ */
 public class GitHandlingServiceResolver extends GitHandlingServiceResolverCE {
app/server/appsmith-git/src/main/java/com/appsmith/git/dto/GitUser.java (1)

8-11: Consider adding @builder and @tostring annotations

For better object creation patterns and debugging support, consider adding these Lombok annotations:

 @Getter
 @Setter
 @NoArgsConstructor
+@Builder
+@ToString
 @JsonInclude(JsonInclude.Include.NON_NULL)
app/server/appsmith-server/src/main/java/com/appsmith/server/git/dtos/ArtifactJsonTransformationDTO.java (3)

7-12: Enhance class documentation and consider a more descriptive name.

The TODO suggests the name needs improvement. Consider something more specific like GitArtifactTransformationDTO or GitResourceMappingDTO to better reflect its purpose.

The documentation could be more specific about:

  • What a "git resource map" is
  • The transformation direction (JSON ↔ resource map)
  • The purpose of path traversal in fs ops

13-27: Consider adding field validation and documentation.

While Lombok's @Data reduces boilerplate, consider:

  1. Adding field-level documentation
  2. Adding validation constraints (e.g., @NotNull, @NotBlank) for required fields
  3. Adding @Builder for easier object creation

Example enhancement:

 @Data
+@Builder
 public class ArtifactJsonTransformationDTO {
 
+    @NotBlank(message = "Workspace ID is required")
     String workspaceId;
 
+    @NotBlank(message = "Artifact ID is required")
     String artifactId;
 
+    @NotBlank(message = "Repository name is required")
     String repoName;
 
+    @NotBlank(message = "Reference name is required")
     String refName;
 
+    @NotNull(message = "Artifact type is required")
     ArtifactType artifactType;
 
+    @NotNull(message = "Reference type is required")
     RefType refType;

1-27: DTO aligns well with Git modularization objectives.

This DTO effectively supports the Git modularization goals by:

  • Providing a common structure for both FS and native implementations
  • Using proper typing for references and artifacts
  • Maintaining a clean separation of concerns

Consider documenting how this DTO fits into the broader Git service architecture.

app/server/appsmith-server/src/main/java/com/appsmith/server/git/resolver/GitArtifactHelperResolver.java (2)

10-12: Consider documenting the class purpose.

While the class structure is clean, adding Javadoc would help explain its role in the Git modularization architecture.

+/**
+ * Resolves appropriate Git artifact helpers based on artifact type.
+ * Part of the Git modularization architecture for handling different artifact types.
+ */
 @Slf4j
 @Component
 public class GitArtifactHelperResolver extends GitArtifactHelperResolverCE {

1-18: Consider interface extraction for better modularity.

Since this is part of the Git modularization effort (issue #37421), consider extracting an interface GitArtifactHelperResolver and renaming this implementation to DefaultGitArtifactHelperResolver. This would better align with the goal of creating a common Git service across different implementations.

Suggested structure:

public interface GitArtifactHelperResolver {
    GitArtifactHelper<?> getArtifactHelper(ArtifactType artifactType);
}

@Slf4j
@Component
public class DefaultGitArtifactHelperResolver extends GitArtifactHelperResolverCE implements GitArtifactHelperResolver {
    // Current implementation
}
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCE.java (2)

11-12: Consider simplifying the return type.

The wildcard with extends (? extends) might be unnecessary here since ArtifactImportDTO is already a specific type.

-    Mono<? extends ArtifactImportDTO> importArtifactFromGit(
+    Mono<ArtifactImportDTO> importArtifactFromGit(

14-19: Consider parameter grouping and return type simplification.

  1. The return type can be simplified similar to the previous method
  2. Consider grouping related parameters into a dedicated DTO for better maintainability
-    Mono<? extends Artifact> connectArtifactToGit(
+    Mono<Artifact> connectArtifactToGit(

Consider creating a dedicated DTO for the connection parameters to improve maintainability and make the method signature cleaner:

public class ArtifactConnectionDTO {
    private String baseArtifactId;
    private GitConnectDTO gitConnectDTO;
    private String originHeader;
    private ArtifactType artifactType;
    private GitType gitType;
    // ... constructors, getters, setters
}
app/server/appsmith-git/src/main/java/com/appsmith/git/handler/FSGitHandlerImpl.java (1)

12-14: Document the purpose of @primary designation.

Since this implementation is marked as @primary, add Javadoc explaining why this is the preferred implementation over potential alternatives.

 @Slf4j
 @Primary
 @Component
+/**
+ * Primary implementation of FSGitHandler for file system-based Git operations.
+ * This implementation is preferred over alternatives when multiple FSGitHandler
+ * beans are present in the application context.
+ */
 public class FSGitHandlerImpl extends FSGitHandlerCEImpl implements FSGitHandler {
app/server/appsmith-server/src/main/java/com/appsmith/server/git/resolver/GitArtifactHelperResolverCE.java (3)

11-13: Add class-level documentation.

Consider adding Javadoc to explain:

  1. The purpose of this resolver
  2. The significance of the CE suffix
  3. The relationship with GitArtifactHelperResolver
+/**
+ * Resolver for Git artifact helpers in the Community Edition.
+ * This class provides the core functionality for resolving appropriate helpers
+ * based on artifact types.
+ */
 @Slf4j
 @RequiredArgsConstructor
 public class GitArtifactHelperResolverCE {

15-16: Document protected fields.

Add field-level documentation to explain the purpose of each protected field, especially since they might be accessed by subclasses.

+    /** Service for handling Git filesystem operations */
     protected final GitFSServiceImpl gitFSService;
+    /** Helper for Git operations on Application artifacts */
     protected final GitArtifactHelper<Application> gitApplicationHelper;

1-24: Consider architectural implications of the resolver pattern.

This resolver implementation aligns with the PR objective of creating a super service for Git operations. However, consider:

  1. Document how this resolver fits into the larger architecture
  2. Add integration tests to verify resolver behavior with both FS and native implementations
  3. Consider using a factory pattern if more artifact types are planned

Would you like assistance in creating the architectural documentation or integration tests?

app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceImpl.java (2)

3-15: Consider breaking down the service responsibilities.

The high number of dependencies (12 injected services) might indicate that this service is handling too many responsibilities. Consider if some of these responsibilities could be extracted into separate specialized services.


22-48: Consider grouping related parameters.

While the constructor implementation is correct, consider organizing the parameters into logical groups using builder pattern or parameter objects. For example:

  • Git-related services (profile, analytics, private repo)
  • Artifact-related services (import, export)
  • Permission-related services
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCECompatibleImpl.java (2)

18-21: Add class-level documentation.

Add Javadoc to explain the purpose of this class and its role in the Git modularization structure.

 @Slf4j
 @Service
+/**
+ * CE Compatible implementation of the Central Git Service.
+ * This class serves as part of the Git backend modularization structure,
+ * providing compatibility layer for Community Edition specific Git operations.
+ */
 public class CentralGitServiceCECompatibleImpl extends CentralGitServiceCEImpl
         implements CentralGitServiceCECompatible {

23-49: Consider reducing the number of dependencies.

The constructor accepts 12 dependencies, which might indicate a violation of the Single Responsibility Principle. Consider grouping related services into facade services or using the builder pattern.

app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitArtifactHelperCE.java (1)

68-68: LGTM! Consider builder pattern for complex artifact creation.

The factory method pattern is appropriate here. For future extensibility, consider implementing a builder pattern in the concrete implementations if artifact creation becomes more complex.

app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceImpl.java (2)

3-28: Consider breaking down the service responsibilities

The large number of dependencies (20+) suggests this service might be handling too many responsibilities. Consider splitting into smaller, focused services following the Single Responsibility Principle.

Consider creating separate services for:

  • Git repository operations
  • Git user management
  • Git analytics
  • Git import/export operations

29-31: Add class-level documentation

Consider adding Javadoc to describe the service's purpose, responsibilities, and its role in the Git modularization structure.

+/**
+ * Implementation of Git file system operations service that handles
+ * Git operations for file system-based repositories.
+ * This service is part of the Git modularization structure and provides
+ * compatibility with the central Git handling interface.
+ */
 @Slf4j
 @Service
 public class GitFSServiceImpl extends GitFSServiceCECompatibleImpl implements GitHandlingService {
app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCECompatibleImpl.java (2)

29-31: Consider documenting the CE compatibility contract.

The class implements a compatibility layer between different Git implementations. Consider adding Javadoc to clarify:

  • The purpose of this compatibility layer
  • The relationship with the CE implementation
  • Any specific behavioral differences from the base implementation

33-79: Consider reducing constructor complexity through dependency grouping.

The constructor has 22 parameters, which could make maintenance and testing challenging. Consider:

  1. Grouping related dependencies into context/configuration objects
  2. Using the builder pattern for cleaner dependency injection
  3. Evaluating if all these dependencies are necessary at this layer

Example grouping:

  • GitConfiguration (keys, helpers, utils)
  • UserContext (session, data, service)
  • ServiceContext (workspace, datasource, plugin)
public class GitConfiguration {
    private final GitDeployKeysRepository gitDeployKeysRepository;
    private final GitPrivateRepoHelper gitPrivateRepoHelper;
    private final CommonGitFileUtils commonGitFileUtils;
    // ... other git-related dependencies
}
app/server/appsmith-server/src/main/java/com/appsmith/server/domains/ce/GitArtifactMetadataCE.java (1)

113-115: Review the necessity of making setDefaultArtifactId public

Making this method public exposes internal state modification. Consider:

  1. Is this change necessary for the Git modularization?
  2. Could we use a more specific public method for the required use case?
  3. Are there any validation requirements for the input?

If this change is required for the Git modularization:

  1. Add input validation
  2. Document the public API
  3. Consider making the class immutable with a builder pattern
 public void setDefaultArtifactId(String defaultArtifactId) {
+    if (!StringUtils.hasText(defaultArtifactId)) {
+        throw new IllegalArgumentException("defaultArtifactId cannot be null or empty");
+    }
     this.defaultArtifactId = defaultArtifactId;
 }
app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/GitApplicationHelperCEImpl.java (2)

312-319: Consider enhancing GitArtifactMetadata initialization

Good refactoring to extract the Application creation logic. Consider initializing more GitArtifactMetadata fields with default values to ensure consistent application state.

 @Override
 public Application getNewArtifact(String workspaceId, String repoName) {
     Application newApplication = new Application();
     newApplication.setName(repoName);
     newApplication.setWorkspaceId(workspaceId);
-    newApplication.setGitApplicationMetadata(new GitArtifactMetadata());
+    GitArtifactMetadata metadata = new GitArtifactMetadata();
+    metadata.setIsRepoPrivate(false);
+    metadata.setLastCommittedAt(Instant.now());
+    newApplication.setGitApplicationMetadata(metadata);
     return newApplication;
 }

312-319: Add parameter validation

Consider adding null checks for the input parameters to prevent potential NPEs.

 @Override
 public Application getNewArtifact(String workspaceId, String repoName) {
+    if (workspaceId == null || repoName == null) {
+        throw new AppsmithException(AppsmithError.INVALID_PARAMETER, "workspaceId and repoName cannot be null");
+    }
     Application newApplication = new Application();
     newApplication.setName(repoName);
     newApplication.setWorkspaceId(workspaceId);
     newApplication.setGitApplicationMetadata(new GitArtifactMetadata());
     return newApplication;
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fdb7e18 and 0c251dd.

📒 Files selected for processing (31)
  • app/server/appsmith-git/src/main/java/com/appsmith/git/dto/CommitDTO.java (1 hunks)
  • app/server/appsmith-git/src/main/java/com/appsmith/git/dto/GitUser.java (1 hunks)
  • app/server/appsmith-git/src/main/java/com/appsmith/git/handler/FSGitHandlerImpl.java (1 hunks)
  • app/server/appsmith-git/src/main/java/com/appsmith/git/handler/ce/FSGitHandlerCEImpl.java (1 hunks)
  • app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/handler/FSGitHandler.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/GitApplicationHelperCEImpl.java (3 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/constants/ce/RefType.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/domains/ce/GitArtifactMetadataCE.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ApplicationImportDTO.java (2 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ArtifactImportDTO.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitService.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCE.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCECompatible.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCECompatibleImpl.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceImpl.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/GitHandlingService.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/GitHandlingServiceCE.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/GitHandlingServiceCECompatible.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/GitType.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/dtos/ArtifactJsonTransformationDTO.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCECompatibleImpl.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCEImpl.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceImpl.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/resolver/GitArtifactHelperResolver.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/resolver/GitArtifactHelperResolverCE.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/resolver/GitHandlingServiceResolver.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/resolver/GitHandlingServiceResolverCE.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/utils/GitAnalyticsUtils.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/utils/GitProfileUtils.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitArtifactHelperCE.java (2 hunks)
✅ Files skipped from review due to trivial changes (7)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/constants/ce/RefType.java
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitService.java
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCECompatible.java
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/GitHandlingService.java
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/GitHandlingServiceCECompatible.java
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/GitType.java
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/resolver/GitHandlingServiceResolverCE.java
🔇 Additional comments (24)
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java (1)

85-91: Logic for checking repository limits is correct

The method isRepositoryLimitReachedForWorkspace correctly handles public and private repository checks.

app/server/appsmith-git/src/main/java/com/appsmith/git/dto/CommitDTO.java (1)

1-20: Verify integration with Git service implementations

The DTO structure seems aligned with the PR objectives for Git modularization, but we should verify its compatibility with both FS and native implementations.

✅ Verification successful

Let me gather more information about the Git service implementations to verify the compatibility.


CommitDTO structure is properly aligned with Git implementations

The CommitDTO class is correctly structured and is being used consistently across both FS and native Git implementations. The code shows:

  • FSGitHandler implementation properly consumes the CommitDTO fields
  • Central Git service properly handles the DTO for both implementations
  • All required fields (message, author, committer) are utilized in the commit flow
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for potential usage patterns and implementation details
rg -A 5 "CommitDTO" 
ast-grep --pattern 'class $_ implements FSGitHandler { $$$ }'

Length of output: 30482


Script:

#!/bin/bash
# Check for Git service implementations and their usage of CommitDTO
ast-grep --pattern 'interface $_ extends GitHandler { $$$ }'
ast-grep --pattern 'class $_ implements GitHandler { $$$ }'
rg -A 5 "GitHandler" 

Length of output: 12939

app/server/appsmith-server/src/main/java/com/appsmith/server/git/resolver/GitHandlingServiceResolver.java (2)

11-13: LGTM! Constructor follows good practices.

The constructor properly injects and delegates to the parent class, following Spring's dependency injection pattern.


1-14: Verify alignment with modularization goals.

The class structure appears correct but minimal. Let's verify if it aligns with the modularization requirements from issue #37421.

✅ Verification successful

Let me check the inheritance hierarchy and usage patterns to verify the modularization.


Class structure aligns with modularization requirements

The implementation follows the proper modularization pattern:

  • Extends CE (Community Edition) base class correctly
  • Maintains clean separation between CE and EE components
  • Properly integrated into the central Git service infrastructure
  • Follows the established resolver pattern for Git service implementations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for related Git service implementations and usage patterns

# Look for other Git service implementations
echo "Checking for related Git service implementations..."
rg -t java "implements.*GitHandlingService|extends.*GitHandlingService" -g "*.java"

# Check for usage patterns of this resolver
echo "Checking for usage patterns of GitHandlingServiceResolver..."
rg -t java "GitHandlingServiceResolver" -g "*.java" -l

# Look for test coverage
echo "Checking for related test files..."
fd -t f "GitHandlingServiceResolver.*Test\.java$"

Length of output: 2154


Script:

#!/bin/bash
# Check the base class implementation and its usage
echo "Checking GitHandlingServiceResolverCE implementation..."
rg -t java -A 10 "class GitHandlingServiceResolverCE" 

# Check how the resolver is being used in Central services
echo "Checking usage in Central services..."
rg -t java -A 5 "GitHandlingServiceResolver" app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceImpl.java

Length of output: 2573

app/server/appsmith-git/src/main/java/com/appsmith/git/dto/GitUser.java (1)

12-12: Verify GitUser usage in CommitDTO

Let's ensure proper integration with CommitDTO as mentioned in the summary.

✅ Verification successful

Let me search for the actual files and references to understand the relationship between these classes better.


GitUser is properly integrated with CommitDTO

The verification confirms that GitUser is correctly used in CommitDTO as both author and committer fields, and is actively used in the codebase's git implementation (CentralGitServiceCEImpl).

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for GitUser usage in CommitDTO
ast-grep --pattern 'class CommitDTO {
  $$$
  GitUser $_ $$$
  $$$
}'

Length of output: 71


Script:

#!/bin/bash
# Search for CommitDTO files and GitUser references
rg -l "CommitDTO" --type java
rg "GitUser" --type java -A 2

Length of output: 3408

app/server/appsmith-server/src/main/java/com/appsmith/server/git/dtos/ArtifactJsonTransformationDTO.java (1)

1-6: LGTM! Clean imports and proper package structure.

The imports are well-organized and necessary for the functionality.

app/server/appsmith-server/src/main/java/com/appsmith/server/git/resolver/GitArtifactHelperResolver.java (2)

1-9: LGTM: Clean imports and package structure.

The imports are well-organized and necessary for the functionality. The package structure follows Java conventions.


14-17: Verify lazy initialization necessity.

The constructor implementation looks good, but let's verify if lazy initialization of GitFSService is required to prevent circular dependencies.

✅ Verification successful

@lazy annotation is necessary - keep it

From the code analysis, we can see that there's a circular dependency between GitFSServiceImpl and GitArtifactHelperResolver. The GitFSServiceImpl has GitArtifactHelperResolver as a protected field, while GitArtifactHelperResolver requires GitFSServiceImpl in its constructor. The @Lazy annotation is correctly used to break this circular dependency.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for potential circular dependencies involving GitFSService
echo "Searching for GitFSService usage in component constructors..."
rg -l "GitFSService" | xargs ast-grep --pattern 'class $_ {
  $$$
  $_($$$GitFSService$$$) {
    $$$
  }
}'

Length of output: 240


Script:

#!/bin/bash
# Let's search for GitFSService implementation and its dependencies
echo "Searching for GitFSService implementation..."
rg -A 10 "class.*GitFSService" 

echo -e "\nSearching for GitFSServiceImpl dependencies..."
ast-grep --pattern 'class GitFSServiceImpl {
  $$$
  GitFSServiceImpl($$$) {
    $$$
  }
}'

echo -e "\nSearching for any circular references..."
rg -l "GitFSServiceImpl|GitArtifactHelperResolver" | xargs rg "new (GitFSServiceImpl|GitArtifactHelperResolver)"

Length of output: 5276


Script:

#!/bin/bash
# Let's check if GitArtifactHelperResolver is used in GitFSService implementation
echo "Checking for GitArtifactHelperResolver usage in GitFSService..."
rg -B 5 -A 5 "GitArtifactHelperResolver" app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceImpl.java app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCEImpl.java

echo -e "\nChecking for bean configuration..."
rg -l "GitFSService|GitArtifactHelperResolver" | xargs rg "@Configuration|@Bean.*Git"

Length of output: 6747

app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ApplicationImportDTO.java (2)

21-24: LGTM! Clean implementation of getArtifact()

The method correctly implements the contract from ArtifactImportDTO and maintains type safety.


Line range hint 13-13: Verify integration with Git import flow

Since this DTO is part of the Git modularization effort, let's verify its integration points.

✅ Verification successful

Verified: ApplicationImportDTO is correctly used in Git import operations

The class is indeed used in Git-related operations, specifically for importing applications from Git repositories:

  • Used in GitControllerCE.importApplicationFromGit() endpoint
  • Integrated with CommonGitServiceCE.importArtifactFromGit() for Git import flows
  • Properly tested in CommonGitServiceCETest with various Git import scenarios
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for Git-related usage of ApplicationImportDTO
rg -l "ApplicationImportDTO" | xargs rg "git|Git" -B 2 -A 2

# Search for implementations of CentralGitServiceCE that might use this DTO
ast-grep --pattern 'class $_ implements CentralGitServiceCE'

Length of output: 131194


Script:

#!/bin/bash
# Search for Git-related usage of ApplicationImportDTO in Git service implementations
ast-grep --pattern 'class $_ implements CentralGitServiceCE {
  $$$
  $_(ApplicationImportDTO $_) {
    $$$
  }
  $$$
}'

# Search for direct usage of ApplicationImportDTO in Git-related operations
rg -B 2 -A 2 "ApplicationImportDTO.*[gG]it|[gG]it.*ApplicationImportDTO"

# Search for Git-related methods that return ApplicationImportDTO
ast-grep --pattern 'importArtifactFromGit($_, $_, $_) {
  $$$
}'

Length of output: 8449

app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCE.java (2)

1-8: LGTM! Clean imports and package structure.

The imports are well-organized and contain only what's necessary for the interface.


1-20: Verify integration with existing Git services.

The interface looks well-structured but we should verify its integration points with existing Git services.

✅ Verification successful

Let me check the implementation details of these Git services to ensure proper integration.


Let me try a different approach to check the implementations.


Git service integration is properly implemented

The interface is well-integrated within the Git service hierarchy:

  • Implemented by CentralGitServiceCEImpl with proper dependency injection
  • Has comprehensive test coverage in CommonGitServiceCETest
  • Used correctly in the controller layer for Git operations
  • Follows the CE (Community Edition) pattern with compatible implementations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other Git service implementations to ensure proper integration
rg -t java "implements.*GitService|interface.*GitService" -g "!CentralGitServiceCE.java"

Length of output: 2075


Script:

#!/bin/bash
# Check implementation of CentralGitServiceCEImpl to verify integration
ast-grep --pattern 'class CentralGitServiceCEImpl implements CentralGitServiceCE {
  $$$
}'

# Also check the implementation details of importArtifactFromGit method
ast-grep --pattern 'Mono<? extends ArtifactImportDTO> importArtifactFromGit($$$)'

Length of output: 177


Script:

#!/bin/bash
# Search for the implementation files with context
rg -t java "class.*CentralGitServiceCEImpl.*implements.*CentralGitServiceCE" -A 10
rg -t java "importArtifactFromGit.*workspaceId.*gitConnectDTO" -A 10

Length of output: 15084

app/server/appsmith-git/src/main/java/com/appsmith/git/handler/FSGitHandlerImpl.java (2)

17-20: LGTM! Constructor follows best practices.

The constructor properly implements dependency injection and correctly forwards dependencies to the parent class.


15-21: Verify if custom implementation is needed.

The class currently only inherits from FSGitHandlerCEImpl without adding any custom behavior. If no additional functionality is planned, consider whether this class is necessary.

✅ Verification successful

Let me check the parent class and interface to better understand if this implementation class is necessary.


The empty implementation class is necessary and correctly structured

This class follows a common enterprise pattern where FSGitHandlerImpl is marked as @Primary to be the preferred implementation, while FSGitHandlerCEImpl serves as the community edition base implementation. The empty implementation allows for future enterprise-specific extensions while maintaining a clean separation of concerns.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if there are any references to specific FSGitHandlerImpl functionality
# that might indicate planned custom implementations

# Search for any TODO comments or references to planned implementations
rg -g "*.java" -g "*.xml" "FSGitHandlerImpl" -C 3

Length of output: 1136


Script:

#!/bin/bash
# Check the parent class and interface
ast-grep --pattern 'interface FSGitHandler {
  $$$
}'

ast-grep --pattern 'class FSGitHandlerCEImpl {
  $$$
}'

# Check if there are any other implementations
rg -g "*.java" "implements FSGitHandler" -C 2

Length of output: 1345

app/server/appsmith-server/src/main/java/com/appsmith/server/git/resolver/GitArtifactHelperResolverCE.java (1)

1-10: LGTM! Imports and package declaration are well-organized.

app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceImpl.java (2)

18-20: LGTM! Well-structured class declaration.

The class follows Spring framework conventions and establishes a clear hierarchy supporting the Git modularization objective.


1-49: Verify isolation from existing codebase.

The PR mentions that this new code should not be connected to the existing codebase. Let's verify this claim:

✅ Verification successful

Let me gather more information to verify the isolation claim thoroughly.


Let me check one more aspect to verify if there are any direct usages of this service in the application code.


Implementation is properly isolated as required

The verification shows that the CentralGitServiceImpl is well-isolated:

  • Only related central Git service files reference it
  • No autowired dependencies found in other components
  • No direct usage of the service methods in the codebase
  • No test configurations currently wire this service
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for references to CentralGitServiceImpl in the codebase
rg -l "CentralGitServiceImpl" --type java

# Search for beans that might autowire this service
ast-grep --pattern 'class $_ {
  $$$
  @Autowired
  private CentralGitService $_
  $$$
}'

Length of output: 233


Script:

#!/bin/bash
# Check for any references to CentralGitService interface
rg -l "CentralGitService" --type java

# Check for any bean configurations that might wire this service
rg -l "CentralGitService.*Bean" --type java

# Look for any Spring configuration classes that might configure this service
ast-grep --pattern 'class $_ {
  $$$
  @Bean
  public CentralGitService $_($$$) {
    $$$
  }
  $$$
}'

Length of output: 804


Script:

#!/bin/bash
# Search for any direct usage of CentralGitService methods in the codebase
rg -l "centralGitService\." --type java

# Look for any test configurations or usages
rg -l "CentralGitService" --type java --glob "*Test*.java"

Length of output: 100

app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCECompatibleImpl.java (1)

20-50: Verify if empty implementation is intentional.

The class currently has no additional methods beyond those inherited from CentralGitServiceCEImpl. If this is intentional as part of the modularization strategy, please add a comment explaining this design decision.

✅ Verification successful

Empty implementation is intentional and correct

The interface CentralGitServiceCECompatible is an empty interface that extends CentralGitServiceCE, and the implementation class correctly inherits all functionality from CentralGitServiceCEImpl. This appears to be an intentional design pattern, likely used for compatibility or future extensibility purposes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if parent class or interface define methods that should be overridden
ast-grep --pattern 'class CentralGitServiceCEImpl {
  $$$
  public $_ $_($$$) {
    $$$
  }
  $$$
}'

ast-grep --pattern 'interface CentralGitServiceCECompatible {
  $$$
  $_ $_($$$);
  $$$
}'

Length of output: 195


Script:

#!/bin/bash
# Let's try a different approach to find the parent class and interface implementations
# First, find the parent class implementation
rg -l "class CentralGitServiceCEImpl" --type java

# Then find the interface definition
rg -l "interface CentralGitServiceCECompatible" --type java

# Once we have the files, we can examine their content
rg "class CentralGitServiceCEImpl" -A 5 --type java
rg "interface CentralGitServiceCECompatible" -A 5 --type java

Length of output: 1468

app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitArtifactHelperCE.java (1)

28-29: LGTM! Verify permission hierarchy.

Let's verify the permission hierarchy implementation:

✅ Verification successful

Let me try another search strategy to verify the permission hierarchy implementation.


Let me try one more search to find the permission implementation in the concrete class.


Permission hierarchy verified and consistent.

The implementation returns AclPermission.WORKSPACE_CREATE_APPLICATION which aligns with existing workspace-level permissions in the codebase. The permission follows the established pattern of other artifact-related permissions in GitApplicationHelperCEImpl.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other workspace-level permissions to ensure consistency
ast-grep --pattern 'AclPermission getWorkspace$$$Permission()'

# Search for usage patterns of the new permission
rg "getWorkspaceArtifactCreationPermission" -A 2

Length of output: 131538


Script:

#!/bin/bash
# Search for permission-related methods in GitArtifactHelperCE.java
ast-grep --pattern 'AclPermission get$_Permission()' app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitArtifactHelperCE.java

# Search for permission-related methods in the implementation class
rg "class.*implements.*GitArtifactHelperCE" -A 5

Length of output: 1126


Script:

#!/bin/bash
# Search for getWorkspaceArtifactCreationPermission implementation
rg "getWorkspaceArtifactCreationPermission" app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/GitApplicationHelperCEImpl.java -A 3

# Search for other permission methods in the same file
rg "Permission.*\{" app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/GitApplicationHelperCEImpl.java

Length of output: 1155

app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceImpl.java (1)

33-79: Verify inheritance structure and consider constructor alternatives

The constructor implementation is clean but complex. Consider using a builder pattern or Spring's configuration properties.

Let's verify the inheritance structure:

Consider refactoring to use a builder pattern:

@Service
public class GitFSServiceImpl extends GitFSServiceCECompatibleImpl implements GitHandlingService {
    public static class Builder {
        private final GitDeployKeysRepository gitDeployKeysRepository;
        // ... other required fields
        
        public Builder(GitDeployKeysRepository gitDeployKeysRepository) {
            this.gitDeployKeysRepository = gitDeployKeysRepository;
        }
        
        public Builder withGitPrivateRepoHelper(GitPrivateRepoHelper helper) {
            // ... builder methods
            return this;
        }
        
        public GitFSServiceImpl build() {
            return new GitFSServiceImpl(this);
        }
    }
    
    private GitFSServiceImpl(Builder builder) {
        super(builder.gitDeployKeysRepository, ...);
    }
}
app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCECompatibleImpl.java (2)

1-28: LGTM! Well-organized imports and clear package structure.

The imports are logically grouped and indicate proper separation of concerns between Git operations, services, and utilities.


1-80: Verify integration points with native Git implementation.

The class provides the FS implementation compatibility layer. To ensure successful completion of issue #37421:

  1. Document the integration points between FS and native implementations
  2. Consider adding integration tests for both implementations
  3. Create a migration guide for existing clients
app/server/appsmith-server/src/main/java/com/appsmith/server/domains/ce/GitArtifactMetadataCE.java (1)

112-113: Clarify the migration status and requirements

The TODOs are unclear about the migration status and requirements. If this is part of the Git modularization effort, we should:

  1. Document the migration status
  2. Remove or update the TODOs with clear requirements

Let's check if there are any related migration tasks:

✅ Verification successful

Let me search for more specific information about Git migration tasks and TODOs.


Let me search for the original TODO comment and any related Git migration context.


Let me check if this method is used in any migration-related code or if there are any migration tasks that depend on it.


Remove redundant TODO comments

The TODO comments are no longer relevant as the Git migration is already implemented. The setDefaultArtifactId method is actively used in CentralGitServiceCEImpl for Git operations and follows the same pattern as other Git-synced entities in the codebase.

  • Remove both TODO comments from GitArtifactMetadataCE.java
  • Keep the method public as it's required for Git operations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for related migration tasks or TODOs
rg -i "git.*migration|migrate.*git" 

Length of output: 157337


Script:

#!/bin/bash
# Search for Git migration related TODOs in the codebase
rg -i "TODO.*git.*migration|TODO.*migrate.*git"

# Also search for any Git migration related files/classes
fd -i "git.*migration|migrate.*git"

Length of output: 131159


Script:

#!/bin/bash
# Search for the original TODO comment and surrounding context
rg -B2 -A2 "TODO.*reevaluate" app/server/appsmith-server/src/main/java/com/appsmith/server/domains/ce/GitArtifactMetadataCE.java

# Also search for any Git migration related code in the same file
rg "migration|migrate" app/server/appsmith-server/src/main/java/com/appsmith/server/domains/ce/GitArtifactMetadataCE.java

Length of output: 583


Script:

#!/bin/bash
# Search for usages of setDefaultArtifactId
rg "setDefaultArtifactId" 

# Search for any Git migration tasks or related code
rg -g "*.java" "GitMigration|GitImport|GitSync"

Length of output: 32573

app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/GitApplicationHelperCEImpl.java (1)

90-94: LGTM: Clean permission method implementation

The method correctly implements the interface requirement by returning the appropriate workspace-level permission for application creation.

// TODO: modify git auth class for native implementation
Mono<GitAuth> getGitAuthForUser();

Boolean isGitAuthInvalid(GitAuth gitAuth);
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

Ensure reactive consistency for isGitAuthInvalid

The method isGitAuthInvalid returns a synchronous Boolean. For consistency with other reactive methods in the interface, consider returning Mono<Boolean>.

Apply this diff to update the return type:

- Boolean isGitAuthInvalid(GitAuth gitAuth);
+ Mono<Boolean> isGitAuthInvalid(GitAuth gitAuth);
📝 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
Boolean isGitAuthInvalid(GitAuth gitAuth);
Mono<Boolean> isGitAuthInvalid(GitAuth gitAuth);

import java.util.HashMap;
import java.util.Map;

import static org.apache.commons.lang.ObjectUtils.defaultIfNull;
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

Update import to use org.apache.commons.lang3

The package org.apache.commons.lang is deprecated. Please update the import to org.apache.commons.lang3.ObjectUtils.defaultIfNull.

Comment on lines +70 to +79
if (defaultGitProfile == null) {
GitProfile userProfile = new GitProfile();
String authorName = StringUtils.isEmptyOrNull(user.getName())
? user.getUsername().split("@")[0]
: user.getName();
userProfile.setAuthorEmail(user.getEmail());
userProfile.setAuthorName(authorName);
userProfile.setUseGlobalProfile(null);
userData.setGitProfiles(userData.setGitProfileByKey(DEFAULT, userProfile));
}
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

Refactor repeated code for creating default GitProfile

The logic for creating a default GitProfile is repeated multiple times. Extract this into a private method to enhance code maintainability.

You can create a private method createDefaultGitProfile(User user) and refactor the code accordingly.

Also applies to: 92-99, 148-154

if (defaultGitProfile == null) {
GitProfile userProfile = new GitProfile();
String authorName = StringUtils.isEmptyOrNull(user.getName())
? user.getUsername().split("@")[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Prevent potential NullPointerException when accessing user information

Ensure user.getUsername() is not null before calling split("@")[0]. Add a null check or default to an empty string.

Consider updating the code as follows:

-String authorName = StringUtils.isEmptyOrNull(user.getName())
-        ? user.getUsername().split("@")[0]
-        : user.getName();
+String authorName;
+if (StringUtils.isEmptyOrNull(user.getName())) {
+    String username = user.getUsername() != null ? user.getUsername() : "";
+    authorName = username.split("@")[0];
+} else {
+    authorName = user.getName();
+}

Also applies to: 94-94, 150-150

import com.appsmith.server.services.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.jgit.util.StringUtils;
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Import the correct StringUtils class

The StringUtils class from org.eclipse.jgit.util does not have the isEmptyOrNull() method. Please import org.apache.commons.lang3.StringUtils instead.

Apply this diff to correct the import:

-import org.eclipse.jgit.util.StringUtils;
+import org.apache.commons.lang3.StringUtils;
📝 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
import org.eclipse.jgit.util.StringUtils;
import org.apache.commons.lang3.StringUtils;

Comment on lines +11 to +19
String message;

String header;

Boolean isAmendCommit;

GitUser author;

GitUser committer;
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

Add access modifiers and validation constraints

The fields lack access modifiers and validation annotations. For a DTO that will be used across different implementations, we should ensure proper encapsulation and validation.

Apply these changes:

-    String message;
+    private String message;
 
-    String header;
+    private String header;
 
-    Boolean isAmendCommit;
+    private Boolean isAmendCommit = false;  // provide default value
 
-    GitUser author;
+    private GitUser author;
 
-    GitUser committer;
+    private GitUser committer;

Also consider adding validation annotations:

import javax.validation.constraints.NotNull;
import javax.validation.constraints.NotBlank;

@NotBlank(message = "Commit message cannot be blank")
private String message;

@NotNull
private GitUser author;

/**
* name of the author/committer
*/
String name;
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

Add private access modifier to class fields

Fields should be explicitly marked as private for better encapsulation. Lombok's @Getter/@Setter will handle the access.

-    String name;
+    private String name;

-    String email;
+    private String email;

-    String timestamp;
+    private String timestamp;

Also applies to: 22-22, 27-27

Comment on lines +24 to +27
/**
* TODO: To be converted to the Instant or a timestamp
*/
String timestamp;
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Convert timestamp field to Instant type

Using String for timestamp storage is not ideal. Consider using java.time.Instant for proper timestamp handling.

-    /**
-     * TODO: To be converted to the Instant or a timestamp
-     */
-    String timestamp;
+    /**
+     * Timestamp of the git operation
+     */
+    private Instant timestamp;

Don't forget to add the import:

+import java.time.Instant;

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +26 to +29
@Override
public void setArtifact(Artifact artifact) {
this.setApplication((Application) artifact);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add type safety checks in setArtifact

The current implementation could throw ClassCastException if the wrong artifact type is provided.

Consider this safer implementation:

@Override
public void setArtifact(Artifact artifact) {
+    if (artifact == null) {
+        this.setApplication(null);
+        return;
+    }
+    if (!(artifact instanceof Application)) {
+        throw new IllegalArgumentException("Artifact must be of type Application");
+    }
    this.setApplication((Application) artifact);
}
📝 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
@Override
public void setArtifact(Artifact artifact) {
this.setApplication((Application) artifact);
}
@Override
public void setArtifact(Artifact artifact) {
if (artifact == null) {
this.setApplication(null);
return;
}
if (!(artifact instanceof Application)) {
throw new IllegalArgumentException("Artifact must be of type Application");
}
this.setApplication((Application) artifact);
}

Comment on lines +18 to +23
public GitArtifactHelper<?> getArtifactHelper(@NonNull ArtifactType artifactType) {
return switch (artifactType) {
case APPLICATION -> gitApplicationHelper;
default -> gitApplicationHelper;
};
}
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

🛠️ Refactor suggestion

Switch implementation needs to handle all artifact types

The current implementation is incomplete as it doesn't handle all defined ArtifactType enum values (PACKAGE and WORKFLOW). Since these types are actively used in the codebase (as seen in CreatorContextType and WorkspaceResourceContext), they should be properly handled.

    public GitArtifactHelper<?> getArtifactHelper(@NonNull ArtifactType artifactType) {
        log.debug("Resolving artifact helper for type: {}", artifactType);
        return switch (artifactType) {
            case APPLICATION -> gitApplicationHelper;
+           case PACKAGE, WORKFLOW -> throw new UnsupportedOperationException(
+               "Artifact type not yet supported: " + artifactType
+           );
-           default -> gitApplicationHelper;
        };
    }
🔗 Analysis chain

Review the switch implementation and error handling.

The current implementation has several potential issues:

  1. Both APPLICATION and default cases return the same helper
  2. Consider throwing UnsupportedOperationException for unhandled types
  3. Add debug logging for better observability

Consider this implementation:

     public GitArtifactHelper<?> getArtifactHelper(@NonNull ArtifactType artifactType) {
+        log.debug("Resolving artifact helper for type: {}", artifactType);
         return switch (artifactType) {
             case APPLICATION -> gitApplicationHelper;
-            default -> gitApplicationHelper;
+            default -> throw new UnsupportedOperationException(
+                "Unsupported artifact type: " + artifactType
+            );
         };
     }

Let me check if these artifact types are actively used and if there are specific helper implementations for them before making the final recommendation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are other ArtifactType enum values that should be handled
rg -A 5 "enum ArtifactType"

Length of output: 546


Script:

#!/bin/bash
# Check if PACKAGE and WORKFLOW types are used in the codebase
rg "ArtifactType\.(PACKAGE|WORKFLOW)" -B 2 -A 2

# Check for other implementations of GitArtifactHelper
ast-grep --pattern 'class $_ implements GitArtifactHelper'

Length of output: 110


Script:

#!/bin/bash
# Let's try a different approach to find GitArtifactHelper implementations
rg "class.*GitArtifactHelper" -B 1 -A 3

# Also check if PACKAGE and WORKFLOW are used in method calls or conditions
rg -t java "PACKAGE|WORKFLOW" -B 2 -A 2

Length of output: 21554

@github-actions github-actions bot added the Task A simple Todo label Nov 29, 2024
@sondermanish sondermanish changed the title Feat: Git modularisation backend structure feat: Git modularisation backend structure Nov 29, 2024
@github-actions github-actions bot added the Enhancement New feature or request label Nov 29, 2024
@sondermanish sondermanish merged commit 731356a into release Nov 29, 2024
@sondermanish sondermanish deleted the feat/super-git branch November 29, 2024 08:11
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Dec 2, 2024
## Description
 - Added structure for git modularisation


Fixes appsmithorg#37434
appsmithorg#37435


### No CI is required as the code is not exposed/ connected to existing
code

## Automation

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

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/12080532772>
> Commit: 0c251dd
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12080532772&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Git`
> Spec:
> <hr>Fri, 29 Nov 2024 08:03:23 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Introduced Git handling capabilities, including committing changes,
managing repositories, and handling branches.
- Added support for managing Git user profiles and permissions related
to artifact creation.
- Enhanced artifact management with new methods for creating and
retrieving artifacts based on workspace and repository details.

- **Bug Fixes**
- Improved error handling and validation for Git operations, ensuring
robust interaction with remote repositories.

- **Documentation**
- Updated documentation to reflect new methods and functionalities
related to Git operations and artifact management.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or request Epic A zenhub epic that describes a project Git Product Issues related to version control product ok-to-test Required label for CI Packages & Git Pod All issues belonging to Packages and Git Task A simple Todo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Task] Switch git import method to super service

2 participants