From 085f6bbbb796d88eb9056de3cf938ccf56953315 Mon Sep 17 00:00:00 2001 From: montero Date: Fri, 26 Sep 2025 22:01:54 +0300 Subject: [PATCH 1/2] refactor(gitea): extract clone URL construction into a reusable function --- packages/server/src/utils/providers/gitea.ts | 34 ++++++++++++-------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/packages/server/src/utils/providers/gitea.ts b/packages/server/src/utils/providers/gitea.ts index 874e2679e..c64d0472a 100644 --- a/packages/server/src/utils/providers/gitea.ts +++ b/packages/server/src/utils/providers/gitea.ts @@ -99,6 +99,19 @@ export const refreshGiteaToken = async (giteaProviderId: string) => { } }; +const buildGiteaCloneUrl = ( + giteaUrl: string, + accessToken: string, + owner: string, + repository: string +) => { + const protocol = giteaUrl.startsWith("http://") ? "http" : "https"; + const baseUrl = giteaUrl.replace(/^https?:\/\//, ""); + const repoClone = `${owner}/${repository}.git`; + const cloneUrl = `${protocol}://oauth2:${accessToken}@${baseUrl}/${repoClone}`; + return cloneUrl; +}; + export type ApplicationWithGitea = InferResultType< "applications", { gitea: true } @@ -148,9 +161,8 @@ export const getGiteaCloneCommand = async ( const basePath = isCompose ? COMPOSE_PATH : APPLICATIONS_PATH; const outputPath = join(basePath, appName, "code"); - const baseUrl = gitea?.giteaUrl.replace(/^https?:\/\//, ""); - const repoClone = `${giteaOwner}/${giteaRepository}.git`; - const cloneUrl = `https://oauth2:${gitea?.accessToken}@${baseUrl}/${repoClone}`; + const repoClone = `${giteaOwner}/${giteaRepository}.git`; + const cloneUrl = buildGiteaCloneUrl(gitea?.giteaUrl!, gitea?.accessToken!, giteaOwner!, giteaRepository!); const cloneCommand = ` rm -rf ${outputPath}; @@ -204,9 +216,8 @@ export const cloneGiteaRepository = async ( const outputPath = join(basePath, appName, "code"); await recreateDirectory(outputPath); - const repoClone = `${giteaOwner}/${giteaRepository}.git`; - const baseUrl = giteaProvider.giteaUrl.replace(/^https?:\/\//, ""); - const cloneUrl = `https://oauth2:${giteaProvider.accessToken}@${baseUrl}/${repoClone}`; + const repoClone = `${giteaOwner}/${giteaRepository}.git`; + const cloneUrl = buildGiteaCloneUrl(giteaProvider.giteaUrl, giteaProvider.accessToken!, giteaOwner!, giteaRepository!); writeStream.write(`\nCloning Repo ${repoClone} to ${outputPath}...\n`); @@ -269,9 +280,7 @@ export const cloneRawGiteaRepository = async (entity: Compose) => { const outputPath = join(basePath, appName, "code"); await recreateDirectory(outputPath); - const repoClone = `${giteaOwner}/${giteaRepository}.git`; - const baseUrl = giteaProvider.giteaUrl.replace(/^https?:\/\//, ""); - const cloneUrl = `https://oauth2:${giteaProvider.accessToken}@${baseUrl}/${repoClone}`; + const cloneUrl = buildGiteaCloneUrl(giteaProvider.giteaUrl, giteaProvider.accessToken!, giteaOwner!, giteaRepository!); try { await spawnAsync("git", [ @@ -317,10 +326,9 @@ export const cloneRawGiteaRepositoryRemote = async (compose: Compose) => { const giteaProvider = await findGiteaById(giteaId); const basePath = COMPOSE_PATH; const outputPath = join(basePath, appName, "code"); - const repoClone = `${giteaOwner}/${giteaRepository}.git`; - const baseUrl = giteaProvider.giteaUrl.replace(/^https?:\/\//, ""); - const cloneUrl = `https://oauth2:${giteaProvider.accessToken}@${baseUrl}/${repoClone}`; - try { + const cloneUrl = buildGiteaCloneUrl(giteaProvider.giteaUrl, giteaProvider.accessToken!, giteaOwner!, giteaRepository!); + + try { const command = ` rm -rf ${outputPath}; git clone --branch ${giteaBranch} --depth 1 ${enableSubmodules ? "--recurse-submodules" : ""} ${cloneUrl} ${outputPath} From 845d2a3ac56be9ef78d13fa29564d55f5b62d3e3 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Sat, 27 Sep 2025 09:15:31 +0000 Subject: [PATCH 2/2] [autofix.ci] apply automated fixes --- packages/server/src/utils/providers/gitea.ts | 52 ++++++++++++++------ 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/packages/server/src/utils/providers/gitea.ts b/packages/server/src/utils/providers/gitea.ts index c64d0472a..db6dcbb78 100644 --- a/packages/server/src/utils/providers/gitea.ts +++ b/packages/server/src/utils/providers/gitea.ts @@ -100,16 +100,16 @@ export const refreshGiteaToken = async (giteaProviderId: string) => { }; const buildGiteaCloneUrl = ( - giteaUrl: string, - accessToken: string, - owner: string, - repository: string + giteaUrl: string, + accessToken: string, + owner: string, + repository: string, ) => { - const protocol = giteaUrl.startsWith("http://") ? "http" : "https"; - const baseUrl = giteaUrl.replace(/^https?:\/\//, ""); - const repoClone = `${owner}/${repository}.git`; - const cloneUrl = `${protocol}://oauth2:${accessToken}@${baseUrl}/${repoClone}`; - return cloneUrl; + const protocol = giteaUrl.startsWith("http://") ? "http" : "https"; + const baseUrl = giteaUrl.replace(/^https?:\/\//, ""); + const repoClone = `${owner}/${repository}.git`; + const cloneUrl = `${protocol}://oauth2:${accessToken}@${baseUrl}/${repoClone}`; + return cloneUrl; }; export type ApplicationWithGitea = InferResultType< @@ -161,8 +161,13 @@ export const getGiteaCloneCommand = async ( const basePath = isCompose ? COMPOSE_PATH : APPLICATIONS_PATH; const outputPath = join(basePath, appName, "code"); - const repoClone = `${giteaOwner}/${giteaRepository}.git`; - const cloneUrl = buildGiteaCloneUrl(gitea?.giteaUrl!, gitea?.accessToken!, giteaOwner!, giteaRepository!); + const repoClone = `${giteaOwner}/${giteaRepository}.git`; + const cloneUrl = buildGiteaCloneUrl( + gitea?.giteaUrl!, + gitea?.accessToken!, + giteaOwner!, + giteaRepository!, + ); const cloneCommand = ` rm -rf ${outputPath}; @@ -216,8 +221,13 @@ export const cloneGiteaRepository = async ( const outputPath = join(basePath, appName, "code"); await recreateDirectory(outputPath); - const repoClone = `${giteaOwner}/${giteaRepository}.git`; - const cloneUrl = buildGiteaCloneUrl(giteaProvider.giteaUrl, giteaProvider.accessToken!, giteaOwner!, giteaRepository!); + const repoClone = `${giteaOwner}/${giteaRepository}.git`; + const cloneUrl = buildGiteaCloneUrl( + giteaProvider.giteaUrl, + giteaProvider.accessToken!, + giteaOwner!, + giteaRepository!, + ); writeStream.write(`\nCloning Repo ${repoClone} to ${outputPath}...\n`); @@ -280,7 +290,12 @@ export const cloneRawGiteaRepository = async (entity: Compose) => { const outputPath = join(basePath, appName, "code"); await recreateDirectory(outputPath); - const cloneUrl = buildGiteaCloneUrl(giteaProvider.giteaUrl, giteaProvider.accessToken!, giteaOwner!, giteaRepository!); + const cloneUrl = buildGiteaCloneUrl( + giteaProvider.giteaUrl, + giteaProvider.accessToken!, + giteaOwner!, + giteaRepository!, + ); try { await spawnAsync("git", [ @@ -326,9 +341,14 @@ export const cloneRawGiteaRepositoryRemote = async (compose: Compose) => { const giteaProvider = await findGiteaById(giteaId); const basePath = COMPOSE_PATH; const outputPath = join(basePath, appName, "code"); - const cloneUrl = buildGiteaCloneUrl(giteaProvider.giteaUrl, giteaProvider.accessToken!, giteaOwner!, giteaRepository!); + const cloneUrl = buildGiteaCloneUrl( + giteaProvider.giteaUrl, + giteaProvider.accessToken!, + giteaOwner!, + giteaRepository!, + ); - try { + try { const command = ` rm -rf ${outputPath}; git clone --branch ${giteaBranch} --depth 1 ${enableSubmodules ? "--recurse-submodules" : ""} ${cloneUrl} ${outputPath}