diff --git a/app/client/cypress/e2e/Regression/ClientSide/Git/GitAutocommit_spec.ts b/app/client/cypress/e2e/Regression/ClientSide/Git/GitAutocommit_spec.ts new file mode 100644 index 000000000000..fbc7b921c5a3 --- /dev/null +++ b/app/client/cypress/e2e/Regression/ClientSide/Git/GitAutocommit_spec.ts @@ -0,0 +1,57 @@ +import ReconnectLocators from "../../../../locators/ReconnectLocators"; +import { featureFlagIntercept } from "../../../../support/Objects/FeatureFlags"; +import { + agHelper, + gitSync, + homePage, +} from "../../../../support/Objects/ObjectsCore"; + +let wsName: string; +let repoName: string = "TED-testrepo1"; + +describe( + "Git Autocommit", + { tags: ["@tag.Git", "@tag.GitAutocommit"] }, + function () { + it("Check if autocommit progress bar is visible and network requests are properly called", function () { + featureFlagIntercept({ + release_git_autocommit_feature_enabled: true, + }); + agHelper.GenerateUUID(); + cy.get("@guid").then((uid) => { + wsName = "GitAC-" + uid; + homePage.CreateNewWorkspace(wsName, true); + + cy.intercept({ + method: "POST", + url: "/api/v1/git/auto-commit/app/*", + }).as("gitAutocommitTriggerApi"); + + cy.intercept( + { + method: "GET", + url: "/api/v1/git/auto-commit/progress/app/*", + }, + (req) => { + req.on("response", (res) => { + res.setDelay(500); + }); + }, + ).as("gitAutocommitProgressApi"); + + gitSync.ImportAppFromGit(wsName, repoName); + agHelper.GetNClick(ReconnectLocators.SkipToAppBtn); + cy.wait("@gitAutocommitTriggerApi").then((interception) => { + expect(interception?.response?.statusCode).to.equal(200); + expect( + interception?.response?.body?.data?.autoCommitResponse, + ).to.equal("PUBLISHED"); + agHelper.WaitUntilEleAppear(gitSync._autocommitStatusbar); + }); + cy.wait("@gitAutocommitProgressApi").then((interceptions) => { + expect(interceptions?.response?.statusCode).to.equal(200); + }); + }); + }); + }, +); diff --git a/app/client/cypress/support/Pages/GitSync.ts b/app/client/cypress/support/Pages/GitSync.ts index 0bf9ffeb4cb7..2fbf3b139a64 100644 --- a/app/client/cypress/support/Pages/GitSync.ts +++ b/app/client/cypress/support/Pages/GitSync.ts @@ -65,6 +65,7 @@ export class GitSync { "[data-testid='t--git-protected-branches-select']"; public _branchProtectionUpdateBtn = "[data-testid='t--git-protected-branches-update-btn']"; + public _autocommitStatusbar = "[data-testid='t--autocommit-statusbar']"; public _disconnectGitBtn = "[data-testid='t--git-disconnect-btn']"; public _mergeLoader = "[data-testid='t--git-merge-loader']"; diff --git a/app/client/src/pages/Editor/gitSync/QuickGitActions/AutocommitStatusbar.tsx b/app/client/src/pages/Editor/gitSync/QuickGitActions/AutocommitStatusbar.tsx index be8245bdc679..169f7cb4929f 100644 --- a/app/client/src/pages/Editor/gitSync/QuickGitActions/AutocommitStatusbar.tsx +++ b/app/client/src/pages/Editor/gitSync/QuickGitActions/AutocommitStatusbar.tsx @@ -57,7 +57,7 @@ export default function AutocommitStatusbar({ } }); return ( - + isServerAutoCommitRequired(String workspaceId, GitArtifactMetadata gitMetadata) { String defaultApplicationId = gitMetadata.getDefaultArtifactId(); @@ -75,7 +72,6 @@ public Mono isServerAutoCommitRequired(String workspaceId, GitArtifactM */ @Override @Deprecated - @FeatureFlagged(featureFlagName = FeatureFlagEnum.release_git_autocommit_eligibility_enabled) public Mono isClientMigrationRequired(PageDTO pageDTO) { return dslMigrationUtils .getLatestDslVersion() @@ -95,7 +91,6 @@ public Mono isClientMigrationRequired(PageDTO pageDTO) { } @Override - @FeatureFlagged(featureFlagName = FeatureFlagEnum.release_git_autocommit_eligibility_enabled) public Mono isClientMigrationRequiredFSOps( String workspaceId, GitArtifactMetadata gitMetadata, PageDTO pageDTO) { String defaultApplicationId = gitMetadata.getDefaultArtifactId(); @@ -127,7 +122,6 @@ public Mono isClientMigrationRequiredFSOps( } @Override - @FeatureFlagged(featureFlagName = FeatureFlagEnum.release_git_autocommit_eligibility_enabled) public Mono isAutoCommitRequired( String workspaceId, GitArtifactMetadata gitArtifactMetadata, PageDTO pageDTO) { diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/GitAutoCommitHelperFallbackImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/GitAutoCommitHelperFallbackImpl.java index 07a5ff852613..052792e35c0e 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/GitAutoCommitHelperFallbackImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/GitAutoCommitHelperFallbackImpl.java @@ -2,9 +2,11 @@ import com.appsmith.server.dtos.AutoCommitResponseDTO; import com.appsmith.server.dtos.AutoCommitTriggerDTO; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import reactor.core.publisher.Mono; +@Slf4j @Component public class GitAutoCommitHelperFallbackImpl implements GitAutoCommitHelper { 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 eb399c0cae91..dfd2421cd60e 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 @@ -89,7 +89,7 @@ private Mono isAutoCommitAllowed(Application defaultApplication, String String defaultApplicationId = defaultApplication.getId(); if (!GitUtils.isAutoCommitEnabled(defaultApplication.getGitApplicationMetadata())) { - log.debug("auto commit is disabled for application: {}", defaultApplicationId); + log.info("Auto commit is disabled for application: {}", defaultApplicationId); return Mono.just(Boolean.FALSE); } @@ -107,14 +107,19 @@ private Mono isAutoCommitAllowed(Application defaultApplication, String Boolean isAutoCommitRunning = tuple.getT2(); if (isBranchProtected || isAutoCommitRunning) { - log.debug( - "auto commit is not applicable for application: {} branch: {}, isAutoCommitDisabledForBranch: {}", + log.info( + "Auto commit is not applicable for application: {} branch: {}, isAutoCommitDisabledForBranch: {}", defaultApplicationId, branchName, isBranchProtected); return Mono.just(Boolean.FALSE); } + log.info( + "Auto commit for application: {} branch: {} is applicable", + defaultApplicationId, + branchName); + return Mono.just(Boolean.TRUE); }) .switchIfEmpty(Mono.just(Boolean.FALSE)); @@ -135,6 +140,8 @@ public Mono autoCommitServerMigration(String defaultApplicationId, Stri public Mono autoCommitApplication( String defaultApplicationId, String branchName, Boolean isClientMigration) { + log.info("Auto commit for application {} and branch {} in the publish flow", defaultApplicationId, branchName); + // if either param is absent, then application is not connected to git. if (!StringUtils.hasText(branchName) || !StringUtils.hasText(defaultApplicationId)) { return Mono.just(Boolean.FALSE); @@ -155,21 +162,33 @@ public Mono autoCommitApplication( .flatMap(defaultApplication -> { return isAutoCommitAllowed(defaultApplication, finalBranchName) .flatMap(isEligible -> { + log.info( + "Auto commit for application {}, and branch name {} is not allowed.", + defaultApplication.getId(), + branchName); if (!Boolean.TRUE.equals(isEligible)) { return Mono.empty(); } + log.info( + "Auto commit for application {}, and branch name {} is applicable", + defaultApplication.getId(), + branchName); return Mono.zip(applicationMono, branchedApplicationMono); }); }) .flatMap(tuple2 -> { Application defaultApplication = tuple2.getT1(); Application branchedApplication = tuple2.getT2(); + log.info( + "Auto commit for application {}, and branch name {} is fetching remote changes", + defaultApplication.getId(), + branchName); return commonGitService .fetchRemoteChanges(defaultApplication, branchedApplication, true) .flatMap(branchTrackingStatus -> { if (branchTrackingStatus.getBehindCount() > 0) { - log.debug( + log.info( "the remote is ahead of the local, aborting autocommit for application {} and branch {}", defaultApplicationId, branchName); @@ -221,6 +240,8 @@ public Mono autoCommitApplication( public Mono publishAutoCommitEvent( AutoCommitTriggerDTO autoCommitTriggerDTO, String defaultApplicationId, String branchName) { + log.info("Trying to publish auto commit for application {} and branch {}", defaultApplicationId, branchName); + if (!Boolean.TRUE.equals(autoCommitTriggerDTO.getIsAutoCommitRequired())) { return Mono.just(Boolean.FALSE); } 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 070b7d525b94..1c53aa243bb9 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 @@ -15,6 +15,7 @@ import com.appsmith.server.domains.Layout; import com.appsmith.server.dtos.ApplicationJson; import com.appsmith.server.dtos.AutoCommitResponseDTO; +import com.appsmith.server.dtos.AutoCommitTriggerDTO; import com.appsmith.server.dtos.PageDTO; import com.appsmith.server.featureflags.CachedFeatures; import com.appsmith.server.git.autocommit.helpers.AutoCommitEligibilityHelper; @@ -106,7 +107,7 @@ public class AutoCommitServiceTest { @MockBean GitPrivateRepoHelper gitPrivateRepoHelper; - @SpyBean + @MockBean AutoCommitEligibilityHelper autoCommitEligibilityHelper; @MockBean @@ -193,20 +194,26 @@ private org.json.JSONObject getMockedDsl() { } private void mockAutoCommitTriggerResponse(Boolean serverMigration, Boolean clientMigration) { - doReturn(Mono.just(getMockedDsl())) - .when(commonGitFileUtils) - .getPageDslVersionNumber(anyString(), any(), any(), anyBoolean(), any()); - - Integer serverVersion = jsonSchemaVersions.getServerVersion(); - Integer dslVersionNumber = clientMigration ? DSL_VERSION_NUMBER + 1 : DSL_VERSION_NUMBER; - Integer serverSchemaVersionNumber = serverMigration ? serverVersion - 1 : serverVersion; - - doReturn(Mono.just(dslVersionNumber)).when(dslMigrationUtils).getLatestDslVersion(); - // server as true - doReturn(Mono.just(serverSchemaVersionNumber)) - .when(commonGitFileUtils) - .getMetadataServerSchemaMigrationVersion(anyString(), any(), anyBoolean(), any()); + Boolean isAutocommitRequired = serverMigration || clientMigration; + doReturn(Mono.just(new AutoCommitTriggerDTO(isAutocommitRequired, clientMigration, serverMigration))) + .when(autoCommitEligibilityHelper) + .isAutoCommitRequired(anyString(), any(), any()); + + // doReturn(Mono.just(getMockedDsl())) + // .when(commonGitFileUtils) + // .getPageDslVersionNumber(anyString(), any(), any(), anyBoolean(), any()); + // + // Integer serverVersion = jsonSchemaVersions.getServerVersion(); + // Integer dslVersionNumber = clientMigration ? DSL_VERSION_NUMBER + 1 : DSL_VERSION_NUMBER; + // Integer serverSchemaVersionNumber = serverMigration ? serverVersion - 1 : serverVersion; + // + // doReturn(Mono.just(dslVersionNumber)).when(dslMigrationUtils).getLatestDslVersion(); + // + // // server as true + // doReturn(Mono.just(serverSchemaVersionNumber)) + // .when(commonGitFileUtils) + // .getMetadataServerSchemaMigrationVersion(anyString(), any(), anyBoolean(), any()); } @BeforeEach @@ -237,9 +244,6 @@ public void beforeTest() { Mockito.when(featureFlagService.getCachedTenantFeatureFlags()) .thenAnswer((Answer) invocations -> cachedFeatures); - Mockito.when(featureFlagService.check(FeatureFlagEnum.release_git_autocommit_eligibility_enabled)) - .thenReturn(Mono.just(TRUE)); - Mockito.when(featureFlagService.check(FeatureFlagEnum.release_git_autocommit_feature_enabled)) .thenReturn(Mono.just(TRUE)); @@ -465,6 +469,7 @@ public void testAutoCommit_whenAutoCommitAlreadyInProgressOnAnotherBranch_return Mockito.when(redisUtils.getAutoCommitProgress(DEFAULT_APP_ID)).thenReturn(Mono.just(70)); + mockAutoCommitTriggerResponse(TRUE, TRUE); // this would not trigger autocommit Mono autoCommitResponseDTOMono = autoCommitService.autoCommitApplication(testApplication.getId()); @@ -486,6 +491,8 @@ public void testAutoCommit_whenAutoCommitAlreadyInProgressOnSameBranch_returnsIn Mockito.when(redisUtils.getAutoCommitProgress(DEFAULT_APP_ID)).thenReturn(Mono.just(70)); + mockAutoCommitTriggerResponse(TRUE, TRUE); + // this would not trigger autocommit Mono autoCommitResponseDTOMono = autoCommitService.autoCommitApplication(testApplication.getId()); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/helpers/AutoCommitEligibilityHelperTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/helpers/AutoCommitEligibilityHelperTest.java index 4eb1de96fae1..e107ffde6546 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/helpers/AutoCommitEligibilityHelperTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/helpers/AutoCommitEligibilityHelperTest.java @@ -106,9 +106,6 @@ public void beforeEach() { Mockito.when(featureFlagService.check(FeatureFlagEnum.release_git_autocommit_feature_enabled)) .thenReturn(Mono.just(Boolean.TRUE)); - Mockito.when(featureFlagService.check(FeatureFlagEnum.release_git_autocommit_eligibility_enabled)) - .thenReturn(Mono.just(Boolean.TRUE)); - Mockito.when(dslMigrationUtils.getLatestDslVersion()).thenReturn(Mono.just(RANDOM_DSL_VERSION_NUMBER)); Mockito.when(gitRedisUtils.addFileLock(DEFAULT_APPLICATION_ID, AUTO_COMMIT_ELIGIBILITY)) @@ -292,8 +289,6 @@ public void isServerMigrationRequired_whenJsonSchemaIsAhead_returnsTrue() { @Test public void isServerMigrationRequired_whenFeatureIsFlagFalse_returnsFalse() { - Mockito.when(featureFlagService.check(FeatureFlagEnum.release_git_autocommit_eligibility_enabled)) - .thenReturn(Mono.just(Boolean.FALSE)); GitArtifactMetadata gitArtifactMetadata = createGitMetadata(); @@ -350,8 +345,6 @@ public void isClientMigrationRequired_whenLatestDslIsAhead_returnsTrue() { @Test public void isClientMigrationRequired_whenFeatureFlagIsFalse_returnsFalse() { - Mockito.when(featureFlagService.check(FeatureFlagEnum.release_git_autocommit_eligibility_enabled)) - .thenReturn(Mono.just(Boolean.FALSE)); PageDTO pageDTO = createPageDTO(RANDOM_DSL_VERSION_NUMBER); Mono isClientMigrationRequiredMono = autoCommitEligibilityHelper.isClientMigrationRequired(pageDTO); @@ -364,8 +357,6 @@ public void isClientMigrationRequired_whenFeatureFlagIsFalse_returnsFalse() { @Test public void isAutoCommitRequired_whenFeatureIsFlagFalse_returnsAllFalse() { - Mockito.when(featureFlagService.check(FeatureFlagEnum.release_git_autocommit_eligibility_enabled)) - .thenReturn(Mono.just(Boolean.FALSE)); GitArtifactMetadata gitArtifactMetadata = createGitMetadata(); PageDTO pageDTO = createPageDTO(RANDOM_DSL_VERSION_NUMBER - 1);