diff --git a/app/server/appsmith-git/src/main/java/com/appsmith/git/service/GitExecutorImpl.java b/app/server/appsmith-git/src/main/java/com/appsmith/git/service/GitExecutorImpl.java index 76d73aba90..2be57d9a08 100644 --- a/app/server/appsmith-git/src/main/java/com/appsmith/git/service/GitExecutorImpl.java +++ b/app/server/appsmith-git/src/main/java/com/appsmith/git/service/GitExecutorImpl.java @@ -629,7 +629,7 @@ public class GitExecutorImpl implements GitExecutor { } errorMessage.append(" while merging branch: ").append(destinationBranch).append(" <= ").append(sourceBranch); mergeStatus.setMessage(errorMessage.toString()); - mergeStatus.setReferenceDoc(ErrorReferenceDocUrl.GIT_MERGE_CONFLICT); + mergeStatus.setReferenceDoc(ErrorReferenceDocUrl.GIT_MERGE_CONFLICT.getDocUrl()); } mergeStatus.setStatus(mergeResult.getMergeStatus().name()); return mergeStatus; diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/ErrorReferenceDocUrl.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/ErrorReferenceDocUrl.java index 322d6a3aef..47bd3ca4e4 100644 --- a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/ErrorReferenceDocUrl.java +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/ErrorReferenceDocUrl.java @@ -2,11 +2,20 @@ package com.appsmith.external.constants; import lombok.Getter; -@Getter -public class ErrorReferenceDocUrl { - public static final String GIT_MERGE_CONFLICT = "https://docs.appsmith.com/core-concepts/version-control-with-git/merging-branches"; - public static final String GIT_PULL_CONFLICT = "https://docs.appsmith.com/core-concepts/version-control-with-git/pull-and-sync"; - public static final String GIT_DEPLOY_KEY = "https://docs.appsmith.com/core-concepts/version-control-with-git/connecting-to-git-repository#generating-a-deploy-key"; - public static final String FILE_PATH_NOT_SET = "https://docs.appsmith.com/core-concepts/version-control-with-git/updating-local-file-path"; - public static final String GIT_UPSTREAM_CHANGES = "https://docs.appsmith.com/core-concepts/version-control-with-git/working-with-branches#syncing-local-with-remote-branch"; +public enum ErrorReferenceDocUrl { + + GIT_MERGE_CONFLICT("https://docs.appsmith.com/core-concepts/version-control-with-git/merging-branches"), + GIT_PULL_CONFLICT("https://docs.appsmith.com/core-concepts/version-control-with-git/pull-and-sync"), + GIT_DEPLOY_KEY("https://docs.appsmith.com/core-concepts/version-control-with-git/connecting-to-git-repository#generating-a-deploy-key"), + FILE_PATH_NOT_SET("https://docs.appsmith.com/core-concepts/version-control-with-git/updating-local-file-path"), + GIT_UPSTREAM_CHANGES("https://docs.appsmith.com/core-concepts/version-control-with-git/working-with-branches#syncing-local-with-remote-branch"), + DEPLOY_KEY_DOC_URL("https://docs.github.com/en/developers/overview/managing-deploy-keys"); + + private final String docUrl; + + ErrorReferenceDocUrl(String docUrl) { + this.docUrl = docUrl; + } + + public String getDocUrl() { return this.docUrl;} } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/constants/GitConstants.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/constants/GitConstants.java deleted file mode 100644 index d1327f2c79..0000000000 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/constants/GitConstants.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.appsmith.server.constants; - -public class GitConstants { - public final static String DEPLOY_KEY_DOC_URL = "https://docs.github.com/en/developers/overview/managing-deploy-keys"; -} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/GitControllerCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/GitControllerCE.java index 714ece31ab..34fb2edcb8 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/GitControllerCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/GitControllerCE.java @@ -14,6 +14,7 @@ import com.appsmith.server.dtos.ApplicationImportDTO; import com.appsmith.server.dtos.GitCommitDTO; import com.appsmith.server.dtos.GitConnectDTO; import com.appsmith.server.dtos.GitDeployKeyDTO; +import com.appsmith.server.dtos.GitDocsDTO; import com.appsmith.server.dtos.GitMergeDTO; import com.appsmith.server.dtos.GitPullDTO; import com.appsmith.server.dtos.ResponseDTO; @@ -35,6 +36,8 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseStatus; import reactor.core.publisher.Mono; +import java.util.ArrayList; +import java.util.EnumSet; import java.util.List; import java.util.Map; @@ -227,11 +230,17 @@ public class GitControllerCE { .map(result -> new ResponseDTO<>((HttpStatus.OK.value()), result, null)); } - @GetMapping("/protocol/keys") + @GetMapping("/protocol/key-types") public Mono>> getSupportedKeys() { log.debug("Going to list the list of supported keys"); return Mono.just(GitDeployKeyGenerator.getSupportedProtocols()) .map(gitDeployKeyDTOS -> new ResponseDTO<>(HttpStatus.OK.value(), gitDeployKeyDTOS, null)); } + @GetMapping("/doc-urls") + public Mono>> getGitDocs() { + return service.getGitDocUrls() + .map(gitDocDTO -> new ResponseDTO<>(HttpStatus.OK.value(), gitDocDTO, null)); + } + } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/GitDocsDTO.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/GitDocsDTO.java new file mode 100644 index 0000000000..efaaf29038 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/GitDocsDTO.java @@ -0,0 +1,13 @@ +package com.appsmith.server.dtos; + +import com.appsmith.external.constants.ErrorReferenceDocUrl; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class GitDocsDTO { + ErrorReferenceDocUrl docKey; + + String docUrl; +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java index c7c9c98350..05412df2f0 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java @@ -79,12 +79,12 @@ public enum AppsmithError { INVALID_CURL_COMMAND(400, 4029, "Invalid cURL command, couldn't import.", AppsmithErrorAction.DEFAULT, null, ErrorType.ARGUMENT_ERROR, null), INVALID_LOGIN_METHOD(401, 4030, "Please use {0} authentication to login to Appsmith", AppsmithErrorAction.DEFAULT, null, ErrorType.INTERNAL_ERROR, null), INVALID_GIT_CONFIGURATION(400, 4031, "Git configuration is invalid. Details: {0}", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_CONFIGURATION_ERROR, null), - INVALID_GIT_SSH_CONFIGURATION(400, 4032, "SSH Key is not configured properly. Did you forget to add SSH key to remote? Can you please try again by reconfiguring the SSH key with write access", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_CONFIGURATION_ERROR, ErrorReferenceDocUrl.GIT_DEPLOY_KEY), + INVALID_GIT_SSH_CONFIGURATION(400, 4032, "SSH Key is not configured properly. Did you forget to add SSH key to remote? Can you please try again by reconfiguring the SSH key with write access", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_CONFIGURATION_ERROR, ErrorReferenceDocUrl.GIT_DEPLOY_KEY.getDocUrl()), INVALID_GIT_REPO(400, 4033, "The remote repo is not empty. Please create a new empty repo and configure the SSH keys. " + "If you want to clone from remote repo and build application, please use import application from git option.", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_CONFIGURATION_ERROR, null), DEFAULT_RESOURCES_UNAVAILABLE(400, 4034, "Unexpected state. Default resources are unavailable for {0} with id {1}. Please reach out to Appsmith customer support to resolve this.", AppsmithErrorAction.LOG_EXTERNALLY, null, ErrorType.BAD_REQUEST, null), - GIT_MERGE_FAILED_REMOTE_CHANGES(406, 4036, "Remote is ahead of local by {0} commits on branch {1}. Please pull remote changes first and try again.", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_ACTION_EXECUTION_ERROR, ErrorReferenceDocUrl.GIT_UPSTREAM_CHANGES), + GIT_MERGE_FAILED_REMOTE_CHANGES(406, 4036, "Remote is ahead of local by {0} commits on branch {1}. Please pull remote changes first and try again.", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_ACTION_EXECUTION_ERROR, ErrorReferenceDocUrl.GIT_UPSTREAM_CHANGES.getDocUrl()), GIT_MERGE_FAILED_LOCAL_CHANGES(406, 4037, "There are uncommitted changes present in your local branch {0}. Please commit them first and try again", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_ACTION_EXECUTION_ERROR, null), REMOVE_LAST_WORKSPACE_ADMIN_ERROR(400, 4038, "The last admin can not be removed from an organization", AppsmithErrorAction.DEFAULT, null, ErrorType.INTERNAL_ERROR, null), INVALID_CRUD_PAGE_REQUEST(400, 4039, "Unable to process page generation request, {0}", AppsmithErrorAction.DEFAULT, null, ErrorType.BAD_REQUEST, null), @@ -128,14 +128,14 @@ public enum AppsmithError { CLOUD_SERVICES_ERROR(500, 5012, "Received error from cloud services {0}", AppsmithErrorAction.DEFAULT, null, ErrorType.INTERNAL_ERROR, null), GIT_APPLICATION_LIMIT_ERROR(402, 4043, "You have reached the maximum number of private git repo counts which can be connected to the organization. Please reach out to Appsmith support to opt for commercial plan.", AppsmithErrorAction.DEFAULT, null, ErrorType.EE_FEATURE_ERROR, null), GIT_ACTION_FAILED(400, 4044, "git {0} failed. \nDetails: {1}", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_ACTION_EXECUTION_ERROR, null), - GIT_FILE_SYSTEM_ERROR(503, 5013, "Error while accessing the file system. {0}", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_CONFIGURATION_ERROR, ErrorReferenceDocUrl.FILE_PATH_NOT_SET), + GIT_FILE_SYSTEM_ERROR(503, 5013, "Error while accessing the file system. {0}", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_CONFIGURATION_ERROR, ErrorReferenceDocUrl.FILE_PATH_NOT_SET.getDocUrl()), GIT_EXECUTION_TIMEOUT(504, 5014, "Git command execution exceeded the maximum allowed time, please contact Appsmith support for more details", AppsmithErrorAction.DEFAULT, null, ErrorType.CONNECTIVITY_ERROR, null), INCOMPATIBLE_IMPORTED_JSON(400, 4045, "Provided file is incompatible, please upgrade your instance to resolve this conflict.", AppsmithErrorAction.DEFAULT, null, ErrorType.BAD_REQUEST, null), - GIT_MERGE_CONFLICTS(400, 4046, "Merge conflicts found: {0}", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_ACTION_EXECUTION_ERROR, ErrorReferenceDocUrl.GIT_MERGE_CONFLICT), - GIT_PULL_CONFLICTS(400, 4047, "Merge conflicts found during the pull operation: {0}", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_ACTION_EXECUTION_ERROR, ErrorReferenceDocUrl.GIT_PULL_CONFLICT), + GIT_MERGE_CONFLICTS(400, 4046, "Merge conflicts found: {0}", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_ACTION_EXECUTION_ERROR, ErrorReferenceDocUrl.GIT_MERGE_CONFLICT.getDocUrl()), + GIT_PULL_CONFLICTS(400, 4047, "Merge conflicts found during the pull operation: {0}", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_ACTION_EXECUTION_ERROR, ErrorReferenceDocUrl.GIT_PULL_CONFLICT.getDocUrl()), SSH_KEY_GENERATION_ERROR(500, 5015, "Failed to generate SSH keys, please contact Appsmith support for more details", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_CONFIGURATION_ERROR, null), GIT_GENERIC_ERROR(504, 5016, "Git command execution error: {0}", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_ACTION_EXECUTION_ERROR, null), - GIT_UPSTREAM_CHANGES(400, 4048, "Looks like there are pending upstream changes. To prevent you from losing history, we will pull the changes and push them to your repo.", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_UPSTREAM_CHANGES_PUSH_EXECUTION_ERROR, ErrorReferenceDocUrl.GIT_UPSTREAM_CHANGES), + GIT_UPSTREAM_CHANGES(400, 4048, "Looks like there are pending upstream changes. To prevent you from losing history, we will pull the changes and push them to your repo.", AppsmithErrorAction.DEFAULT, null, ErrorType.GIT_UPSTREAM_CHANGES_PUSH_EXECUTION_ERROR, ErrorReferenceDocUrl.GIT_UPSTREAM_CHANGES.getDocUrl()), GENERIC_JSON_IMPORT_ERROR(400, 4049, "Unable to import application in organization {0} with error {1}", AppsmithErrorAction.DEFAULT, null, ErrorType.BAD_REQUEST, null), FILE_PART_DATA_BUFFER_ERROR(500, 5017, "Failed to upload file with error: {0}", AppsmithErrorAction.DEFAULT, null, ErrorType.BAD_REQUEST, null), MIGRATION_ERROR(500, 5018, "This action is already migrated", AppsmithErrorAction.DEFAULT, null, ErrorType.INTERNAL_ERROR, null), diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCE.java index ebba3de5a2..e94bc84d22 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCE.java @@ -11,10 +11,12 @@ import com.appsmith.server.domains.GitProfile; import com.appsmith.server.dtos.GitCommitDTO; import com.appsmith.server.dtos.GitConnectDTO; import com.appsmith.server.dtos.ApplicationImportDTO; +import com.appsmith.server.dtos.GitDocsDTO; import com.appsmith.server.dtos.GitMergeDTO; import com.appsmith.server.dtos.GitPullDTO; import reactor.core.publisher.Mono; +import java.util.EnumSet; import java.util.List; import java.util.Map; @@ -70,4 +72,6 @@ public interface GitServiceCE { Mono discardChanges(String defaultApplicationId, String branchName, Boolean doPull); + Mono> getGitDocUrls(); + } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCEImpl.java index 2d5a534de4..99587fa568 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCEImpl.java @@ -26,6 +26,7 @@ import com.appsmith.server.domains.UserData; import com.appsmith.server.dtos.ApplicationImportDTO; import com.appsmith.server.dtos.GitCommitDTO; import com.appsmith.server.dtos.GitConnectDTO; +import com.appsmith.server.dtos.GitDocsDTO; import com.appsmith.server.dtos.GitMergeDTO; import com.appsmith.server.dtos.GitPullDTO; import com.appsmith.server.exceptions.AppsmithError; @@ -69,6 +70,7 @@ import reactor.core.publisher.Mono; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; import java.time.Instant; import java.util.HashMap; import java.util.List; @@ -1764,7 +1766,7 @@ public class GitServiceCEImpl implements GitServiceCE { mergeStatus.setConflictingFiles(((CheckoutConflictException) error) .getConflictingPaths()); } - mergeStatus.setReferenceDoc(ErrorReferenceDocUrl.GIT_MERGE_CONFLICT); + mergeStatus.setReferenceDoc(ErrorReferenceDocUrl.GIT_MERGE_CONFLICT.getDocUrl()); return mergeStatus; }); } catch (GitAPIException | IOException e) { @@ -2180,6 +2182,25 @@ public class GitServiceCEImpl implements GitServiceCE { ); } + /** + * In some scenarios: + * connect: after loading the modal, keyTypes is not available, so a network call has to be made to ssh-keypair. + * import: cannot make a ssh-keypair call because application Id doesn’t exist yet, so API fails. + * @return Git docs urls for all the scenarios, client will cache this data and use it + */ + @Override + public Mono> getGitDocUrls() { + ErrorReferenceDocUrl[] docSet = ErrorReferenceDocUrl.values(); + List gitDocsDTOList = new ArrayList<>(); + for(ErrorReferenceDocUrl docUrl : docSet ) { + GitDocsDTO gitDocsDTO = new GitDocsDTO(); + gitDocsDTO.setDocKey(docUrl); + gitDocsDTO.setDocUrl(docUrl.getDocUrl()); + gitDocsDTOList.add(gitDocsDTO); + } + return Mono.just(gitDocsDTOList); + } + private Mono deleteApplicationCreatedFromGitImport(String applicationId, String workspaceId, String repoName) { Path repoSuffix = Paths.get(workspaceId, applicationId, repoName); return fileUtils.deleteLocalRepo(repoSuffix)