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: pr for delete references #38210

Merged
merged 2 commits into from
Dec 17, 2024
Merged

chore: pr for delete references #38210

merged 2 commits into from
Dec 17, 2024

Conversation

sondermanish
Copy link
Contributor

@sondermanish sondermanish commented Dec 17, 2024

Description

  • Implementation for delete references

Fixes #37456

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/12374977893
Commit: ccb37fc
Cypress dashboard.
Tags: @tag.Git
Spec:


Tue, 17 Dec 2024 15:09:45 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a method to delete Git references, enhancing reference management capabilities.
    • Added error handling for branch deletion scenarios.
  • Changes

    • Renamed existing method for clarity regarding Git reference creation.
    • Updated method signatures to reflect new functionality and improved naming conventions.
    • Added new methods to retrieve and set reference names in Git artifact metadata.

@sondermanish sondermanish requested a review from a team as a code owner December 17, 2024 13:21
Copy link
Contributor

coderabbitai bot commented Dec 17, 2024

Walkthrough

The pull request introduces enhancements to the Git reference management system in the Appsmith server. A new deleteGitReference method has been added to the CentralGitServiceCE interface and implemented in CentralGitServiceCEImpl. The changes include renaming prepareForNewRefCreation to createGitReference across multiple service classes and adding a new deleteGitReference method to handle branch deletion operations.

Changes

File Change Summary
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCE.java Added deleteGitReference method to interface
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java Implemented deleteGitReference method and modified createReference method
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/GitHandlingServiceCE.java Renamed prepareForNewRefCreation to createGitReference and added deleteGitReference method
app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCEImpl.java Renamed method and added deleteGitReference with error handling
app/server/appsmith-server/src/main/java/com/appsmith/server/domains/ce/GitArtifactMetadataCE.java Added getRefName and setRefName methods

Assessment against linked issues

