-
Notifications
You must be signed in to change notification settings - Fork 4.6k
chore: reference lifecycle #38174
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: reference lifecycle #38174
Changes from 12 commits
9e090e7
7d556ed
e74219c
21933b8
4cd584f
a7b8606
9f2f3bc
592833e
f5dcc3f
73a48ae
376d3ba
804ed27
fe1648a
5cf5026
03a3843
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.appsmith.external.dtos; | ||
|
|
||
| import com.appsmith.external.git.constants.ce.RefType; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Data | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| public class GitRefDTO { | ||
|
|
||
| String refName; | ||
|
|
||
| RefType refType; | ||
|
|
||
| boolean isDefault; | ||
|
|
||
| boolean createdFromLocal; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.appsmith.external.git.constants.ce; | ||
|
|
||
| public enum RefType { | ||
| BRANCH, | ||
| TAG | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| package com.appsmith.server.git.central; | ||
|
|
||
| import com.appsmith.external.dtos.GitStatusDTO; | ||
| import com.appsmith.external.git.constants.ce.RefType; | ||
| import com.appsmith.git.dto.CommitDTO; | ||
| import com.appsmith.server.constants.ArtifactType; | ||
| import com.appsmith.server.constants.ce.RefType; | ||
| import com.appsmith.server.domains.Artifact; | ||
| import com.appsmith.server.dtos.ArtifactImportDTO; | ||
| import com.appsmith.server.dtos.GitConnectDTO; | ||
|
|
@@ -33,4 +34,15 @@ Mono<String> fetchRemoteChanges( | |
| RefType refType); | ||
|
|
||
| Mono<? extends Artifact> discardChanges(String branchedArtifactId, ArtifactType artifactType, GitType gitType); | ||
|
|
||
| Mono<GitStatusDTO> getStatus( | ||
| String branchedArtifactId, boolean compareRemote, ArtifactType artifactType, GitType gitType); | ||
|
|
||
| Mono<? extends Artifact> checkoutReference( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit, should we not be able to make a DTO out of these params?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we can!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will you be replacing usage in a separate PR? |
||
| String referenceArtifactId, | ||
| String referenceToBeCheckedOut, | ||
| boolean addFileLock, | ||
| ArtifactType artifactType, | ||
| GitType gitType, | ||
| RefType refType); | ||
| } | ||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,8 +2,10 @@ | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| import com.appsmith.external.constants.AnalyticsEvents; | ||||||||||||||||||||||||||||||||||||||||||
| import com.appsmith.external.dtos.GitBranchDTO; | ||||||||||||||||||||||||||||||||||||||||||
| import com.appsmith.external.dtos.GitStatusDTO; | ||||||||||||||||||||||||||||||||||||||||||
| import com.appsmith.external.git.constants.GitConstants; | ||||||||||||||||||||||||||||||||||||||||||
| import com.appsmith.external.git.constants.GitSpan; | ||||||||||||||||||||||||||||||||||||||||||
| import com.appsmith.external.git.constants.ce.RefType; | ||||||||||||||||||||||||||||||||||||||||||
| import com.appsmith.external.git.handler.FSGitHandler; | ||||||||||||||||||||||||||||||||||||||||||
| import com.appsmith.git.dto.CommitDTO; | ||||||||||||||||||||||||||||||||||||||||||
| import com.appsmith.server.acl.AclPermission; | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -261,22 +263,46 @@ public Mono<List<String>> listBranches(ArtifactJsonTransformationDTO artifactJso | |||||||||||||||||||||||||||||||||||||||||
| GitArtifactHelper<?> gitArtifactHelper = | ||||||||||||||||||||||||||||||||||||||||||
| gitArtifactHelperResolver.getArtifactHelper(artifactJsonTransformationDTO.getArtifactType()); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| return listBranches(artifactJsonTransformationDTO, Boolean.FALSE); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||
| public Mono<List<String>> listBranches( | ||||||||||||||||||||||||||||||||||||||||||
| ArtifactJsonTransformationDTO jsonTransformationDTO, Boolean listRemoteBranches) { | ||||||||||||||||||||||||||||||||||||||||||
| GitArtifactHelper<?> gitArtifactHelper = | ||||||||||||||||||||||||||||||||||||||||||
| gitArtifactHelperResolver.getArtifactHelper(jsonTransformationDTO.getArtifactType()); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| Path repoSuffix = gitArtifactHelper.getRepoSuffixPath( | ||||||||||||||||||||||||||||||||||||||||||
| artifactJsonTransformationDTO.getWorkspaceId(), | ||||||||||||||||||||||||||||||||||||||||||
| artifactJsonTransformationDTO.getBaseArtifactId(), | ||||||||||||||||||||||||||||||||||||||||||
| artifactJsonTransformationDTO.getRepoName()); | ||||||||||||||||||||||||||||||||||||||||||
| jsonTransformationDTO.getWorkspaceId(), | ||||||||||||||||||||||||||||||||||||||||||
| jsonTransformationDTO.getBaseArtifactId(), | ||||||||||||||||||||||||||||||||||||||||||
| jsonTransformationDTO.getRepoName()); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| return fsGitHandler | ||||||||||||||||||||||||||||||||||||||||||
| .listBranches(repoSuffix) | ||||||||||||||||||||||||||||||||||||||||||
| .flatMapMany(Flux::fromIterable) | ||||||||||||||||||||||||||||||||||||||||||
| .filter(gitBranchDTO -> { | ||||||||||||||||||||||||||||||||||||||||||
| return StringUtils.hasText(gitBranchDTO.getBranchName()) | ||||||||||||||||||||||||||||||||||||||||||
| && !gitBranchDTO.getBranchName().startsWith("origin"); | ||||||||||||||||||||||||||||||||||||||||||
| boolean branchToBeListed = !gitBranchDTO.getBranchName().startsWith("origin") | ||||||||||||||||||||||||||||||||||||||||||
| || Boolean.TRUE.equals(listRemoteBranches); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| return StringUtils.hasText(gitBranchDTO.getBranchName()) && branchToBeListed; | ||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
| .map(GitBranchDTO::getBranchName) | ||||||||||||||||||||||||||||||||||||||||||
| .collectList(); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||
| public Mono<List<String>> listReferences( | ||||||||||||||||||||||||||||||||||||||||||
| ArtifactJsonTransformationDTO artifactJsonTransformationDTO, | ||||||||||||||||||||||||||||||||||||||||||
| Boolean checkRemoteReferences, | ||||||||||||||||||||||||||||||||||||||||||
| RefType refType) { | ||||||||||||||||||||||||||||||||||||||||||
| if (RefType.BRANCH.equals(refType)) { | ||||||||||||||||||||||||||||||||||||||||||
| listBranches(artifactJsonTransformationDTO, checkRemoteReferences); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| // TODO: include ref type for tags in fsGit Handler | ||||||||||||||||||||||||||||||||||||||||||
| return Mono.just(List.of()); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+282
to
+304
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the branch listing implementation The method has two critical issues:
Apply this fix: @Override
public Mono<List<String>> listReferences(
ArtifactJsonTransformationDTO artifactJsonTransformationDTO, RefType refType) {
if (RefType.BRANCH.equals(refType)) {
- listBranches(artifactJsonTransformationDTO);
+ return listBranches(artifactJsonTransformationDTO);
}
// TODO: include ref type for tags in fsGit Handler
return Mono.just(List.of());
}📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||
| public Mono<Boolean> validateEmptyRepository(ArtifactJsonTransformationDTO artifactJsonTransformationDTO) { | ||||||||||||||||||||||||||||||||||||||||||
| GitArtifactHelper<?> gitArtifactHelper = | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -579,7 +605,8 @@ private Mono<String> pushArtifactErrorRecovery(String pushResult, Artifact artif | |||||||||||||||||||||||||||||||||||||||||
| * @return : returns string for remote fetch | ||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||
| public Mono<String> fetchRemoteChanges(ArtifactJsonTransformationDTO jsonTransformationDTO, GitAuth gitAuth) { | ||||||||||||||||||||||||||||||||||||||||||
| public Mono<String> fetchRemoteChanges( | ||||||||||||||||||||||||||||||||||||||||||
| ArtifactJsonTransformationDTO jsonTransformationDTO, GitAuth gitAuth, Boolean isFetchAll) { | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| String workspaceId = jsonTransformationDTO.getWorkspaceId(); | ||||||||||||||||||||||||||||||||||||||||||
| String baseArtifactId = jsonTransformationDTO.getBaseArtifactId(); | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -594,7 +621,7 @@ public Mono<String> fetchRemoteChanges(ArtifactJsonTransformationDTO jsonTransfo | |||||||||||||||||||||||||||||||||||||||||
| Mono<Boolean> checkoutBranchMono = fsGitHandler.checkoutToBranch(repoSuffix, refName); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| Mono<String> fetchRemoteMono = fsGitHandler.fetchRemote( | ||||||||||||||||||||||||||||||||||||||||||
| repoPath, gitAuth.getPublicKey(), gitAuth.getPrivateKey(), true, refName, false); | ||||||||||||||||||||||||||||||||||||||||||
| repoPath, gitAuth.getPublicKey(), gitAuth.getPrivateKey(), true, refName, isFetchAll); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| return checkoutBranchMono.then(Mono.defer(() -> fetchRemoteMono)); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -617,4 +644,32 @@ public Mono<? extends ArtifactExchangeJson> recreateArtifactJsonFromLastCommit( | |||||||||||||||||||||||||||||||||||||||||
| workspaceId, baseArtifactId, repoName, refName, artifactType); | ||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||
| public Mono<GitStatusDTO> getStatus(ArtifactJsonTransformationDTO jsonTransformationDTO) { | ||||||||||||||||||||||||||||||||||||||||||
| String workspaceId = jsonTransformationDTO.getWorkspaceId(); | ||||||||||||||||||||||||||||||||||||||||||
| String baseArtifactId = jsonTransformationDTO.getBaseArtifactId(); | ||||||||||||||||||||||||||||||||||||||||||
| String repoName = jsonTransformationDTO.getRepoName(); | ||||||||||||||||||||||||||||||||||||||||||
| String refName = jsonTransformationDTO.getRefName(); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ArtifactType artifactType = jsonTransformationDTO.getArtifactType(); | ||||||||||||||||||||||||||||||||||||||||||
| GitArtifactHelper<?> gitArtifactHelper = gitArtifactHelperResolver.getArtifactHelper(artifactType); | ||||||||||||||||||||||||||||||||||||||||||
| Path repoSuffix = gitArtifactHelper.getRepoSuffixPath(workspaceId, baseArtifactId, repoName); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| Path repoPath = fsGitHandler.createRepoPath(repoSuffix); | ||||||||||||||||||||||||||||||||||||||||||
| return fsGitHandler.getStatus(repoPath, refName); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+634
to
+661
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling for Git operations The method should handle potential Git exceptions that could occur during status retrieval. Apply this improvement: @Override
public Mono<GitStatusDTO> getStatus(ArtifactJsonTransformationDTO jsonTransformationDTO) {
String workspaceId = jsonTransformationDTO.getWorkspaceId();
String baseArtifactId = jsonTransformationDTO.getBaseArtifactId();
String repoName = jsonTransformationDTO.getRepoName();
String refName = jsonTransformationDTO.getRefName();
ArtifactType artifactType = jsonTransformationDTO.getArtifactType();
GitArtifactHelper<?> gitArtifactHelper = gitArtifactHelperResolver.getArtifactHelper(artifactType);
Path repoSuffix = gitArtifactHelper.getRepoSuffixPath(workspaceId, baseArtifactId, repoName);
Path repoPath = fsGitHandler.createRepoPath(repoSuffix);
- return fsGitHandler.getStatus(repoPath, refName);
+ return fsGitHandler.getStatus(repoPath, refName)
+ .onErrorResume(error -> {
+ log.error("Error getting Git status: {}", error.getMessage());
+ return Mono.error(new AppsmithException(
+ AppsmithError.GIT_ACTION_FAILED,
+ "status",
+ error.getMessage()));
+ });
}
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||
| public Mono<String> prepareForNewRefCreation(ArtifactJsonTransformationDTO jsonTransformationDTO) { | ||||||||||||||||||||||||||||||||||||||||||
| GitArtifactHelper<?> gitArtifactHelper = | ||||||||||||||||||||||||||||||||||||||||||
| gitArtifactHelperResolver.getArtifactHelper(jsonTransformationDTO.getArtifactType()); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| Path repoSuffix = gitArtifactHelper.getRepoSuffixPath( | ||||||||||||||||||||||||||||||||||||||||||
| jsonTransformationDTO.getWorkspaceId(), | ||||||||||||||||||||||||||||||||||||||||||
| jsonTransformationDTO.getBaseArtifactId(), | ||||||||||||||||||||||||||||||||||||||||||
| jsonTransformationDTO.getRepoName()); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| return fsGitHandler.createAndCheckoutToBranch(repoSuffix, jsonTransformationDTO.getRefName()); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add field validation and documentation.
The fields would benefit from: