Skip to content

chore: Added git resource map types#37746

Merged
nidhi-nair merged 2 commits intoreleasefrom
chore/git-resource-map-type
Nov 27, 2024
Merged

chore: Added git resource map types#37746
nidhi-nair merged 2 commits intoreleasefrom
chore/git-resource-map-type

Conversation

@nidhi-nair
Copy link
Contributor

@nidhi-nair nidhi-nair commented Nov 26, 2024

Description

Introducing types to use when switching out of artifactreference types.

Automation

/ok-to-test tags=""

🔍 Cypress test results

Warning

Tests have not run on the HEAD c8f080c yet


Tue, 26 Nov 2024 13:29:23 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features
    • Introduced GitResourceIdentity class to encapsulate Git resource identities.
    • Added GitResourceMap class for managing mappings of Git resources and tracking modifications.
    • Implemented GitResourceType enum to standardize representation of various Git resource types.

These enhancements improve the management and synchronization of resources within the application.

@nidhi-nair nidhi-nair requested a review from a team as a code owner November 26, 2024 13:13
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 26, 2024

Walkthrough

This pull request introduces three new classes in the com.appsmith.external.git.models package: GitResourceIdentity, GitResourceMap, and GitResourceType. GitResourceIdentity encapsulates the identity of a Git resource with fields for file path, SHA, resource type, and identifier. GitResourceMap manages a mapping of GitResourceIdentity objects to their corresponding values, utilizing a ConcurrentHashMap for thread safety. GitResourceType is an enum that defines various constants representing different Git resource types, enhancing the structure and organization of Git-related operations.

Changes

File Change Summary
app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/models/GitResourceIdentity.java Class added: GitResourceIdentity with fields for filePath, sha, resourceType, and resourceIdentifier.
app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/models/GitResourceMap.java Class added: GitResourceMap with fields gitResourceMap (ConcurrentHashMap) and modifiedResources.
app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/models/GitResourceType.java Enum added: GitResourceType with constants for various Git resource types.

Suggested reviewers

  • sharat87
  • abhvsn
  • sagar-qa007

Poem

In the land of code where resources thrive,
New classes emerge, keeping Git alive.
Identity, mapping, and types all in line,
With Lombok's magic, the structure will shine.
So let's celebrate this code with glee,
For in every change, there's a new legacy! 🎉


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 271a15d and c8f080c.

📒 Files selected for processing (1)
  • app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/models/GitResourceType.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/models/GitResourceType.java

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 Nov 26, 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: 3

🧹 Outside diff range and nitpick comments (5)
app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/models/GitResourceMap.java (2)

9-10: Consider adding class-level documentation

The class seems to play a crucial role in Git resource management. Adding Javadoc would help other developers understand its purpose and usage.

