-
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: checkout remote #38390
base: release
Are you sure you want to change the base?
chore: checkout remote #38390
Conversation
WalkthroughThe pull request introduces significant enhancements to the Git service layer in the Appsmith server, focusing on branch protection and auto-commit features. The changes primarily modify the Changes
Possibly Related PRs
Suggested Labels
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: 1
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
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/CentralGitServiceCECompatibleImpl.java
(4 hunks)app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java
(11 hunks)app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceImpl.java
(4 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/fs/GitFSServiceCEImpl.java
(2 hunks)app/server/appsmith-server/src/main/java/com/appsmith/server/git/utils/GitAnalyticsUtils.java
(2 hunks)
🔇 Additional comments (34)
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/GitHandlingServiceCE.java (1)
50-50
: Check for backward compatibility due to parameter removal.
Removing the RefType refType
parameter may break callers who rely on it. Confirm that all usages of listReferences
have been updated accordingly and that none depend on the missing parameter's functionality. If you intend to maintain backward compatibility, consider overloading this method or communicating a clear migration path to other teams.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCEImpl.java (1)
621-626
: Confirm whether checkout is truly required.
The TODO
hints you may not always need to checkout the branch after fetching. If this is conditional or optional, consider branching logic or clarifying the intent to avoid unnecessary checkouts.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java (8)
19-19
: No issues with the added import.
The newly introduced AutoCommitConfig
class is referenced properly.
29-29
: Import convention is fine.
Nothing suspicious about adding AutoCommitResponseDTO
.
35-35
: Import looks correct.
The GitAutoCommitHelper
dependency is needed for auto-commit operations.
56-56
: Transactional support import acknowledged.
TransactionalOperator
provides robust transactional behavior.
67-67
: No issues with the added import.
This ArrayList
import is consistent with standard usage.
93-93
: Field addition is consistent.
Keeping gitRedisUtils
as final aligns with your dependency injection pattern.
113-114
: Properly introduced final fields.
gitAutoCommitHelper
and transactionalOperator
are standard dependencies for auto-commit & transactions.
1857-1979
: Enhance user awareness in error handling.
When rejecting protection of multiple or non-default branches, consider making the error message more descriptive for better clarity.
Validate concurrency safety.
While transactionalOperator
helps, verify that parallel updates to protected branches cannot result in inconsistent states or race conditions.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCE.java (7)
10-10
: LGTM on import.
AutoCommitResponseDTO
is properly introduced.
14-14
: List import is fine.
No conflicts spotted with existing classes.
47-50
: Signature update noted.
Switching to GitRefDTO
parameter clarifies reference details and is consistent with the new approach.
58-60
: New method: updateProtectedBranches.
Provides needed branch protection updates. Looks well-defined.
61-62
: New method: getProtectedBranches.
Retrieves branch protection info. Straightforward addition.
63-64
: New method: toggleAutoCommitEnabled.
Good to see a direct toggle approach for auto-commit.
65-66
: New method: getAutoCommitProgress.
Offers insight into auto-commit status. Method naming is clear.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceImpl.java (6)
6-6
: Auto-commit helper import looks correct.
This import ensures usage of the newly introduced helper.
21-21
: Transactional handling import.
Essential for ensuring atomic operations.
28-28
: Constructor injection changes observed.
Reorganizing constructor parameters to meet new dependencies is standard practice.
42-43
: Additional params for dependencies.
gitAutoCommitHelper
& transactionalOperator
are now part of the constructor, consistent with the updated logic.
46-46
: Super constructor call.
Ensures inherited functionality remains intact after refactor.
60-61
: Extended dependencies.
All references well-initialized in the superclass call.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCECompatibleImpl.java (6)
6-6
: Import for auto-commit.
This addition aligns with the new features introduced in CentralGitServiceCEImpl
.
21-21
: Transaction import is standard.
Indicates use of reactive transactions across methods.
29-29
: Constructor change seen.
The shift in dependencies from GitRedisUtils
to additional helpers is acceptable.
43-44
: Parameters for helper & operator.
Appropriately injects GitAutoCommitHelper
and transactionalOperator
.
47-47
: Super invocation.
Properly forwarding gitRedisUtils
to the parent.
61-62
: Dependency passing to superclass.
Maintains consistency with CentralGitServiceCEImpl
.
app/server/appsmith-server/src/main/java/com/appsmith/server/git/utils/GitAnalyticsUtils.java (5)
16-16
: Added Flux & Mono.
Enables asynchronous event operations for analytics.
19-21
: Additions for collection handling.
ArrayList
and List
are standard classes for storing new/old protected branches.
24-25
: New analytics event constants.
GIT_ADD_PROTECTED_BRANCH
& GIT_REMOVE_PROTECTED_BRANCH
are aligned with your naming convention.
154-189
: Comprehensive analytics method added.
sendBranchProtectionAnalytics
cleanly logs newly protected vs removed branches. Implementation is succinct and uses flux merging for parallel event emission.
168-189
: Fine-grained branch analytics.
Sending separate events for added or removed protected branches fosters detailed tracking.
ArtifactJsonTransformationDTO artifactJsonTransformationDTO, Boolean checkRemoteReferences) { | ||
if (RefType.BRANCH.equals(artifactJsonTransformationDTO.getRefType())) { |
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.
Complete the reactive chain for listReferences().
The current code calls listBranches(...)
but does not return its result, instead returning an empty list. This likely breaks the intended functionality for listing references.
Here is a potential fix that returns the list of branch names when RefType.BRANCH
is detected:
- if (RefType.BRANCH.equals(artifactJsonTransformationDTO.getRefType())) {
- listBranches(artifactJsonTransformationDTO, checkRemoteReferences);
- }
-
- return Mono.just(List.of());
+ if (RefType.BRANCH.equals(artifactJsonTransformationDTO.getRefType())) {
+ return listBranches(artifactJsonTransformationDTO, checkRemoteReferences);
+ } else {
+ // TODO: Add logic for other reference types (e.g., tags)
+ return Mono.just(List.of());
+ }
Committable suggestion skipped: line range outside the PR's diff.
Updated the client version from 1 to 2 in the JsonSchemaVersionsFallback class to align with the latest schema changes. With introduction fo HTML column type in appsmith table, we don't want, apps exported from a newer version to be importable in the older version.
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
♻️ Duplicate comments (1)
app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCEImpl.java (1)
298-299
:⚠️ Potential issueFix missing return value in listReferences method.
The method calls
listBranches
but doesn't return its result, which breaks the functionality for listing references.Apply this fix:
-if (RefType.BRANCH.equals(artifactJsonTransformationDTO.getRefType())) { - listBranches(artifactJsonTransformationDTO, checkRemoteReferences); -} +if (RefType.BRANCH.equals(artifactJsonTransformationDTO.getRefType())) { + return listBranches(artifactJsonTransformationDTO, checkRemoteReferences); +}
🧹 Nitpick comments (5)
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCE.java (1)
61-69
: Consider using a structured DTO for protected branch rulesWhile the current implementation using
List<String>
works, consider creating aProtectedBranchDTO
to support more complex branch protection rules in the future (e.g., required reviewers, build checks).Example structure:
public class ProtectedBranchDTO { private String branchName; private boolean requirePullRequest; private int requiredReviewers; // Add more rules as needed }app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java (4)
Line range hint
58-70
: UnusedPath
variable.
Path repoSuffix
at line 1695 is declared but not used. Consider removing it if not needed.
378-387
: Duplicate input validation.
Both this method and the overloaded one above validategitRefDTO
. Consider consolidating to reduce duplication.
461-542
: Multiple checkoutReference methods.
The approach is correct, but there's potential repetition across the codebase. A combined utility might be clearer.
2019-2052
: Branch protection constraints.
Imposing only one protected branch (the default) may be a business requirement. If not, confirm it aligns with future plans.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
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
(13 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/fs/GitFSServiceCEImpl.java
(4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/GitHandlingServiceCE.java
🔇 Additional comments (13)
app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCEImpl.java (1)
622-627
: Verify necessity of unconditional branch checkout.
The TODO comment suggests reviewing if branch checkout is always required after fetch. Consider making the checkout conditional based on the use case.
Run this script to analyze the usage patterns:
✅ Verification successful
Let me analyze the implementation and test cases to understand if the checkout is always required after fetch.
Let me analyze the implementation to understand if the checkout is always required and in what contexts it's being used.
Let me analyze the full context of the GitFSService implementation to understand the checkout requirement.
Branch checkout is required after fetch
Based on the test cases and implementation context, the checkout operation appears necessary after fetch to ensure the working directory reflects the fetched changes. The TODO comment can be removed since:
- The method is used in auto-commit and merge operations that require the working directory to be in sync
- Test cases verify branch tracking status after fetch, implying the need for checkout
- The method is part of GitFSService which handles file system operations
Note: If you want to optimize this in the future, consider adding a parameter to make checkout optional, but for current use cases, it's required.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Find callers of fetchRemoteChanges to understand checkout requirements
# Search for method calls
ast-grep --pattern 'fetchRemoteChanges($$$)'
# Search for tests to understand expected behavior
rg -l "fetchRemoteChanges.*test" -g "*.java"
Length of output: 66818
Script:
#!/bin/bash
# Search for fetchRemoteChanges method implementation and its callers
ast-grep --pattern 'fetchRemoteChanges($$$) {
$$$
}'
# Search for tests related to fetchRemoteChanges
rg -A 5 'fetchRemoteChanges' -g '*Test.java'
Length of output: 5212
Script:
#!/bin/bash
# Search for the implementation of fetchRemoteChanges to understand its usage context
rg -A 10 'fetchRemoteChanges.*\{' -g '*.java'
# Search for the implementation of checkoutToBranch to understand its purpose
ast-grep --pattern 'checkoutToBranch($$$) {
$$$
}'
Length of output: 1844
Script:
#!/bin/bash
# Search for the GitFSServiceCEImpl class implementation to understand the context
rg -A 20 'class GitFSServiceCEImpl' -g '*.java'
# Search for the specific method implementation
rg -B 5 -A 20 'fetchRemoteChanges.*\{.*repoSuffix' -g '*.java'
Length of output: 2986
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCE.java (2)
10-15
: LGTM: Required imports added for new functionality
46-53
: LGTM: Enhanced type safety in Git operations
The changes improve type safety by:
- Using GitPullDTO for structured pull responses
- Replacing String reference with GitRefDTO for checkout operations
Let's verify the GitRefDTO usage across the codebase:
✅ Verification successful
Proceed with the type-safe changes
The changes to use GitRefDTO and structured GitPullDTO responses are safe to implement. No legacy String-based reference checkouts were found in the codebase that would need updating.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for any remaining String-based reference checkouts that might need updating
ast-grep --pattern 'checkout$_($_, String $_)'
Length of output: 48
Script:
#!/bin/bash
# Let's try a different pattern to find checkout method implementations and usages
ast-grep --pattern 'checkoutReference($$$)'
# Also search for GitRefDTO usage
rg "GitRefDTO" -A 2
Length of output: 66313
Script:
#!/bin/bash
# Let's search for GitRefDTO class definition and usages
ast-grep --pattern 'class GitRefDTO'
# Also search for checkoutReference method implementations
ast-grep --pattern 'checkoutReference($_, $_, $_, $_, $_)'
Length of output: 802
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java (10)
Line range hint 6-37
: No issues with the newly added imports.
They look properly utilized in subsequent code references.
Line range hint 96-117
: Initialization looks good.
All newly introduced dependencies appear valid and properly referenced.
355-367
: Method signature is consistent.
Input validation is handled correctly. Consider adding JavaDoc for clarity if needed.
373-373
: Direct delegation is clean.
This single-line return helps keep logic centralized in the protected method. Nicely done.
396-396
: Validate preconditions on refName replacement.
Ensure the user-supplied ref indeed starts with "origin/" before replacing.
415-431
: Logic for remote vs local references looks sound.
Ensure coverage in unit tests for edge cases (e.g., ref already local).
2054-2072
: Straightforward update.
The transactional flow is appropriate. The analytics step is a nice touch.
2073-2098
: Single default branch protection.
Consistently returning only the default branch if protected. This implementation matches the current business logic.
2099-2136
: Concurrency consideration for auto-commit toggle.
If multiple toggles occur in parallel, the final state might be uncertain. Evaluate synchronization if this is a concern.
2137-2141
: Pass-through method for auto-commit progress.
Implementation is minimal yet effective.
|
||
@Override | ||
public Mono<MergeStatusDTO> pullArtifact( | ||
ArtifactJsonTransformationDTO jsonTransformationDTO, GitArtifactMetadata baseMetadata) { | ||
GitArtifactHelper<?> gitArtifactHelper = | ||
gitArtifactHelperResolver.getArtifactHelper(jsonTransformationDTO.getArtifactType()); | ||
|
||
Path repoSuffix = gitArtifactHelper.getRepoSuffixPath( | ||
jsonTransformationDTO.getWorkspaceId(), | ||
jsonTransformationDTO.getBaseArtifactId(), | ||
jsonTransformationDTO.getRepoName()); | ||
|
||
String branchName = jsonTransformationDTO.getRefName(); | ||
|
||
// git checkout and pull origin branchName | ||
try { | ||
return fsGitHandler | ||
.checkoutToBranch(repoSuffix, jsonTransformationDTO.getRefName()) | ||
.then(fsGitHandler.pullApplication( | ||
repoSuffix, | ||
baseMetadata.getRemoteUrl(), | ||
branchName, | ||
baseMetadata.getGitAuth().getPrivateKey(), | ||
baseMetadata.getGitAuth().getPublicKey())) | ||
.onErrorResume(error -> { | ||
if (error.getMessage().contains("conflict")) { | ||
return Mono.error( | ||
new AppsmithException(AppsmithError.GIT_PULL_CONFLICTS, error.getMessage())); | ||
} else if (error.getMessage().contains("Nothing to fetch")) { | ||
MergeStatusDTO mergeStatus = new MergeStatusDTO(); | ||
mergeStatus.setStatus("Nothing to fetch from remote. All changes are up to date."); | ||
mergeStatus.setMergeAble(true); | ||
return Mono.just(mergeStatus); | ||
} | ||
return Mono.error( | ||
new AppsmithException(AppsmithError.GIT_ACTION_FAILED, "pull", error.getMessage())); | ||
}); | ||
} catch (IOException e) { | ||
return Mono.error(new AppsmithException(AppsmithError.GIT_FILE_SYSTEM_ERROR, e.getMessage())); | ||
} | ||
} |
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
Improve error handling in pullArtifact method.
The error handling can be enhanced in several ways:
- Remove the redundant IOException try-catch as fsGitHandler methods already handle these exceptions
- Use more robust error detection than string contains
- Provide more specific error messages for different types of conflicts
Apply these improvements:
- try {
return fsGitHandler
.checkoutToBranch(repoSuffix, jsonTransformationDTO.getRefName())
.then(fsGitHandler.pullApplication(
repoSuffix,
baseMetadata.getRemoteUrl(),
branchName,
baseMetadata.getGitAuth().getPrivateKey(),
baseMetadata.getGitAuth().getPublicKey()))
.onErrorResume(error -> {
- if (error.getMessage().contains("conflict")) {
+ if (error instanceof org.eclipse.jgit.api.errors.CheckoutConflictException) {
return Mono.error(
- new AppsmithException(AppsmithError.GIT_PULL_CONFLICTS, error.getMessage()));
+ new AppsmithException(AppsmithError.GIT_PULL_CONFLICTS,
+ "Conflicts detected in: " + error.getMessage()));
- } else if (error.getMessage().contains("Nothing to fetch")) {
+ } else if (error instanceof org.eclipse.jgit.api.errors.NoHeadException) {
MergeStatusDTO mergeStatus = new MergeStatusDTO();
mergeStatus.setStatus("Nothing to fetch from remote. All changes are up to date.");
mergeStatus.setMergeAble(true);
return Mono.just(mergeStatus);
}
return Mono.error(
new AppsmithException(AppsmithError.GIT_ACTION_FAILED, "pull", error.getMessage()));
});
- } catch (IOException e) {
- return Mono.error(new AppsmithException(AppsmithError.GIT_FILE_SYSTEM_ERROR, e.getMessage()));
- }
Committable suggestion skipped: line range outside the PR's diff.
Description
Tip
Add a TL;DR when the description is longer than 500 words or extremely technical (helps the content, marketing, and DevRel team).
Please also include relevant motivation and context. List any dependencies that are required for this change. Add links to Notion, Figma or any other documents that might be relevant to the PR.
Fixes #
Issue Number
or
Fixes
Issue URL
Warning
If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.
Automation
/ok-to-test tags=""
🔍 Cypress test results
Warning
Tests have not run on the HEAD 9737897 yet
Fri, 27 Dec 2024 15:34:35 UTC
Communication
Should the DevRel and Marketing teams inform users about this change?
Summary by CodeRabbit
New Features
Bug Fixes
Chores