Skip to content

Commit

Permalink
chore: Add code-split for Git integration for packages (#39166)
Browse files Browse the repository at this point in the history
## Description
EE counterpart: appsmithorg/appsmith-ee#6032


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.ImportExport, @tag.Git"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/13520092700>
> Commit: 57eb731
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=13520092700&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.ImportExport, @tag.Git`
> Spec:
> <hr>Tue, 25 Feb 2025 12:14:10 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
- Improved Git integration when discarding changes by adding extra
validation and enhanced error reporting. These enhancements ensure that
modifications are handled more reliably, resulting in a smoother and
more consistent experience for users.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
subrata71 authored Feb 25, 2025
1 parent c2bef37 commit 63b391d
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2259,7 +2259,7 @@ protected Mono<? extends Artifact> discardChanges(Artifact branchedArtifact, Git
.flatMap(artifactExchangeJson -> importService.importArtifactInWorkspaceFromGit(
workspaceId, branchedArtifact.getId(), artifactExchangeJson, branchName))
.flatMap(artifactFromLastCommit ->
gitArtifactHelper.publishArtifact(artifactFromLastCommit, true))
gitArtifactHelper.validateAndPublishArtifact(artifactFromLastCommit, true))
.flatMap(publishedArtifact -> gitAnalyticsUtils.addAnalyticsForGitOperation(
AnalyticsEvents.GIT_DISCARD_CHANGES, publishedArtifact, null))
.onErrorResume(exception -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.appsmith.server.git;

import com.appsmith.external.constants.PluginConstants;
import com.appsmith.external.models.ActionConfiguration;
import com.appsmith.external.models.ActionDTO;
import com.appsmith.external.models.Datasource;
import com.appsmith.external.models.PluginType;
import com.appsmith.server.domains.Application;
import com.appsmith.server.domains.Artifact;
import com.appsmith.server.domains.Plugin;
import com.appsmith.server.plugins.base.PluginService;
import com.appsmith.server.services.LayoutActionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

import java.util.UUID;

@Component
public class GitApplicationTestUtils implements GitArtifactTestUtils<Application> {

@Autowired
LayoutActionService layoutActionService;
@Autowired
PluginService pluginService;


@Override
public Mono<Void> createADiff(Artifact artifact) {

Application application = (Application) artifact;
String pageId = application.getPages().get(0).getId();
Plugin plugin = pluginService.findByPackageName("restapi-plugin").block();

Datasource datasource = new Datasource();
datasource.setName(PluginConstants.DEFAULT_REST_DATASOURCE);
datasource.setWorkspaceId(application.getWorkspaceId());
datasource.setPluginId(plugin.getId());

ActionDTO action = new ActionDTO();
action.setPluginType(PluginType.API);
action.setName("aGetAction_" + UUID.randomUUID());
action.setDatasource(datasource);
action.setActionConfiguration(new ActionConfiguration());
action.getActionConfiguration().setHttpMethod(HttpMethod.GET);
action.setPageId(pageId);

return layoutActionService
.createSingleAction(action, Boolean.FALSE)
.then();
}
}
Original file line number Diff line number Diff line change
@@ -1,52 +1,8 @@
package com.appsmith.server.git;

import com.appsmith.external.constants.PluginConstants;
import com.appsmith.external.models.ActionConfiguration;
import com.appsmith.external.models.ActionDTO;
import com.appsmith.external.models.Datasource;
import com.appsmith.external.models.PluginType;
import com.appsmith.server.domains.Application;
import com.appsmith.server.domains.Artifact;
import com.appsmith.server.domains.Plugin;
import com.appsmith.server.plugins.base.PluginService;
import com.appsmith.server.services.LayoutActionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

import java.util.UUID;

@Component
public class GitArtifactTestUtils<T extends Artifact> {

@Autowired
LayoutActionService layoutActionService;
@Autowired
PluginService pluginService;

Mono<Void> createADiff(Artifact artifact) {

Application application = (Application) artifact;

String pageId = application.getPages().get(0).getId();
Plugin plugin = pluginService.findByPackageName("restapi-plugin").block();

Datasource datasource = new Datasource();
datasource.setName(PluginConstants.DEFAULT_REST_DATASOURCE);
datasource.setWorkspaceId(application.getWorkspaceId());
datasource.setPluginId(plugin.getId());

ActionDTO action = new ActionDTO();
action.setPluginType(PluginType.API);
action.setName("aGetAction_" + UUID.randomUUID());
action.setDatasource(datasource);
action.setActionConfiguration(new ActionConfiguration());
action.getActionConfiguration().setHttpMethod(HttpMethod.GET);
action.setPageId(pageId);

return layoutActionService
.createSingleAction(action, Boolean.FALSE)
.then();
}
public interface GitArtifactTestUtils<T extends Artifact> {
Mono<Void> createADiff(Artifact artifact);
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
package com.appsmith.server.git;

import com.appsmith.server.constants.ArtifactType;

import com.appsmith.server.domains.Application;
import com.appsmith.server.domains.Artifact;
import lombok.RequiredArgsConstructor;
import com.appsmith.server.git.ce.GitTestUtilsCE;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

@RequiredArgsConstructor
@Component
public class GitTestUtils {

private final GitArtifactTestUtils<Application> gitApplicationTestUtils;

private GitArtifactTestUtils<?> getArtifactSpecificUtils(ArtifactType artifactType) {
// TODO For now just work with apps
return gitApplicationTestUtils;
}


public Mono<Void> createADiffInArtifact(Artifact artifact) {
GitArtifactTestUtils<?> artifactSpecificUtils = getArtifactSpecificUtils(artifact.getArtifactType());

return artifactSpecificUtils.createADiff(artifact);
public class GitTestUtils extends GitTestUtilsCE {
public GitTestUtils(GitArtifactTestUtils<Application> gitApplicationTestUtils) {
super(gitApplicationTestUtils);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.appsmith.server.git.ce;

import com.appsmith.server.constants.ArtifactType;
import com.appsmith.server.domains.Application;
import com.appsmith.server.domains.Artifact;
import com.appsmith.server.git.GitArtifactTestUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

@RequiredArgsConstructor
@Component
public class GitTestUtilsCE {

private final GitArtifactTestUtils<Application> gitApplicationTestUtils;
protected GitArtifactTestUtils<?> getArtifactSpecificUtils(ArtifactType artifactType) {
return gitApplicationTestUtils;
}


public Mono<Void> createADiffInArtifact(Artifact artifact) {
GitArtifactTestUtils<?> artifactSpecificUtils = getArtifactSpecificUtils(artifact.getArtifactType());

return artifactSpecificUtils.createADiff(artifact);
}
}

0 comments on commit 63b391d

Please sign in to comment.