Skip to content
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: Added changes for discard #38152

Merged
merged 3 commits into from
Dec 13, 2024
Merged

chore: Added changes for discard #38152

merged 3 commits into from
Dec 13, 2024

Conversation

sondermanish
Copy link
Contributor

@sondermanish sondermanish commented Dec 13, 2024

Description

  • Added implementation for discard

Fixes #37438

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


Fri, 13 Dec 2024 12:18:45 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Introduced a method to discard changes associated with a specified branched artifact.
    • Added functionality to recreate artifact JSON from the last commit.
  • Bug Fixes

    • Enhanced handling of lock requirements in Git operations, allowing for null values.
  • Documentation

    • Updated method signatures and added descriptions for new functionalities.

@sondermanish sondermanish requested a review from a team as a code owner December 13, 2024 08:39
@sondermanish sondermanish self-assigned this Dec 13, 2024
Copy link
Contributor

coderabbitai bot commented Dec 13, 2024

Walkthrough

The changes in this pull request involve modifications to method signatures in the GitRedisUtils class to allow for nullable parameters. Additionally, new methods have been introduced in the CentralGitServiceCE, CentralGitServiceCEImpl, GitHandlingServiceCE, and GitFSServiceCEImpl classes. These new methods facilitate the discarding of changes and the recreation of artifact JSON from the last commit, enhancing the functionality related to Git operations within the application.

Changes

File Change Summary
appsmith-server/src/main/java/com/appsmith/server/git/GitRedisUtils.java Updated method signatures of acquireGitLock and releaseFileLock to change boolean to Boolean.
appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCE.java Added method discardChanges for handling the discarding of changes.
appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java Added method discardChanges to reset an artifact to its last committed state.
appsmith-server/src/main/java/com/appsmith/server/git/central/GitHandlingServiceCE.java Added method recreateArtifactJsonFromLastCommit to recreate artifact JSON from the last commit.
appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCEImpl.java Added method recreateArtifactJsonFromLastCommit to implement JSON reconstruction from the last commit.

Assessment against linked issues