+/**
+ * Maps Git resources to their corresponding objects and tracks modifications.
+ * This class is thread-safe through the use of ConcurrentHashMap.
+ */
 @Data
 public class GitResourceMap {

12-12: Consider using a more specific type than Object

Using Object as the value type loses type safety. Consider creating a generic type parameter or using a more specific type if possible.

-public class GitResourceMap {
-    private Map<GitResourceIdentity, Object> gitResourceMap = new ConcurrentHashMap<>();
+public class GitResourceMap<T> {
+    private Map<GitResourceIdentity, T> gitResourceMap = new ConcurrentHashMap<>();
app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/models/GitResourceType.java (2)

16-19: Remove or utilize empty separator sections

The empty sections marked with separators seem unnecessary. If these are placeholders for future implementation, consider adding TODO comments or remove them entirely.

-    // ----------------------------------
-
-    // ----------------------------------

5-14: LGTM! Consider adding Javadoc

The enum implementation is clean and follows best practices:

  • Good naming convention for constants
  • Proper use of Locale.ROOT in toString()
  • Comprehensive coverage of git resource types

Consider adding Javadoc to document the purpose of each resource type:

+/**
+ * Represents different types of Git resources in the system.
+ */
 public enum GitResourceType {
+    /** Configuration for root level resources */
     ROOT_CONFIG,
+    /** Configuration for data source entities */
     DATASOURCE_CONFIG,
     // ... add documentation for other constants

Also applies to: 22-25

app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/models/GitResourceIdentity.java (1)

8-10: Consider using more specific Lombok annotations instead of @DaTa

@DaTa generates toString, which might expose sensitive information in logs. Consider using @Getter, @Setter, and @EqualsAndHashCode instead.

-@Data
+@Getter
+@Setter
+@EqualsAndHashCode(onlyExplicitlyIncluded = true)
 @RequiredArgsConstructor
 public class GitResourceIdentity {
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1ea45e8 and 271a15d.

📒 Files selected for processing (3)
  • app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/models/GitResourceIdentity.java (1 hunks)
  • app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/models/GitResourceMap.java (1 hunks)
  • app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/models/GitResourceType.java (1 hunks)
🔇 Additional comments (2)
app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/models/GitResourceMap.java (2)

1-8: LGTM: Imports are appropriate and well-organized

The imports are minimal and necessary, showing good organization with concurrent utilities and Lombok.


14-14: Consider initializing modifiedResources

The modifiedResources field is not initialized. Consider whether it should have a default value to prevent NPEs.

Comment on lines +20 to +27
// This is gitSyncId for most resources, where available
// It could otherwise point to whatever defines uniqueness for that resource
// Exceptions: widgets, jsLibs, json files in root dir
// widgets -> pageGitSyncId-widgetId
// jsLibs -> jsLibFileName
// root dir files -> fileName
@NonNull @EqualsAndHashCode.Include
String resourceIdentifier;
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 validation for resourceIdentifier formats

The documentation indicates different formats for widgets, jsLibs, and root dir files. Consider adding validation to ensure the format matches the resourceType.

@AssertTrue(message = "Invalid resource identifier format")
private boolean isResourceIdentifierValid() {
    if (resourceType == null || resourceIdentifier == null) {
        return false;
    }
    switch (resourceType) {
        case WIDGET:
            return resourceIdentifier.matches(".*-.*"); // pageGitSyncId-widgetId
        case JS_LIB:
            return resourceIdentifier.matches(".*\\.js$"); // jsLibFileName
        // Add other cases
        default:
            return true;
    }
}

Comment on lines +14 to +15
// TODO @Nidhi should we persist this sha against the Appsmith domain to integrate with the isModified logic?
String sha;
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

Consider SHA validation and resolve TODO comment

The SHA field might benefit from:

  1. Format validation (git SHA is typically 40 characters)
  2. Clear documentation about the isModified logic integration
-    String sha;
+    @Pattern(regexp = "[0-9a-f]{40}", message = "Must be a valid SHA-1 hash")
+    String sha;

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

Comment on lines +11 to +12
// TODO @Nidhi should we persist the info from parsing this filePath ?
String filePath;
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

Based on the analysis of the codebase, I can generate the final response:

Add @nonnull annotation and remove TODO comment

The filePath field is a critical part of GitResourceIdentity and is used extensively throughout the codebase for file operations, particularly in git-related functionality. The field should never be null as evidenced by its usage in FileOperationsCE interface and its implementations.

  • Add @nonnull annotation to filePath field
  • Remove the TODO comment as the field is clearly used for git operations without persistence needs
🔗 Analysis chain

Address TODO comment and consider field constraints

The TODO comment needs resolution before proceeding. Additionally, consider:

  1. Should filePath be @nonnull?
  2. Should we add validation for the file path format?

Let's analyze the usage patterns of filePath and similar fields to determine if @nonnull is commonly used and how filePath is validated or processed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if filePath is used as required in other files
rg "filePath.*=.*null" --type java

Length of output: 36


Script:

#!/bin/bash
# Check how filePath is used in the codebase
rg "filePath" --type java -A 2

# Check for NonNull annotations in similar model classes
ast-grep --pattern 'class $_ {
  $$$
  @NonNull
  $$$
}'

# Check GitResourceIdentity usage
rg "GitResourceIdentity" --type java -A 2

Length of output: 37266

@github-actions
Copy link

Failed server tests

  • com.appsmith.server.refactors.ce.RefactoringServiceCETest#testRefactorCollection_withModifiedName_ignoresName

@nidhi-nair nidhi-nair merged commit 61960ed into release Nov 27, 2024
@nidhi-nair nidhi-nair deleted the chore/git-resource-map-type branch November 27, 2024 04:47
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Nov 27, 2024
@coderabbitai coderabbitai bot mentioned this pull request Dec 3, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants