From 4cf4a3b4b1b2ad68e90c2ec18ce2b2940707f0f9 Mon Sep 17 00:00:00 2001 From: shivam-bit Date: Fri, 4 Oct 2024 19:29:56 +0530 Subject: [PATCH 1/2] Refactor GitLab validity check to include custom domain support --- .../content/Dashboards/ConfigureGitlabModalBody.tsx | 2 +- web-server/src/utils/auth.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/web-server/src/content/Dashboards/ConfigureGitlabModalBody.tsx b/web-server/src/content/Dashboards/ConfigureGitlabModalBody.tsx index 20cdde2b..2868a148 100644 --- a/web-server/src/content/Dashboards/ConfigureGitlabModalBody.tsx +++ b/web-server/src/content/Dashboards/ConfigureGitlabModalBody.tsx @@ -79,7 +79,7 @@ export const ConfigureGitlabModalBody: FC<{ } depFn(isLoading.true); - await checkGitLabValidity(token.value) + await checkGitLabValidity(token.value, customDomain.value) .then(async (res) => { return res; }) diff --git a/web-server/src/utils/auth.ts b/web-server/src/utils/auth.ts index a3f97507..db3fb5d4 100644 --- a/web-server/src/utils/auth.ts +++ b/web-server/src/utils/auth.ts @@ -63,8 +63,14 @@ export const getMissingPATScopes = async (pat: string) => { // Gitlab functions -export const checkGitLabValidity = async (accessToken: string) => { - const url = 'https://gitlab.com/api/v4/personal_access_tokens/self'; +export const checkGitLabValidity = async ( + accessToken: string, + customDomain?: string +) => { + const baseUrl = customDomain + ? `https://${customDomain}` + : 'https://gitlab.com'; + const url = `${baseUrl}/api/v4/personal_access_tokens/self`; try { const response = await axios.get(url, { headers: { From 6c83ce519cf1810d53dadef965fba9dd9ab710c2 Mon Sep 17 00:00:00 2001 From: shivam-bit Date: Fri, 4 Oct 2024 19:34:28 +0530 Subject: [PATCH 2/2] Refactor GitLab validity check to include custom domain support --- .../src/content/Dashboards/ConfigureGitlabModalBody.tsx | 3 +-- web-server/src/utils/auth.ts | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/web-server/src/content/Dashboards/ConfigureGitlabModalBody.tsx b/web-server/src/content/Dashboards/ConfigureGitlabModalBody.tsx index 2868a148..6aef9ff5 100644 --- a/web-server/src/content/Dashboards/ConfigureGitlabModalBody.tsx +++ b/web-server/src/content/Dashboards/ConfigureGitlabModalBody.tsx @@ -48,10 +48,9 @@ export const ConfigureGitlabModalBody: FC<{ const checkDomainWithRegex = (domain: string) => { const regex = - /^(https:\/\/)?[a-zA-Z0-9]+([-.][a-zA-Z0-9]+)*\.[a-zA-Z]{2,}(:[0-9]{1,5})?(\/.*)?$/; + /^(https?:\/\/)[a-zA-Z0-9]+([-.][a-zA-Z0-9]+)*\.[a-zA-Z]{2,}(:[0-9]{1,5})?(\/.*)?$/; return regex.test(domain); }; - const handleTokenChange = (e: string) => { token.set(e); showScopeError.set(''); diff --git a/web-server/src/utils/auth.ts b/web-server/src/utils/auth.ts index db3fb5d4..991e78a8 100644 --- a/web-server/src/utils/auth.ts +++ b/web-server/src/utils/auth.ts @@ -67,9 +67,7 @@ export const checkGitLabValidity = async ( accessToken: string, customDomain?: string ) => { - const baseUrl = customDomain - ? `https://${customDomain}` - : 'https://gitlab.com'; + const baseUrl = customDomain || 'https://gitlab.com'; const url = `${baseUrl}/api/v4/personal_access_tokens/self`; try { const response = await axios.get(url, {