Skip to content

Commit

Permalink
added reviewed changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sondermanish committed Dec 17, 2024
1 parent 89764d4 commit ccb37fc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,17 @@ public void setDefaultApplicationId(String defaultApplicationId) {
this.defaultArtifactId = defaultApplicationId;
}

/**
* this returns the branchName instead of reference name
* @return returns the ref name.
*/
public String getRefName() {
return this.getBranchName();
}

public void setRefName(String refName) {
this.branchName = refName;
}

public static class Fields {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ Mono<? extends Artifact> checkoutReference(
Mono<? extends Artifact> createReference(
String referencedArtifactId, GitRefDTO refDTO, ArtifactType artifactType, GitType gitType);

Mono<? extends Artifact> deleteReference(
String baseArtifactId, String refName, ArtifactType artifactType, GitType gitType, RefType refType);
Mono<? extends Artifact> deleteGitReference(
String baseArtifactId, GitRefDTO gitRefDTO, ArtifactType artifactType, GitType gitType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -573,15 +573,18 @@ public Mono<? extends Artifact> createReference(
}

@Override
public Mono<? extends Artifact> deleteReference(
String baseArtifactId, String refName, ArtifactType artifactType, GitType gitType, RefType refType) {
public Mono<? extends Artifact> deleteGitReference(
String baseArtifactId, GitRefDTO gitRefDTO, ArtifactType artifactType, GitType gitType) {

String refName = gitRefDTO.getRefName();
RefType refType = gitRefDTO.getRefType();

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));
return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, REF_NAME));
}

if (!hasText(baseArtifactId)) {
Expand All @@ -600,11 +603,11 @@ public Mono<? extends Artifact> deleteReference(
return Mono.zip(baseArtifactMono, branchedArtifactMono).flatMap(tuple2 -> {
Artifact baseArtifact = tuple2.getT1();
Artifact referenceArtifact = tuple2.getT2();
return deleteReference(baseArtifact, referenceArtifact, gitType, refType);
return deleteGitReference(baseArtifact, referenceArtifact, gitType, refType);
});
}

protected Mono<? extends Artifact> deleteReference(
protected Mono<? extends Artifact> deleteGitReference(
Artifact baseArtifact, Artifact referenceArtifact, GitType gitType, RefType refType) {

GitArtifactMetadata baseGitMetadata = baseArtifact.getGitArtifactMetadata();
Expand All @@ -615,7 +618,7 @@ protected Mono<? extends Artifact> deleteReference(
gitArtifactHelperResolver.getArtifactHelper(baseArtifact.getArtifactType());

// TODO: write a migration to shift everything to refName in gitMetadata
final String finalRefName = referenceArtifactMetadata.getBranchName();
final String finalRefName = referenceArtifactMetadata.getRefName();
final String baseArtifactId = referenceArtifact.getGitArtifactMetadata().getDefaultArtifactId();

if (finalRefName.equals(baseGitMetadata.getDefaultBranchName())) {
Expand Down Expand Up @@ -662,6 +665,10 @@ protected Mono<? extends Artifact> deleteReference(
return gitArtifactHelper
.deleteArtifactByResource(referenceArtifact)
.onErrorResume(throwable -> {
log.error(
"An error occurred while deleting db artifact and resources for reference {}",
throwable.getMessage());

return gitAnalyticsUtils
.addAnalyticsForGitOperation(
AnalyticsEvents.GIT_DELETE_BRANCH,
Expand Down

0 comments on commit ccb37fc

Please sign in to comment.