Skip to content

chore: git detach and push algorithm refinement #39298

Merged
sondermanish merged 3 commits intoreleasefrom
chore/git-detach
Feb 14, 2025
Merged

chore: git detach and push algorithm refinement #39298
sondermanish merged 3 commits intoreleasefrom
chore/git-detach

Conversation

@sondermanish
Copy link
Contributor

@sondermanish sondermanish commented Feb 14, 2025

Description

  • logic modification for two flows
  • git detach
  • git push

Fixes #Issue Number
or
Fixes Issue URL

Warning

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

Automation

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

🔍 Cypress test results

Tip

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


Fri, 14 Feb 2025 14:41:10 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • Refactor

    • Streamlined version control operations for more consistent and reliable artifact management.
    • Simplified method signatures for better usability in artifact management processes.
  • Bug Fixes

    • Improved error messaging and recovery during remote interactions, providing clearer feedback when issues occur.

@sondermanish sondermanish requested a review from a team as a code owner February 14, 2025 12:29
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 14, 2025

Walkthrough

This PR updates the artifact processing logic in two services. In the Central Git service, the detachRemote method now accepts a GitType parameter, and its logic regarding artifact removal has been refined. In the Git FS service, the pushArtifact method signature has been simplified by removing the isFileLock parameter, and both the commitArtifact method call and the error handling logic have been streamlined for clarity.

Changes

File Path Change Summary
app/.../git/central/CentralGitServiceCEImpl.java Updated detachRemote method to include a GitType parameter and revised its artifact removal logic/comments.
app/.../git/fs/GitFSServiceCEImpl.java Removed isFileLock parameter from pushArtifact; updated commitArtifact call accordingly and refined error handling logic.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant CentralGitService
    participant Database
    Client->>CentralGitService: detachRemote(artifactId, artifactType, gitType)
    CentralGitService->>Database: Query branched artifact & metadata
    Database-->>CentralGitService: Artifact data
    CentralGitService->>Database: Remove branched artifacts except base
    Database-->>CentralGitService: Confirmation
    CentralGitService-->>Client: Returns base artifact
Loading
sequenceDiagram
    participant Client
    participant GitFSService
    participant GitRepo
    participant Logger
    Client->>GitFSService: commitArtifact(artifact, commitDTO, transformationDTO)
    GitFSService->>GitRepo: pushArtifact(artifact)
    alt Push Successful
        GitRepo-->>GitFSService: Push confirmation
    else Push Failure (TransportException)
        GitFSService->>Logger: Log error & trigger error recovery
        Logger-->>GitFSService: Error acknowledged
    end
    GitFSService-->>Client: Returns (artifact, commit message)
Loading

Possibly related PRs

Suggested labels

Bug, Enhancement, Git Product, Task

Suggested reviewers

  • nidhi-nair
  • subrata71

Poem

Code flows like a gentle stream,
Artifacts dance, a coder's dream.
Parameters shift, logic refined,
In the world of Git, clarity we find.
Errors logged with a thoughtful grace,
A cleaner path for the code we embrace!

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@sondermanish sondermanish self-assigned this Feb 14, 2025
@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Feb 14, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (7)
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java (4)

1602-1602: Clarify doc comment for branched artifacts
The updated comment more precisely states that only the base artifact is excluded from removal. This is clear and succinct.


1617-1638: Ensure robust error handling in Mono chain
While the chaining logic is clear, handle potential null or unexpected states (e.g. missing metadata) to avoid hidden exceptions.


1617-1624: Validate branchedArtifact.getGitArtifactMetadata() before usage.

You already have a check at line 1624, but ensure any subsequent usage also handles potential null references. This helps guard against unexpected NullPointerExceptions.


1677-1679: Analytics scopes might be expanded.

Currently, you send an event with a false marker for isRepoPrivate. Consider whether a distinction is needed if the repository was previously private. This can give more accurate insights.

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

495-577: Refine pushArtifact logic
The push logic is streamlined. Watch for corner cases like missing keys or empty remote URL, which could cause push failures.


595-610: Improved push error recovery logic.

The pushArtifactErrorRecovery method now clearly identifies and reacts to typical push failures like branch protection rules. The logic that checks the string "pre-receive hook declined" is practical, but you may consider a more robust detection approach (e.g., checking exception types or codes) if available to avoid relying on string matching alone.


559-578: Refined push error handling.

Applying extra checks for “REJECTED_NONFASTFORWARD” vs. “REJECTED_OTHERREASON” is good. Consider capturing more granular error codes from the Git library if needed. This will further improve diagnostic clarity.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2e73bfe and c544815.

📒 Files selected for processing (2)
  • 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/fs/GitFSServiceCEImpl.java (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: server-spotless / spotless-check
  • GitHub Check: server-unit-tests / server-unit-tests
🔇 Additional comments (15)
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java (9)

1606-1607: Add doc detail for gitType parameter
Including the @param gitType annotation is good for clarity and helps future maintainers.


1609-1612: Extend method signature to accept GitType
Verifying that all existing callers and references are updated accordingly is recommended.


1602-1685: Streamlined removal of branched artifacts and local repo.

The updated detachRemote method effectively removes all branch artifacts while preserving the base artifact’s metadata. The use of Mono.zip to parallelize discarding DB references and removing the local repository is sensible, provided that these operations are indeed independent and do not require a particular sequence. If the sequence matters, consider chaining them with flatMap instead. Otherwise, the overall flow for disconnecting the repository and resetting the base artifact’s Git metadata appears consistent. Nicely done!


1602-1602: Documentation enhancement is aligned with updated logic.

Including in the docstring that all branched artifacts (except the base) will be removed clarifies expectations for developers.


1609-1612: Method signature now accepts GitType.

The extra parameter helps route the correct handling service. Verify that all callers of detachRemote have been updated accordingly.


1630-1634: Ensure consistency of naming convention.

Variables baseArtifactId, repoName, workspaceId, refName are introduced in a concise block. This naming style is consistent but make sure it’s uniformly applied throughout the class to improve readability.


1636-1640: JSON transformation steps are logical.

Retaining ref information in the ArtifactJsonTransformationDTO clarifies the context for further operations.


1645-1660: Handle concurrency carefully.

You acquire an edit permission and filter + operate on multiple artifacts. This is typically safe with short operations, but double-check that no race conditions arise when concurrently detaching multiple artifacts from the same base.


1667-1674: Deletion of branched artifacts is appropriate.

You remove all non-base artifacts while resetting the base artifact’s metadata. This aligns with your docstring. Good approach for a clean detach.

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

484-485: Remove isFileLock argument from pushArtifact call
Check all usages to ensure they now conform to the updated signature.


609-610: Handle upstream changes
Immediately throwing an error for upstream changes is valid. Consider offering ways to auto-resolve or stash local changes if needed.


484-484: Updated commit flow invocation.

The direct invocation of pushArtifact(tuple.getT2()) removes the file-lock parameter, simplifying the call site. This aligns with the new push flow design without apparent side effects. Good job!


495-583: Removal of file-lock parameter from pushArtifact.

The newly introduced pushArtifact(Artifact branchedArtifact) signature drops the isFileLock parameter, which might affect concurrency safeguards previously in place. Confirm that all locking or synchronization needs are handled elsewhere or are no longer necessary in this flow. Otherwise, the error handling for transport failures and remote rejections (e.g., TransportException) is neatly structured here.


484-484: Commit flow updated to invoke pushArtifact without isFileLock.

This aligns with the simplified signature. Ensure all internal calls and error paths are tested to confirm no file lock logic is unintentionally lost.


495-546: Simplified pushArtifact signature and improved logging.

  1. Removing isFileLock helps streamline usage.
  2. The logging statements provide helpful context on success/fail.
  3. Verify that older references to the old signature are removed or updated to prevent compile errors.

@sondermanish sondermanish added the ok-to-test Required label for CI label Feb 14, 2025

return fsGitHandler
.checkoutToBranch(
.pushApplication(
Copy link
Collaborator

@subrata71 subrata71 Feb 14, 2025

Choose a reason for hiding this comment

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

Nit: Naming. You wanted to mean pushArtifact maybe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an already existing method, can I take this in another refactor session?

Mono<String> gitPushResult = gitArtifactMetadataMono
.flatMap(gitMetadata -> {
return gitRedisUtils
.acquireGitLock(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please state the reason of removing Git lock placement logic here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because this is always getting called from inside the commit section

Copy link
Contributor Author

Choose a reason for hiding this comment

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

which means that the redis lock would never be required

@@ -493,7 +492,7 @@ public Mono<Tuple2<? extends Artifact, String>> commitArtifact(
* @param branchedArtifact application which needs to be pushed to remote repo
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: comment has reference to application

.map(Tuple3::getT1);
if (artifact.getGitArtifactMetadata() == null
|| RefType.tag.equals(artifact.getGitArtifactMetadata()
.getRefType())) {
Copy link
Collaborator

@subrata71 subrata71 Feb 14, 2025

Choose a reason for hiding this comment

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

It seems llike this logic should precede the above logic from L#1649-L#1659

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java (1)

1612-1679: Consider batch operations for artifact deletion.

While the logic is correct, consider using batch operations for deleting branched artifacts to improve performance when dealing with repositories having many branches.

-                    Mono<? extends Artifact> deleteAllBranchesExceptBase = gitArtifactHelper
-                            .getAllArtifactByBaseId(baseArtifactId, artifactEditPermission)
-                            .flatMap(artifact -> {
-                                if (artifact.getGitArtifactMetadata() == null
-                                        || RefType.tag.equals(artifact.getGitArtifactMetadata()
-                                                .getRefType())) {
-                                    return Mono.just(artifact);
-                                }
-
-                                // it's established that git artifact metadata is not null
-                                if (!artifact.getId().equals(baseArtifactId)) {
-                                    return gitArtifactHelper.deleteArtifactByResource(artifact);
-                                }
+                    Mono<? extends Artifact> deleteAllBranchesExceptBase = gitArtifactHelper
+                            .getAllArtifactByBaseId(baseArtifactId, artifectEditPermission)
+                            .collectList()
+                            .flatMap(artifacts -> {
+                                List<Artifact> artifactsToDelete = artifacts.stream()
+                                        .filter(artifact -> 
+                                            artifact.getGitArtifactMetadata() != null &&
+                                            !RefType.tag.equals(artifact.getGitArtifactMetadata().getRefType()) &&
+                                            !artifact.getId().equals(baseArtifactId))
+                                        .collect(Collectors.toList());
+                                
+                                return Flux.fromIterable(artifactsToDelete)
+                                        .flatMap(gitArtifactHelper::deleteArtifactByResource)
+                                        .then(Mono.justOrEmpty(artifacts.stream()
+                                                .filter(artifact -> artifact.getId().equals(baseArtifactId))
+                                                .findFirst()));
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c544815 and 888cf6f.

📒 Files selected for processing (2)
  • 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/fs/GitFSServiceCEImpl.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/git/fs/GitFSServiceCEImpl.java
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: server-unit-tests / server-unit-tests
  • GitHub Check: server-spotless / spotless-check
🔇 Additional comments (1)
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java (1)

1599-1611: LGTM! Method signature and documentation improvements.

The updated signature with GitType parameter and clarified documentation about artifact removal behavior enhances the API's clarity.

@sondermanish sondermanish merged commit 007f598 into release Feb 14, 2025
45 checks passed
@sondermanish sondermanish deleted the chore/git-detach branch February 14, 2025 16:43
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Apr 12, 2025
## Description
 - logic modification for two flows
 - git detach
 - git push


Fixes #`Issue Number`  
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

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

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/13330609252>
> Commit: 888cf6f
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=13330609252&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Git`
> Spec:
> <hr>Fri, 14 Feb 2025 14:41:10 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

- **Refactor**
- Streamlined version control operations for more consistent and
reliable artifact management.
- Simplified method signatures for better usability in artifact
management processes.

- **Bug Fixes**
- Improved error messaging and recovery during remote interactions,
providing clearer feedback when issues occur.
<!-- 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

ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants