From 22e6d07f60f1de98642f69a222b652049e21a4c9 Mon Sep 17 00:00:00 2001 From: djknaeckebrot Date: Tue, 10 Dec 2024 08:37:55 +0100 Subject: [PATCH 1/5] fix: hardcoded gitlab.com to gitlabUrl --- apps/dokploy/pages/api/providers/gitlab/callback.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/dokploy/pages/api/providers/gitlab/callback.ts b/apps/dokploy/pages/api/providers/gitlab/callback.ts index 8de9b7fa..547de357 100644 --- a/apps/dokploy/pages/api/providers/gitlab/callback.ts +++ b/apps/dokploy/pages/api/providers/gitlab/callback.ts @@ -7,13 +7,15 @@ export default async function handler( ) { const { code, gitlabId } = req.query; + console.log("DEBUG: res.query: ", res); + if (!code || Array.isArray(code)) { return res.status(400).json({ error: "Missing or invalid code" }); } const gitlab = await findGitlabById(gitlabId as string); - const response = await fetch("https://gitlab.com/oauth/token", { + const response = await fetch(`${gitlab.gitlabUrl}/oauth/token`, { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded", From 7ced6840fa2b5f38f5fded6354a31d34e22aa96a Mon Sep 17 00:00:00 2001 From: djknaeckebrot Date: Tue, 10 Dec 2024 08:53:53 +0100 Subject: [PATCH 2/5] fix: change hardcoded gitlab.com to gitlabUrl --- apps/dokploy/server/api/routers/gitlab.ts | 1 + packages/server/src/utils/providers/gitlab.ts | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/dokploy/server/api/routers/gitlab.ts b/apps/dokploy/server/api/routers/gitlab.ts index c057061f..6b96b647 100644 --- a/apps/dokploy/server/api/routers/gitlab.ts +++ b/apps/dokploy/server/api/routers/gitlab.ts @@ -78,6 +78,7 @@ export const gitlabRouter = createTRPCRouter({ .input(apiFindOneGitlab) .query(async ({ input, ctx }) => { const gitlabProvider = await findGitlabById(input.gitlabId); + console.log("DEBUG: gitlabProvider: ", gitlabProvider); if (IS_CLOUD && gitlabProvider.gitProvider.adminId !== ctx.user.adminId) { //TODO: Remove this line when the cloud version is ready throw new TRPCError({ diff --git a/packages/server/src/utils/providers/gitlab.ts b/packages/server/src/utils/providers/gitlab.ts index b99e64e3..504ff841 100644 --- a/packages/server/src/utils/providers/gitlab.ts +++ b/packages/server/src/utils/providers/gitlab.ts @@ -244,7 +244,7 @@ export const getGitlabRepositories = async (gitlabId?: string) => { const gitlabProvider = await findGitlabById(gitlabId); const response = await fetch( - `https://gitlab.com/api/v4/projects?membership=true&owned=true&page=${0}&per_page=${100}`, + `${gitlabProvider.gitlabUrl}/api/v4/projects?membership=true&owned=true&page=${0}&per_page=${100}`, { headers: { Authorization: `Bearer ${gitlabProvider.accessToken}`, @@ -304,7 +304,7 @@ export const getGitlabBranches = async (input: { const gitlabProvider = await findGitlabById(input.gitlabId); const branchesResponse = await fetch( - `https://gitlab.com/api/v4/projects/${input.id}/repository/branches`, + `${gitlabProvider.gitlabUrl}/api/v4/projects/${input.id}/repository/branches`, { headers: { Authorization: `Bearer ${gitlabProvider.accessToken}`, @@ -352,7 +352,7 @@ export const cloneRawGitlabRepository = async (entity: Compose) => { await recreateDirectory(outputPath); const gitlabUrl = gitlabProvider.gitlabUrl; // What happen with oauth in self hosted instances? - const repoclone = `gitlab.com/${gitlabPathNamespace}.git`; + const repoclone = `${gitlabProvider.gitlabUrl}/${gitlabPathNamespace}.git`; const cloneUrl = `https://oauth2:${gitlabProvider?.accessToken}@${repoclone}`; try { @@ -392,7 +392,7 @@ export const cloneRawGitlabRepositoryRemote = async (compose: Compose) => { await refreshGitlabToken(gitlabId); const basePath = COMPOSE_PATH; const outputPath = join(basePath, appName, "code"); - const repoclone = `gitlab.com/${gitlabPathNamespace}.git`; + const repoclone = `${gitlabProvider.gitlabUrl}/${gitlabPathNamespace}.git`; const cloneUrl = `https://oauth2:${gitlabProvider?.accessToken}@${repoclone}`; try { const command = ` From 0698ac831884354942049719a64736cd0eceef6d Mon Sep 17 00:00:00 2001 From: djknaeckebrot Date: Tue, 10 Dec 2024 08:54:22 +0100 Subject: [PATCH 3/5] chore: remove debug output --- apps/dokploy/server/api/routers/gitlab.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/dokploy/server/api/routers/gitlab.ts b/apps/dokploy/server/api/routers/gitlab.ts index 6b96b647..c057061f 100644 --- a/apps/dokploy/server/api/routers/gitlab.ts +++ b/apps/dokploy/server/api/routers/gitlab.ts @@ -78,7 +78,6 @@ export const gitlabRouter = createTRPCRouter({ .input(apiFindOneGitlab) .query(async ({ input, ctx }) => { const gitlabProvider = await findGitlabById(input.gitlabId); - console.log("DEBUG: gitlabProvider: ", gitlabProvider); if (IS_CLOUD && gitlabProvider.gitProvider.adminId !== ctx.user.adminId) { //TODO: Remove this line when the cloud version is ready throw new TRPCError({ From 1cb1da8097716eb81bbc6ae3118e932963316cd1 Mon Sep 17 00:00:00 2001 From: djknaeckebrot Date: Tue, 10 Dec 2024 09:19:01 +0100 Subject: [PATCH 4/5] fix: replace hardcoded gitlab.com with dynamic urls --- packages/server/src/utils/providers/gitlab.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/server/src/utils/providers/gitlab.ts b/packages/server/src/utils/providers/gitlab.ts index 504ff841..096f9e28 100644 --- a/packages/server/src/utils/providers/gitlab.ts +++ b/packages/server/src/utils/providers/gitlab.ts @@ -26,7 +26,7 @@ export const refreshGitlabToken = async (gitlabProviderId: string) => { return; } - const response = await fetch("https://gitlab.com/oauth/token", { + const response = await fetch(`${gitlabProvider.gitlabUrl}/oauth/token`, { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded", @@ -122,7 +122,7 @@ export const cloneGitlabRepository = async ( const basePath = isCompose ? COMPOSE_PATH : APPLICATIONS_PATH; const outputPath = join(basePath, appName, "code"); await recreateDirectory(outputPath); - const repoclone = `gitlab.com/${gitlabPathNamespace}.git`; + const repoclone = `${gitlab?.gitlabUrl.replace(/^https?:\/\//, "")}/${gitlabPathNamespace}.git`; const cloneUrl = `https://oauth2:${gitlab?.accessToken}@${repoclone}`; try { @@ -218,7 +218,7 @@ export const getGitlabCloneCommand = async ( const basePath = isCompose ? COMPOSE_PATH : APPLICATIONS_PATH; const outputPath = join(basePath, appName, "code"); await recreateDirectory(outputPath); - const repoclone = `gitlab.com/${gitlabPathNamespace}.git`; + const repoclone = `${gitlab?.gitlabUrl.replace(/^https?:\/\//, "")}/${gitlabPathNamespace}.git`; const cloneUrl = `https://oauth2:${gitlab?.accessToken}@${repoclone}`; const cloneCommand = ` @@ -352,7 +352,7 @@ export const cloneRawGitlabRepository = async (entity: Compose) => { await recreateDirectory(outputPath); const gitlabUrl = gitlabProvider.gitlabUrl; // What happen with oauth in self hosted instances? - const repoclone = `${gitlabProvider.gitlabUrl}/${gitlabPathNamespace}.git`; + const repoclone = `${gitlabUrl.replace(/^https?:\/\//, "")}/${gitlabPathNamespace}.git`; const cloneUrl = `https://oauth2:${gitlabProvider?.accessToken}@${repoclone}`; try { @@ -392,7 +392,7 @@ export const cloneRawGitlabRepositoryRemote = async (compose: Compose) => { await refreshGitlabToken(gitlabId); const basePath = COMPOSE_PATH; const outputPath = join(basePath, appName, "code"); - const repoclone = `${gitlabProvider.gitlabUrl}/${gitlabPathNamespace}.git`; + const repoclone = `${gitlabProvider.gitlabUrl.replace(/^https?:\/\//, "")}/${gitlabPathNamespace}.git`; const cloneUrl = `https://oauth2:${gitlabProvider?.accessToken}@${repoclone}`; try { const command = ` From 2c22aa3689854676bfc1a2ed234695cc82171145 Mon Sep 17 00:00:00 2001 From: djknaeckebrot Date: Tue, 10 Dec 2024 10:25:48 +0100 Subject: [PATCH 5/5] chore: remove debug logs --- apps/dokploy/pages/api/providers/gitlab/callback.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/dokploy/pages/api/providers/gitlab/callback.ts b/apps/dokploy/pages/api/providers/gitlab/callback.ts index 547de357..e32e0a7a 100644 --- a/apps/dokploy/pages/api/providers/gitlab/callback.ts +++ b/apps/dokploy/pages/api/providers/gitlab/callback.ts @@ -7,8 +7,6 @@ export default async function handler( ) { const { code, gitlabId } = req.query; - console.log("DEBUG: res.query: ", res); - if (!code || Array.isArray(code)) { return res.status(400).json({ error: "Missing or invalid code" }); }