Objective Addressed Explanation
Switch git discard and pull method to super service (#37438)

Possibly related PRs

Suggested labels

Bug

Suggested reviewers

  • nidhi-nair

🎉 In the realm of code where changes flow,
Boolean now dances, with a nullable glow.
Methods added, new paths to explore,
Discarding changes, unlocking the core.
With Git in our hands, we craft and we weave,
In the world of Appsmith, we dare to believe! 🎉


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. (Experiment)
  • @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 Git Product Issues related to version control product Packages & Git Pod All issues belonging to Packages and Git potential-duplicate This label marks issues that are potential duplicates of already open issues Task A simple Todo labels Dec 13, 2024
@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Dec 13, 2024
@sondermanish sondermanish added the ok-to-test Required label for CI label Dec 13, 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: 2

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

Line range hint 72-77: LGTM! Consider using Optional for better null handling.

The change from boolean to Boolean is acceptable, but consider using Optional<Boolean> for more explicit null handling.

-public Mono<Boolean> acquireGitLock(String baseArtifactId, String commandName, Boolean isLockRequired) {
+public Mono<Boolean> acquireGitLock(String baseArtifactId, String commandName, Optional<Boolean> isLockRequired) {
-    if (!Boolean.TRUE.equals(isLockRequired)) {
+    if (!isLockRequired.orElse(false)) {
         return Mono.just(Boolean.TRUE);
     }

Line range hint 89-95: Fix parameter type inconsistency.

The parameter type for isLockRequired should be Boolean to maintain consistency with acquireGitLock.

-public Mono<Boolean> releaseFileLock(String baseArtifactId, boolean isLockRequired) {
+public Mono<Boolean> releaseFileLock(String baseArtifactId, Boolean isLockRequired) {

71-71: Address TODO comments in follow-up PR.

The TODO comments indicate a need to add artifactType reference. Consider creating a follow-up task.

Would you like me to create a GitHub issue to track the addition of artifactType reference?

Also applies to: 88-88

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

1171-1172: Improve error logging.

The error log is missing the actual error message from the throwable.

-log.error("Git recreate ArtifactJsonFailed", throwable.getMessage());
+log.error("Git recreate ArtifactJsonFailed: {}", throwable.getMessage(), throwable);

1139-1196: Consider breaking down the reactive chain.

The reactive chain is complex and could be simplified for better maintainability.

Extract the artifact recreation logic into a separate method:

private Mono<? extends Artifact> recreateArtifactFromLastCommit(
        Artifact branchedArtifact, 
        GitHandlingService gitHandlingService) {
    GitArtifactMetadata branchedGitData = branchedArtifact.getGitArtifactMetadata();
    ArtifactJsonTransformationDTO jsonTransformationDTO = new ArtifactJsonTransformationDTO();
    jsonTransformationDTO.setArtifactType(artifactType);
    // ... set other fields ...

    return gitHandlingService
            .recreateArtifactJsonFromLastCommit(jsonTransformationDTO)
            .flatMap(artifactExchangeJson -> importService.importArtifactInWorkspaceFromGit(/*...*/))
            .flatMap(importedArtifact -> gitArtifactHelper.publishArtifact(importedArtifact, true));
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6eb44a1 and 826eb18.

📒 Files selected for processing (5)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/GitRedisUtils.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/CentralGitServiceCEImpl.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/fs/GitFSServiceCEImpl.java (1 hunks)
🔇 Additional comments (3)
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCE.java (1)

34-35: LGTM! Verify method implementation coverage.

The new discardChanges method signature aligns well with the interface's existing patterns.

Let's verify the implementation coverage:

✅ Verification successful

Implementation coverage verified

The discardChanges method is properly implemented in CentralGitServiceCEImpl with:

  • Complete error handling for invalid parameters
  • Integration with git operations
  • Proper permission checks
  • Consistent with interface contract
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for implementation of discardChanges method
ast-grep --pattern 'class $_ implements CentralGitServiceCE {
  $$$
  public Mono<? extends Artifact> discardChanges($_, $_, $_) {
    $$$
  }
  $$$
}'

Length of output: 153


Script:

#!/bin/bash
# Let's try a different approach to find implementations
# First, find files that might contain the implementation
rg -l "CentralGitService" --type java

# Then look for the actual implementation with context
rg "discardChanges.*\(.*\)" --type java -A 5

Length of output: 7730


Script:

#!/bin/bash
# Let's check the implementation in CentralGitServiceCEImpl
cat app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java

Length of output: 65644

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

61-63: LGTM! Verify method implementation coverage.

The new recreateArtifactJsonFromLastCommit method is well-defined with appropriate parameter and return types.

Let's verify the implementation coverage:

✅ Verification successful

Method is properly implemented and used in the codebase

The method is implemented in GitFSServiceCEImpl and correctly used in CentralGitServiceCEImpl, maintaining the contract defined in the interface.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for implementation of recreateArtifactJsonFromLastCommit method
ast-grep --pattern 'class $_ implements GitHandlingServiceCE {
  $$$
  public Mono<? extends ArtifactExchangeJson> recreateArtifactJsonFromLastCommit(ArtifactJsonTransformationDTO $_) {
    $$$
  }
  $$$
}'

Length of output: 208


Script:

#!/bin/bash
# Let's try a different approach to find implementations
# First, find all Java files that might contain the implementation
fd -e java | xargs rg -l "class.*implements.*GitHandlingServiceCE"

# Then search for the method name to ensure it exists
rg "recreateArtifactJsonFromLastCommit" -A 2

Length of output: 1736

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

1127-1129: LGTM: Input validation is properly handled.

The method correctly validates the input parameter before proceeding.

Comment on lines +602 to +619
@Override
public Mono<? extends ArtifactExchangeJson> recreateArtifactJsonFromLastCommit(
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);

return fsGitHandler.rebaseBranch(repoSuffix, refName).flatMap(rebaseStatus -> {
return commonGitFileUtils.reconstructArtifactExchangeJsonFromGitRepoWithAnalytics(
workspaceId, baseArtifactId, repoName, refName, artifactType);
});
}
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 error handling and consider transaction boundary.

The method performs critical Git operations but:

  1. Lacks explicit error handling for rebase conflicts
  2. Missing transaction boundary for atomic operations

Consider wrapping the operations in a transaction and add specific error handling:

@Override
public Mono<? extends ArtifactExchangeJson> recreateArtifactJsonFromLastCommit(
        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);

-   return fsGitHandler.rebaseBranch(repoSuffix, refName).flatMap(rebaseStatus -> {
+   return transactionalOperator.transactional(
+       fsGitHandler.rebaseBranch(repoSuffix, refName)
+           .onErrorResume(error -> {
+               if (error instanceof org.eclipse.jgit.api.errors.RebaseConflictException) {
+                   return Mono.error(new AppsmithException(
+                       AppsmithError.GIT_ACTION_FAILED,
+                       "rebase",
+                       "Conflicts detected during rebase. Please resolve conflicts and try again."
+                   ));
+               }
+               return Mono.error(error);
+           })
+   ).flatMap(rebaseStatus -> {
        return commonGitFileUtils.reconstructArtifactExchangeJsonFromGitRepoWithAnalytics(
                workspaceId, baseArtifactId, repoName, refName, artifactType);
    });
}

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

Comment on lines 1148 to 1154
return gitRedisUtils
.acquireGitLock(
branchedGitData.getDefaultArtifactId(),
GitConstants.GitCommandConstants.DISCARD,
TRUE)
.thenReturn(branchedArtifact);
})
Copy link
Contributor

@coderabbitai coderabbitai bot Dec 13, 2024

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider using doFinally for lock release.

The lock release should be guaranteed even if subsequent operations fail.

Move the lock release to a doFinally operator:

-return gitRedisUtils
-        .acquireGitLock(
-                branchedGitData.getDefaultArtifactId(),
-                GitConstants.GitCommandConstants.DISCARD,
-                TRUE)
-        .thenReturn(branchedArtifact);
+return gitRedisUtils
+        .acquireGitLock(
+                branchedGitData.getDefaultArtifactId(),
+                GitConstants.GitCommandConstants.DISCARD,
+                TRUE)
+        .thenReturn(branchedArtifact)
+        .doFinally(signalType -> 
+            gitRedisUtils.releaseFileLock(
+                branchedGitData.getDefaultArtifactId(), 
+                TRUE
+            ).subscribe()
+        );
📝 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
return gitRedisUtils
.acquireGitLock(
branchedGitData.getDefaultArtifactId(),
GitConstants.GitCommandConstants.DISCARD,
TRUE)
.thenReturn(branchedArtifact);
})
return gitRedisUtils
.acquireGitLock(
branchedGitData.getDefaultArtifactId(),
GitConstants.GitCommandConstants.DISCARD,
TRUE)
.thenReturn(branchedArtifact)
.doFinally(signalType ->
gitRedisUtils.releaseFileLock(
branchedGitData.getDefaultArtifactId(),
TRUE
).subscribe()
);
})

Copy link
Contributor

Choose a reason for hiding this comment

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

@sondermanish It makes sense to move this logic related to releasing the lock in a doFinally operator. Do you see any problem with this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here it wouldn't make any issue, however if we are preprocessing then doFinally doesn't make sense as we may run into error signal and then we wouldn't want to acquire lock

Comment on lines 1148 to 1154
return gitRedisUtils
.acquireGitLock(
branchedGitData.getDefaultArtifactId(),
GitConstants.GitCommandConstants.DISCARD,
TRUE)
.thenReturn(branchedArtifact);
})
Copy link
Contributor

Choose a reason for hiding this comment

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

@sondermanish It makes sense to move this logic related to releasing the lock in a doFinally operator. Do you see any problem with this?

.flatMap(importedArtifact -> gitArtifactHelper.publishArtifact(importedArtifact, true));
})
.flatMap(branchedArtifact -> gitRedisUtils
.releaseFileLock(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also move this in a doFinally operator?

new AppsmithException(
AppsmithError.GIT_ACTION_FAILED,
"discard changes",
"Please create a new branch and resolve the conflicts on remote repository before proceeding ahead."));
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: "ahead" seems redundant here. How about "Please create a new branch and resolve conflicts in the remote repository before proceeding." ?

GitArtifactHelper<?> gitArtifactHelper = gitArtifactHelperResolver.getArtifactHelper(artifactType);
Path repoSuffix = gitArtifactHelper.getRepoSuffixPath(workspaceId, baseArtifactId, repoName);

return fsGitHandler.rebaseBranch(repoSuffix, refName).flatMap(rebaseStatus -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

QQ: We don't do a complete discard, do we? Given that there are commits exist in the local branch but not in the remote, we just rebase changes on top of those commits, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, however the idea is that the local and remote are always in sync.

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: 2

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

1116-1122: Consider using a specific type instead of wildcard generic.

The return type Mono<? extends Artifact> could be more specific to improve type safety and readability.


1175-1175: Simplify error message.

The error message is redundant with "ahead" in the previous review comment.

Apply this change:

-                                                "Please create a new branch and resolve conflicts in the remote repository before proceeding."));
+                                                "Please create a new branch and resolve conflicts in the remote repository."));
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 826eb18 and 0db248a.

