-
Notifications
You must be signed in to change notification settings - Fork 4.5k
chore: git detach and push algorithm refinement #39298
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -5,7 +5,6 @@ | |
| import com.appsmith.external.dtos.GitRefDTO; | ||
| import com.appsmith.external.dtos.GitStatusDTO; | ||
| import com.appsmith.external.dtos.MergeStatusDTO; | ||
| import com.appsmith.external.git.constants.GitConstants; | ||
| import com.appsmith.external.git.constants.GitConstants.GitCommandConstants; | ||
| import com.appsmith.external.git.constants.GitSpan; | ||
| import com.appsmith.external.git.constants.ce.RefType; | ||
|
|
@@ -482,18 +481,17 @@ public Mono<Tuple2<? extends Artifact, String>> commitArtifact( | |
| result.append(".\nPush Result : "); | ||
| return Mono.zip( | ||
| Mono.just(tuple.getT2()), | ||
| pushArtifact(tuple.getT2(), false) | ||
| pushArtifact(tuple.getT2()) | ||
| .map(pushResult -> result.append(pushResult).toString())); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Push flow for dehydrated apps | ||
| * | ||
| * @param branchedArtifact application which needs to be pushed to remote repo | ||
| * @param branchedArtifact artifact which needs to be pushed to remote repo | ||
| * @return Success message | ||
| */ | ||
| protected Mono<String> pushArtifact(Artifact branchedArtifact, boolean isFileLock) { | ||
| protected Mono<String> pushArtifact(Artifact branchedArtifact) { | ||
| ArtifactType artifactType = branchedArtifact.getArtifactType(); | ||
| GitArtifactHelper<?> gitArtifactHelper = gitArtifactHelperResolver.getArtifactHelper(artifactType); | ||
| Mono<GitArtifactMetadata> gitArtifactMetadataMono = Mono.just(branchedArtifact.getGitArtifactMetadata()); | ||
|
|
@@ -515,16 +513,7 @@ protected Mono<String> pushArtifact(Artifact branchedArtifact, boolean isFileLoc | |
| // Make sure that ssh Key is unEncrypted for the use. | ||
| Mono<String> gitPushResult = gitArtifactMetadataMono | ||
| .flatMap(gitMetadata -> { | ||
| return gitRedisUtils | ||
| .acquireGitLock( | ||
|
Collaborator
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. Can you please state the reason of removing Git lock placement logic here?
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. Because this is always getting called from inside the commit section
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. which means that the redis lock would never be required |
||
| artifactType, | ||
| gitMetadata.getDefaultArtifactId(), | ||
| GitConstants.GitCommandConstants.PUSH, | ||
| isFileLock) | ||
| .thenReturn(branchedArtifact); | ||
| }) | ||
| .flatMap(artifact -> { | ||
| GitArtifactMetadata gitData = artifact.getGitArtifactMetadata(); | ||
| GitArtifactMetadata gitData = branchedArtifact.getGitArtifactMetadata(); | ||
|
|
||
| if (gitData == null | ||
| || !StringUtils.hasText(gitData.getRefName()) | ||
|
|
@@ -536,61 +525,55 @@ protected Mono<String> pushArtifact(Artifact branchedArtifact, boolean isFileLoc | |
| } | ||
|
|
||
| Path baseRepoSuffix = gitArtifactHelper.getRepoSuffixPath( | ||
| artifact.getWorkspaceId(), gitData.getDefaultArtifactId(), gitData.getRepoName()); | ||
| branchedArtifact.getWorkspaceId(), gitData.getDefaultArtifactId(), gitData.getRepoName()); | ||
| GitAuth gitAuth = gitData.getGitAuth(); | ||
|
|
||
| return fsGitHandler | ||
| .checkoutToBranch( | ||
| .pushApplication( | ||
|
Collaborator
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: Naming. You wanted to mean
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. This is an already existing method, can I take this in another refactor session? |
||
| baseRepoSuffix, | ||
| artifact.getGitArtifactMetadata().getRefName()) | ||
| .then(Mono.defer(() -> fsGitHandler | ||
| .pushApplication( | ||
| baseRepoSuffix, | ||
| gitData.getRemoteUrl(), | ||
| gitAuth.getPublicKey(), | ||
| gitAuth.getPrivateKey(), | ||
| gitData.getRefName()) | ||
| .zipWith(Mono.just(artifact)))) | ||
| gitData.getRemoteUrl(), | ||
| gitAuth.getPublicKey(), | ||
| gitAuth.getPrivateKey(), | ||
| gitData.getRefName()) | ||
| .onErrorResume(error -> gitAnalyticsUtils | ||
| .addAnalyticsForGitOperation( | ||
| AnalyticsEvents.GIT_PUSH, | ||
| artifact, | ||
| branchedArtifact, | ||
| error.getClass().getName(), | ||
| error.getMessage(), | ||
| artifact.getGitArtifactMetadata().getIsRepoPrivate()) | ||
| .flatMap(application1 -> { | ||
| gitData.getIsRepoPrivate()) | ||
| .flatMap(artifact -> { | ||
| log.error("Error during git push: {}", error.getMessage()); | ||
| if (error instanceof TransportException) { | ||
| return Mono.error( | ||
| new AppsmithException(AppsmithError.INVALID_GIT_SSH_CONFIGURATION)); | ||
| } | ||
|
|
||
| return Mono.error(new AppsmithException( | ||
| AppsmithError.GIT_ACTION_FAILED, "push", error.getMessage())); | ||
| AppsmithError.GIT_ACTION_FAILED, | ||
| GitCommandConstants.PUSH, | ||
| error.getMessage())); | ||
| })); | ||
| }) | ||
| .flatMap(tuple -> { | ||
| String pushResult = tuple.getT1(); | ||
| Artifact artifact = tuple.getT2(); | ||
| return pushArtifactErrorRecovery(pushResult, artifact).zipWith(Mono.just(artifact)); | ||
| }) | ||
| // Add BE analytics | ||
| .flatMap(tuple2 -> { | ||
| String pushStatus = tuple2.getT1(); | ||
| Artifact artifact = tuple2.getT2(); | ||
| Mono<Boolean> fileLockReleasedMono = Mono.just(TRUE).flatMap(flag -> { | ||
| if (!TRUE.equals(isFileLock)) { | ||
| return Mono.just(flag); | ||
| } | ||
| return Mono.defer(() -> gitRedisUtils.releaseFileLock( | ||
| artifactType, artifact.getGitArtifactMetadata().getDefaultArtifactId(), true)); | ||
| }); | ||
|
|
||
| return pushArtifactErrorRecovery(pushStatus, artifact) | ||
| .then(fileLockReleasedMono) | ||
| .then(gitAnalyticsUtils.addAnalyticsForGitOperation( | ||
| AnalyticsEvents.GIT_PUSH, | ||
| artifact, | ||
| artifact.getGitArtifactMetadata().getIsRepoPrivate())) | ||
| .thenReturn(pushStatus); | ||
| .flatMap(pushResult -> { | ||
| log.info( | ||
| "Push result for artifact {} with id {} : {}", | ||
| branchedArtifact.getName(), | ||
| branchedArtifact.getId(), | ||
| pushResult); | ||
|
|
||
| return pushArtifactErrorRecovery(pushResult, branchedArtifact) | ||
| .flatMap(pushStatus -> { | ||
| // Add analytics | ||
| return gitAnalyticsUtils | ||
| .addAnalyticsForGitOperation( | ||
| AnalyticsEvents.GIT_PUSH, | ||
| branchedArtifact, | ||
| branchedArtifact | ||
| .getGitArtifactMetadata() | ||
| .getIsRepoPrivate()) | ||
| .thenReturn(pushStatus); | ||
| }); | ||
| }) | ||
| .name(GitSpan.OPS_PUSH) | ||
| .tap(Micrometer.observation(observationRegistry)); | ||
|
|
@@ -622,7 +605,8 @@ private Mono<String> pushArtifactErrorRecovery(String pushResult, Artifact artif | |
| AppsmithError.GIT_UPSTREAM_CHANGES.getErrorType(), | ||
| AppsmithError.GIT_UPSTREAM_CHANGES.getMessage(), | ||
| gitMetadata.getIsRepoPrivate()) | ||
| .flatMap(application1 -> Mono.error(new AppsmithException(AppsmithError.GIT_UPSTREAM_CHANGES))); | ||
| .then(Mono.error(new AppsmithException(AppsmithError.GIT_UPSTREAM_CHANGES))); | ||
|
|
||
| } else if (pushResult.contains("REJECTED_OTHERREASON") || pushResult.contains("pre-receive hook declined")) { | ||
|
|
||
| Path path = gitArtifactHelper.getRepoSuffixPath( | ||
|
|
@@ -632,7 +616,7 @@ private Mono<String> pushArtifactErrorRecovery(String pushResult, Artifact artif | |
| .resetHard(path, gitMetadata.getRefName()) | ||
| .then(Mono.error(new AppsmithException( | ||
| AppsmithError.GIT_ACTION_FAILED, | ||
| "push", | ||
| GitCommandConstants.PUSH, | ||
| "Unable to push changes as pre-receive hook declined. Please make sure that you don't have any rules enabled on the branch " | ||
| + gitMetadata.getRefName()))); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
It seems llike this logic should precede the above logic from L#1649-L#1659
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.
true!