From d5ee69016a63aa7ce3924309a508b75336324dc3 Mon Sep 17 00:00:00 2001 From: Manish Kumar <107841575+sondermanish@users.noreply.github.com> Date: Wed, 24 Sep 2025 11:01:43 +0530 Subject: [PATCH] chore: enabled autocommit (#41255) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 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="@tag.Git" ### :mag: Cypress test results > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: > Commit: 02dea2de752e6171fa3e4cefd8650b7fcf9b332f > Cypress dashboard. > Tags: `@tag.Git` > Spec: >
Tue, 23 Sep 2025 12:56:31 UTC ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No ## Summary by CodeRabbit * **New Features** * Auto-commit now accepts author name and email so commits reflect the initiating user. * Auto-commit processing can run asynchronously in the background. * **Improvements** * Auto-commit flows will fall back to generated author info when a stored Git profile is unavailable. * Controller now delegates auto-commit to a central service for consistent responses. * Enhanced logging for clearer Git operation traceability. * **Tests** * Updated and un-skipped end-to-end and unit tests covering auto-commit paths. --- .../ClientSide/Git/GitAutocommit_spec.ts | 2 +- .../appsmith/server/annotations/GitRoute.java | 4 ++ .../server/aspect/GitRouteAspect.java | 40 +++++++++++++---- .../autocommit/AutoCommitEventHandler.java | 3 -- .../git/autocommit/AutoCommitSolution.java | 3 ++ ...ndlerCE.java => AutoCommitSolutionCE.java} | 6 +-- ...mpl.java => AutoCommitSolutionCEImpl.java} | 35 ++++++--------- ...rImpl.java => AutoCommitSolutionImpl.java} | 7 +-- .../helpers/AutoCommitAsyncEventManager.java | 10 +++++ .../AutoCommitAsyncEventManagerImpl.java | 45 +++++++++++++++++++ .../helpers/GitAutoCommitHelperImpl.java | 9 ++-- .../git/constants/GitRouteOperation.java | 1 + .../GitApplicationControllerCE.java | 10 ++--- .../appsmith/server/helpers/RedisUtils.java | 20 --------- .../appsmith/server/git/GitBranchesIT.java | 2 +- .../git/GitBranchesWithCentralServiceIT.java | 2 +- .../ServerSchemaMigrationEnforcerTest.java | 13 +++--- .../git/autocommit/AutoCommitServiceTest.java | 10 ++++- ...t.java => AutoCommitSolutionImplTest.java} | 32 ++++++------- .../helpers/GitAutoCommitHelperImplTest.java | 5 +-- 20 files changed, 154 insertions(+), 105 deletions(-) delete mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/AutoCommitEventHandler.java create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/AutoCommitSolution.java rename app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/{AutoCommitEventHandlerCE.java => AutoCommitSolutionCE.java} (61%) rename app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/{AutoCommitEventHandlerCEImpl.java => AutoCommitSolutionCEImpl.java} (94%) rename app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/{AutoCommitEventHandlerImpl.java => AutoCommitSolutionImpl.java} (79%) create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/AutoCommitAsyncEventManager.java create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/AutoCommitAsyncEventManagerImpl.java rename app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/{AutoCommitEventHandlerImplTest.java => AutoCommitSolutionImplTest.java} (96%) diff --git a/app/client/cypress/e2e/Regression/ClientSide/Git/GitAutocommit_spec.ts b/app/client/cypress/e2e/Regression/ClientSide/Git/GitAutocommit_spec.ts index cdadb595e0..fd4953708c 100644 --- a/app/client/cypress/e2e/Regression/ClientSide/Git/GitAutocommit_spec.ts +++ b/app/client/cypress/e2e/Regression/ClientSide/Git/GitAutocommit_spec.ts @@ -26,7 +26,7 @@ describe( ], }, function () { - it.skip("Check if autocommit progress bar is visible and network requests are properly called", function () { + it("Check if autocommit progress bar is visible and network requests are properly called", function () { agHelper.GenerateUUID(); cy.get("@guid").then((uid) => { wsName = "GitAC-" + uid; diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/annotations/GitRoute.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/annotations/GitRoute.java index 05f57570d0..f3b75d0aac 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/annotations/GitRoute.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/annotations/GitRoute.java @@ -18,4 +18,8 @@ public @interface GitRoute { ArtifactType artifactType(); GitRouteOperation operation(); + + String authorName() default ""; + + String authorEmail() default ""; } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/aspect/GitRouteAspect.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/aspect/GitRouteAspect.java index 45dd6eb184..3e32289084 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/aspect/GitRouteAspect.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/aspect/GitRouteAspect.java @@ -142,6 +142,8 @@ public class GitRouteAspect { // Intermediate Inputs private String fieldValue; + private String authorName; + private String authorEmail; // Tasks private Artifact artifact; @@ -229,6 +231,14 @@ public class GitRouteAspect { return execute(ctx); } + String authorName = extractFieldValue(joinPoint, gitRoute.authorName()); + String authorEmail = extractFieldValue(joinPoint, gitRoute.authorEmail()); + + if (StringUtils.hasText(authorName) && StringUtils.hasText(authorEmail)) { + ctx.setAuthorEmail(authorEmail); + ctx.setAuthorName(authorName); + } + String fieldValue = extractFieldValue(joinPoint, gitRoute.fieldName()); ctx.setFieldValue(fieldValue); return run(ctx, State.ROUTE_FILTER).flatMap(unused -> { @@ -267,14 +277,15 @@ public class GitRouteAspect { Outcome.SUCCESS.name(), result, duration); + } else { + log.info( + "Operation : {}, State {} : {}, Time: {}ms", + ctx.getGitRoute().operation(), + current, + Outcome.SUCCESS.name(), + duration); } - log.info( - "Operation : {}, State {} : {}, Time: {}ms", - ctx.getGitRoute().operation(), - current, - Outcome.SUCCESS.name(), - duration); return run(ctx, config.next(Outcome.SUCCESS)); }) .onErrorResume(e -> { @@ -460,10 +471,23 @@ public class GitRouteAspect { * @return Mono emitting the Git profile, or error if not configured */ private Mono gitProfile(Context ctx) { - return gitProfileUtils - .getGitProfileForUser(ctx.getFieldValue()) + Mono alternativeGitProfileMono = Mono.defer(() -> Mono.justOrEmpty(getProfileFromArgs(ctx))) .switchIfEmpty(Mono.error(new AppsmithException( AppsmithError.INVALID_GIT_CONFIGURATION, "Git profile is not configured"))); + + return gitProfileUtils.getGitProfileForUser(ctx.getFieldValue()).switchIfEmpty(alternativeGitProfileMono); + } + + private GitProfile getProfileFromArgs(Context ctx) { + if (!StringUtils.hasText(ctx.getAuthorEmail()) || !StringUtils.hasText(ctx.getAuthorName())) { + return null; + } + + GitProfile gitProfile = new GitProfile(); + gitProfile.setAuthorName(ctx.getAuthorName()); + gitProfile.setAuthorEmail(ctx.getAuthorEmail()); + gitProfile.setUseGlobalProfile(Boolean.TRUE); + return gitProfile; } /** diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/AutoCommitEventHandler.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/AutoCommitEventHandler.java deleted file mode 100644 index 11385a9c4d..0000000000 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/AutoCommitEventHandler.java +++ /dev/null @@ -1,3 +0,0 @@ -package com.appsmith.server.git.autocommit; - -public interface AutoCommitEventHandler extends AutoCommitEventHandlerCE {} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/AutoCommitSolution.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/AutoCommitSolution.java new file mode 100644 index 0000000000..daa4ec884c --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/AutoCommitSolution.java @@ -0,0 +1,3 @@ +package com.appsmith.server.git.autocommit; + +public interface AutoCommitSolution extends AutoCommitSolutionCE {} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/AutoCommitEventHandlerCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/AutoCommitSolutionCE.java similarity index 61% rename from app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/AutoCommitEventHandlerCE.java rename to app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/AutoCommitSolutionCE.java index 8255d95781..8a1a76cd08 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/AutoCommitEventHandlerCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/AutoCommitSolutionCE.java @@ -3,10 +3,10 @@ package com.appsmith.server.git.autocommit; import com.appsmith.server.events.AutoCommitEvent; import reactor.core.publisher.Mono; -public interface AutoCommitEventHandlerCE { - void publish(AutoCommitEvent autoCommitEvent); +public interface AutoCommitSolutionCE { - void handle(AutoCommitEvent event); + Mono startApplicationAutoCommit( + String baseArtifactId, String authorName, String authorEmail, AutoCommitEvent event); Mono autoCommitDSLMigration(AutoCommitEvent autoCommitEvent); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/AutoCommitEventHandlerCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/AutoCommitSolutionCEImpl.java similarity index 94% rename from app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/AutoCommitEventHandlerCEImpl.java rename to app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/AutoCommitSolutionCEImpl.java index 5b1fe4e193..3c173bf494 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/AutoCommitEventHandlerCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/AutoCommitSolutionCEImpl.java @@ -6,6 +6,7 @@ import com.appsmith.external.git.constants.GitConstants.GitCommandConstants; import com.appsmith.external.git.constants.ce.RefType; import com.appsmith.external.git.handler.FSGitHandler; import com.appsmith.external.git.models.GitResourceType; +import com.appsmith.server.annotations.GitRoute; import com.appsmith.server.configurations.ProjectProperties; import com.appsmith.server.constants.ArtifactType; import com.appsmith.server.constants.FieldName; @@ -18,6 +19,7 @@ import com.appsmith.server.events.AutoCommitEvent; import com.appsmith.server.exceptions.AppsmithError; import com.appsmith.server.exceptions.AppsmithException; import com.appsmith.server.git.GitRedisUtils; +import com.appsmith.server.git.constants.GitRouteOperation; import com.appsmith.server.git.dtos.ArtifactJsonTransformationDTO; import com.appsmith.server.git.resolver.GitArtifactHelperResolver; import com.appsmith.server.helpers.CollectionUtils; @@ -29,9 +31,6 @@ import com.appsmith.server.services.AnalyticsService; import com.appsmith.server.services.GitArtifactHelper; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.context.event.EventListener; -import org.springframework.scheduling.annotation.Async; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.core.scheduler.Schedulers; @@ -51,8 +50,7 @@ import static java.lang.Boolean.TRUE; @RequiredArgsConstructor @Slf4j -public class AutoCommitEventHandlerCEImpl implements AutoCommitEventHandlerCE { - private final ApplicationEventPublisher applicationEventPublisher; +public class AutoCommitSolutionCEImpl implements AutoCommitSolutionCE { private final GitRedisUtils gitRedisUtils; private final RedisUtils redisUtils; private final DSLMigrationUtils dslMigrationUtils; @@ -66,16 +64,15 @@ public class AutoCommitEventHandlerCEImpl implements AutoCommitEventHandlerCE { "System generated commit, to support new features in Appsmith %s"; @Override - public void publish(AutoCommitEvent autoCommitEvent) { - applicationEventPublisher.publishEvent(autoCommitEvent); - log.info("published event for auto commit: {}", autoCommitEvent); - } - - @Async - @EventListener - @Override - public void handle(AutoCommitEvent event) { - log.info("received event for auto commit: {}", event); + @GitRoute( + artifactType = ArtifactType.APPLICATION, + operation = GitRouteOperation.AUTO_COMMIT_SOLUTION, + fieldName = "baseArtifactId", + authorEmail = "authorEmail", + authorName = "authorName") + public Mono startApplicationAutoCommit( + String baseArtifactId, String authorName, String authorEmail, AutoCommitEvent event) { + log.info("Starting auto-commit process for event: {}", event); Mono autocommitMigration; if (Boolean.TRUE.equals(event.getIsServerSideEvent())) { autocommitMigration = this.autoCommitServerMigration(event); @@ -83,13 +80,7 @@ public class AutoCommitEventHandlerCEImpl implements AutoCommitEventHandlerCE { autocommitMigration = this.autoCommitDSLMigration(event); } - autocommitMigration - .subscribeOn(Schedulers.boundedElastic()) - .subscribe( - result -> log.info( - "Auto-commit completed successfully for application: {}", event.getApplicationId()), - error -> log.error( - "Error during auto-commit for application: {}", event.getApplicationId(), error)); + return autocommitMigration.subscribeOn(Schedulers.boundedElastic()); } private Mono setProgress(T result, String applicationId, int progress) { diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/AutoCommitEventHandlerImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/AutoCommitSolutionImpl.java similarity index 79% rename from app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/AutoCommitEventHandlerImpl.java rename to app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/AutoCommitSolutionImpl.java index d4c480bf9b..80659b29f2 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/AutoCommitEventHandlerImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/AutoCommitSolutionImpl.java @@ -8,14 +8,12 @@ import com.appsmith.server.helpers.CommonGitFileUtils; import com.appsmith.server.helpers.DSLMigrationUtils; import com.appsmith.server.helpers.RedisUtils; import com.appsmith.server.services.AnalyticsService; -import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Component; @Component -public class AutoCommitEventHandlerImpl extends AutoCommitEventHandlerCEImpl implements AutoCommitEventHandler { +public class AutoCommitSolutionImpl extends AutoCommitSolutionCEImpl implements AutoCommitSolution { - public AutoCommitEventHandlerImpl( - ApplicationEventPublisher applicationEventPublisher, + public AutoCommitSolutionImpl( GitRedisUtils gitRedisUtils, RedisUtils redisUtils, DSLMigrationUtils dslMigrationUtils, @@ -25,7 +23,6 @@ public class AutoCommitEventHandlerImpl extends AutoCommitEventHandlerCEImpl imp ProjectProperties projectProperties, AnalyticsService analyticsService) { super( - applicationEventPublisher, gitRedisUtils, redisUtils, dslMigrationUtils, diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/AutoCommitAsyncEventManager.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/AutoCommitAsyncEventManager.java new file mode 100644 index 0000000000..f674813da2 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/AutoCommitAsyncEventManager.java @@ -0,0 +1,10 @@ +package com.appsmith.server.git.autocommit.helpers; + +import com.appsmith.server.events.AutoCommitEvent; + +public interface AutoCommitAsyncEventManager { + + void publishAsyncEvent(AutoCommitEvent autoCommitEvent); + + void autoCommitPublishEventListener(AutoCommitEvent event); +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/AutoCommitAsyncEventManagerImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/AutoCommitAsyncEventManagerImpl.java new file mode 100644 index 0000000000..7a33a2739b --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/AutoCommitAsyncEventManagerImpl.java @@ -0,0 +1,45 @@ +package com.appsmith.server.git.autocommit.helpers; + +import com.appsmith.server.events.AutoCommitEvent; +import com.appsmith.server.git.autocommit.AutoCommitSolution; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.context.event.EventListener; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; +import reactor.core.scheduler.Schedulers; + +@Component +@Slf4j +@RequiredArgsConstructor +public class AutoCommitAsyncEventManagerImpl implements AutoCommitAsyncEventManager { + + private final ApplicationEventPublisher applicationEventPublisher; + private final AutoCommitSolution autoCommitSolution; + + @Override + public void publishAsyncEvent(AutoCommitEvent autoCommitEvent) { + log.info("published event for auto commit: {}", autoCommitEvent); + applicationEventPublisher.publishEvent(autoCommitEvent); + } + + @Async + @EventListener + @Override + public void autoCommitPublishEventListener(AutoCommitEvent event) { + log.info("received event for auto commit: {}", event); + String baseArtifactId = event.getApplicationId(); + String authorName = event.getAuthorName(); + String authorEmail = event.getAuthorEmail(); + + autoCommitSolution + .startApplicationAutoCommit(baseArtifactId, authorName, authorEmail, event) + .subscribeOn(Schedulers.boundedElastic()) + .subscribe( + result -> log.info( + "Auto-commit completed successfully for application: {}", event.getApplicationId()), + error -> log.error( + "Error during auto-commit for application: {}", event.getApplicationId(), error)); + } +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/GitAutoCommitHelperImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/GitAutoCommitHelperImpl.java index f4fec09c58..e3acec0c60 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/GitAutoCommitHelperImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/GitAutoCommitHelperImpl.java @@ -8,7 +8,6 @@ import com.appsmith.server.domains.GitProfile; import com.appsmith.server.dtos.AutoCommitResponseDTO; import com.appsmith.server.dtos.AutoCommitTriggerDTO; import com.appsmith.server.events.AutoCommitEvent; -import com.appsmith.server.git.autocommit.AutoCommitEventHandler; import com.appsmith.server.git.central.CentralGitService; import com.appsmith.server.git.central.GitType; import com.appsmith.server.helpers.GitPrivateRepoHelper; @@ -30,7 +29,7 @@ import static com.appsmith.server.dtos.AutoCommitResponseDTO.AutoCommitResponse. @Service public class GitAutoCommitHelperImpl implements GitAutoCommitHelper { private final GitPrivateRepoHelper gitPrivateRepoHelper; - private final AutoCommitEventHandler autoCommitEventHandler; + private final AutoCommitAsyncEventManager autoCommitAsyncEventManager; private final UserDataService userDataService; private final ApplicationService applicationService; private final ApplicationPermission applicationPermission; @@ -39,14 +38,14 @@ public class GitAutoCommitHelperImpl implements GitAutoCommitHelper { public GitAutoCommitHelperImpl( GitPrivateRepoHelper gitPrivateRepoHelper, - AutoCommitEventHandler autoCommitEventHandler, + AutoCommitAsyncEventManager autoCommitAsyncEventManager, UserDataService userDataService, ApplicationService applicationService, ApplicationPermission applicationPermission, RedisUtils redisUtils, @Lazy CentralGitService centralGitService) { this.gitPrivateRepoHelper = gitPrivateRepoHelper; - this.autoCommitEventHandler = autoCommitEventHandler; + this.autoCommitAsyncEventManager = autoCommitAsyncEventManager; this.userDataService = userDataService; this.applicationService = applicationService; this.applicationPermission = applicationPermission; @@ -217,7 +216,7 @@ public class GitAutoCommitHelperImpl implements GitAutoCommitHelper { } // it's a synchronous call, no need to return anything - autoCommitEventHandler.publish(autoCommitEvent); + autoCommitAsyncEventManager.publishAsyncEvent(autoCommitEvent); return Boolean.TRUE; }) .defaultIfEmpty(Boolean.FALSE) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/constants/GitRouteOperation.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/constants/GitRouteOperation.java index 867ba44f72..2a18abfe33 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/constants/GitRouteOperation.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/constants/GitRouteOperation.java @@ -23,6 +23,7 @@ public enum GitRouteOperation { DISCARD_CHANGES(true), LIST_REFS(true), AUTO_COMMIT(true), + AUTO_COMMIT_SOLUTION(true), // whitelisted ones diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/controllers/GitApplicationControllerCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/controllers/GitApplicationControllerCE.java index f26eeae706..91b611d8b9 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/controllers/GitApplicationControllerCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/controllers/GitApplicationControllerCE.java @@ -15,7 +15,6 @@ import com.appsmith.server.domains.Artifact; import com.appsmith.server.domains.GitArtifactMetadata; import com.appsmith.server.domains.GitAuth; import com.appsmith.server.dtos.AutoCommitResponseDTO; -import com.appsmith.server.dtos.AutoCommitResponseDTO.AutoCommitResponse; import com.appsmith.server.dtos.BranchProtectionRequestDTO; import com.appsmith.server.dtos.GitAuthDTO; import com.appsmith.server.dtos.GitConnectDTO; @@ -289,12 +288,9 @@ public class GitApplicationControllerCE { artifactType = ArtifactType.APPLICATION, operation = GitRouteOperation.AUTO_COMMIT) public Mono> autoCommitApplication(@PathVariable String branchedApplicationId) { - // disabling autocommit till in-memory git has been incorporated in the auto-commit - AutoCommitResponseDTO autoCommitResponseDTO = new AutoCommitResponseDTO(); - autoCommitResponseDTO.setAutoCommitResponse(AutoCommitResponse.IDLE); - autoCommitResponseDTO.setProgress(0); - - return Mono.just(autoCommitResponseDTO).map(data -> new ResponseDTO<>(HttpStatus.OK, data)); + return autoCommitService + .autoCommitApplication(branchedApplicationId) + .map(data -> new ResponseDTO<>(HttpStatus.OK, data)); } @JsonView(Views.Public.class) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/RedisUtils.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/RedisUtils.java index 1f6e2859fe..f9a276e4e5 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/RedisUtils.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/RedisUtils.java @@ -70,19 +70,11 @@ public class RedisUtils { return redisOperations.opsForValue().delete(key); } - @Deprecated public Mono hasKey(String key) { - if (gitServiceConfig.isGitInMemory()) { - return Mono.just(false); - } return redisOperations.hasKey(key); } - @Deprecated public Mono startAutoCommit(String defaultApplicationId, String branchName) { - if (gitServiceConfig.isGitInMemory()) { - return Mono.just(true); - } String key = String.format(AUTO_COMMIT_KEY_FORMAT, defaultApplicationId); return redisOperations.hasKey(key).flatMap(isKeyPresent -> { if (Boolean.TRUE.equals(isKeyPresent)) { @@ -102,20 +94,12 @@ public class RedisUtils { return redisOperations.opsForValue().get(key).map(Integer::valueOf); } - @Deprecated public Mono finishAutoCommit(String defaultApplicationId) { - if (gitServiceConfig.isGitInMemory()) { - return Mono.just(true); - } String key = String.format(AUTO_COMMIT_KEY_FORMAT, defaultApplicationId); return redisOperations.opsForValue().delete(key); } - @Deprecated public Mono getRunningAutoCommitBranchName(String defaultApplicationId) { - if (gitServiceConfig.isGitInMemory()) { - return Mono.empty(); - } String key = String.format(AUTO_COMMIT_KEY_FORMAT, defaultApplicationId); return redisOperations.hasKey(key).flatMap(hasKey -> { if (hasKey) { @@ -131,11 +115,7 @@ public class RedisUtils { * This would be required for whenever any attribute related to sessions becomes invalid at a systemic level. * Use with caution, every user will be logged out. */ - @Deprecated public Mono deleteAllSessionsIncludingCurrentUser() { - if (gitServiceConfig.isGitInMemory()) { - return Mono.empty(); - } AtomicInteger deletedKeysCount = new AtomicInteger(0); return redisOperations diff --git a/app/server/appsmith-server/src/test/it/com/appsmith/server/git/GitBranchesIT.java b/app/server/appsmith-server/src/test/it/com/appsmith/server/git/GitBranchesIT.java index cba8496fd8..09198dd7cb 100644 --- a/app/server/appsmith-server/src/test/it/com/appsmith/server/git/GitBranchesIT.java +++ b/app/server/appsmith-server/src/test/it/com/appsmith/server/git/GitBranchesIT.java @@ -50,7 +50,7 @@ import java.util.List; import static com.appsmith.external.git.constants.GitConstants.DEFAULT_COMMIT_MESSAGE; import static com.appsmith.external.git.constants.GitConstants.EMPTY_COMMIT_ERROR_MESSAGE; import static com.appsmith.server.exceptions.AppsmithError.GIT_MERGE_FAILED_LOCAL_CHANGES; -import static com.appsmith.server.git.autocommit.AutoCommitEventHandlerImpl.AUTO_COMMIT_MSG_FORMAT; +import static com.appsmith.server.git.autocommit.AutoCommitSolutionImpl.AUTO_COMMIT_MSG_FORMAT; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.fail; diff --git a/app/server/appsmith-server/src/test/it/com/appsmith/server/git/GitBranchesWithCentralServiceIT.java b/app/server/appsmith-server/src/test/it/com/appsmith/server/git/GitBranchesWithCentralServiceIT.java index d4b4d53afd..cbb33d846d 100644 --- a/app/server/appsmith-server/src/test/it/com/appsmith/server/git/GitBranchesWithCentralServiceIT.java +++ b/app/server/appsmith-server/src/test/it/com/appsmith/server/git/GitBranchesWithCentralServiceIT.java @@ -53,7 +53,7 @@ import java.util.List; import static com.appsmith.external.git.constants.GitConstants.DEFAULT_COMMIT_MESSAGE; import static com.appsmith.external.git.constants.GitConstants.EMPTY_COMMIT_ERROR_MESSAGE; import static com.appsmith.server.exceptions.AppsmithError.GIT_MERGE_FAILED_LOCAL_CHANGES; -import static com.appsmith.server.git.autocommit.AutoCommitEventHandlerImpl.AUTO_COMMIT_MSG_FORMAT; +import static com.appsmith.server.git.autocommit.AutoCommitSolutionImpl.AUTO_COMMIT_MSG_FORMAT; import static org.assertj.core.api.Assertions.assertThat; /** diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ServerSchemaMigrationEnforcerTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ServerSchemaMigrationEnforcerTest.java index da0aea3f57..7d58c3e34d 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ServerSchemaMigrationEnforcerTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ServerSchemaMigrationEnforcerTest.java @@ -12,8 +12,8 @@ import com.appsmith.server.dtos.ApplicationImportDTO; import com.appsmith.server.dtos.ApplicationJson; import com.appsmith.server.events.AutoCommitEvent; import com.appsmith.server.exports.internal.ExportService; -import com.appsmith.server.git.autocommit.AutoCommitEventHandler; -import com.appsmith.server.git.autocommit.AutoCommitEventHandlerImpl; +import com.appsmith.server.git.autocommit.AutoCommitSolution; +import com.appsmith.server.git.autocommit.AutoCommitSolutionImpl; import com.appsmith.server.git.resolver.GitArtifactHelperResolver; import com.appsmith.server.helpers.CommonGitFileUtils; import com.appsmith.server.helpers.DSLMigrationUtils; @@ -62,7 +62,7 @@ import java.util.UUID; import java.util.stream.Collectors; import static com.appsmith.server.constants.ArtifactType.APPLICATION; -import static com.appsmith.server.git.autocommit.AutoCommitEventHandlerCEImpl.AUTO_COMMIT_MSG_FORMAT; +import static com.appsmith.server.git.autocommit.AutoCommitSolutionCEImpl.AUTO_COMMIT_MSG_FORMAT; import static java.lang.Boolean.TRUE; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -124,7 +124,7 @@ public class ServerSchemaMigrationEnforcerTest { @MockBean PluginExecutorHelper pluginExecutorHelper; - AutoCommitEventHandler autoCommitEventHandler; + AutoCommitSolution autoCommitSolution; @Autowired ProjectProperties projectProperties; @@ -395,8 +395,7 @@ public class ServerSchemaMigrationEnforcerTest { public void autocommitMigration_WhenServerVersionIsBehindDiffOccursAnd_CommitSuccess() throws URISyntaxException, IOException, GitAPIException { - autoCommitEventHandler = new AutoCommitEventHandlerImpl( - applicationEventPublisher, + autoCommitSolution = new AutoCommitSolutionImpl( gitRedisUtils, redisUtils, dslMigrationUtils, @@ -425,7 +424,7 @@ public class ServerSchemaMigrationEnforcerTest { gitFileSystemTestHelper.setupGitRepository(autoCommitEvent, applicationJson); - StepVerifier.create(autoCommitEventHandler + StepVerifier.create(autoCommitSolution .autoCommitServerMigration(autoCommitEvent) .zipWhen(a -> redisUtils.getAutoCommitProgress(autoCommitEvent.getApplicationId()))) .assertNext(tuple2 -> { diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitServiceTest.java index 26997da912..a0d8c0f890 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitServiceTest.java @@ -4,6 +4,7 @@ import com.appsmith.external.dtos.GitLogDTO; import com.appsmith.external.git.constants.ce.RefType; import com.appsmith.external.git.handler.FSGitHandler; import com.appsmith.external.helpers.AppsmithBeanUtils; +import com.appsmith.git.configurations.GitServiceConfig; import com.appsmith.server.acl.AclPermission; import com.appsmith.server.applications.base.ApplicationService; import com.appsmith.server.domains.Application; @@ -54,7 +55,7 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import static com.appsmith.server.git.autocommit.AutoCommitEventHandlerCEImpl.AUTO_COMMIT_MSG_FORMAT; +import static com.appsmith.server.git.autocommit.AutoCommitSolutionCEImpl.AUTO_COMMIT_MSG_FORMAT; import static java.lang.Boolean.FALSE; import static java.lang.Boolean.TRUE; import static org.assertj.core.api.Assertions.assertThat; @@ -109,6 +110,9 @@ public class AutoCommitServiceTest { @SpyBean JsonSchemaMigration jsonSchemaMigration; + @SpyBean + GitServiceConfig gitServiceConfig; + Application testApplication; Path baseRepoSuffix; @@ -252,6 +256,8 @@ public class AutoCommitServiceTest { AppsmithBeanUtils.copyNewFieldValuesIntoOldObject(applicationJson, applicationJson1); applicationJson1.setServerSchemaVersion(jsonSchemaVersions.getServerVersion() + 1); + doReturn(FALSE).when(gitServiceConfig).isGitInMemory(); + doReturn(Mono.just(applicationJson1)) .when(jsonSchemaMigration) .migrateApplicationJsonToLatestSchema( @@ -309,6 +315,8 @@ public class AutoCommitServiceTest { ApplicationJson applicationJson = gitFileSystemTestHelper.getApplicationJson(this.getClass().getResource(APP_JSON_NAME)); + doReturn(FALSE).when(gitServiceConfig).isGitInMemory(); + int pageDSLNumber = applicationJson .getPageList() .get(0) diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitEventHandlerImplTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitSolutionImplTest.java similarity index 96% rename from app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitEventHandlerImplTest.java rename to app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitSolutionImplTest.java index 3a02fa11a8..f683593f4d 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitEventHandlerImplTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitSolutionImplTest.java @@ -35,7 +35,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.SpyBean; -import org.springframework.context.ApplicationEventPublisher; import org.springframework.test.annotation.DirtiesContext; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -49,7 +48,7 @@ import java.util.Set; import java.util.UUID; import java.util.stream.Collectors; -import static com.appsmith.server.git.autocommit.AutoCommitEventHandlerCEImpl.AUTO_COMMIT_MSG_FORMAT; +import static com.appsmith.server.git.autocommit.AutoCommitSolutionCEImpl.AUTO_COMMIT_MSG_FORMAT; import static java.lang.Boolean.TRUE; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -59,9 +58,7 @@ import static org.mockito.Mockito.doReturn; @SpringBootTest @Slf4j @DirtiesContext -public class AutoCommitEventHandlerImplTest { - @MockBean - ApplicationEventPublisher applicationEventPublisher; +public class AutoCommitSolutionImplTest { @SpyBean RedisUtils redisUtils; @@ -96,7 +93,7 @@ public class AutoCommitEventHandlerImplTest { @Autowired ProjectProperties projectProperties; - AutoCommitEventHandler autoCommitEventHandler; + AutoCommitSolution autoCommitSolution; JsonSchemaVersions jsonSchemaVersions = new JsonSchemaVersions(); @@ -106,8 +103,7 @@ public class AutoCommitEventHandlerImplTest { @BeforeEach public void beforeTest() { - autoCommitEventHandler = new AutoCommitEventHandlerImpl( - applicationEventPublisher, + autoCommitSolution = new AutoCommitSolutionImpl( gitRedisUtils, redisUtils, dslMigrationUtils, @@ -135,7 +131,7 @@ public class AutoCommitEventHandlerImplTest { Mono map = redisUtils .startAutoCommit(defaultApplicationId, branchName) - .then(autoCommitEventHandler.autoCommitDSLMigration(autoCommitEvent)); + .then(autoCommitSolution.autoCommitDSLMigration(autoCommitEvent)); StepVerifier.create(map) .assertNext(x -> { @@ -243,7 +239,7 @@ public class AutoCommitEventHandlerImplTest { autoCommitEvent.getPrivateKey(), autoCommitEvent.getBranchName()); - StepVerifier.create(autoCommitEventHandler + StepVerifier.create(autoCommitSolution .autoCommitDSLMigration(autoCommitEvent) .zipWhen(a -> redisUtils.getAutoCommitProgress(autoCommitEvent.getApplicationId()))) .assertNext(tuple2 -> { @@ -292,7 +288,7 @@ public class AutoCommitEventHandlerImplTest { .constructArtifactExchangeJsonFromGitRepository(jsonTransformationDTO); // the rest of the process should not trigger as no migration is required - StepVerifier.create(autoCommitEventHandler + StepVerifier.create(autoCommitSolution .autoCommitDSLMigration(autoCommitEvent) .zipWhen(result -> redisUtils.getAutoCommitProgress(autoCommitEvent.getApplicationId()))) .assertNext(tuple2 -> { @@ -353,7 +349,7 @@ public class AutoCommitEventHandlerImplTest { autoCommitEvent.getPrivateKey(), autoCommitEvent.getBranchName()); - StepVerifier.create(autoCommitEventHandler + StepVerifier.create(autoCommitSolution .autoCommitServerMigration(autoCommitEvent) .zipWhen(result -> redisUtils.getAutoCommitProgress(autoCommitEvent.getApplicationId()))) .assertNext(tuple2 -> { @@ -371,7 +367,7 @@ public class AutoCommitEventHandlerImplTest { Mono map = redisUtils .startAutoCommit(defaultApplicationId, branchName) - .then(autoCommitEventHandler.autoCommitServerMigration(autoCommitEvent)); + .then(autoCommitSolution.autoCommitServerMigration(autoCommitEvent)); StepVerifier.create(map) .assertNext(x -> { @@ -414,7 +410,7 @@ public class AutoCommitEventHandlerImplTest { .saveArtifactToLocalRepoNew(baseRepoSuffix, applicationJson, autoCommitEvent.getBranchName()); // the rest of the process should not trigger as no migration is required - StepVerifier.create(autoCommitEventHandler + StepVerifier.create(autoCommitSolution .autoCommitServerMigration(autoCommitEvent) .zipWhen(result -> redisUtils.getAutoCommitProgress(autoCommitEvent.getApplicationId()))) .assertNext(tuple2 -> { @@ -479,7 +475,7 @@ public class AutoCommitEventHandlerImplTest { autoCommitEvent.getPrivateKey(), autoCommitEvent.getBranchName()); - StepVerifier.create(autoCommitEventHandler + StepVerifier.create(autoCommitSolution .autoCommitServerMigration(autoCommitEvent) .zipWhen(a -> redisUtils.getAutoCommitProgress(autoCommitEvent.getApplicationId()))) .assertNext(tuple2 -> { @@ -501,7 +497,7 @@ public class AutoCommitEventHandlerImplTest { gitFileSystemTestHelper.getApplicationJson(this.getClass().getResource("application.json")); gitFileSystemTestHelper.setupGitRepository(autoCommitEvent, applicationJson); - StepVerifier.create(autoCommitEventHandler + StepVerifier.create(autoCommitSolution .autoCommitServerMigration(autoCommitEvent) .zipWhen(a -> redisUtils.getAutoCommitProgress(autoCommitEvent.getApplicationId()))) .assertNext(tuple2 -> { @@ -544,7 +540,7 @@ public class AutoCommitEventHandlerImplTest { gitFileSystemTestHelper.setupGitRepository(autoCommitEvent, applicationJson); - StepVerifier.create(autoCommitEventHandler + StepVerifier.create(autoCommitSolution .autoCommitServerMigration(autoCommitEvent) .zipWhen(a -> redisUtils.getAutoCommitProgress(autoCommitEvent.getApplicationId()))) .assertNext(tuple2 -> { @@ -603,7 +599,7 @@ public class AutoCommitEventHandlerImplTest { autoCommitEvent.getBranchName()); gitFileSystemTestHelper.setupGitRepository(autoCommitEvent, applicationJson); - StepVerifier.create(autoCommitEventHandler + StepVerifier.create(autoCommitSolution .autoCommitDSLMigration(autoCommitEvent) .zipWhen(a -> redisUtils.getAutoCommitProgress(autoCommitEvent.getApplicationId()))) .assertNext(tuple2 -> { diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/helpers/GitAutoCommitHelperImplTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/helpers/GitAutoCommitHelperImplTest.java index f080ac1ba1..9f56aff0bd 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/helpers/GitAutoCommitHelperImplTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/helpers/GitAutoCommitHelperImplTest.java @@ -10,7 +10,6 @@ import com.appsmith.server.domains.GitAuth; import com.appsmith.server.domains.GitProfile; import com.appsmith.server.dtos.AutoCommitResponseDTO; import com.appsmith.server.events.AutoCommitEvent; -import com.appsmith.server.git.autocommit.AutoCommitEventHandler; import com.appsmith.server.git.central.CentralGitService; import com.appsmith.server.git.central.GitType; import com.appsmith.server.helpers.GitPrivateRepoHelper; @@ -43,7 +42,7 @@ import static org.mockito.ArgumentMatchers.eq; public class GitAutoCommitHelperImplTest { @MockBean - AutoCommitEventHandler autoCommitEventHandler; + AutoCommitAsyncEventManager autoCommitAsyncEventManager; @SpyBean ApplicationService applicationService; @@ -205,7 +204,7 @@ public class GitAutoCommitHelperImplTest { StepVerifier.create(gitAutoCommitHelper.autoCommitClientMigration(defaultApplicationId, branchName)) .assertNext(aBoolean -> { assertThat(aBoolean).isTrue(); - Mockito.verify(autoCommitEventHandler).publish(autoCommitEvent); + Mockito.verify(autoCommitAsyncEventManager).publishAsyncEvent(autoCommitEvent); }) .verifyComplete(); }