From 978c4d85c5b8f29d6ed58ef7ea715189528e687c Mon Sep 17 00:00:00 2001 From: croatialu Date: Fri, 11 Jul 2025 12:39:14 +0800 Subject: [PATCH 1/2] fix(gitlab): Support dynamically generating clone URLs based on protocols --- packages/server/src/utils/providers/gitlab.ts | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/packages/server/src/utils/providers/gitlab.ts b/packages/server/src/utils/providers/gitlab.ts index 7f14e008a..8fa480ba9 100644 --- a/packages/server/src/utils/providers/gitlab.ts +++ b/packages/server/src/utils/providers/gitlab.ts @@ -84,6 +84,20 @@ export type ApplicationWithGitlab = InferResultType< export type ComposeWithGitlab = InferResultType<"compose", { gitlab: true }>; +export type GitlabInfo = ApplicationWithGitlab['gitlab'] | ComposeWithGitlab['gitlab']; + +const getGitlabRepoClone = (gitlab: GitlabInfo, gitlabPathNamespace: string | null) => { + const repoClone = `${gitlab?.gitlabUrl.replace(/^https?:\/\//, "")}/${gitlabPathNamespace}.git`; + return repoClone; +}; + +const getGitlabCloneUrl = (gitlab: GitlabInfo, repoClone: string) => { + const isSecure = gitlab?.gitlabUrl.startsWith("https://"); + const cloneUrl = `http${isSecure ? "s" : ""}://oauth2:${gitlab?.accessToken}@${repoClone}`; + return cloneUrl; +}; + + export const cloneGitlabRepository = async ( entity: ApplicationWithGitlab | ComposeWithGitlab, logPath: string, @@ -128,11 +142,10 @@ export const cloneGitlabRepository = async ( const basePath = isCompose ? COMPOSE_PATH : APPLICATIONS_PATH; const outputPath = join(basePath, appName, "code"); await recreateDirectory(outputPath); - const repoclone = `${gitlab?.gitlabUrl.replace(/^https?:\/\//, "")}/${gitlabPathNamespace}.git`; - const cloneUrl = `https://oauth2:${gitlab?.accessToken}@${repoclone}`; - + const repoClone = getGitlabRepoClone(gitlab, gitlabPathNamespace); + const cloneUrl = getGitlabCloneUrl(gitlab, repoClone); try { - writeStream.write(`\nCloning Repo ${repoclone} to ${outputPath}: ✅\n`); + writeStream.write(`\nCloning Repo ${repoClone} to ${outputPath}: ✅\n`); const cloneArgs = [ "clone", "--branch", @@ -150,7 +163,7 @@ export const cloneGitlabRepository = async ( writeStream.write(data); } }); - writeStream.write(`\nCloned ${repoclone}: ✅\n`); + writeStream.write(`\nCloned ${repoClone}: ✅\n`); } catch (error) { writeStream.write(`ERROR Cloning: ${error}: ❌`); throw error; @@ -221,17 +234,16 @@ export const getGitlabCloneCommand = async ( const basePath = isCompose ? COMPOSE_PATH : APPLICATIONS_PATH; const outputPath = join(basePath, appName, "code"); await recreateDirectory(outputPath); - const repoclone = `${gitlab?.gitlabUrl.replace(/^https?:\/\//, "")}/${gitlabPathNamespace}.git`; - const cloneUrl = `https://oauth2:${gitlab?.accessToken}@${repoclone}`; - + const repoClone = getGitlabRepoClone(gitlab, gitlabPathNamespace); + const cloneUrl = getGitlabCloneUrl(gitlab, repoClone); const cloneCommand = ` rm -rf ${outputPath}; mkdir -p ${outputPath}; if ! git clone --branch ${gitlabBranch} --depth 1 ${enableSubmodules ? "--recurse-submodules" : ""} --progress ${cloneUrl} ${outputPath} >> ${logPath} 2>&1; then - echo "❌ [ERROR] Fail to clone the repository ${repoclone}" >> ${logPath}; + echo "❌ [ERROR] Fail to clone the repository ${repoClone}" >> ${logPath}; exit 1; fi -echo "Cloned ${repoclone} to ${outputPath}: ✅" >> ${logPath}; +echo "Cloned ${repoClone} to ${outputPath}: ✅" >> ${logPath}; `; return cloneCommand; @@ -340,11 +352,8 @@ export const cloneRawGitlabRepository = async (entity: Compose) => { const basePath = COMPOSE_PATH; const outputPath = join(basePath, appName, "code"); await recreateDirectory(outputPath); - const gitlabUrl = gitlabProvider.gitlabUrl; - // What happen with oauth in self hosted instances? - const repoclone = `${gitlabUrl.replace(/^https?:\/\//, "")}/${gitlabPathNamespace}.git`; - const cloneUrl = `https://oauth2:${gitlabProvider?.accessToken}@${repoclone}`; - + const repoClone = getGitlabRepoClone(gitlabProvider, gitlabPathNamespace); + const cloneUrl = getGitlabCloneUrl(gitlabProvider, repoClone); try { const cloneArgs = [ "clone", @@ -390,8 +399,8 @@ export const cloneRawGitlabRepositoryRemote = async (compose: Compose) => { await refreshGitlabToken(gitlabId); const basePath = COMPOSE_PATH; const outputPath = join(basePath, appName, "code"); - const repoclone = `${gitlabProvider.gitlabUrl.replace(/^https?:\/\//, "")}/${gitlabPathNamespace}.git`; - const cloneUrl = `https://oauth2:${gitlabProvider?.accessToken}@${repoclone}`; + const repoClone = getGitlabRepoClone(gitlabProvider, gitlabPathNamespace); + const cloneUrl = getGitlabCloneUrl(gitlabProvider, repoClone); try { const command = ` rm -rf ${outputPath}; From 691c83c256bfc6b7af39a89b8fa2d7e0990aef43 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Sun, 13 Jul 2025 17:54:36 +0000 Subject: [PATCH 2/2] [autofix.ci] apply automated fixes --- packages/server/src/utils/providers/gitlab.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/server/src/utils/providers/gitlab.ts b/packages/server/src/utils/providers/gitlab.ts index 8fa480ba9..369951699 100644 --- a/packages/server/src/utils/providers/gitlab.ts +++ b/packages/server/src/utils/providers/gitlab.ts @@ -84,9 +84,14 @@ export type ApplicationWithGitlab = InferResultType< export type ComposeWithGitlab = InferResultType<"compose", { gitlab: true }>; -export type GitlabInfo = ApplicationWithGitlab['gitlab'] | ComposeWithGitlab['gitlab']; +export type GitlabInfo = + | ApplicationWithGitlab["gitlab"] + | ComposeWithGitlab["gitlab"]; -const getGitlabRepoClone = (gitlab: GitlabInfo, gitlabPathNamespace: string | null) => { +const getGitlabRepoClone = ( + gitlab: GitlabInfo, + gitlabPathNamespace: string | null, +) => { const repoClone = `${gitlab?.gitlabUrl.replace(/^https?:\/\//, "")}/${gitlabPathNamespace}.git`; return repoClone; }; @@ -96,7 +101,6 @@ const getGitlabCloneUrl = (gitlab: GitlabInfo, repoClone: string) => { const cloneUrl = `http${isSecure ? "s" : ""}://oauth2:${gitlab?.accessToken}@${repoClone}`; return cloneUrl; }; - export const cloneGitlabRepository = async ( entity: ApplicationWithGitlab | ComposeWithGitlab,