-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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: reference lifecycle #38174
chore: reference lifecycle #38174
Conversation
WalkthroughThis pull request introduces enhancements to Git-related services and constants in the Appsmith server codebase. The changes primarily focus on expanding Git reference handling capabilities, introducing new methods for branch and reference management, and updating constants. The modifications span multiple files across server and interface packages, introducing new DTOs, enums, and service methods to improve Git operation flexibility. Changes
Assessment against linked issues
Possibly related PRs
Suggested reviewers
Poem
Tip CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command 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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (5)
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCE.java (2)
38-40
: Add JavaDoc comments forgetStatus
methodIncluding JavaDoc for the
getStatus
method would improve code readability and maintainability.
41-47
: Document thecheckoutReference
methodAdding JavaDoc comments to
checkoutReference
will help clarify its purpose and usage.app/server/appsmith-interfaces/src/main/java/com/appsmith/external/dtos/ce/GitStatusCE_DTO.java (1)
11-11
: Address the TODO commentPlease resolve the TODO or create a follow-up task to ensure it doesn't get overlooked.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/GitHandlingServiceCE.java (2)
46-47
: Include JavaDoc forlistReferences
Adding documentation to the
listReferences
method would enhance understanding for future maintainers.
70-70
: Add documentation forgetStatus
methodProviding JavaDoc comments for
getStatus
will improve code clarity and usability.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
app/server/appsmith-interfaces/src/main/java/com/appsmith/external/dtos/ce/GitStatusCE_DTO.java
(1 hunks)app/server/appsmith-server/src/main/java/com/appsmith/server/constants/ce/FieldNameCE.java
(1 hunks)app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCE.java
(2 hunks)app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java
(6 hunks)app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/GitHandlingServiceCE.java
(4 hunks)app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCEImpl.java
(3 hunks)
🔇 Additional comments (5)
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java (3)
339-359
: Well-implemented checkoutReference
method
The new checkoutReference
method is correctly overloaded and includes proper input validation and error handling.
361-433
: Efficient overload of checkoutReference
The protected overload of checkoutReference
effectively reuses logic and maintains consistency.
1038-1167
: Comprehensive implementation of getStatus
methods
The getStatus
methods are well-structured, with clear delegation and error handling. They enhance the Git operation capabilities effectively.
app/server/appsmith-server/src/main/java/com/appsmith/server/constants/ce/FieldNameCE.java (1)
105-105
: LGTM!
The new constant follows the established naming patterns and is appropriately placed.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCEImpl.java (1)
Line range hint 282-647
: Verify consistent Git command patterns
Let's verify that the new Git operations follow the same patterns as existing ones across the codebase.
@Override | ||
public Mono<List<String>> listReferences( | ||
ArtifactJsonTransformationDTO artifactJsonTransformationDTO, RefType refType) { | ||
if (RefType.BRANCH.equals(refType)) { | ||
listBranches(artifactJsonTransformationDTO); | ||
} | ||
|
||
// TODO: include ref type for tags in fsGit Handler | ||
return Mono.just(List.of()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the branch listing implementation
The method has two critical issues:
- The
listBranches
result is not being returned (missingreturn
) - The method always returns an empty list regardless of the branch listing result
Apply this fix:
@Override
public Mono<List<String>> listReferences(
ArtifactJsonTransformationDTO artifactJsonTransformationDTO, RefType refType) {
if (RefType.BRANCH.equals(refType)) {
- listBranches(artifactJsonTransformationDTO);
+ return listBranches(artifactJsonTransformationDTO);
}
// TODO: include ref type for tags in fsGit Handler
return Mono.just(List.of());
}
📝 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.
@Override | |
public Mono<List<String>> listReferences( | |
ArtifactJsonTransformationDTO artifactJsonTransformationDTO, RefType refType) { | |
if (RefType.BRANCH.equals(refType)) { | |
listBranches(artifactJsonTransformationDTO); | |
} | |
// TODO: include ref type for tags in fsGit Handler | |
return Mono.just(List.of()); | |
} | |
@Override | |
public Mono<List<String>> listReferences( | |
ArtifactJsonTransformationDTO artifactJsonTransformationDTO, RefType refType) { | |
if (RefType.BRANCH.equals(refType)) { | |
return listBranches(artifactJsonTransformationDTO); | |
} | |
// TODO: include ref type for tags in fsGit Handler | |
return Mono.just(List.of()); | |
} |
@Override | ||
public Mono<GitStatusDTO> getStatus(ArtifactJsonTransformationDTO jsonTransformationDTO) { | ||
String workspaceId = jsonTransformationDTO.getWorkspaceId(); | ||
String baseArtifactId = jsonTransformationDTO.getBaseArtifactId(); | ||
String repoName = jsonTransformationDTO.getRepoName(); | ||
String refName = jsonTransformationDTO.getRefName(); | ||
|
||
ArtifactType artifactType = jsonTransformationDTO.getArtifactType(); | ||
GitArtifactHelper<?> gitArtifactHelper = gitArtifactHelperResolver.getArtifactHelper(artifactType); | ||
Path repoSuffix = gitArtifactHelper.getRepoSuffixPath(workspaceId, baseArtifactId, repoName); | ||
|
||
Path repoPath = fsGitHandler.createRepoPath(repoSuffix); | ||
return fsGitHandler.getStatus(repoPath, refName); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add error handling for Git operations
The method should handle potential Git exceptions that could occur during status retrieval.
Apply this improvement:
@Override
public Mono<GitStatusDTO> getStatus(ArtifactJsonTransformationDTO jsonTransformationDTO) {
String workspaceId = jsonTransformationDTO.getWorkspaceId();
String baseArtifactId = jsonTransformationDTO.getBaseArtifactId();
String repoName = jsonTransformationDTO.getRepoName();
String refName = jsonTransformationDTO.getRefName();
ArtifactType artifactType = jsonTransformationDTO.getArtifactType();
GitArtifactHelper<?> gitArtifactHelper = gitArtifactHelperResolver.getArtifactHelper(artifactType);
Path repoSuffix = gitArtifactHelper.getRepoSuffixPath(workspaceId, baseArtifactId, repoName);
Path repoPath = fsGitHandler.createRepoPath(repoSuffix);
- return fsGitHandler.getStatus(repoPath, refName);
+ return fsGitHandler.getStatus(repoPath, refName)
+ .onErrorResume(error -> {
+ log.error("Error getting Git status: {}", error.getMessage());
+ return Mono.error(new AppsmithException(
+ AppsmithError.GIT_ACTION_FAILED,
+ "status",
+ error.getMessage()));
+ });
}
Committable suggestion skipped: line range outside the PR's diff.
Mono<GitStatusDTO> getStatus( | ||
String branchedArtifactId, boolean compareRemote, ArtifactType artifactType, GitType gitType); | ||
|
||
Mono<? extends Artifact> checkoutReference( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, should we not be able to make a DTO out of these params?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we can!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will you be replacing usage in a separate PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (3)
app/server/appsmith-interfaces/src/main/java/com/appsmith/external/dtos/GitRefDTO.java (1)
8-11
: Consider adding @builder annotation for flexible object creation.The Lombok annotations are good, but adding
@Builder
would provide a more flexible way to create instances, especially useful when not all fields are required.@Data @AllArgsConstructor @NoArgsConstructor +@Builder public class GitRefDTO {
app/server/appsmith-server/src/main/java/com/appsmith/server/git/dtos/ArtifactJsonTransformationDTO.java (1)
7-7
: Address the TODO comment about DTO namingThe TODO indicates uncertainty about the DTO name. Consider renaming to
GitArtifactTransformationDTO
to better reflect its purpose.app/server/appsmith-server/src/main/java/com/appsmith/server/domains/ce/GitArtifactMetadataCE.java (1)
Line range hint
31-34
: Track completion of transient field implementationThe TODO comments and @transient annotations indicate incomplete implementation. Consider creating tracking issues for:
- Making fields public
- Removing @transient annotations
Would you like me to create GitHub issues to track these implementation tasks?
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
app/server/appsmith-interfaces/src/main/java/com/appsmith/external/dtos/GitRefDTO.java
(1 hunks)app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/constants/ce/RefType.java
(1 hunks)app/server/appsmith-server/src/main/java/com/appsmith/server/constants/ce/RefType.java
(0 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/git/central/CentralGitServiceCE.java
(2 hunks)app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java
(6 hunks)app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/GitHandlingServiceCE.java
(3 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/GitFSServiceCEImpl.java
(5 hunks)
💤 Files with no reviewable changes (1)
- app/server/appsmith-server/src/main/java/com/appsmith/server/constants/ce/RefType.java
✅ Files skipped from review due to trivial changes (1)
- app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/constants/ce/RefType.java
🚧 Files skipped from review as they are similar to previous changes (1)
- app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCE.java
👮 Files not reviewed due to content moderation or server errors (2)
- app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCEImpl.java
- app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java
🔇 Additional comments (6)
app/server/appsmith-interfaces/src/main/java/com/appsmith/external/dtos/GitRefDTO.java (2)
1-7
: LGTM! Package structure and imports are well-organized.
1-20
: Verify REST API usage and enum alignment.
Please verify:
- If this DTO will be used in REST endpoints, consider adding Jackson annotations
- Ensure RefType enum values cover all necessary Git reference types (branches, tags, remote refs)
✅ Verification successful
GitRefDTO implementation is appropriate for its usage context
The verification shows:
- GitRefDTO is only used internally in the service layer (CentralGitServiceCEImpl), not exposed via REST endpoints, so Jackson annotations aren't needed
- RefType enum correctly covers the essential Git reference types (BRANCH, TAG) which aligns with the DTO's usage in Git operations
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check if this DTO is used in REST controllers and if we need Jackson annotations
rg -l "GitRefDTO" | grep -i "controller"
# Verify RefType enum values
ast-grep --pattern 'enum RefType {
$$$
}'
Length of output: 84
Script:
#!/bin/bash
# Search for GitRefDTO usage in all files
rg -l "GitRefDTO"
# Check if GitRefDTO is used in any REST-related context
rg "GitRefDTO" -A 5 -B 5
# Search for RefType enum definition
fd -e java -e kt -x rg -l "enum.*RefType"
# If found, show the enum content
fd -e java -e kt -x rg "enum.*RefType" -A 10
Length of output: 4284
app/server/appsmith-server/src/main/java/com/appsmith/server/git/dtos/ArtifactJsonTransformationDTO.java (1)
3-3
: LGTM! Import change aligns with external Git types
The RefType import change is appropriate as it moves towards using common Git types from the external package.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/GitHandlingServiceCE.java (2)
71-72
: Verify impact of isFetchAll parameter
The new isFetchAll
parameter in fetchRemoteChanges
could significantly impact performance with large repositories.
44-45
: Consider adding validation for remote branch operations
The new branch and reference listing methods should include error handling for network failures and invalid remote states.
Also applies to: 49-52
app/server/appsmith-server/src/main/java/com/appsmith/server/domains/ce/GitArtifactMetadataCE.java (1)
Line range hint 109-110
: Clarify TODO comment intention
The TODO comment about restricting access needs clarification. Consider:
- What specific access restrictions are needed?
- When will the migration be performed?
String refName; | ||
|
||
RefType refType; | ||
|
||
boolean isDefault; | ||
|
||
boolean createdFromLocal; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add field validation and documentation.
The fields would benefit from:
- Validation annotations for refName
- JavaDoc documentation explaining each field's purpose
- Making fields final for immutability
+import javax.validation.constraints.NotNull;
+
@Data
@AllArgsConstructor
@NoArgsConstructor
public class GitRefDTO {
+ /** The name of the Git reference (e.g., branch name or tag name) */
+ @NotNull
- String refName;
+ private final String refName;
+ /** The type of the Git reference (BRANCH or TAG) */
+ @NotNull
- RefType refType;
+ private final RefType refType;
+ /** Indicates if this is the default reference (e.g., default branch) */
- boolean isDefault;
+ private final boolean isDefault;
+ /** Indicates if the reference was created in the local repository */
- boolean createdFromLocal;
+ private final boolean createdFromLocal;
Committable suggestion skipped: line range outside the PR's diff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (6)
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java (6)
349-351
: Refactor duplicated null checks forreferenceToBeCheckedOut
The null check for
referenceToBeCheckedOut
is duplicated in both methods. Consider refactoring to eliminate code duplication.Also applies to: 369-371
413-416
: Clarify error message for existing local referenceThe error message can be clearer. Suggest rephrasing to:
"Reference '" + referenceToBeCheckedOut + "' already exists locally as '" + finalRefName + "'."
419-419
: Address the TODO: Refactor method to account forRefName
Please address the TODO comment to refactor the method and include
RefName
handling.Would you like assistance with this refactor?
486-486
: IncluderefType
in error messagesUpdate the error handling to include
refType
for better clarity.
525-525
: Address the TODO: AddrefType
supportPlease implement
refType
support as indicated by the TODO comment.Would you like assistance in adding this support?
538-538
: Refine error handling strategyConsider refactoring to handle this error in the appropriate layer, as suggested by the TODO.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java
(4 hunks)
🔇 Additional comments (1)
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java (1)
553-554
: Review use of doOnSuccess
for state changes
Using doOnSuccess
to call discardChanges
may cause unintended side effects. Verify if flatMap
is more appropriate for this operation.
GitConstants.GitCommandConstants.CREATE_BRANCH, | ||
FALSE); | ||
Mono<String> fetchRemoteMono = | ||
gitHandlingService.fetchRemoteChanges(jsonTransformationDTO, baseGitAuth, TRUE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update fetchRemoteChanges
calls to match new method signature
The fetchRemoteChanges
method signature has changed. Update the calls at lines 498 and 1334 to match the new parameters, preventing compilation errors.
Example correction:
- gitHandlingService.fetchRemoteChanges(jsonTransformationDTO, baseGitAuth, TRUE);
+ gitHandlingService.fetchRemoteChanges(baseArtifact, refArtifact, TRUE, gitType, refType);
Also applies to: 1334-1335
GitRefDTO refDTO, | ||
ArtifactType artifactType, | ||
GitType gitType, | ||
RefType refType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we sending ref type separately here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can put it in the DTO itself, right.
Failed server tests
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java (2)
491-492
: Add RefType in error message.The TODO comment indicates missing RefType in error message which could make debugging harder.
Consider updating the error message to include RefType:
- new AppsmithException( - AppsmithError.INVALID_GIT_CONFIGURATION, - "Unable to find the parent reference. Please create a reference from other available references")); + new AppsmithException( + AppsmithError.INVALID_GIT_CONFIGURATION, + "Unable to find the parent reference of type " + refType + ". Please create a reference from other available references"));
542-543
: Consider moving error handling to handling layer.The TODO comment suggests moving error handling to a dedicated layer for better separation of concerns.
Consider creating a dedicated error handling service/layer for Git operations to maintain consistency across the codebase.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
app/server/appsmith-server/src/main/java/com/appsmith/server/constants/ce/FieldNameCE.java
(1 hunks)app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCE.java
(2 hunks)app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java
(5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- app/server/appsmith-server/src/main/java/com/appsmith/server/constants/ce/FieldNameCE.java
🔇 Additional comments (4)
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCE.java (2)
42-48
: LGTM! Well-structured method signature.
The method signature is comprehensive and follows reactive programming patterns with Mono return type.
50-51
: LGTM! Clean method signature using DTO pattern.
The method signature appropriately uses GitRefDTO to encapsulate reference details.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java (2)
110-111
: LGTM! Well-defined constants.
Constants are appropriately named and scoped for Git reference handling.
1339-1340
: LGTM! Proper method call with updated parameters.
The fetchRemoteChanges call correctly uses the new parameter structure.
// TODO @Manish: add checkout Remote Branch | ||
protected Mono<? extends Artifact> checkoutRemoteBranch(Artifact baseArtifact, String finalRefName) { | ||
return null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implement the checkoutRemoteBranch method.
The method is currently returning null which could lead to NullPointerException when checking out remote branches.
Would you like me to help implement this method or create a GitHub issue to track this task?
Description
Fixes #37451, #37455, #37448
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/12370910561
Commit: 03a3843
Cypress dashboard.
Tags:
@tag.Git
Spec:
Tue, 17 Dec 2024 11:05:27 UTC
Communication
Should the DevRel and Marketing teams inform users about this change?
Summary by CodeRabbit
New Features
GitRefDTO
created to represent Git references.RefType
defined to categorize reference types.Bug Fixes
Chores
ORGANIZATION_ID
constant and introducedREF_NAME
.RefType
across multiple classes.