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 autocommit and protected branches methods #38370

Merged
merged 4 commits into from
Dec 27, 2024

Conversation

sondermanish
Copy link
Contributor

@sondermanish sondermanish commented Dec 26, 2024

Description

  • Implementation for autocommit and protected branches

Fixes #37445, #37446 , #37447, #37457, #37458

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/12513470547
Commit: 20cae3e
Cypress dashboard.
Tags: @tag.Git
Spec:


Fri, 27 Dec 2024 08:43:08 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Introduced methods for managing protected branches and auto-commit features.
    • Added analytics functionality for tracking changes in protected branches.
  • Bug Fixes

    • Enhanced error handling for unsupported operations and invalid parameters in new methods.
  • Refactor

    • Updated dependency management in several service classes to include auto-commit functionality.
  • Documentation

    • Improved method documentation for clarity on parameters and behavior.

@sondermanish sondermanish requested a review from a team as a code owner December 26, 2024 06:20
Copy link
Contributor

coderabbitai bot commented Dec 26, 2024

Walkthrough

The pull request introduces enhancements to the Git service in the Appsmith server, focusing on branch protection and auto-commit functionality. New methods have been added to the CentralGitServiceCE interface and implemented in CentralGitServiceCEImpl, enabling operations like updating protected branches, toggling auto-commit, and tracking auto-commit progress. The changes involve modifying service constructors to include new dependencies like GitAutoCommitHelper and TransactionalOperator.

Changes

File Change Summary
.../CentralGitServiceCE.java Added 4 new interface methods for branch protection and auto-commit management
.../CentralGitServiceCECompatibleImpl.java Updated constructor to include GitAutoCommitHelper and TransactionalOperator
.../CentralGitServiceCEImpl.java Implemented new methods for protected branches and auto-commit features
.../CentralGitServiceImpl.java Modified constructor to integrate auto-commit helper
.../GitAnalyticsUtils.java Added sendBranchProtectionAnalytics method for tracking branch protection changes

Assessment against linked issues

Objective Addressed Explanation
Switch toggle autocommit method to super service [#37445]

Possibly related PRs

Suggested labels

Enhancement

Suggested reviewers

  • nidhi-nair
  • subrata71

Poem

🌿 Branches protected, commits in flight
Git's magic dancing left and right
Code flows smooth, with new-found grace
Auto-commit sets a nimble pace!
Appsmith's version control takes flight 🚀

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 labels Dec 26, 2024
@sondermanish sondermanish self-assigned this Dec 26, 2024
@sondermanish sondermanish added the ok-to-test Required label for CI label Dec 26, 2024
@sondermanish sondermanish changed the title added autocommit and protected branches methods chore: added autocommit and protected branches methods Dec 26, 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 26, 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: 0

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

60-61: Dependency ordering suggestion.
Consider grouping these new parameters consistently with the others for better readability, maintaining a uniform ordering (e.g., grouping Git-related helpers together).

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

1855-1891: Minor typo in the log statement.
The log message "failed tp toggle auto commit" could be changed to "failed to toggle auto commit".

- log.error("failed tp toggle auto commit. reason: {} is not the id of the base Artifact", baseArtifactId);
+ log.error("failed to toggle auto commit. reason: {} is not the id of the base Artifact", baseArtifactId);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3c802d9 and 43626f8.

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

6-6: Looks good – new import aligns with the introduced dependency.


21-21: Seamless integration with Spring’s reactive transaction support.


42-43: Constructor expansion helps incorporate auto-commit features.
If there's an existing set of integration tests for Git operations, we strongly recommend adding coverage for auto-commit logic to ensure these new dependencies work as intended.

app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCECompatibleImpl.java (3)

6-6: LGTM! Required imports added for new functionality.

The new imports align with the PR objectives for adding auto-commit functionality and transactional support.

Also applies to: 21-21


61-62: LGTM! Proper delegation to parent class.

The new dependencies are correctly passed to the parent class constructor, maintaining the inheritance contract.


43-44: Verify transaction boundary requirements.

The addition of TransactionalOperator suggests new transactional operations. Ensure that the transaction boundaries are properly defined in the parent class implementation.

✅ Verification successful

No transaction boundaries found - safe to proceed

Based on the codebase analysis, while TransactionalOperator is injected, there are no explicit usages found in the implementation. This suggests it's being added for future use or as part of a broader refactoring. The current changes don't introduce any transaction-related operations that would require boundary verification.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for transactional operation usage in the parent class
ast-grep --pattern 'class CentralGitServiceCEImpl {
  $$$
  transactionalOperator.$$$
  $$$
}'

Length of output: 96


Script:

#!/bin/bash
# Let's first check if the file exists and its content
fd "CentralGitServiceCEImpl.java" --type f --exec cat {}

# Also check for any transactional operations in the implementation
rg -A 3 "transactionalOperator" 

Length of output: 65626


Script:

#!/bin/bash
# Let's check for transactional operations in the implementation
rg -A 3 "transactionalOperator\." --type java

# Also check for any transaction-related method signatures
ast-grep --pattern 'class $_ {
  $$$
  @Transactional
  $$$
}'

Length of output: 112

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

19-19: No issues found for this import.


29-29: Import statement looks good.


35-35: Import statement verified.


56-56: Import is valid.


67-67: No concerns with this import.


113-114: Fields added for auto-commit and transactional management.
Looks straightforward and consistent with dependency injection patterns.


1777-1808: Verify logic for protecting only one default branch.
This logic is strict, which may align with the requirement that only the default branch can be protected.


1810-1827: Branch protection updates and analytics call look solid.
No obvious concurrency or correctness issues observed.


1829-1853: Retrieves only the default protected branch.
Implementation is concise and appears correct.


1893-1897: Logic to retrieve auto-commit progress is straightforward.
No issues identified.

app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCE.java (6)

10-10: Import for AutoCommitResponseDTO is valid.


14-15: Importing java.util.List is acceptable here.


59-61: Method signature for updating protected branches.
Matches implementation policy from the implementation class.


62-63: Method signature for retrieving protected branches.
No issues noted.


64-65: Method signature for toggling auto-commit.
Appropriately typed return value and parameters.


66-67: Method signature for fetching auto-commit progress.
Matches the associated implementation.

app/server/appsmith-server/src/main/java/com/appsmith/server/git/utils/GitAnalyticsUtils.java (5)

16-16: Import statement is fine.


19-19: No issues with the added import.


21-21: Import confirmed.


24-25: Static imports of analytics events.
Fits conventional usage.


154-189: sendBranchProtectionAnalytics method is well-structured.
Efficient approach to send events for added/removed protected branches.

CollectionUtils.isEmpty(branchNames) ? new ArrayList<>() : branchNames;

// user cannot protect multiple branches
if (incomingProtectedBranches.size() > 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

QQ: Since user cannot protect multiple branches what's the reason behind being it a list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When we select the list from the UI, we are essentially sending multiple protected branches, hence this is take as a list. This api request is stateless, what this essentially means is that your request is the absolute value which is going to be saved.

GitArtifactMetadata baseGitMetadata = baseArtifact.getGitArtifactMetadata();
if (!baseArtifact.getId().equals(baseGitMetadata.getDefaultArtifactId())) {
log.error(
"failed tp toggle auto commit. reason: {} is not the id of the base Artifact",
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: failed to ...

Copy link
Contributor Author

@sondermanish sondermanish Dec 26, 2024

Choose a reason for hiding this comment

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

Can I get this done in the subsequent PR (Gonna raise it today only), reason for this is an extra run for a string. Let me know if you think otherwise

subrata71
subrata71 previously approved these changes Dec 26, 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: 0

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

1869-1871: Fix error message formatting.

The error message should start with a capital letter and end with a period.

-                                "failed to toggle auto commit. reason: {} is not the id of the base Artifact",
+                                "Failed to toggle auto commit. Reason: {} is not the id of the base Artifact.",

1855-1891: Consider adding null check for AutoCommitConfig.

The code assumes AutoCommitConfig is never null when accessing it. Add a null check or ensure it's initialized with default values.

-                    AutoCommitConfig autoCommitConfig = baseGitMetadata.getAutoCommitConfig();
+                    AutoCommitConfig autoCommitConfig = baseGitMetadata.getAutoCommitConfig();
+                    if (autoCommitConfig == null) {
+                        autoCommitConfig = new AutoCommitConfig();
+                        autoCommitConfig.setEnabled(FALSE);
+                    }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 43626f8 and d443eeb.

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

1776-1808: LGTM! The protected branches validation logic is well-implemented.

The method correctly enforces business rules:

  1. Only one branch can be protected
  2. Only the default branch can be protected

1893-1897: LGTM! Clean delegation to helper.

The method correctly delegates to the specialized helper class.

@sondermanish sondermanish enabled auto-merge (squash) December 26, 2024 09:56
@sondermanish sondermanish merged commit 0255bce into release Dec 27, 2024
42 checks passed
@sondermanish sondermanish deleted the chore/protected-branches branch December 27, 2024 08:43
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 toggle autocommit method to super service
2 participants