📒 Files selected for processing (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java (1 hunks)
🔇 Additional comments (1)
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java (1)

1127-1129: LGTM! Parameter validation is correct.

The null/empty check for branchedArtifactId is properly implemented with appropriate error handling.

Comment on lines +1186 to +1189
.addAnalyticsForGitOperation(AnalyticsEvents.GIT_DISCARD_CHANGES, branchedArtifact, null)
.doFinally(signalType -> gitRedisUtils.releaseFileLock(
branchedArtifact.getGitArtifactMetadata().getDefaultArtifactId(), TRUE)))
.name(GitSpan.OPS_DISCARD_CHANGES)
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

Lock release should handle errors gracefully.

The lock release in doFinally should handle potential errors to ensure the lock is always released, even in error cases.

Apply this change:

-                        .doFinally(signalType -> gitRedisUtils.releaseFileLock(
-                                branchedArtifact.getGitArtifactMetadata().getDefaultArtifactId(), TRUE)))
+                        .doFinally(signalType -> gitRedisUtils
+                                .releaseFileLock(
+                                        branchedArtifact.getGitArtifactMetadata().getDefaultArtifactId(),
+                                        TRUE)
+                                .onErrorResume(error -> {
+                                    log.error("Error releasing git lock: {}", error.getMessage());
+                                    return Mono.empty();
+                                })
+                                .subscribe()))
📝 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
.addAnalyticsForGitOperation(AnalyticsEvents.GIT_DISCARD_CHANGES, branchedArtifact, null)
.doFinally(signalType -> gitRedisUtils.releaseFileLock(
branchedArtifact.getGitArtifactMetadata().getDefaultArtifactId(), TRUE)))
.name(GitSpan.OPS_DISCARD_CHANGES)
.addAnalyticsForGitOperation(AnalyticsEvents.GIT_DISCARD_CHANGES, branchedArtifact, null)
.doFinally(signalType -> gitRedisUtils
.releaseFileLock(
branchedArtifact.getGitArtifactMetadata().getDefaultArtifactId(),
TRUE)
.onErrorResume(error -> {
log.error("Error releasing git lock: {}", error.getMessage());
return Mono.empty();
})
.subscribe())
.name(GitSpan.OPS_DISCARD_CHANGES)

Comment on lines +1148 to +1153
return Mono.just(branchedArtifact)
.doFinally(signalType -> gitRedisUtils.acquireGitLock(
branchedGitData.getDefaultArtifactId(),
GitConstants.GitCommandConstants.DISCARD,
TRUE));
})
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

Lock acquisition should be moved to a reactive chain.

The lock acquisition in doFinally is not properly integrated into the reactive chain. This could lead to timing issues.

Apply this change:

-            .doFinally(signalType -> gitRedisUtils.acquireGitLock(
-                    branchedGitData.getDefaultArtifactId(),
-                    GitConstants.GitCommandConstants.DISCARD,
-                    TRUE));
+            .flatMap(artifact -> gitRedisUtils
+                    .acquireGitLock(
+                            branchedGitData.getDefaultArtifactId(),
+                            GitConstants.GitCommandConstants.DISCARD,
+                            TRUE)
+                    .thenReturn(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
return Mono.just(branchedArtifact)
.doFinally(signalType -> gitRedisUtils.acquireGitLock(
branchedGitData.getDefaultArtifactId(),
GitConstants.GitCommandConstants.DISCARD,
TRUE));
})
return Mono.just(branchedArtifact)
.flatMap(artifact -> gitRedisUtils
.acquireGitLock(
branchedGitData.getDefaultArtifactId(),
GitConstants.GitCommandConstants.DISCARD,
TRUE)
.thenReturn(artifact));
})

@sondermanish sondermanish enabled auto-merge (squash) December 13, 2024 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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 potential-duplicate This label marks issues that are potential duplicates of already open issues skip-changelog Adding this label to a PR prevents it from being listed in the changelog Task A simple Todo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task] Switch git discard and pull method to super service
2 participants