Objective Addressed Explanation
Switch delete branch method to super service [#37456]

Possibly related PRs

  • feat: added commit changes #37922: This PR adds a new method commitArtifact to the CentralGitServiceCE interface, which is directly related to the changes made in the main PR that introduced the deleteGitReference method in the same interface.
  • chore: Added changes for discard #38152: This PR introduces a discardChanges method in the CentralGitServiceCE interface, which is conceptually similar to the deleteGitReference method in terms of managing Git references and artifacts.
  • chore: added status changes #38170: This PR adds a getStatus method to the CentralGitServiceCE interface, which aligns with the overall theme of managing Git operations and references, similar to the changes in the main PR.
  • chore: reference lifecycle #38174: This PR introduces methods for checking out references and creating references in the CentralGitServiceCE interface, which are related to the management of Git references, similar to the deleteGitReference method added in the main PR.

Suggested labels

Enhancement

Suggested reviewers

  • nidhi-nair

Poem

🌿 Branches dance, references sway
Git's magic weaves its subtle play
Delete and create with gentle might
Code flows free, a developer's delight!
🌱 Refactoring's sweet melody

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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.

@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 skip-changelog Adding this label to a PR prevents it from being listed in the changelog labels Dec 17, 2024
@sondermanish sondermanish self-assigned this Dec 17, 2024
@sondermanish sondermanish added the ok-to-test Required label for CI label Dec 17, 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: 1

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

621-623: Remove leading space in error message

There is an unnecessary leading space in the error message.

Apply this diff:

-return Mono.error(new AppsmithException(
-        AppsmithError.GIT_ACTION_FAILED, "delete ref", " Cannot delete default branch"));
+return Mono.error(new AppsmithException(
+        AppsmithError.GIT_ACTION_FAILED, "delete ref", "Cannot delete default branch"));
app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCE.java (1)

53-54: Add Javadoc for the new method

Consider adding Javadoc comments to deleteReference to explain its purpose and usage.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5d213dd and 89764d4.

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

541-544: Change approved

Refactoring to use createGitReference improves clarity and consistency.

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

79-81: Approve addition of new methods

The addition of createGitReference and deleteGitReference methods enhances the interface's functionality.

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

677-700: Error handling in deleteGitReference is appropriate

The implementation correctly handles exceptions when deleting a branch.

Comment on lines +652 to +655
if (FALSE.equals(isReferenceDeleted)) {
return Mono.error(new AppsmithException(
AppsmithError.GIT_ACTION_FAILED,
" delete branch. Branch does not exists in the repo"));
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

Correct the error message formatting

Fix the grammatical error and improve consistency in the error message.

Apply this diff:

-return Mono.error(new AppsmithException(
-        AppsmithError.GIT_ACTION_FAILED,
-        " delete branch. Branch does not exists in the repo"));
+return Mono.error(new AppsmithException(
+        AppsmithError.GIT_ACTION_FAILED,
+        "delete",
+        "Branch does not exist in the repository"));
📝 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
if (FALSE.equals(isReferenceDeleted)) {
return Mono.error(new AppsmithException(
AppsmithError.GIT_ACTION_FAILED,
" delete branch. Branch does not exists in the repo"));
if (FALSE.equals(isReferenceDeleted)) {
return Mono.error(new AppsmithException(
AppsmithError.GIT_ACTION_FAILED,
"delete",
"Branch does not exist in the repository"));

}

if (!hasText(refName)) {
return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, BRANCH_NAME));
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit, ref name

@@ -572,6 +572,120 @@ public Mono<? extends Artifact> createReference(
return Mono.create(sink -> createBranchMono.subscribe(sink::success, sink::error, null, sink.currentContext()));
}

@Override
public Mono<? extends Artifact> deleteReference(
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit, deleteGitReference in method name

@@ -572,6 +572,120 @@ public Mono<? extends Artifact> createReference(
return Mono.create(sink -> createBranchMono.subscribe(sink::success, sink::error, null, sink.currentContext()));
}

@Override
public Mono<? extends Artifact> deleteReference(
String baseArtifactId, String refName, ArtifactType artifactType, GitType gitType, RefType refType) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit, can we use dto 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.

same gitRefDTO?

}

GitArtifactHelper<?> gitArtifactHelper = gitArtifactHelperResolver.getArtifactHelper(artifactType);
AclPermission artifactEditPermission = gitArtifactHelper.getArtifactEditPermission();
Copy link
Contributor

Choose a reason for hiding this comment

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

We ended up creating a lot of permission methods in the helper. Should we instead create a single getArtifactPermision method and access its methods directly for all our use cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you mean a separate service?

gitArtifactHelperResolver.getArtifactHelper(baseArtifact.getArtifactType());

// TODO: write a migration to shift everything to refName in gitMetadata
final String finalRefName = referenceArtifactMetadata.getBranchName();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you in the mean time create an internal annotated getRefName method that returns branch name when ref name is null?

Mono<? extends Artifact> deleteReferenceMono = gitPrivateRepoHelper
.isBranchProtected(baseGitMetadata, finalRefName)
.flatMap(isBranchProtected -> {
if (!TRUE.equals(isBranchProtected)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this meant to be an instance of where we can flip the conditional like you've been suggesting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same stuff, even if we flip we are returning the error.

" delete branch. Branch does not exists in the repo"));
}

if (referenceArtifact.getId().equals(baseArtifactId)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't we delete in this case, do you know?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we don't delete baseArtifact, where would we keep the gitMetadata then?

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a bug then .. It's a stray object that we can never get rid of. Let's add a TODO to clean this up when we pull metadata out of artifact

return gitArtifactHelper
.deleteArtifactByResource(referenceArtifact)
.onErrorResume(throwable -> {
return gitAnalyticsUtils
Copy link
Contributor

Choose a reason for hiding this comment

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

Should log error before transofrming

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

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

620-621: Address TODO comment for reference name migration

There's a pending migration to shift everything to refName in gitMetadata.

Would you like me to help create a GitHub issue to track this migration task?


632-641: Consider inverting the condition for better readability

The nested if-else structure could be simplified by inverting the condition.

-if (!TRUE.equals(isBranchProtected)) {
-    return gitRedisUtils.acquireGitLock(
-            baseArtifactId, GitConstants.GitCommandConstants.DELETE, TRUE);
-}
-
-return Mono.error(new AppsmithException(
-        AppsmithError.GIT_ACTION_FAILED,
-        "delete",
-        "Cannot delete protected branch " + finalRefName));
+if (TRUE.equals(isBranchProtected)) {
+    return Mono.error(new AppsmithException(
+            AppsmithError.GIT_ACTION_FAILED,
+            "delete",
+            "Cannot delete protected branch " + finalRefName));
+}
+
+return gitRedisUtils.acquireGitLock(
+        baseArtifactId, GitConstants.GitCommandConstants.DELETE, 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 89764d4 and ccb37fc.

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

52-54: LGTM! Method signature follows interface conventions

The new deleteGitReference method signature is well-defined and consistent with other methods in the interface.

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

575-593: LGTM! Comprehensive parameter validation

The implementation properly validates all required parameters before proceeding.


655-659: Fix error message formatting

The error message needs improvement for clarity and consistency.

Apply this diff:

-return Mono.error(new AppsmithException(
-        AppsmithError.GIT_ACTION_FAILED,
-        " delete branch. Branch does not exists in the repo"));
+return Mono.error(new AppsmithException(
+        AppsmithError.GIT_ACTION_FAILED,
+        "delete",
+        "Branch does not exist in the repository"));

668-672: Log error before analytics

The error should be logged before transforming for analytics to ensure proper error tracking.

Move the log statement before the analytics transformation.


541-541: Method name change from prepareForNewRefCreation to createGitReference

The method name has been updated to better reflect its purpose.

Comment on lines +141 to +143
public void setRefName(String refName) {
this.branchName = refName;
}
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

Ensure consistent state between refName and branchName

The setter directly updates branchName instead of refName, which could lead to inconsistent state.

-public void setRefName(String refName) {
-    this.branchName = refName;
+public void setRefName(String refName) {
+    this.refName = refName;
+    this.branchName = refName; // Temporary until migration is complete
}
📝 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
public void setRefName(String refName) {
this.branchName = refName;
}
public void setRefName(String refName) {
this.refName = refName;
this.branchName = refName; // Temporary until migration is complete
}

Comment on lines +133 to +139
/**
* this returns the branchName instead of reference name
* @return returns the ref name.
*/
public String getRefName() {
return this.getBranchName();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider improving the reference name handling

The current implementation returns branchName instead of refName, creating tight coupling. Based on the TODO comment, this appears to be temporary, but should be addressed to properly separate branch and reference concepts.

Consider:

  1. Implementing proper reference name handling
  2. Adding validation for reference types
  3. Documenting the migration plan in the TODO
-public String getRefName() {
-    return this.getBranchName();
-}
+public String getRefName() {
+    return StringUtils.hasText(this.refName) ? this.refName : this.getBranchName();
+}

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

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 delete branch method to super service
2 participants