Skip to content

Commit

Permalink
chore: added interface changes to the server (#38258)
Browse files Browse the repository at this point in the history
## Description
- interface layer changes for Git executor


Fixes #
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## 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/12481281011>
> Commit: e510ca6
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12481281011&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Git`
> Spec:
> <hr>Tue, 24 Dec 2024 16:05:39 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

## Summary by CodeRabbit

- **New Features**
- Introduced methods for creating and checking out branches and tags in
Git.
- Added functionality for validating reference creation based on
artifact status.
- Enhanced artifact publishing with new methods related to reference
creation.
  - Added a method for checking out artifacts based on provided details.

- **Bug Fixes**
- Improved error handling for Git operations, providing more specific
error messages.

- **Documentation**
- Updated method signatures to reflect new parameters and
functionalities.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
sondermanish authored Dec 24, 2024
1 parent c0d393a commit a8cb8aa
Show file tree
Hide file tree
Showing 8 changed files with 335 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import com.appsmith.external.constants.ErrorReferenceDocUrl;
import com.appsmith.external.dtos.GitBranchDTO;
import com.appsmith.external.dtos.GitLogDTO;
import com.appsmith.external.dtos.GitRefDTO;
import com.appsmith.external.dtos.GitStatusDTO;
import com.appsmith.external.dtos.MergeStatusDTO;
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.external.helpers.Stopwatch;
import com.appsmith.git.configurations.GitServiceConfig;
Expand Down Expand Up @@ -344,6 +346,52 @@ public Mono<String> createAndCheckoutToBranch(Path repoSuffix, String branchName
.subscribeOn(scheduler);
}

private String createAndCheckoutBranch(Git git, GitRefDTO gitRefDTO) throws GitAPIException, IOException {
String branchName = gitRefDTO.getRefName();
git.checkout()
.setCreateBranch(TRUE)
.setName(branchName)
.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK)
.call();

repositoryHelper.updateRemoteBranchTrackingConfig(branchName, git);
return git.getRepository().getBranch();
}

private String createTag(Git git, GitRefDTO gitRefDTO) throws GitAPIException {
String tagName = gitRefDTO.getRefName();
String message = gitRefDTO.getMessage();
return git.tag().setName(tagName).setMessage(message).call().getName();
}

@Override
public Mono<String> createAndCheckoutReference(Path repoSuffix, GitRefDTO gitRefDTO) {
RefType refType = gitRefDTO.getRefType();
String refName = gitRefDTO.getRefName();

return Mono.using(
() -> Git.open(createRepoPath(repoSuffix).toFile()),
git -> Mono.fromCallable(() -> {
log.info(
"{} : Creating reference of type {} and name {} for the repo {}",
Thread.currentThread().getName(),
refType.name(),
refName,
repoSuffix);

if (RefType.TAG.equals(refType)) {
return createTag(git, gitRefDTO);
}

return createAndCheckoutBranch(git, gitRefDTO);
})
.timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS))
.name(GitSpan.FS_CREATE_BRANCH)
.tap(Micrometer.observation(observationRegistry)),
Git::close)
.subscribeOn(scheduler);
}

@Override
public Mono<Boolean> deleteBranch(Path repoSuffix, String branchName) {
// We can safely assume that repo has been already initialised either in commit or clone flow and can directly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public class GitRefDTO {

RefType refType;

/**
* for tags, while tagging we require messages.
*/
String message;

boolean isDefault;

boolean createdFromLocal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.appsmith.external.dtos.GitBranchDTO;
import com.appsmith.external.dtos.GitLogDTO;
import com.appsmith.external.dtos.GitRefDTO;
import com.appsmith.external.dtos.GitStatusDTO;
import com.appsmith.external.dtos.MergeStatusDTO;
import org.eclipse.jgit.api.errors.GitAPIException;
Expand Down Expand Up @@ -80,6 +81,8 @@ Mono<String> pushApplication(
*/
Mono<String> createAndCheckoutToBranch(Path repoSuffix, String branchName);

Mono<String> createAndCheckoutReference(Path repoSuffix, GitRefDTO gitRefDTO);

/**
* Delete a branch in the local repo
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.appsmith.server.applications.git;

import com.appsmith.external.git.constants.ce.RefType;
import com.appsmith.server.acl.AclPermission;
import com.appsmith.server.actioncollections.base.ActionCollectionService;
import com.appsmith.server.applications.base.ApplicationService;
Expand Down Expand Up @@ -327,4 +328,16 @@ public Mono<Application> publishArtifactPostCommit(Artifact committedArtifact) {
public Mono<? extends Artifact> validateAndPublishArtifact(Artifact artifact, boolean publish) {
return publishArtifact(artifact, publish);
}

@Override
public Mono<Application> publishArtifactPostRefCreation(
Artifact artifact, RefType refType, Boolean isPublishedManually) {
// TODO: create publish for ref type creation.
Application application = (Application) artifact;
if (RefType.TAG.equals(refType)) {
return Mono.just(application);
}

return Mono.just(application);
}
}
Loading

0 comments on commit a8cb8aa

Please sign in to comment.