refactor(patch): simplify patch repository management and enhance git configuration handling

- Removed redundant helper functions for retrieving git configurations for applications and composes, streamlining the codebase.
- Updated the `ensurePatchRepo` function to directly handle repository cloning based on the application or compose type, improving clarity and maintainability.
- Refactored patch creation logic to eliminate unnecessary checks and streamline the process of creating patches.
- Enhanced the handling of output paths in repository cloning functions across different git providers, ensuring consistent behavior.
This commit is contained in:
Mauricio Siu
2026-02-17 01:11:23 -06:00
parent 20320639ce
commit 9818e3c3ba
8 changed files with 71 additions and 381 deletions

View File

@@ -86,6 +86,7 @@ interface CloneBitbucketRepository {
enableSubmodules: boolean;
serverId: string | null;
type?: "application" | "compose";
outputPathOverride?: string;
}
export const cloneBitbucketRepository = async ({
@@ -101,6 +102,7 @@ export const cloneBitbucketRepository = async ({
bitbucketId,
enableSubmodules,
serverId,
outputPathOverride,
} = entity;
const { COMPOSE_PATH, APPLICATIONS_PATH } = paths(!!serverId);
@@ -115,7 +117,7 @@ export const cloneBitbucketRepository = async ({
return command;
}
const basePath = type === "compose" ? COMPOSE_PATH : APPLICATIONS_PATH;
const outputPath = join(basePath, appName, "code");
const outputPath = outputPathOverride ?? join(basePath, appName, "code");
command += `rm -rf ${outputPath};`;
command += `mkdir -p ${outputPath};`;
const repoToUse = entity.bitbucketRepositorySlug || bitbucketRepository;

View File

@@ -14,6 +14,7 @@ interface CloneGitRepository {
enableSubmodules?: boolean;
serverId: string | null;
type?: "application" | "compose";
outputPathOverride?: string;
}
export const cloneGitRepository = async ({
@@ -28,6 +29,7 @@ export const cloneGitRepository = async ({
customGitSSHKeyId,
enableSubmodules,
serverId,
outputPathOverride,
} = entity;
const { SSH_PATH, COMPOSE_PATH, APPLICATIONS_PATH } = paths(!!serverId);
@@ -47,7 +49,7 @@ export const cloneGitRepository = async ({
`;
}
const basePath = type === "compose" ? COMPOSE_PATH : APPLICATIONS_PATH;
const outputPath = join(basePath, appName, "code");
const outputPath = outputPathOverride ?? join(basePath, appName, "code");
const knownHostsPath = path.join(SSH_PATH, "known_hosts");
if (!isHttpOrHttps(customGitUrl)) {

View File

@@ -130,6 +130,7 @@ interface CloneGiteaRepository {
enableSubmodules: boolean;
serverId: string | null;
type?: "application" | "compose";
outputPathOverride?: string;
}
export const cloneGiteaRepository = async ({
@@ -145,6 +146,7 @@ export const cloneGiteaRepository = async ({
giteaRepository,
enableSubmodules,
serverId,
outputPathOverride,
} = entity;
const { APPLICATIONS_PATH, COMPOSE_PATH } = paths(!!serverId);
@@ -162,7 +164,7 @@ export const cloneGiteaRepository = async ({
}
const basePath = type === "compose" ? COMPOSE_PATH : APPLICATIONS_PATH;
const outputPath = join(basePath, appName, "code");
const outputPath = outputPathOverride ?? join(basePath, appName, "code");
command += `rm -rf ${outputPath};`;
command += `mkdir -p ${outputPath};`;

View File

@@ -121,6 +121,7 @@ interface CloneGithubRepository {
type?: "application" | "compose";
enableSubmodules: boolean;
serverId: string | null;
outputPathOverride?: string;
}
export const cloneGithubRepository = async ({
type = "application",
@@ -136,6 +137,7 @@ export const cloneGithubRepository = async ({
githubId,
enableSubmodules,
serverId,
outputPathOverride,
} = entity;
const { APPLICATIONS_PATH, COMPOSE_PATH } = paths(!!serverId);
@@ -155,7 +157,7 @@ export const cloneGithubRepository = async ({
const githubProvider = await findGithubById(githubId);
const basePath = isCompose ? COMPOSE_PATH : APPLICATIONS_PATH;
const outputPath = join(basePath, appName, "code");
const outputPath = outputPathOverride ?? join(basePath, appName, "code");
const octokit = authGithub(githubProvider);
const token = await getGithubToken(octokit);
const repoclone = `github.com/${owner}/${repository}.git`;

View File

@@ -107,6 +107,7 @@ interface CloneGitlabRepository {
enableSubmodules: boolean;
serverId: string | null;
type?: "application" | "compose";
outputPathOverride?: string;
}
export const cloneGitlabRepository = async ({
@@ -121,6 +122,7 @@ export const cloneGitlabRepository = async ({
gitlabPathNamespace,
enableSubmodules,
serverId,
outputPathOverride,
} = entity;
const { COMPOSE_PATH, APPLICATIONS_PATH } = paths(!!serverId);
@@ -141,7 +143,7 @@ export const cloneGitlabRepository = async ({
}
const basePath = type === "compose" ? COMPOSE_PATH : APPLICATIONS_PATH;
const outputPath = join(basePath, appName, "code");
const outputPath = outputPathOverride ?? join(basePath, appName, "code");
command += `rm -rf ${outputPath};`;
command += `mkdir -p ${outputPath};`;
const repoClone = getGitlabRepoClone(gitlab, gitlabPathNamespace);