Skip to content
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

chore: added interface changes to the server #38258

Merged
merged 6 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading