-
Notifications
You must be signed in to change notification settings - Fork 4.7k
chore: pr for delete references #38210
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 1 commit
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 | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -538,7 +538,7 @@ public Mono<? extends Artifact> createReference( | |||||||||||||||||||
| Artifact newRefArtifact = tuple.getT1(); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Mono<String> refCreationMono = gitHandlingService | ||||||||||||||||||||
| .prepareForNewRefCreation(jsonTransformationDTO) | ||||||||||||||||||||
| .createGitReference(jsonTransformationDTO) | ||||||||||||||||||||
| // TODO: ths error could be shipped to handling layer as well? | ||||||||||||||||||||
| .onErrorResume(error -> Mono.error(new AppsmithException( | ||||||||||||||||||||
| AppsmithError.GIT_ACTION_FAILED, | ||||||||||||||||||||
|
|
@@ -572,6 +572,120 @@ public Mono<? extends Artifact> createReference( | |||||||||||||||||||
| return Mono.create(sink -> createBranchMono.subscribe(sink::success, sink::error, null, sink.currentContext())); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @Override | ||||||||||||||||||||
| public Mono<? extends Artifact> deleteReference( | ||||||||||||||||||||
| String baseArtifactId, String refName, ArtifactType artifactType, GitType gitType, RefType refType) { | ||||||||||||||||||||
|
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, can we use dto 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. same gitRefDTO? |
||||||||||||||||||||
|
|
||||||||||||||||||||
| if (refType == null) { | ||||||||||||||||||||
| return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, REF_TYPE)); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (!hasText(refName)) { | ||||||||||||||||||||
| return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, BRANCH_NAME)); | ||||||||||||||||||||
|
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, ref name |
||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (!hasText(baseArtifactId)) { | ||||||||||||||||||||
| return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.ID)); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| GitArtifactHelper<?> gitArtifactHelper = gitArtifactHelperResolver.getArtifactHelper(artifactType); | ||||||||||||||||||||
| AclPermission artifactEditPermission = gitArtifactHelper.getArtifactEditPermission(); | ||||||||||||||||||||
|
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. We ended up creating a lot of permission methods in the helper. Should we instead create a single getArtifactPermision method and access its methods directly for all our use cases?
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. do you mean a separate service? |
||||||||||||||||||||
|
|
||||||||||||||||||||
| Mono<? extends Artifact> baseArtifactMono = | ||||||||||||||||||||
| gitArtifactHelper.getArtifactById(baseArtifactId, artifactEditPermission); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Mono<? extends Artifact> branchedArtifactMono = | ||||||||||||||||||||
| gitArtifactHelper.getArtifactByBaseIdAndBranchName(baseArtifactId, refName, artifactEditPermission); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return Mono.zip(baseArtifactMono, branchedArtifactMono).flatMap(tuple2 -> { | ||||||||||||||||||||
| Artifact baseArtifact = tuple2.getT1(); | ||||||||||||||||||||
| Artifact referenceArtifact = tuple2.getT2(); | ||||||||||||||||||||
| return deleteReference(baseArtifact, referenceArtifact, gitType, refType); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| protected Mono<? extends Artifact> deleteReference( | ||||||||||||||||||||
| Artifact baseArtifact, Artifact referenceArtifact, GitType gitType, RefType refType) { | ||||||||||||||||||||
|
|
||||||||||||||||||||
| GitArtifactMetadata baseGitMetadata = baseArtifact.getGitArtifactMetadata(); | ||||||||||||||||||||
| GitArtifactMetadata referenceArtifactMetadata = referenceArtifact.getGitArtifactMetadata(); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| GitHandlingService gitHandlingService = gitHandlingServiceResolver.getGitHandlingService(gitType); | ||||||||||||||||||||
| GitArtifactHelper<?> gitArtifactHelper = | ||||||||||||||||||||
| gitArtifactHelperResolver.getArtifactHelper(baseArtifact.getArtifactType()); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // TODO: write a migration to shift everything to refName in gitMetadata | ||||||||||||||||||||
| final String finalRefName = referenceArtifactMetadata.getBranchName(); | ||||||||||||||||||||
|
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. Can you in the mean time create an internal annotated getRefName method that returns branch name when ref name is null? |
||||||||||||||||||||
| final String baseArtifactId = referenceArtifact.getGitArtifactMetadata().getDefaultArtifactId(); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (finalRefName.equals(baseGitMetadata.getDefaultBranchName())) { | ||||||||||||||||||||
| return Mono.error(new AppsmithException( | ||||||||||||||||||||
| AppsmithError.GIT_ACTION_FAILED, "delete ref", " Cannot delete default branch")); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Mono<? extends Artifact> deleteReferenceMono = gitPrivateRepoHelper | ||||||||||||||||||||
| .isBranchProtected(baseGitMetadata, finalRefName) | ||||||||||||||||||||
| .flatMap(isBranchProtected -> { | ||||||||||||||||||||
| if (!TRUE.equals(isBranchProtected)) { | ||||||||||||||||||||
|
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. Is this meant to be an instance of where we can flip the conditional like you've been suggesting?
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. same stuff, even if we flip we are returning the error. |
||||||||||||||||||||
| return gitRedisUtils.acquireGitLock( | ||||||||||||||||||||
| baseArtifactId, GitConstants.GitCommandConstants.DELETE, TRUE); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return Mono.error(new AppsmithException( | ||||||||||||||||||||
| AppsmithError.GIT_ACTION_FAILED, | ||||||||||||||||||||
| "delete", | ||||||||||||||||||||
| "Cannot delete protected branch " + finalRefName)); | ||||||||||||||||||||
| }) | ||||||||||||||||||||
| .flatMap(ignoreLockAcquisition -> { | ||||||||||||||||||||
| ArtifactJsonTransformationDTO jsonTransformationDTO = new ArtifactJsonTransformationDTO(); | ||||||||||||||||||||
| jsonTransformationDTO.setWorkspaceId(baseArtifact.getWorkspaceId()); | ||||||||||||||||||||
| jsonTransformationDTO.setArtifactType(baseArtifact.getArtifactType()); | ||||||||||||||||||||
| jsonTransformationDTO.setRefType(refType); | ||||||||||||||||||||
| jsonTransformationDTO.setRefName(finalRefName); | ||||||||||||||||||||
| jsonTransformationDTO.setBaseArtifactId(baseArtifactId); | ||||||||||||||||||||
| jsonTransformationDTO.setRepoName(referenceArtifactMetadata.getRepoName()); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return gitHandlingService | ||||||||||||||||||||
| .deleteGitReference(jsonTransformationDTO) | ||||||||||||||||||||
| .doFinally(signalType -> gitRedisUtils.releaseFileLock(baseArtifactId, TRUE)) | ||||||||||||||||||||
| .flatMap(isReferenceDeleted -> { | ||||||||||||||||||||
| if (FALSE.equals(isReferenceDeleted)) { | ||||||||||||||||||||
| return Mono.error(new AppsmithException( | ||||||||||||||||||||
| AppsmithError.GIT_ACTION_FAILED, | ||||||||||||||||||||
| " delete branch. Branch does not exists in the repo")); | ||||||||||||||||||||
|
Comment on lines
+655
to
+658
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 Correct the error message formatting Fix the grammatical error and improve consistency in the error message. Apply this diff: -return Mono.error(new AppsmithException(
- AppsmithError.GIT_ACTION_FAILED,
- " delete branch. Branch does not exists in the repo"));
+return Mono.error(new AppsmithException(
+ AppsmithError.GIT_ACTION_FAILED,
+ "delete",
+ "Branch does not exist in the repository"));📝 Committable suggestion
Suggested change
|
||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (referenceArtifact.getId().equals(baseArtifactId)) { | ||||||||||||||||||||
|
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. Why don't we delete in this case, do you know?
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. we don't delete baseArtifact, where would we keep the gitMetadata then?
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. That's a bug then .. It's a stray object that we can never get rid of. Let's add a TODO to clean this up when we pull metadata out of artifact |
||||||||||||||||||||
| return Mono.just(referenceArtifact); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return gitArtifactHelper | ||||||||||||||||||||
| .deleteArtifactByResource(referenceArtifact) | ||||||||||||||||||||
| .onErrorResume(throwable -> { | ||||||||||||||||||||
| return gitAnalyticsUtils | ||||||||||||||||||||
|
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. Should log error before transofrming |
||||||||||||||||||||
| .addAnalyticsForGitOperation( | ||||||||||||||||||||
| AnalyticsEvents.GIT_DELETE_BRANCH, | ||||||||||||||||||||
| referenceArtifact, | ||||||||||||||||||||
| throwable.getClass().getName(), | ||||||||||||||||||||
| throwable.getMessage(), | ||||||||||||||||||||
| baseGitMetadata.getIsRepoPrivate()) | ||||||||||||||||||||
| .then(Mono.error(new AppsmithException( | ||||||||||||||||||||
| AppsmithError.GIT_ACTION_FAILED, | ||||||||||||||||||||
| "Cannot delete branch from database"))); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
| }) | ||||||||||||||||||||
| .flatMap(deletedArtifact -> gitAnalyticsUtils.addAnalyticsForGitOperation( | ||||||||||||||||||||
| AnalyticsEvents.GIT_DELETE_BRANCH, | ||||||||||||||||||||
| deletedArtifact, | ||||||||||||||||||||
| deletedArtifact.getGitArtifactMetadata().getIsRepoPrivate())) | ||||||||||||||||||||
| .name(GitSpan.OPS_DELETE_BRANCH) | ||||||||||||||||||||
| .tap(Micrometer.observation(observationRegistry)); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return Mono.create( | ||||||||||||||||||||
| sink -> deleteReferenceMono.subscribe(sink::success, sink::error, null, sink.currentContext())); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /** | ||||||||||||||||||||
| * Connect the artifact from Appsmith to a git repo | ||||||||||||||||||||
| * This is the prerequisite step needed to perform all the git operation for an artifact | ||||||||||||||||||||
|
|
||||||||||||||||||||
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.
Nit, deleteGitReference in method name