Skip to content

Commit

Permalink
feat: added commit changes (#37922)
Browse files Browse the repository at this point in the history
## Description

Fixes #37437 

## Automation

/ok-to-test tags="@tag.Git"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/12152404326>
> Commit: 6dc1f5a
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12152404326&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Git`
> Spec:
> <hr>Wed, 04 Dec 2024 04:58:02 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Release Notes

- **New Features**
- Introduced methods for acquiring and releasing Git locks, enhancing
the locking mechanism.
- Added `commitArtifact` method for committing artifacts in Git
operations.
- New method `publishArtifactPostCommit` for publishing artifacts after
a commit.
  
- **Improvements**
- Enhanced error handling and parameter naming consistency across
various Git-related services.
  
- **Refactor**
- Updated method signatures and added detailed documentation for clarity
and maintainability.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
sondermanish authored Dec 4, 2024
1 parent a2c5caa commit 1078a03
Show file tree
Hide file tree
Showing 10 changed files with 686 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,9 @@ public Application getNewArtifact(String workspaceId, String repoName) {
newApplication.setGitApplicationMetadata(new GitArtifactMetadata());
return newApplication;
}

@Override
public Mono<Application> publishArtifactPostCommit(Artifact committedArtifact) {
return publishArtifact(committedArtifact, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,20 @@ public class GitRedisUtils {
private final RedisUtils redisUtils;
private final ObservationRegistry observationRegistry;

public Mono<Boolean> addFileLock(String defaultApplicationId, String commandName, Boolean isRetryAllowed) {
/**
* Adds a baseArtifact id as a key in redis, the presence of this key represents a symbolic lock, essentially meaning that no new operations
* should be performed till this key remains present.
* @param baseArtifactId : base id of the artifact for which the key is getting added.
* @param commandName : Name of the operation which is trying to acquire the lock, this value will be added against the key
* @param isRetryAllowed : Boolean for whether retries for adding the value is allowed
* @return a boolean publisher for the added file locks
*/
public Mono<Boolean> addFileLock(String baseArtifactId, String commandName, Boolean isRetryAllowed) {
long numberOfRetries = Boolean.TRUE.equals(isRetryAllowed) ? MAX_RETRIES : 0L;

log.info(
"Git command {} is trying to acquire the lock for application id {}",
commandName,
defaultApplicationId);
log.info("Git command {} is trying to acquire the lock for application id {}", commandName, baseArtifactId);
return redisUtils
.addFileLock(defaultApplicationId, commandName)
.addFileLock(baseArtifactId, commandName)
.retryWhen(Retry.fixedDelay(numberOfRetries, RETRY_DELAY)
.onRetryExhaustedThrow((retryBackoffSpec, retrySignal) -> {
if (retrySignal.failure() instanceof AppsmithException) {
Expand All @@ -54,4 +59,38 @@ public Mono<Boolean> releaseFileLock(String defaultApplicationId) {
.name(GitSpan.RELEASE_FILE_LOCK)
.tap(Micrometer.observation(observationRegistry));
}

/**
* This is a wrapper method for acquiring git lock, since multiple ops are used in sequence
* for a complete composite operation not all ops require to acquire the lock hence a dummy flag is sent back for
* operations in that is getting executed in between
* @param baseArtifactId : id of the base artifact for which ops would be locked
* @param isLockRequired : is lock really required or is it a proxy function
* @return : Boolean for whether the lock is acquired
*/
// TODO @Manish add artifactType reference in incoming prs.
public Mono<Boolean> acquireGitLock(String baseArtifactId, String commandName, boolean isLockRequired) {
if (!Boolean.TRUE.equals(isLockRequired)) {
return Mono.just(Boolean.TRUE);
}

return addFileLock(baseArtifactId, commandName);
}

/**
* This is a wrapper method for releasing git lock, since multiple ops are used in sequence
* for a complete composite operation not all ops require to acquire the lock hence a dummy flag is sent back for
* operations in that is getting executed in between
* @param baseArtifactId : id of the base artifact for which ops would be locked
* @param isLockRequired : is lock really required or is it a proxy function
* @return : Boolean for whether the lock is released
*/
// TODO @Manish add artifactType reference in incoming prs
public Mono<Boolean> releaseFileLock(String baseArtifactId, boolean isLockRequired) {
if (!Boolean.TRUE.equals(isLockRequired)) {
return Mono.just(Boolean.TRUE);
}

return releaseFileLock(baseArtifactId);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.appsmith.server.git.central;

import com.appsmith.git.dto.CommitDTO;
import com.appsmith.server.constants.ArtifactType;
import com.appsmith.server.domains.Artifact;
import com.appsmith.server.dtos.ArtifactImportDTO;
Expand All @@ -17,4 +18,7 @@ Mono<? extends Artifact> connectArtifactToGit(
String originHeader,
ArtifactType artifactType,
GitType gitType);

Mono<String> commitArtifact(
CommitDTO commitDTO, String branchedArtifactId, ArtifactType artifactType, GitType gitType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.appsmith.server.datasources.base.DatasourceService;
import com.appsmith.server.exports.internal.ExportService;
import com.appsmith.server.git.GitRedisUtils;
import com.appsmith.server.git.resolver.GitArtifactHelperResolver;
import com.appsmith.server.git.resolver.GitHandlingServiceResolver;
import com.appsmith.server.git.utils.GitAnalyticsUtils;
Expand All @@ -12,6 +13,7 @@
import com.appsmith.server.services.UserDataService;
import com.appsmith.server.services.WorkspaceService;
import com.appsmith.server.solutions.DatasourcePermission;
import io.micrometer.observation.ObservationRegistry;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

Expand All @@ -32,7 +34,9 @@ public CentralGitServiceCECompatibleImpl(
WorkspaceService workspaceService,
PluginService pluginService,
ImportService importService,
ExportService exportService) {
ExportService exportService,
GitRedisUtils gitRedisUtils,
ObservationRegistry observationRegistry) {
super(
gitProfileUtils,
gitAnalyticsUtils,
Expand All @@ -45,6 +49,8 @@ public CentralGitServiceCECompatibleImpl(
workspaceService,
pluginService,
importService,
exportService);
exportService,
gitRedisUtils,
observationRegistry);
}
}
Loading

0 comments on commit 1078a03

Please sign in to comment.